コード例 #1
0
ファイル: NewConvert.xaml.cs プロジェクト: msorescu/SpeedUp
        private void GenerateDefFilesButton_Click(object sender, RoutedEventArgs e)
        {
            if (!IsValidInputFields())
            {
                return;
            }
            _stopProgressDialog = false;
            ModuleId            = ModuleIDTextBox.Text;
            try
            {
                ProgressDialogResult result = ProgressDialog.Execute(this, "Loading data", (bw, we) =>
                {
                    //1.Creating Def files from template def files
                    if (ProgressDialog.ReportWithCancellationCheck(bw, we, 10,
                                                                   "Creating Def files from template def files...",
                                                                   1))
                    {
                        return;
                    }
                    Thread.Sleep(1000);
                    this.Dispatcher.Invoke((Action)(CreateNewDefFiles));
                    if (_stopProgressDialog)
                    {
                        ProgressDialog.CloseProgressDialog(bw, we);
                        return;
                    }
                    //2.Download Metadata
                    if (ProgressDialog.ReportWithCancellationCheck(bw, we, 20, "Downloading Metadata...", 2))
                    {
                        return;
                    }
                    Thread.Sleep(1000);

                    this.Dispatcher.Invoke((Action)(DownloadMlsMetadata));
                    if (_stopProgressDialog)
                    {
                        ProgressDialog.CloseProgressDialog(bw, we);
                        return;
                    }

                    //6.Generate search field
                    if (ProgressDialog.ReportWithCancellationCheck(bw, we, 60, "Generating Def Files...", 9))
                    {
                        return;
                    }
                    Thread.Sleep(1000);
                    this.Dispatcher.Invoke((Action)(GenerateSearchFields));
                    if (_stopProgressDialog)
                    {
                        ProgressDialog.CloseProgressDialog(bw, we);
                        return;
                    }
                    if (ProgressDialog.ReportWithCancellationCheck(bw, we, 100, "Done", 10))
                    {
                        return;
                    }
                    Thread.Sleep(1000);


                    //7.Status
                    //8.Property type

                    // So this check in order to avoid default processing after the Cancel button has been pressed.
                    // This call will set the Cancelled flag on the result structure.
                    ProgressDialog.CheckForPendingCancellation(bw, we);
                }, new ProgressDialogSettings(true, true, false));

                if (result.Cancelled)
                {
                    MessageBox.Show("Failed to generate Def files.");
                }
                else if (result.OperationFailed)
                {
                    MessageBox.Show("ProgressDialog failed.");
                }
                else
                {
                    MessageBox.Show("Def files have been successfully generated.");
                }
                if (!_stopProgressDialog)
                {
                    //Add Rets account info to db

                    using (TCSEntities tcsDb = new TCSEntities())
                    {
                        short moduleId = Convert.ToInt16(ModuleIDTextBox.Text);
                        if (!tcsDb.tcs_rets_connection_info.Any(x => x.module_id == moduleId))
                        {
                            tcs_rets_connection_info retsInfo = new tcs_rets_connection_info();
                            retsInfo.module_id    = moduleId;
                            retsInfo.account_type = 1;
                            retsInfo.rdc_code     = "N/A";
                            retsInfo.user_name    = LoginNameTextBox.Text;
                            retsInfo.password     = PasswordTextBox.Text;
                            retsInfo.user_agent   = UserAgentTextBox.Text;
                            retsInfo.ua_password  = UAPasswordTextBox.Text;
                            retsInfo.login_url    = LoginURLTextBox.Text;

                            tcsDb.AddTotcs_rets_connection_info(retsInfo);
                            tcsDb.SaveChanges();
                        }
                    }

                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to generate Def files. \r\n" + ex.Message);
            }
        }