예제 #1
0
        private async void WakeUpServerMFI_Click(object sender, RoutedEventArgs e)
        {
            ConnectionItem selectedConnection = (ConnectionItem)(sender as MenuFlyoutItem).DataContext;

            if (selectedConnection.SubnetMask == null || selectedConnection.MACAddress == null)
            {
                MessageDialog message = new MessageDialog(loader.GetString("WOLMacNotFoundMessage"), loader.GetString("WOLMacNotFoundHeader"));
                await message.ShowAsync();

                return;
            }
            SetPageState(PageStates.Busy, loader.GetString("WakingUp"));
            uint result = await WOLHelper.WakeUp(selectedConnection);

            await Task.Delay(3500);

            SetPageState(PageStates.Ready);
            if (result != 102)
            {
                string messageText;
                switch (result)
                {
                case 10:
                    messageText = loader.GetString("IPErrorMessage");
                    break;

                default:
                    messageText = loader.GetString("WOLErrorMessage") + result;
                    break;
                }
                MessageDialog message = new MessageDialog(messageText, loader.GetString("WakeUpFailed"));
                await message.ShowAsync();
            }
        }
예제 #2
0
        private async Task ConnectToServer(ConnectionItem connectionItem)
        {
            string connectingTo = loader.GetString("ConnectingTo");

            SetPageState(PageStates.Busy, string.Format(connectingTo, connectionItem.ConnectionName));

            string bePatientText = loader.GetString("BePatient");
            int    wakeupTime    = connectionItem.WakeUpTime < 5 ? 5 : connectionItem.WakeUpTime;
            int    stepSize      = 5;

            DateTime wakeUpStart  = DateTime.Now;
            bool     isSuccessful = false;

            if (connectionItem.AutoWake)
            {
                uint result = await WOLHelper.WakeUp(connectionItem);

                if (result != 102)
                {
                    string messageText;
                    switch (result)
                    {
                    case 10:
                        messageText = loader.GetString("IPErrorMessage");
                        break;

                    default:
                        messageText = loader.GetString("WOLErrorMessage") + result;
                        break;
                    }
                    MessageDialog message = new MessageDialog(messageText, loader.GetString("WakeUpFailed"));
                    await message.ShowAsync();

                    SetPageState(PageStates.Ready);
                    return;
                }
                bePatientText = String.Format(loader.GetString("WakeupPatientMessage"), MathExtension.CurrentStep(wakeupTime, stepSize), MathExtension.UpperStep(wakeupTime, stepSize));
            }

            MessageDialog tryMessage  = new MessageDialog(loader.GetString("WOLConnectionErrorMessage"), loader.GetString("WOLConnectionErrorHeader"));
            string        keepTrying  = loader.GetString("KeepTryingCommand");
            string        stopCommand = loader.GetString("StopCommand");

            tryMessage.Commands.Add(new UICommand(keepTrying));
            tryMessage.Commands.Add(new UICommand(stopCommand));

            DateTime lastPopupTime = DateTime.Now;

            while (!isSuccessful)
            {
                var timeSinceWakeUp = (DateTime.Now - wakeUpStart).TotalSeconds;
                var timeSincePopup  = (DateTime.Now - lastPopupTime).TotalSeconds;
                if (timeSinceWakeUp > 5)
                {
                    SetPageState(PageStates.Busy, bePatientText);
                }
                if (timeSincePopup > 10)
                {
                    var selectedCommand = await tryMessage.ShowAsync();

                    lastPopupTime = DateTime.Now;
                    if (selectedCommand.Label == stopCommand)
                    {
                        break;
                    }
                }
                isSuccessful = await JSONRPC.Ping(connectionItem);
            }

            if (isSuccessful)
            {
                ConnectionManager.CurrentConnection = connectionItem;
                SettingsHelper.SetValue("RecentServerIP", connectionItem.IpAddress);

                int newWakeupTime = (int)(DateTime.Now - wakeUpStart).TotalSeconds;
                connectionItem.WakeUpTime = newWakeupTime < 5 ? connectionItem.WakeUpTime : newWakeupTime;
                App.ConnectionsVM.UpdateConnectionItem();
                Frame.Navigate(typeof(CoverPage));
            }
            SetPageState(PageStates.Ready);
        }