private async void ParseBatchFile_Clicked(object sender, RoutedEventArgs e) { SucceededBatchGeocodes.Text = string.Empty; FailedBatchGeocodes.Text = string.Empty; var type = (BatchFileFormat)Enum.Parse(typeof(BatchFileFormat), ((string)(BatchFileFormatCbx.SelectedItem as ComboBoxItem).Content)); string filters, defaultExt; FileExtensionUtilities.GetFileExtensions(type, out defaultExt, out filters); var ofd = new OpenFileDialog() { DefaultExt = defaultExt, Filter = filters }; var b = ofd.ShowDialog(); if (b.HasValue && b.Value) { using (var s = ofd.OpenFile()) { var batchFile = await GeocodeFeed.ReadAsync(s, type); var serializer = new XmlSerializer(typeof(GeocodeFeed)); using (var writer = new StringWriter()){ serializer.Serialize(writer, batchFile); SucceededBatchGeocodes.Text = writer.ToString(); } } } }
private async void SelectFile_Clicked(object sender, RoutedEventArgs e) { var type = (DataSourceFormat)Enum.Parse(typeof(DataSourceFormat), ((string)(DataSourceFormatCbx.SelectedItem as ComboBoxItem).Content)); string filters, defaultExt; FileExtensionUtilities.GetFileExtensions(type, out defaultExt, out filters); var ofd = new OpenFileDialog() { DefaultExt = defaultExt, Filter = filters }; var b = ofd.ShowDialog(); if (b.HasValue && b.Value) { if (type == DataSourceFormat.SHP || type == DataSourceFormat.KML) { _dataSource = null; _dataSourceStream = ofd.OpenFile(); UploadBtn.IsEnabled = true; EntityTypeNameTbx.IsEnabled = false; } else { _dataSourceStream = null; EntityTypeNameTbx.IsEnabled = true; var dataSource = new DataSource(); using (var s = ofd.OpenFile()) { if (await dataSource.ReadAsync(s, type)) { _dataSource = dataSource; _dataSource.GeocodeStatusChanged += (msg) => { OutputTbx.Text += msg + "\r\n"; }; if (type == DataSourceFormat.XML) { _info.DataSourceName = _dataSource.Info.DataSourceName; } _info.EntityTypeName = _dataSource.Info.EntityTypeName; this.DataContext = null; this.DataContext = _info; UploadBtn.IsEnabled = true; ValidateBtn.IsEnabled = true; } } } } }
private async void Convert_Clicked(object sender, RoutedEventArgs e) { var inputType = (DataSourceFormat)Enum.Parse(typeof(DataSourceFormat), ((string)(FromFormatCbx.SelectedItem as ComboBoxItem).Content)); var outputType = (DataSourceFormat)Enum.Parse(typeof(DataSourceFormat), ((string)(ToFormatCbx.SelectedItem as ComboBoxItem).Content)); string filters, defaultExt; FileExtensionUtilities.GetFileExtensions(inputType, out defaultExt, out filters); var ofd = new OpenFileDialog() { DefaultExt = defaultExt, Filter = filters }; var b = ofd.ShowDialog(); if (b.HasValue && b.Value) { var dataSource = new DataSource(); using (var s = ofd.OpenFile()) { if (await dataSource.ReadAsync(s, inputType)) { FileExtensionUtilities.GetFileExtensions(outputType, out defaultExt, out filters); var sfd = new SaveFileDialog() { DefaultExt = defaultExt, Filter = filters }; b = sfd.ShowDialog(); if (b.HasValue && b.Value) { using (var outputStream = sfd.OpenFile()) { await dataSource.WriteAsync(outputStream, outputType); } } } } } MessageBox.Show("Data source conversion complete."); this.Close(); }