Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using MediaPortal.GUI.Library;
  7. using MediaPortal.Dialogs;
  8. using System.Net;
  9. using System.Net.Sockets;
  10.  
  11.  
  12.  
  13. namespace WOLPowerManager
  14. {
  15.     public class WOLPowerManager : GUIWindow, ISetupForm
  16.     {
  17.  
  18.     // Constructor
  19.     public WOLPowerManager()
  20.     {
  21.             //Abonent der Event-Funktion
  22.             GUIWindowManager.OnActivateWindow += new GUIWindowManager.WindowActivationHandler(GUIWindowManager_OnActivateWindow);
  23.     }
  24.  
  25.         private void MacUmwandeln(object sender, EventArgs e)
  26.         {
  27.             //Umwandeln der MAC Adresse von String zu byte
  28.             string[] arr_mac = Settings.MAC.Split(':');
  29.             byte[] macadresse = new byte[6];
  30.  
  31.             for (int x = 0; x < macadresse.Length; x++)
  32.                 macadresse[x] = byte.Parse(arr_mac[x],
  33.                                          System.Globalization.NumberStyles.HexNumber);
  34.  
  35.             WakeOnLan(macadresse);
  36.         }
  37.  
  38.  
  39.         private static void WakeOnLan(byte[] mac)
  40.         {
  41.             /*
  42.               Das WOL Signal wird als Broadcast verschickt.
  43.               Es enthält 6x den Wert FF, direkt danach folgt 16x die MAC Adresse.
  44.             */
  45.  
  46.  
  47.             UdpClient WOLclient = new UdpClient();
  48.             WOLclient.Connect(IPAddress.Broadcast, 0);
  49.  
  50.             //Startsignal 6x(FF) + 16x(Mac-Adresse) = 102bytes
  51.             byte[] Startsignal = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  52.             byte[] WOLSignal = new byte[102];
  53.  
  54.             // Startsignal einf&uuml;gen
  55.             Startsignal.CopyTo(WOLSignal, 0);
  56.  
  57.             // Die Mac-Adresse wird 16x in das WOL Signal kopiert
  58.             for (int i = 1; i <= 16; i++)
  59.                 mac.CopyTo(WOLSignal, i * 6);
  60.  
  61.             //Signal senden
  62.             WOLclient.Send(WOLSignal, WOLSignal.Length);
  63.         }
  64.  
  65.         void GUIWindowManager_OnActivateWindow(int windowID)
  66.         {
  67.            
  68.         }
  69.  
  70.         #region ISetupForm Members
  71.  
  72.         // Returns the name of the plugin which is shown in the plugin menu
  73.         public string PluginName()
  74.         {
  75.             return "WOL-Power-Manager";
  76.         }
  77.  
  78.         // Returns the description of the plugin is shown in the plugin menu
  79.         public string Description()
  80.         {
  81.             return "Sends WOL-Packages when entering the specified plugins";
  82.         }
  83.  
  84.         // Returns the author of the plugin which is shown in the plugin menu
  85.         public string Author()
  86.         {
  87.             return "jojo1411";
  88.         }
  89.  
  90.         // show the setup dialog
  91.         public void ShowPlugin()
  92.         {
  93.             MessageBox.Show("Nothing to configure, this is just an example");
  94.         }
  95.  
  96.         // Indicates whether plugin can be enabled/disabled
  97.         public bool CanEnable()
  98.         {
  99.             return true;
  100.         }
  101.  
  102.         // Get Windows-ID
  103.         public int GetWindowId()
  104.         {
  105.             // WindowID of windowplugin belonging to this setup
  106.             // enter your own unique code
  107.             return -1;
  108.         }
  109.  
  110.         // Indicates if plugin is enabled by default;
  111.         public bool DefaultEnabled()
  112.         {
  113.             return true;
  114.         }
  115.  
  116.         // indicates if a plugin has it's own setup screen
  117.         public bool HasSetup()
  118.         {
  119.             return true;
  120.         }
  121.  
  122.         /// <summary>
  123.         /// If the plugin should have it's own button on the main menu of MediaPortal then it
  124.         /// should return true to this method, otherwise if it should not be on home
  125.         /// it should return false
  126.         /// </summary>
  127.         /// <param name="strButtonText">text the button should have</param>
  128.         /// <param name="strButtonImage">image for the button, or empty for default</param>
  129.         /// <param name="strButtonImageFocus">image for the button, or empty for default</param>
  130.         /// <param name="strPictureImage">subpicture for the button or empty for none</param>
  131.         /// <returns>true : plugin needs it's own button on home
  132.         /// false : plugin does not need it's own button on home</returns>
  133.  
  134.         public bool GetHome(out string strButtonText, out string strButtonImage,
  135.           out string strButtonImageFocus, out string strPictureImage)
  136.         {
  137.             strButtonText = String.Empty;
  138.             strButtonImage = String.Empty;
  139.             strButtonImageFocus = String.Empty;
  140.             strPictureImage = String.Empty;
  141.             return false;
  142.         }
  143.  
  144.         #endregion
  145.  
  146.     }
  147.  
  148.  
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement