Esempio n. 1
0
        private async void UploadFile()
        {
            Logger logger = new Logger();

            try
            {
                CreateDatabaseButton.Visibility = Visibility.Hidden;
                Kml2SqlConfig config  = GetConfig();
                string        kmlFile = KMLFileLocationBox.Text;
                if (!config.PolygonToClipboard)
                {
                    string connectionString             = BuildConnectionString();
                    Progress <ProgressReoprt> progresss = new Progress <ProgressReoprt>(p =>
                    {
                        UpdateProgressBar(p.PercentDone);
                        logger.AddToLog(p.Message);
                        if (p.Exception != null)
                        {
                            AlertFailure(p.Exception);
                            logger.AddToLog(p.Exception);
                            logger.WriteOut();
                            CreateDatabaseButton.Visibility = Visibility.Visible;
                        }
                        if (p.PercentDone == 100)
                        {
                            logger.WriteOut();
                        }
                    });
                    bool dropTable = Convert.ToBoolean(dropExisting.IsChecked);
                    if (tabControl.SelectedIndex == 0)
                    {
                        await Task.Run(() =>
                        {
                            Uploader uploader = new Uploader(kmlFile, config, progresss);
                            uploader.Upload(connectionString, dropTable);
                        });
                    }
                    else
                    {
                        string fileLoc = saveScriptTo.Text;
                        await Task.Run(() =>
                        {
                            Uploader uploader = new Uploader(kmlFile, config, progresss);
                            string script     = uploader.GetScript();
                            File.WriteAllText(fileLoc, script);
                        });
                    }
                }
                else
                {
                    Progress <ProgressReoprt> progresss = new Progress <ProgressReoprt>(p =>
                    {
                        UpdateProgressBar(p.PercentDone);
                    });

                    Uploader uploader = new Uploader(kmlFile, config, progresss);
                    string   script   = uploader.GetScript();
                    Clipboard.Clear();
                    Clipboard.SetText(script);
                }

                await Task.Delay(2000);

                ResetUploadButton();
            }
            catch (Exception ex)
            {
                CreateDatabaseButton.Visibility = Visibility.Visible;
                logger.AddToLog(ex);
                AlertFailure(ex);
            }
        }