private async void UploadFile() { var logger = new Logger(); try { CreateDatabaseButton.Visibility = Visibility.Hidden; var connectionString = BuildConnectionString(); var config = GetConfig(); var 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(); } }); var dropTable = Convert.ToBoolean(dropExisting.IsChecked); var kmlFile = KMLFileLocationBox.Text; if (tabControl.SelectedIndex == 0) { await Task.Run(() => { var uploader = new Uploader(kmlFile, config, progresss); uploader.Upload(connectionString, dropTable); }); } else { var fileLoc = saveScriptTo.Text; await Task.Run(() => { var uploader = new Uploader(kmlFile, config, progresss); var script = uploader.GetScript(); File.WriteAllText(fileLoc, script); }); } } catch (Exception ex) { CreateDatabaseButton.Visibility = Visibility.Visible; logger.AddToLog(ex); AlertFailure(ex); } }
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); } }