Exemplo n.º 1
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            if (!IsSetupMode)
            {
                ButtonCancel.IsEnabled = true;
                TextBoxEndpoint.Text   = Properties.Settings.Default.DataEndpoint;
            }

            TextBoxEndpoint.Focus();
        }
Exemplo n.º 2
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            new Thread(delegate()
            {
                Application.Current.Dispatcher.Invoke(delegate
                {
                    SettingsCheckStarted?.Invoke(this, new EventArgs());
                    TextBoxEndpoint.IsEnabled = false;
                    ButtonCancel.IsEnabled    = false;
                });

                try
                {
                    // Request AWS info to check entered URL is valid
                    string awsInfoUrl = null;
                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        awsInfoUrl = Path
                                     .Combine(TextBoxEndpoint.Text + "/", "data/aws-info.php");
                    });

                    string awsInfoData = Helpers.RequestURL(awsInfoUrl);
                    if (awsInfoData == "1")
                    {
                        throw new Exception("Server-side error");
                    }

                    AWSInfo awsInfoJson = JsonConvert.DeserializeObject <AWSInfo>(
                        awsInfoData, new JsonSerializerSettings
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    });

                    Application.Current.Dispatcher.Invoke(delegate
                                                          { Properties.Settings.Default.DataEndpoint = TextBoxEndpoint.Text; });
                    Properties.Settings.Default.AWSTimeZone = awsInfoJson.TimeZone;
                    Properties.Settings.Default.IsFirstRun  = false;
                    Properties.Settings.Default.Save();

                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        SettingsCheckCompleted?.Invoke(this, new EventArgs());
                        SettingsDismissed?.Invoke(this,
                                                  new SettingsDismissedEventArgs(DismissType.Save));
                    });
                }
                catch
                {
                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        TextBoxEndpoint.IsEnabled = true;
                        TextBoxEndpoint.Focus();
                        TextBoxEndpoint.SelectAll();
                        if (!IsSetupMode)
                        {
                            ButtonCancel.IsEnabled = true;
                        }

                        SettingsCheckCompleted?.Invoke(this, new EventArgs());
                    });
                }
            }).Start();
        }