How-to for Plugin Developers with Code Examples (1 Viewer)

Was it useful?


  • Total voters
    11

regeszter

Retired Team Member
  • Premium Supporter
  • October 29, 2005
    5,335
    4,954
    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:
        private void SaveMAC(string uncPath)
        {
          String macAddress;
          byte[] hwAddress;
    
          WakeOnLanManager wakeOnLanManager = new WakeOnLanManager();
    
          IPAddress ipAddress = null;
          string hostName = Util.Utils.GetServerNameFromUNCPath(uncPath);
    
          using (Profile.Settings xmlreader = new MPSettings())
          {
            macAddress = xmlreader.GetValueAsString("macAddress", hostName, null);
          }
    
          if (wakeOnLanManager.Ping(hostName, 100) && !string.IsNullOrEmpty(macAddress))
          {
            Log.Debug("WakeUpServer: The {0} server already started and mac address is learnt!", hostName);
            return;
          }
    
          // Check if we already have a valid IP address stored,
          // otherwise try to resolve the IP address
          if (!IPAddress.TryParse(hostName, out ipAddress))
          {
            // Get IP address of the server
            try
            {
              IPAddress[] ips;
    
              ips = Dns.GetHostAddresses(hostName);
    
              Log.Debug("WakeUpServer: WOL - GetHostAddresses({0}) returns:", hostName);
    
              foreach (IPAddress ip in ips)
              {
                Log.Debug("    {0}", ip);
    
                ipAddress = ip;
                // Check for valid IP address
                if (ipAddress != null)
                {
                  // Update the MAC address if possible
                  hwAddress = wakeOnLanManager.GetHardwareAddress(ipAddress);
    
                  if (wakeOnLanManager.IsValidEthernetAddress(hwAddress))
                  {
                    Log.Debug("WakeUpServer: WOL - Valid auto MAC address: {0:x}:{1:x}:{2:x}:{3:x}:{4:x}:{5:x}"
                      , hwAddress[0], hwAddress[1], hwAddress[2], hwAddress[3], hwAddress[4], hwAddress[5]);
    
                    // Store MAC address
                    macAddress = BitConverter.ToString(hwAddress).Replace("-", ":");
    
                    Log.Debug("WakeUpServer: WOL - Store MAC address: {0}", macAddress);
    
                    using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.MPSettings())
                    {
                      xmlwriter.SetValue("macAddress", hostName, macAddress);
                    }
                  }
                  else
                  {
                    Log.Debug("WakeUpServer: WOL - Not a valid IPv4 address: {0}", ipAddress);
                  }
                }
              }
            }
            catch (Exception ex)
            {
              Log.Error("WakeUpServer: WOL - Failed GetHostAddress - {0}", ex.Message);
            }
          }
        }

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

    Code:
    serverName = Util.Utils.GetServerNameFromUNCPath(uncPath);
    WakeupUtils.HandleWakeUpServer(serverName, wolTimeout);
     

    Dadeo

    Docs Group Manager
  • Premium Supporter
  • November 26, 2006
    5,340
    3,321
    Himalayas, India
    Canada Canada
    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?
     

    SpudR

    Documentation Group
  • Team MediaPortal
  • July 27, 2007
    2,634
    704
    Yorkshire, UK
    England England
    Country flag
    Last edited:

    SpudR

    Documentation Group
  • Team MediaPortal
  • July 27, 2007
    2,634
    704
    Yorkshire, UK
    England England
    Country flag
    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!
     

    Edalex

    Community Plugin Dev
  • Premium Supporter
  • January 3, 2008
    2,922
    1,228
    Saratov
    Russian Federation Russian Federation
    Country flag
    Old tips and tricks are fully working! One little change is that untested trick from Frodo is fully working too ;)
     

    Users Who Are Viewing This Thread (Users: 0, Guests: 1)

    OP Similar threads Forum Replies Date
    morpheus_xx [WiP] "What's New" plugin for MP2 upgrades MediaPortal 2 20
    da3dsoul [Request] An MVP Plugin example for custom settings in MP2 Plugin Development 2
    da3dsoul MP2 Plugin - Getting Started (Directory Tree and Player) Plugin Development 27
    M Installing Plugins Newcomers Forum 2
    joecrow 1.25.0 Radio Time plugin fails after Resume from Sleep with MP 1.25 Bugreports 10
    P MP2: US user, OTA - can NOT get SchedulesDirect plugin to work on MP1 or MP2 --> how do I get OTA schedule? General 5
    E aktuelle englische Forums Webseite von - Showtime Plugin v3 Plugins & Erweiterungen 4
    mrmojo666 [Tv Server Plugin ]Direct Show Video Control Plugin 0.0.0.1 for Hauppauge PVR cards MediaPortal 1 Plugins 0
    joecrow MultiShortcut Plugin (Uavailable) in DWHD skin General Support 58
    vapourEyes Building TV Plugin General Development (no feature request here!) 49
    Golf4 Nach Windows-Updates läuft TV-Plugin nicht mehr Allgemeines Support- und Diskussionsforum 0
    joecrow How about a Launcher plugin for MP1? MediaPortal 1 6
    D [solved] TVServer Plugin must be missing something. General Development (no feature request here!) 1
    framug Nouveau plugin XmlTvFR pour récupérer le guide télé français Kazer / ZguideTv (WebEPGfr) 11
    emphatic Allow remote control mapping of all plugins Improvement Suggestions 0
    D Where should plugins be located on hard drive? General Support 0
    D how to disengage from one version of a plugin to use another Newcomers Forum 0
    cbr954rr How to disable a pre-configured plugin? General 2
    mrmojo666 [Plugin]Marantz Control Plugin 0.0.0.2 MediaPortal 1 Plugins 2
    mrmojo666 beginner: trying to write a plugin, need help to catch event General Development (no feature request here!) 3
    framug [Rejected] Fix PowerScheduler plugin for MP2 single seat Submit: Code Patches 9
    doskabouter [Question] Stale plugins Developer Discussions 9
    M MP1 stops responding after Starting Plugins General Support 14
    Terra LAVFilter Plugin cannot be updated (MP1.23) MediaPortal 1 Plugins 10
    L Mediaportal 1.21 and Windows 10: user schedules de-activated when powerscheduler plugin is selected General Support 1
    Similar threads

























    Top Bottom