public CSVConfigWindow(CSVViewModel viewModel) { InitializeComponent(); this.configControl.DataContext = viewModel; HelpContainer.Content = HelpResourceHelper.GetHelpButton("ConfigureDelimitedFileHelp", HelpButtonMode.NormalButton); }
protected override Collection <Layer> GetLayersCore(GetLayersParameters getLayersParameters) { Collection <Layer> resultLayers = base.GetLayersCore(getLayersParameters); Collection <CSVInfoModel> entities = new Collection <CSVInfoModel>(); bool hasUnconfiguredCsv = false; foreach (string fileName in getLayersParameters.LayerUris.Select(u => u.LocalPath)) { string configFileName = Path.ChangeExtension(fileName, Path.GetExtension(fileName) + ".config"); if (File.Exists(configFileName)) { var csvFileLastWriteTime = new FileInfo(fileName).LastWriteTime; var csvConfLastWriteTime = GetConfigFileLastWriteTime(fileName); if (csvFileLastWriteTime.ToString(CultureInfo.InvariantCulture).Equals(csvConfLastWriteTime.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase)) { entities.Add(CSVInfoModel.FromConfig(configFileName)); } else { CleanAttachedFiles(fileName, configFileName); entities.Add(new CSVInfoModel(fileName, ",")); hasUnconfiguredCsv = true; } } else { entities.Add(new CSVInfoModel(fileName, ",")); hasUnconfiguredCsv = true; } } try { if (entities.Count == 0) { return(resultLayers); } List <CSVModel> csvModels = new List <CSVModel>(); if (hasUnconfiguredCsv) { var viewModel = new CSVViewModel(entities); CSVConfigWindow window = new CSVConfigWindow(viewModel); viewModel.SelectedCSVModel.AutoMatch(); if (window.ShowDialog().GetValueOrDefault()) { window.CSVModelList.ForEach(csvModels.Add); } } else { foreach (var csvModel in new CSVViewModel(entities).CSVModelList) { csvModels.Add(csvModel); } } csvModels.ForEach(m => resultLayers.Add(m.CsvFeatureLayer)); foreach (CsvFeatureLayer delimitedFeatureLayer in resultLayers.OfType <CsvFeatureLayer>()) { delimitedFeatureLayer.FeatureSource.CommittedTransaction -= delegate { CSVModel.BuildDelimitedConfigurationFile(delimitedFeatureLayer); }; delimitedFeatureLayer.FeatureSource.CommittedTransaction += delegate { CSVModel.BuildDelimitedConfigurationFile(delimitedFeatureLayer); }; } } catch (Exception ex) { GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex)); System.Windows.Forms.MessageBox.Show(ex.Message, "Warning", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } return(resultLayers); }