Exemplo n.º 1
0
        private async void ServerConfigMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MessageDialogResult mdr = await this.ShowMessageAsync("Настройка сервера", $"Адрес сервера: {Current.ServerAddress}", MessageDialogStyle.AffirmativeAndNegativeAndDoubleAuxiliary, new MetroDialogSettings()
            {
                AnimateShow               = true,
                AnimateHide               = true,
                NegativeButtonText        = "Отмена",
                FirstAuxiliaryButtonText  = "Изменить...",
                SecondAuxiliaryButtonText = "Проверить соединение"
            });

            switch (mdr)
            {
            // Изменить: тут надо показать инпут
            case MessageDialogResult.FirstAuxiliary:
                string newAddress = await this.ShowInputAsync("Настройка сервера", "Укажите адрес сервера", new MetroDialogSettings()
                {
                    AnimateShow = true,
                    AnimateHide = true,
                    DefaultText = Current.ServerAddress
                });

                if (!string.IsNullOrWhiteSpace(newAddress))
                {
                    Current.ServerAddress = newAddress;
                    await this.ShowMessageAsync("Настройка сервера", $"Новый адрес {newAddress} успешно сохранен", MessageDialogStyle.Affirmative, new MetroDialogSettings()
                    {
                        AnimateShow = true,
                        AnimateHide = true
                    });
                }
                break;

            // Проверить соединение - вешаем лоадер и делаем запрос
            case MessageDialogResult.SecondAuxiliary:
                await this.ShowOverlayAsync();

                loader.Visibility = Visibility.Visible;
                bool isOK = await AppClient.Ping(Current.ServerAddress);

                loader.Visibility = Visibility.Hidden;
                if (isOK)
                {
                    await this.ShowMessageAsync("Запрос успешно выполнен", $"Сервер {Current.ServerAddress} работает", MessageDialogStyle.Affirmative, new MetroDialogSettings()
                    {
                        AnimateShow = true,
                        AnimateHide = true
                    });
                }
                else
                {
                    await this.ShowMessageAsync("Ошибка запроса", $"В настоящее время сервер {Current.ServerAddress} недоступен, либо не является сервером для этой программы, попробуйте повторить запрос позднее или уточните адрес у Вашего системного администратора", MessageDialogStyle.Affirmative, new MetroDialogSettings()
                    {
                        AnimateShow = true,
                        AnimateHide = true
                    });
                }
                break;

            default:
                break;
            }
        }