Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using MediaPortal.GUI.Library;
- using MediaPortal.Dialogs;
- using System.Net;
- using System.Net.Sockets;
- namespace WOLPowerManager
- {
- public class WOLPowerManager : GUIWindow, ISetupForm
- {
- // Constructor
- public WOLPowerManager()
- {
- //Abonent der Event-Funktion
- GUIWindowManager.OnActivateWindow += new GUIWindowManager.WindowActivationHandler(GUIWindowManager_OnActivateWindow);
- }
- private void MacUmwandeln(object sender, EventArgs e)
- {
- //Umwandeln der MAC Adresse von String zu byte
- string[] arr_mac = Settings.MAC.Split(':');
- byte[] macadresse = new byte[6];
- for (int x = 0; x < macadresse.Length; x++)
- macadresse[x] = byte.Parse(arr_mac[x],
- System.Globalization.NumberStyles.HexNumber);
- WakeOnLan(macadresse);
- }
- private static void WakeOnLan(byte[] mac)
- {
- /*
- Das WOL Signal wird als Broadcast verschickt.
- Es enthält 6x den Wert FF, direkt danach folgt 16x die MAC Adresse.
- */
- UdpClient WOLclient = new UdpClient();
- WOLclient.Connect(IPAddress.Broadcast, 0);
- //Startsignal 6x(FF) + 16x(Mac-Adresse) = 102bytes
- byte[] Startsignal = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
- byte[] WOLSignal = new byte[102];
- // Startsignal einfügen
- Startsignal.CopyTo(WOLSignal, 0);
- // Die Mac-Adresse wird 16x in das WOL Signal kopiert
- for (int i = 1; i <= 16; i++)
- mac.CopyTo(WOLSignal, i * 6);
- //Signal senden
- WOLclient.Send(WOLSignal, WOLSignal.Length);
- }
- void GUIWindowManager_OnActivateWindow(int windowID)
- {
- }
- #region ISetupForm Members
- // Returns the name of the plugin which is shown in the plugin menu
- public string PluginName()
- {
- return "WOL-Power-Manager";
- }
- // Returns the description of the plugin is shown in the plugin menu
- public string Description()
- {
- return "Sends WOL-Packages when entering the specified plugins";
- }
- // Returns the author of the plugin which is shown in the plugin menu
- public string Author()
- {
- return "jojo1411";
- }
- // show the setup dialog
- public void ShowPlugin()
- {
- MessageBox.Show("Nothing to configure, this is just an example");
- }
- // Indicates whether plugin can be enabled/disabled
- public bool CanEnable()
- {
- return true;
- }
- // Get Windows-ID
- public int GetWindowId()
- {
- // WindowID of windowplugin belonging to this setup
- // enter your own unique code
- return -1;
- }
- // Indicates if plugin is enabled by default;
- public bool DefaultEnabled()
- {
- return true;
- }
- // indicates if a plugin has it's own setup screen
- public bool HasSetup()
- {
- return true;
- }
- /// <summary>
- /// If the plugin should have it's own button on the main menu of MediaPortal then it
- /// should return true to this method, otherwise if it should not be on home
- /// it should return false
- /// </summary>
- /// <param name="strButtonText">text the button should have</param>
- /// <param name="strButtonImage">image for the button, or empty for default</param>
- /// <param name="strButtonImageFocus">image for the button, or empty for default</param>
- /// <param name="strPictureImage">subpicture for the button or empty for none</param>
- /// <returns>true : plugin needs it's own button on home
- /// false : plugin does not need it's own button on home</returns>
- public bool GetHome(out string strButtonText, out string strButtonImage,
- out string strButtonImageFocus, out string strPictureImage)
- {
- strButtonText = String.Empty;
- strButtonImage = String.Empty;
- strButtonImageFocus = String.Empty;
- strPictureImage = String.Empty;
- return false;
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement