A4WaterUtilities.GeoNetTools.DisconnectSelected C# (CSharp) Метод

DisconnectSelected() публичный статический метод

public static DisconnectSelected ( IApplication app ) : void
app IApplication
Результат void
        public static void DisconnectSelected(IApplication app)
        {
            try
            {
                //Get list of editable layers
                IEditor editor = Globals.getEditor(ref app);

                if (editor.EditState != esriEditState.esriStateEditing)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg"), A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_2"));
                    return;
                }
                IEditLayers eLayers = (IEditLayers)editor;

                IMap map = editor.Map;
                IActiveView activeView = map as IActiveView;

                if (map.SelectionCount > 0)
                {
                    //If above threshold, prompt to cancel
                    if ((map.SelectionCount > 1) &&
                       (MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsAsk_9a") + map.SelectionCount + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsAsk_9b"), A4LGSharedFunctions.Localizer.GetString("Confirm"), System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No))
                        return;

                    bool test = false;
                    ESRI.ArcGIS.esriSystem.IStatusBar statusBar = null;
                    ESRI.ArcGIS.esriSystem.IAnimationProgressor animationProgressor = null;
                    ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = null;
                    ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null;
                    ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null;
                    ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = null;
                    try
                    {
                        // Create an edit operation enabling undo/redo
                        editor.StartOperation();

                        //Get list of feature layers
                        UID geoFeatureLayerID = new UIDClass();
                        geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
                        IEnumLayer enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true);

                        IFeatureLayer fLayer;
                        IFeatureSelection fSel;
                        ILayer layer;
                        ICursor cursor = null; IFeatureCursor fCursor = null;

                        int lyrCnt = 0;
                        while ((layer = enumLayer.Next()) != null)
                        {
                            lyrCnt = lyrCnt + 1;

                        }
                        enumLayer.Reset();

                        statusBar = app.StatusBar;
                        animationProgressor = statusBar.ProgressAnimation;

                        animationProgressor.Show();
                        animationProgressor.Play(0, -1, -1);

                        statusBar.set_Message(0, A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_7"));

                        // Create a CancelTracker
                        trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();

                        progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();

                        // Set the properties of the Step Progressor
                        System.Int32 int32_hWnd = app.hWnd;
                        stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
                        stepProgressor.MinRange = 0;
                        stepProgressor.MaxRange = lyrCnt - 1;
                        stepProgressor.StepValue = 1;
                        stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_10");

                        // Create the ProgressDialog. This automatically displays the dialog
                        progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast

                        // Set the properties of the ProgressDialog
                        progressDialog2.CancelEnabled = true;
                        progressDialog2.Description = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDesc_10");
                        progressDialog2.Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsTitle_10");
                        progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe;

                        // Step. Do your big process here.
                        System.Boolean boolean_Continue = false;
                        boolean_Continue = true;

                        // Step through each geofeature layer in the map
                        enumLayer.Reset();
                        while ((layer = enumLayer.Next()) != null)
                        {
                            // Verify that this is a valid, visible layer and that this layer is editable
                            fLayer = (IFeatureLayer)layer;
                            if (fLayer.Valid && fLayer.Visible && eLayers.IsEditable(fLayer))
                            {
                                stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_10a") + fLayer.Name;

                                // Verify selected features and network
                                INetworkClass netClass = fLayer.FeatureClass as INetworkClass;
                                fSel = (IFeatureSelection)fLayer;
                                if ((netClass != null) && (fSel.SelectionSet.Count > 0))
                                {
                                    test = true;

                                    fSel.SelectionSet.Search(null, false, out cursor);
                                    fCursor = cursor as IFeatureCursor;
                                    INetworkFeature netFeature;
                                    while ((netFeature = (INetworkFeature)fCursor.NextFeature()) != null)
                                    {
                                        try
                                        {
                                            netFeature.Disconnect();
                                        }
                                        catch
                                        { }
                                        //IFeature feat = (IFeature)netFeature;
                                        //int fieldPos = feat.Fields.FindField("ENABLED");

                                        //if (fieldPos > -1)
                                        //{
                                        //    feat.set_Value(fieldPos, feat.get_Value(fieldPos));
                                        //    feat.Store();
                                        //}

                                    }

                                    Marshal.ReleaseComObject(cursor);
                                    Marshal.ReleaseComObject(fCursor);

                                }

                            }
                            stepProgressor.Step();

                            boolean_Continue = trackCancel.Continue();
                            if (!boolean_Continue)
                            {
                                break;
                            }
                        }

                        // Stop the edit operation
                        editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDone_10"));

                    }
                    catch (Exception ex)
                    {
                        editor.AbortOperation();
                        MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDone_10") + "\n" + ex.Message, ex.Source);
                        return;
                    }
                    finally
                    {
                        if (animationProgressor != null)
                        {
                            animationProgressor.Stop();
                            animationProgressor.Hide();
                        }
                        // Done
                        trackCancel = null;
                        stepProgressor = null;
                        if (progressDialog2 != null)
                        {
                            progressDialog2.HideDialog();
                        }

                        progressDialog2 = null;

                    }

                    //Alert the user know if no work was performed
                    if (!(test))
                        MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_8a"), A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_10"));
                    else
                        activeView.Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDone_10") + "\n" + ex.Message, ex.Source);
                return;
            }
        }