home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
MediaPortal 1 Plugins
How-to for Plugin Developers with Code Examples
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="regeszter" data-source="post: 1106106" data-attributes="member: 15874"><p>Using Wake On Lan in plugins.</p><p></p><p>Extract the server IP from the UNC path ("<a href="https://forum.team-mediaportal.com/file://\\server\share" target="_blank">\\server\share</a>") and store the MAC address in MediaPortal.xml</p><p>Use it in configure.exe or setting screen of your plugin.</p><p></p><p>[CODE=C#] private void SaveMAC(string uncPath)</p><p> {</p><p> String macAddress;</p><p> byte[] hwAddress;</p><p></p><p> WakeOnLanManager wakeOnLanManager = new WakeOnLanManager();</p><p></p><p> IPAddress ipAddress = null;</p><p> string hostName = Util.Utils.GetServerNameFromUNCPath(uncPath);</p><p></p><p> using (Profile.Settings xmlreader = new MPSettings())</p><p> {</p><p> macAddress = xmlreader.GetValueAsString("macAddress", hostName, null);</p><p> }</p><p></p><p> if (wakeOnLanManager.Ping(hostName, 100) && !string.IsNullOrEmpty(macAddress))</p><p> {</p><p> Log.Debug("WakeUpServer: The {0} server already started and mac address is learnt!", hostName);</p><p> return;</p><p> }</p><p></p><p> // Check if we already have a valid IP address stored,</p><p> // otherwise try to resolve the IP address</p><p> if (!IPAddress.TryParse(hostName, out ipAddress))</p><p> {</p><p> // Get IP address of the server</p><p> try</p><p> {</p><p> IPAddress[] ips;</p><p></p><p> ips = Dns.GetHostAddresses(hostName);</p><p></p><p> Log.Debug("WakeUpServer: WOL - GetHostAddresses({0}) returns:", hostName);</p><p></p><p> foreach (IPAddress ip in ips)</p><p> {</p><p> Log.Debug(" {0}", ip);</p><p></p><p> ipAddress = ip;</p><p> // Check for valid IP address</p><p> if (ipAddress != null)</p><p> {</p><p> // Update the MAC address if possible</p><p> hwAddress = wakeOnLanManager.GetHardwareAddress(ipAddress);</p><p></p><p> if (wakeOnLanManager.IsValidEthernetAddress(hwAddress))</p><p> {</p><p> Log.Debug("WakeUpServer: WOL - Valid auto MAC address: {0:x}:{1:x}:{2:x}:{3:x}:{4:x}:{5:x}"</p><p> , hwAddress[0], hwAddress[1], hwAddress[2], hwAddress[3], hwAddress[4], hwAddress[5]);</p><p></p><p> // Store MAC address</p><p> macAddress = BitConverter.ToString(hwAddress).Replace("-", ":");</p><p></p><p> Log.Debug("WakeUpServer: WOL - Store MAC address: {0}", macAddress);</p><p></p><p> using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.MPSettings())</p><p> {</p><p> xmlwriter.SetValue("macAddress", hostName, macAddress);</p><p> }</p><p> }</p><p> else</p><p> {</p><p> Log.Debug("WakeUpServer: WOL - Not a valid IPv4 address: {0}", ipAddress);</p><p> }</p><p> }</p><p> }</p><p> }</p><p> catch (Exception ex)</p><p> {</p><p> Log.Error("WakeUpServer: WOL - Failed GetHostAddress - {0}", ex.Message);</p><p> }</p><p> }</p><p> }[/CODE]</p><p></p><p></p><p>Wake up the server before read the files from the share.</p><p></p><p>[CODE=C#]serverName = Util.Utils.GetServerNameFromUNCPath(uncPath);</p><p>WakeupUtils.HandleWakeUpServer(serverName, wolTimeout);[/CODE]</p></blockquote><p></p>
[QUOTE="regeszter, post: 1106106, member: 15874"] Using Wake On Lan in plugins. Extract the server IP from the UNC path ("[URL='https://forum.team-mediaportal.com/file://\\server\share']\\server\share[/URL]") and store the MAC address in MediaPortal.xml Use it in configure.exe or setting screen of your plugin. [CODE=C#] 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); } } }[/CODE] Wake up the server before read the files from the share. [CODE=C#]serverName = Util.Utils.GetServerNameFromUNCPath(uncPath); WakeupUtils.HandleWakeUpServer(serverName, wolTimeout);[/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
MediaPortal 1 Plugins
How-to for Plugin Developers with Code Examples
Contact us
RSS
Top
Bottom