public static void AddFlagsForSewerProfile(IApplication app, double snapTol, List<ProfileGraphDetails> ProfileGraph)
        {
            IFeatureCursor pFeatCursor = null;
            IMxDocument pMxDoc = null;

            IPoint pTracePoint = null;
            ISpatialFilter pSpatialFilter = null;
            // set the symbol for the flag, red circle
            IMarkerSymbol pMarkerSym = null;
            IRgbColor pRGBColor = null;

            IFeatureLayer pManholeLayer = null;
            IFeatureLayer pMainLayer = null;
            IFeatureLayer pTapLayer = null;
            IGraphicsContainer gc = null;

            IElement pProfileElemFirst = null;
            IElementProperties3 pProfileElemPropFirst = null;

            IElement element = null;
            IElementProperties3 elementProp = null;
            ITopologicalOperator pTopoOp = null;

            IFeature pFeature = null;
            double snapdistnet; // NetworkExt search tolerance
            IPolygon pBuffGeometry = null;
            IMarkerElement markerelem = null;
            IGeometricNetwork gn = null;

            IEnumNetEID juncEIDs = null;
            IEnumNetEID edgeEIDs = null;
            try
            {
                pMxDoc = ((IMxDocument)app.Document);

                pTracePoint = pMxDoc.CurrentLocation;

                pMarkerSym = Globals.FindMarkerSym("Esri.style", "Default", "Circle 2", pMxDoc);
                pRGBColor = Globals.GetColor(255, 0, 0);

                pMarkerSym.Color = pRGBColor;
                pMarkerSym.Size = 11;

                gc = pMxDoc.FocusMap as IGraphicsContainer;

                pProfileElemFirst = null;
                pProfileElemPropFirst = null;

                gc.Reset();
                element = gc.Next();

                while (element != null)
                {
                    elementProp = element as IElementProperties3;
                    if (elementProp.Name.Contains("ProfileGraphFlag"))
                    {
                        if (pProfileElemFirst == null)
                        {
                            pProfileElemFirst = element;
                            pProfileElemPropFirst = elementProp;
                            break;
                        }

                    }
                    element = gc.Next();
                }

                for (int i = 0; i < ProfileGraph.Count; i++)
                {
                    if (pProfileElemFirst != null)
                    {
                        if (!pProfileElemPropFirst.Name.Contains(ProfileGraph[i].Network_Name))
                        {
                            //MessageBox.Show("The network (" + ProfileGraph[i].Network_Name + ") was not found, please update the config to make the name of the layer in the mxd");

                            continue;
                        }

                    }
                    bool FCorLayerManhole = true;
                    pManholeLayer = (IFeatureLayer)Globals.FindLayer(pMxDoc.FocusMap, ProfileGraph[i].Point_LayerName, ref FCorLayerManhole);

                    if (pManholeLayer == null)
                    {
                       // MessageBox.Show("The point layer (" + ProfileGraph[i].Point_LayerName + ") was not found, please update the config to make the name of the layer in the mxd");

                        continue;
                    }
                    bool FCorLayerMain = true;
                    pMainLayer = (IFeatureLayer)Globals.FindLayer(pMxDoc.FocusMap, ProfileGraph[i].Line_LayerName, ref FCorLayerMain);
                    if (pMainLayer == null)
                    {
                       // MessageBox.Show("The Main layer (" + ProfileGraph[i].Line_LayerName + ") was not found, please update the config to make the name of the layer in the mxd");

                        continue;
                    }
                    bool FCorLayerTap = true;
                    if (ProfileGraph[i].PointAlong_LayerName != "")
                    {
                        pTapLayer = (IFeatureLayer)Globals.FindLayer(pMxDoc.FocusMap, ProfileGraph[i].PointAlong_LayerName, ref FCorLayerTap);

                    }
                    else
                        pTapLayer = null;
                    // make sure a manhole was selected
                    // buffer the point by the snap tolerance, this is faster than checking
                    //the flag to see if it is on a manhole

                    pTopoOp = (ITopologicalOperator)pTracePoint;  // QI
                    snapdistnet = Globals.ConvertPixelsToMap(snapTol, pMxDoc.FocusMap);
                    pBuffGeometry = (IPolygon)pTopoOp.Buffer(snapdistnet);

                    // get the feature the user clicked to be sure it's a manhole

                    pSpatialFilter = new SpatialFilterClass();
                    pSpatialFilter.Geometry = pBuffGeometry;
                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;
                    pFeatCursor = pManholeLayer.Search(pSpatialFilter, true);

                    // there is a layer definition set to show only manholes, cursor
                    // will return nothing if user didn't click on a manhole
                    pFeature = pFeatCursor.NextFeature();

                    if (pFeature != null)
                    {
                        pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pBuffGeometry.Envelope);

                        markerelem = new MarkerElementClass();
                        markerelem.Symbol = pMarkerSym;
                        element = (IElement)markerelem;
                        element.Geometry = pFeature.ShapeCopy;
                        elementProp = element as IElementProperties3;
                        elementProp.Name = "ProfileGraphFlag-" + ProfileGraph[i].Network_Name;

                        elementProp.ReferenceScale = pMxDoc.FocusMap.ReferenceScale;
                        gc.AddElement(element, 0);

                        if (pProfileElemFirst == null)
                            return;
                        else
                        {
                            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;

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

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

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

                            // 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 = 3;
                            stepProgressor.StepValue = 1;
                            stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDesc_19a");

                            // 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_19a");
                            progressDialog2.Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsTitle_19a");
                            progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;

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

                            stepProgressor.Step();

                            GeoNetTools.TracePath(new double[] { (pProfileElemFirst.Geometry as IPoint).X, (element.Geometry as IPoint).X },
                                new double[] { (pProfileElemFirst.Geometry as IPoint).Y, (element.Geometry as IPoint).Y },
                                ProfileGraph[i].Network_Name, app, pMxDoc.FocusMap, true, snapTol, true, out juncEIDs, out edgeEIDs, out gn);
                            boolean_Continue = trackCancel.Continue();
                            if (!boolean_Continue)
                            {
                                return;
                            }
                            stepProgressor.Step();
                            stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_19a");
                            if (juncEIDs != null && edgeEIDs != null)
                            {
                                GeoNetTools.ProfileGetRelatedElevData(app, ProfileGraph, gn, edgeEIDs, juncEIDs, i, ref pManholeLayer, ref pMainLayer, ref pTapLayer);
                            }
                            else
                            {

                            }

                            //ProfileFindPath();

                            // unpress the UIToolControl button
                            app.CurrentTool = null;
                            app.RefreshWindow();
                            progressDialog2.HideDialog();
                            progressDialog2 = null;
                            return;
                        }

                    }
                    else//Next Layer in the config
                    {
                    }

                }

                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_19a"));

            }
            catch (Exception Ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + "AddFlagsForSewerProfile " + Ex.Message);
            }
            finally
            {
                if (pFeatCursor != null)
                {
                    Marshal.ReleaseComObject(pFeatCursor);

                }
                pMxDoc.ActiveView.Refresh();
                pFeatCursor = null;
                pMxDoc = null;

                pTracePoint = null;
                pSpatialFilter = null;
                // set the symbol for the flag, red circle
                pMarkerSym = null;
                pRGBColor = null;

                pManholeLayer = null;
                pMainLayer = null;
                pTapLayer = null;
                gc = null;

                pProfileElemFirst = null;
                pProfileElemPropFirst = null;

                element = null;
                elementProp = null;
                pTopoOp = null;

                pFeature = null;

                pBuffGeometry = null;
                markerelem = null;
                gn = null;

                juncEIDs = null;
                edgeEIDs = null;
            }
        }
        public static void MoveConnectionsToNewLine(IApplication app, double snapTol, List<MoveConnectionsDetails> moveConDetails)
        {
            IEditor editor = null;

            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;
            ICommandItem pCmdItem;

            IMxDocument pMxDoc = ((IMxDocument)app.Document);
            IGeometricNetwork pGN = null;
            IFeature pFeature = null;
            IPoint pTracePoint = null;
            ISimpleLineSymbol pSimpleLineSym = null;
            IRgbColor pRGBColor = null;

            IGraphicsContainer gc = null;

            IElement pMoveElemFirst = null;
            IElementProperties3 pMoveElemPropFirst = null;

            IElement element = null;
            IElementProperties3 elementProp = null;
            ILineElement lineElem = null;
            IJunctionFeature pJuncFeat = null;

            IFeatureLayer pSourceLayer = null;
            IFeature pSourceFeature = null;
            IFeature pMoveFeat = null;
            INetworkFeature pNetworkSourceFeature = null;
            IEdgeFeature iTargetEdgeFeat = null;
            IComplexEdgeFeature iCEdge = null;
            IFeatureClass pOraphFC = null;

            List<int> OIDs = new List<int>();
            List<string> FeatLoc = new List<string>();
            List<IObjectClass> FCs = new List<IObjectClass>();
            IPolyline pL;

            IHitTest pHtTest = null;//= pPolyline as IHitTest;

            IPoint pHitPntOne = new PointClass();
            double pHitDistOne = -1;
            int pHitPrtOne = -1;
            int pHitSegOne = -1;
            bool pHitSideOne = false;

            //IFeatureCursor pFeatCursor = null;
            IFeatureLayer pMainLayer = null;
            //IFeatureLayer pMainLayer = null;
            //IFeatureLayer pTapLayer = null;
            ILayer pLay = null;
            try
            {
                editor = Globals.getEditor(ref app);

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

                pTracePoint = pMxDoc.CurrentLocation;
                pFeature = Globals.GetNetworkAndFeatureAtLocation(pTracePoint, app, esriElementType.esriETEdge, out pGN, snapTol);

                if (pFeature == null)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("NoFtrFndOnClck"));
                    return;
                }

                int idxDet = -1;

                for (int i = 0; i < moveConDetails.Count; i++)
                {
                    //MoveConnectionsDetails conDet = moveConDetails[i];
                    bool FCorLayerTemp = true;
                    pMainLayer = (IFeatureLayer)Globals.FindLayer(app, moveConDetails[i].LineLayer, ref FCorLayerTemp);
                    if (pMainLayer != null)
                    {
                        if (pMainLayer.FeatureClass.ObjectClassID == pFeature.Class.ObjectClassID)
                        {
                            idxDet = i;

                            break;

                        }
                    }
                }

                if (idxDet == -1)
                    return;

                if (Globals.IsEditable(ref pFeature, ref editor) == false)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_13b"));
                    return;
                }
                if (pFeature.FeatureType != esriFeatureType.esriFTComplexEdge)
                {
                    MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_13c"));
                    return;
                }
                pRGBColor = Globals.GetColor(255, 0, 0);

                pSimpleLineSym = Globals.CreateSimpleLineSymbol(pRGBColor, 2, esriSimpleLineStyle.esriSLSSolid);

                gc = pMxDoc.FocusMap as IGraphicsContainer;

                gc.Reset();
                element = gc.Next();

                while (element != null)
                {
                    elementProp = element as IElementProperties3;
                    if (elementProp.Name.Contains("MoveFeatureFlag"))
                    {
                        if (pMoveElemFirst == null)
                        {

                            pMoveElemFirst = element;

                            pMoveElemPropFirst = elementProp;
                            string[] firstVals = pMoveElemPropFirst.Name.ToString().Split(':');
                            if (firstVals[1] != pFeature.Class.ObjectClassID.ToString())
                            {
                                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13a"));
                                return;

                            }

                            break;
                        }

                    }
                    element = gc.Next();
                }

                lineElem = new LineElementClass();
                lineElem.Symbol = pSimpleLineSym;
                element = (IElement)lineElem;
                element.Geometry = pFeature.ShapeCopy;
                elementProp = element as IElementProperties3;
                elementProp.Name = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_13a") + ": " + pFeature.Class.ObjectClassID.ToString() + ":" + pFeature.OID;

                elementProp.ReferenceScale = pMxDoc.FocusMap.ReferenceScale;
                gc.AddElement(element, 0);
                pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pFeature.Shape.Envelope);

                if (pMoveElemFirst == null)
                    return;
                else
                {
                    List<int> LayersToMoveIDs = new List<int>();
                    foreach (string Lay in moveConDetails[idxDet].LayersToMove)
                    {
                        bool FCorLayerTemp = true;
                        pLay = Globals.FindLayer(app, Lay, ref FCorLayerTemp);
                        if (pLay != null)
                        {
                            LayersToMoveIDs.Add(((IFeatureLayer)pLay).FeatureClass.ObjectClassID);

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

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

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

                    // 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 = 4;
                    stepProgressor.StepValue = 1;
                    stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13a");

                    // 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("GeoNetToolsProc_13a");
                    progressDialog2.Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13a");
                    progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral;

                    System.Boolean boolean_Continue = true;

                    stepProgressor.Step();

                    boolean_Continue = trackCancel.Continue();
                    if (!boolean_Continue)
                    {
                        return;
                    }
                    stepProgressor.Step();
                    stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_13b");
                    //ProfileFindPath();
                    pCmdItem = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOffCommand", app);
                    if (pCmdItem != null)
                    {
                        pCmdItem.Execute();
                    }
                    string[] elemInfo = (elementProp = pMoveElemFirst as IElementProperties3).Name.Split(':');

                    pSourceLayer = Globals.FindLayerByClassID(pMxDoc.FocusMap, elemInfo[1]) as IFeatureLayer;
                    pSourceFeature = pSourceLayer.FeatureClass.GetFeature(Convert.ToInt32(elemInfo[2]));
                    pNetworkSourceFeature = (INetworkFeature)pSourceFeature;
                    iTargetEdgeFeat = (IEdgeFeature)pNetworkSourceFeature;
                    iCEdge = (pNetworkSourceFeature) as IComplexEdgeFeature;
                    pOraphFC = pGN.OrphanJunctionFeatureClass;

                    editor.StartOperation();
                    pL = pSourceFeature.ShapeCopy as IPolyline;
                    boolean_Continue = trackCancel.Continue();
                    if (!boolean_Continue)
                    {
                        return;
                    }
                    stepProgressor.Step();
                    stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13b");

                    for (int i = 0; i < iCEdge.JunctionFeatureCount; i++)
                    {
                        pJuncFeat = iCEdge.get_JunctionFeature(i);

                        if ((pJuncFeat as IFeature).Class.ObjectClassID != pOraphFC.ObjectClassID && LayersToMoveIDs.Contains((pJuncFeat as IFeature).Class.ObjectClassID))
                        {

                            if (pL.FromPoint.X == ((pJuncFeat as IFeature).Shape as IPoint).X && pL.FromPoint.Y == ((pJuncFeat as IFeature).Shape as IPoint).Y)
                            {
                                FeatLoc.Add("From");
                            }
                            else if (pL.ToPoint.X == ((pJuncFeat as IFeature).Shape as IPoint).X && pL.ToPoint.Y == ((pJuncFeat as IFeature).Shape as IPoint).Y)
                            {
                                FeatLoc.Add("To");
                            }
                            else
                            {
                                FeatLoc.Add("Along");
                            }

                            OIDs.Add((pJuncFeat as IFeature).OID);
                            FCs.Add((pJuncFeat as IFeature).Class);
                        }
                    }
                    boolean_Continue = trackCancel.Continue();
                    if (!boolean_Continue)
                    {
                        return;
                    }
                    stepProgressor.Step();
                    stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13c");

                    pNetworkSourceFeature.Disconnect();

                    boolean_Continue = trackCancel.Continue();
                    if (!boolean_Continue)
                    {
                        return;
                    }
                    stepProgressor.Step();
                    stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13d");
                    string msg = "";
                    List<IFeature> pM = new List<IFeature>();
                    for (int i = 0; i < OIDs.Count; i++)
                    {
                        pMoveFeat = (FCs[i] as IFeatureClass).GetFeature(OIDs[i]);
                        esriGeometryHitPartType pSearchLoc;
                        if (FeatLoc[i] == "From" || FeatLoc[i] == "To")
                        {
                            pSearchLoc = esriGeometryHitPartType.esriGeometryPartEndpoint;
                        }
                        else
                        {
                            pSearchLoc = esriGeometryHitPartType.esriGeometryPartBoundary;
                        }
                        pHtTest = pFeature.ShapeCopy as IHitTest;
                        bool bHitOne = pHtTest.HitTest(pMoveFeat.Shape as IPoint, 50, pSearchLoc,
                                        pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne);

                        if (bHitOne != false)
                        {
                            if ((pMoveFeat.Shape as IPoint).Z != null && Globals.IsNumeric((pMoveFeat.Shape as IPoint).Z.ToString()))
                                pHitPntOne.Z = (pMoveFeat.Shape as IPoint).Z;

                            pMoveFeat.Shape = pHitPntOne;
                            pM.Add(pMoveFeat);

                            try
                            {
                                pMoveFeat.Store();
                                INetworkFeature netFeature = null;
                                netFeature = pMoveFeat as INetworkFeature;
                                netFeature.Connect();

                            }
                            catch
                            {
                                if (msg == "")
                                {
                                    msg = A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (FCs[i] as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b");

                                }
                                else
                                {
                                    msg = msg + "\n" + A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (FCs[i] as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b");

                                }
                            }

                        }
                    }

                    ////foreach (IFeature pF in pM)
                    ////{
                    ////    try
                    ////    {
                    ////        pF.Store();
                    ////        INetworkFeature netFeature = null;
                    ////        netFeature = pF as INetworkFeature;
                    ////        netFeature.Connect();

                    ////    }
                    ////    catch
                    ////    {
                    ////        if (msg == "")
                    ////        {
                    ////            msg = A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (pF.Class as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b");

                    ////        }
                    ////        else
                    ////        {
                    ////            msg = msg + "\n" + A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (pF.Class as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b");

                    ////        }
                    ////    }

                    ////    if (msg != "")
                    ////    {
                    ////        MessageBox.Show(msg);

                    ////    }
                    ////}
                    //INetworkFeature pNetworkTargetFeature = (INetworkFeature)pFeature;
                    // IFeatureLayer pTargetLayer = Globals.FindLayerByClassID(pMxDoc.FocusMap,pFeature.Class.CLSID.ToString()) as IFeatureLayer;

                    boolean_Continue = trackCancel.Continue();
                    if (!boolean_Continue)
                    {
                        return;
                    }
                    stepProgressor.Step();
                    stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("Complete");

                    try
                    {
                        Globals.RemoveTraceGraphics(pMxDoc.FocusMap, true);
                    }
                    catch
                    { }
                    // unpress the UIToolControl button
                    app.CurrentTool = null;
                    app.RefreshWindow();
                    pMxDoc.ActiveView.Refresh();
                    return;
                }
            }
            catch (Exception ex)
            {
                try
                {
                    editor.AbortOperation();

                }
                catch
                { }

                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13c") + ex.Message);
                return;
            }
            finally
            {
                try
                {
                    editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDone_13a"));
                }
                catch
                { }

                if (progressDialog2 != null)
                    progressDialog2.HideDialog();
                progressDialog2 = null;
                pCmdItem = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOnCommand", app);
                if (pCmdItem != null)
                {
                    pCmdItem.Execute();
                }
                pLay = null;
                statusBar = null;
                animationProgressor = null;
                trackCancel = null;
                progressDialogFactory = null;
                stepProgressor = null;
                progressDialog2 = null;
                pCmdItem = null;

                pMxDoc = null;
                pGN = null;
                pFeature = null;
                pTracePoint = null;
                pSimpleLineSym = null;
                pRGBColor = null;

                gc = null;

                pMoveElemFirst = null;
                pMoveElemPropFirst = null;

                element = null;
                elementProp = null;
                lineElem = null;
                pJuncFeat = null;

                pSourceLayer = null;
                pSourceFeature = null;
                pMoveFeat = null;
                pNetworkSourceFeature = null;
                iTargetEdgeFeat = null;
                iCEdge = null;
                pOraphFC = null;

                OIDs = null;
                FeatLoc = null;
                FCs = null;
                pL = null;

                pHtTest = null;//= pPolyline as IHitTest;

                pHitPntOne = null;
                editor = null;

            }
        }