protected override TaskPlugin GetTaskPluginCore() { OutputShapeFileNames.Clear(); OverlaysToRefresh.Clear(); FeatureSource featureSource = null; if (UseSelectedFeaturesOnly) { SaveSelectedFeaturesToTempFile(); featureSource = new ShapeFileFeatureSource(tempFilePath); } else { featureSource = SelectedLayerToSplit.FeatureSource; } if (featureSource.IsOpen) { featureSource.Close(); if (featureSource.Projection != null) { featureSource.Projection.Close(); } } Dictionary <string, string> exportConfigs = new Dictionary <string, string>(); var plugin = GisEditor.TaskManager.GetActiveTaskPlugins <SplitTaskPlugin>().FirstOrDefault(); if (plugin != null) { InitializePlugin(plugin, featureSource, exportConfigs); } var configsNeedToExport = ExportConfiguration.Where(config => config.NeedsToExport); foreach (var item in configsNeedToExport) { string finalShapeFilePath = Path.Combine(OutputPath, item.OutputFileName + ".shp"); if (File.Exists(finalShapeFilePath) && overwriteOutputFiles) { CloseExistingLayersAndCollectOverlaysToRefresh(finalShapeFilePath); } OutputShapeFileNames.Add(finalShapeFilePath); exportConfigs.Add(item.ColumnValue, item.OutputFileName + ".shp"); } return(plugin); }
private void CloseExistingLayersAndCollectOverlaysToRefresh(string shapefileLayerPath) { foreach (var overlay in GisEditor.ActiveMap.Overlays.OfType <LayerOverlay>()) { foreach (var layer in overlay.Layers.OfType <ShapeFileFeatureLayer>()) { if (layer.ShapePathFilename.Equals(shapefileLayerPath, StringComparison.OrdinalIgnoreCase)) { lock (layer) { layer.Close(); if (layer.FeatureSource.Projection != null) { layer.FeatureSource.Projection.Close(); } } if (!OverlaysToRefresh.Contains(overlay)) { OverlaysToRefresh.Add(overlay); } } } } }