Example #1
0
 private static void Write(AWSInfo awsInfo)
 {
     // For AWSInfo
     var newAWSInfo = Build(awsInfo);
     var newMapper = new Klib.BookMapper();
     newMapper.AWSInfo = awsInfo.UID;
     newMapper.Book = awsInfo.AssociatedBookUID;
     db.AWSInfos.InsertOnSubmit(newAWSInfo);
     db.BookMappers.InsertOnSubmit(newMapper);
     db.SubmitChanges();
 }
        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();
        }
Example #3
0
 private static Klib.AWSInfo Build(AWSInfo awsInfo)
 {
     var builtInfo = new Klib.AWSInfo();
     builtInfo.UID = awsInfo.UID;
     builtInfo.Title = awsInfo.Title;
     builtInfo.Author = awsInfo.Author;
     builtInfo.ISBN10 = awsInfo.ISBN10;
     builtInfo.ISBN13 = awsInfo.ISBN13;
     builtInfo.URL = awsInfo.URL;
     return builtInfo;
 }