Ejemplo n.º 1
0
        /// <summary>
        /// Tries to determine whether the server is awake and if not tries to wake the server by sending
        /// a WOL packet to the address saved in settings.
        /// </summary>
        /// <returns></returns>
        protected async Task WakeServerAsync()
        {
            var sm       = ServiceRegistration.Get <ISettingsManager>();
            var settings = sm.Load <WakeOnLanSettings>();

            if (!settings.EnableWakeOnLan)
            {
                return;
            }

            lock (_wolSendSync)
            {
                if (_isSendingWol)
                {
                    //wol request already in progress
                    return;
                }
                _isSendingWol = true;
            }

            try
            {
                WakeOnLanAddress wolAddress = settings.ServerWakeOnLanAddress;
                if (wolAddress == null || !WakeOnLanHelper.IsValidHardwareAddress(wolAddress.HardwareAddress))
                {
                    ServiceRegistration.Get <ILogger>().Debug("WakeOnLanClient: No address stored for the server yet");
                    return;
                }

                //Wait for the network connection to become available, can be delayed if we have just woken from sleep
                if (!await WaitForNetworkConnection(settings.NetworkConnectedTimeout))
                {
                    ServiceRegistration.Get <ILogger>().Warn("WakeOnLanClient: No network connection found within timeout {0}ms", settings.NetworkConnectedTimeout);
                    return;
                }

                ServiceRegistration.Get <ILogger>().Info("WakeOnLanHelper: Waking server at {0} using port {1}", wolAddress.IPAddress, settings.Port);
                await WakeOnLanHelper.WakeServer(NetworkUtils.GetAllLocalIPv4Networks(),
                                                 wolAddress.IPAddress, wolAddress.HardwareAddress, settings.Port, settings.PingTimeout, settings.WakeTimeout);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error("WakeOnLanClient: Error waking server", ex);
            }
            finally
            {
                lock (_wolSendSync)
                    _isSendingWol = false;
            }
        }
Ejemplo n.º 2
0
 private void appBarButtonWol_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         foreach (Remote remote in listViewRemotes.SelectedItems.ToList())
         {
             WakeOnLanHelper.WakeUp(remote.WolMac, remote.WolMask, remote.WolPort);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }