How-to for Plugin Developers with Code Examples | Page 2

Discussion in 'MediaPortal 1 Plugins' started by Edalex, October 21, 2014.

?

Was it useful?

  1. Yes

    100.0%
  2. No

    0 vote(s)
    0.0%
  1. Edalex
    • Premium Supporter

    Edalex Community Plugin Dev

    Joined:
    January 3, 2008
    Messages:
    2,904
    Likes Received:
    710
    Gender:
    Male
    Location:
    Saratov
    Ratings:
    +1,225 / 9
    Home Country:
    Russian Federation Russian Federation
    Show System Specs
    Thanks guys but we need MOAR samples! :D
    It will be awesome to get some tips from such well-known plugin developers as @ltfearme @seco @fforde :)


     
    • Thank You! Thank You! x 1
    • Great Idea! Great Idea! x 1
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. regeszter
    • Premium Supporter

    regeszter Retired Team Member

    Joined:
    October 29, 2005
    Messages:
    5,335
    Likes Received:
    2,863
    Ratings:
    +5,152 / 18
    Home Country:
    Hungary Hungary
    Using Wake On Lan in plugins.

    Extract the server IP from the UNC path ("\\server\share") and store the MAC address in MediaPortal.xml
    Use it in configure.exe or setting screen of your plugin.

    Code (C):
    1.     private void SaveMAC(string uncPath)
    2.     {
    3.       String macAddress;
    4.       byte[] hwAddress;
    5.  
    6.       WakeOnLanManager wakeOnLanManager = new WakeOnLanManager();
    7.  
    8.       IPAddress ipAddress = null;
    9.       string hostName = Util.Utils.GetServerNameFromUNCPath(uncPath);
    10.  
    11.       using (Profile.Settings xmlreader = new MPSettings())
    12.       {
    13.         macAddress = xmlreader.GetValueAsString("macAddress", hostName, null);
    14.       }
    15.  
    16.       if (wakeOnLanManager.Ping(hostName, 100) && !string.IsNullOrEmpty(macAddress))
    17.       {
    18.         Log.Debug("WakeUpServer: The {0} server already started and mac address is learnt!", hostName);
    19.         return;
    20.       }
    21.  
    22.       // Check if we already have a valid IP address stored,
    23.       // otherwise try to resolve the IP address
    24.       if (!IPAddress.TryParse(hostName, out ipAddress))
    25.       {
    26.         // Get IP address of the server
    27.         try
    28.         {
    29.           IPAddress[] ips;
    30.  
    31.           ips = Dns.GetHostAddresses(hostName);
    32.  
    33.           Log.Debug("WakeUpServer: WOL - GetHostAddresses({0}) returns:", hostName);
    34.  
    35.           foreach (IPAddress ip in ips)
    36.           {
    37.             Log.Debug("    {0}", ip);
    38.  
    39.             ipAddress = ip;
    40.             // Check for valid IP address
    41.             if (ipAddress != null)
    42.             {
    43.               // Update the MAC address if possible
    44.               hwAddress = wakeOnLanManager.GetHardwareAddress(ipAddress);
    45.  
    46.               if (wakeOnLanManager.IsValidEthernetAddress(hwAddress))
    47.               {
    48.                 Log.Debug("WakeUpServer: WOL - Valid auto MAC address: {0:x}:{1:x}:{2:x}:{3:x}:{4:x}:{5:x}"
    49.                   , hwAddress[0], hwAddress[1], hwAddress[2], hwAddress[3], hwAddress[4], hwAddress[5]);
    50.  
    51.                 // Store MAC address
    52.                 macAddress = BitConverter.ToString(hwAddress).Replace("-", ":");
    53.  
    54.                 Log.Debug("WakeUpServer: WOL - Store MAC address: {0}", macAddress);
    55.  
    56.                 using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.MPSettings())
    57.                 {
    58.                   xmlwriter.SetValue("macAddress", hostName, macAddress);
    59.                 }
    60.               }
    61.               else
    62.               {
    63.                 Log.Debug("WakeUpServer: WOL - Not a valid IPv4 address: {0}", ipAddress);
    64.               }
    65.             }
    66.           }
    67.         }
    68.         catch (Exception ex)
    69.         {
    70.           Log.Error("WakeUpServer: WOL - Failed GetHostAddress - {0}", ex.Message);
    71.         }
    72.       }
    73.     }

    Wake up the server before read the files from the share.

    Code (C):
    1. serverName = Util.Utils.GetServerNameFromUNCPath(uncPath);
    2. WakeupUtils.HandleWakeUpServer(serverName, wolTimeout);
     
    • Like Like x 3
    • Thank You! Thank You! x 1
  4. Dadeo
    • Premium Supporter

    Dadeo Docs Group Manager

    Joined:
    November 26, 2006
    Messages:
    5,340
    Likes Received:
    2,802
    Location:
    Himalayas, India
    Ratings:
    +3,053 / 0
    Home Country:
    Canada Canada
    Show System Specs
    Fantastic guys - I've been wanting/trying to get this type of info added to plugin devs guide for years - so you are making me very happy :D
    @SpudR - I really like the 'FAQ' style format (y) I'm just wondering why you put it under MP1 Development instead of MP1 Plugin Development?
    I suggest we move the whole section to http://wiki.team-mediaportal.com/1_MEDIAPORTAL_1/18_Contribute/6_Plugins or even http://wiki.team-mediaportal.com/1_MEDIAPORTAL_1/18_Contribute/6_Plugins/Plugin_Developer's_Guide
    any objections?
     
    • Like Like x 2
  5. Edalex
    • Premium Supporter

    Edalex Community Plugin Dev

    Joined:
    January 3, 2008
    Messages:
    2,904
    Likes Received:
    710
    Gender:
    Male
    Location:
    Saratov
    Ratings:
    +1,225 / 9
    Home Country:
    Russian Federation Russian Federation
    Show System Specs
    And some of "old" tips and trocks could be copied to dialogs overviews in wiki
     
    • Like Like x 1
  6. SpudR
    • Team MediaPortal

    SpudR Documentation Group

    Joined:
    July 27, 2007
    Messages:
    2,606
    Likes Received:
    449
    Occupation:
    CTO, MD
    Location:
    Yorkshire, UK
    Ratings:
    +676 / 2
    Home Country:
    England England
    Show System Specs
    Last edited: October 24, 2014
    • Thank You! Thank You! x 1
  7. SpudR
    • Team MediaPortal

    SpudR Documentation Group

    Joined:
    July 27, 2007
    Messages:
    2,606
    Likes Received:
    449
    Occupation:
    CTO, MD
    Location:
    Yorkshire, UK
    Ratings:
    +676 / 2
    Home Country:
    England England
    Show System Specs
    I've moved the section as per my bosses orders and added all the 'Tips and Tricks' to the same format too.
    Not confident enough to delete the old tricks and tips page though!
     
  8. Edalex
    • Premium Supporter

    Edalex Community Plugin Dev

    Joined:
    January 3, 2008
    Messages:
    2,904
    Likes Received:
    710
    Gender:
    Male
    Location:
    Saratov
    Ratings:
    +1,225 / 9
    Home Country:
    Russian Federation Russian Federation
    Show System Specs
    Old tips and tricks are fully working! One little change is that untested trick from Frodo is fully working too ;)
     
  9. SpudR
    • Team MediaPortal

    SpudR Documentation Group

    Joined:
    July 27, 2007
    Messages:
    2,606
    Likes Received:
    449
    Occupation:
    CTO, MD
    Location:
    Yorkshire, UK
    Ratings:
    +676 / 2
    Home Country:
    England England
    Show System Specs
    Fixed :)
     
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!