private void btnSelect_Click(object sender, EventArgs e) { ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null; ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = null; // Create a CancelTracker ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = null; ISpatialFilter pSpatFilt = null; IFeatureLayer pFL = null; IFeatureCursor pFCurs = null; IFeature pFeat = null; ISimpleJunctionFeature pSimpFeat = null; // Create an edit operation enabling undo/redo try { (_app.Document as IMxDocument).FocusMap.ClearSelection(); trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); // Set the properties of the Step Progressor System.Int32 int32_hWnd = _app.hWnd; progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.MinRange = 0; stepProgressor.MaxRange = lstJunctionLayers.Items.Count; stepProgressor.StepValue = 1; stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("SltByJctCountProc_1"); // Create the ProgressDialog. This automatically displays the dialog progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog.CancelEnabled = true; progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("SltByJctCountProc_1"); progressDialog.Title = A4LGSharedFunctions.Localizer.GetString("SltByJctCountProc_1"); progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; progressDialog.ShowDialog(); for (int i = 0; i < lstJunctionLayers.Items.Count; i++) { bool boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { return; } progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("SltByJctCountProc_2") + lstJunctionLayers.Items[i].ToString(); if (lstJunctionLayers.GetItemCheckState(i) == CheckState.Checked) { bool FCorLayer = true; pFL = (IFeatureLayer)Globals.FindLayer(_app, lstJunctionLayers.Items[i].ToString(), ref FCorLayer); if (pFL != null) { pSpatFilt = new SpatialFilterClass(); pSpatFilt.Geometry = _env as IGeometry; pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatFilt.GeometryField = pFL.FeatureClass.ShapeFieldName; int featCnt = pFL.FeatureClass.FeatureCount(pSpatFilt); if (featCnt > 0) { pFCurs = pFL.Search(pSpatFilt, true); pFeat = pFCurs.NextFeature(); int loopCnt = 1; while (pFeat != null) { boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { return; } stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("SltByJctCountProc_3") + loopCnt + A4LGSharedFunctions.Localizer.GetString("Of") + featCnt; if (pFeat is SimpleJunctionFeature) { pSimpFeat = (ISimpleJunctionFeature)pFeat; if (pSimpFeat.EdgeFeatureCount >= numMinEdge.Value && pSimpFeat.EdgeFeatureCount <= numMaxEdge.Value) { (_app.Document as IMxDocument).FocusMap.SelectFeature(pFL as ILayer, pFeat); } } loopCnt++; pFeat = pFCurs.NextFeature(); } } } } stepProgressor.Step(); } } catch (Exception Ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("SltByJctCountLbl_22") + "\r\n" + Ex.Message); } finally { if (progressDialog != null) { progressDialog.HideDialog(); } progressDialogFactory = null; stepProgressor = null; progressDialog = null; trackCancel = null; pSpatFilt = null; pFL = null; if (pFCurs != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(pFCurs); } pFCurs = null; pFeat = null; pSimpFeat = null; this.Hide(); (_app.Document as IMxDocument).ActiveView.Refresh(); MessageBox.Show((_app.Document as IMxDocument).FocusMap.SelectionCount + A4LGSharedFunctions.Localizer.GetString("SltByJctCountMess_1")); } }
private bool RemoveFiberCableConfigDomains(IWorkspace wksp) { bool result = true; if (wksp == null || ((wksp as IWorkspaceDomains3) == null)) { return(false); } try { // get Handles to everything we need first or bail. IFeatureClass cableFc = FindFeatureClass(ConfigUtil.FiberCableFtClassName); if (cableFc == null) { return(false); } ISubtypes subs = cableFc as ISubtypes; if (subs == null) { return(false); } IClassSchemaEdit4 schEdit = cableFc as IClassSchemaEdit4; if (schEdit == null) { return(false); } // ---------------------------------------------------- // First we have to unassign the domains from the FC fields // ---------------------------------------------------- schEdit.AlterDomain(ConfigUtil.NumberOfFibersFieldName, null); schEdit.AlterDomain(ConfigUtil.NumberOfBuffersFieldName, null); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Unassigned FiberCable domains", "NumberOfFibers + NumberOfBuffers"); // ---------------------------------------------------- // Also have to remove domain from the subtypes (arghh) // 1 & 2 are overhead and underground. // ---------------------------------------------------- IEnumSubtype types = subs.Subtypes; subs.set_Domain(1, ConfigUtil.NumberOfFibersFieldName, null); subs.set_Domain(2, ConfigUtil.NumberOfFibersFieldName, null); subs.set_Domain(1, ConfigUtil.NumberOfBuffersFieldName, null); subs.set_Domain(2, ConfigUtil.NumberOfBuffersFieldName, null); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Removed FiberCable subtype domains", "NumberOfFibers + NumberOfBuffers"); // ---------------------------------------------------- // Now we can remove the domains // ---------------------------------------------------- IWorkspaceDomains3 wkspDomains = wksp as IWorkspaceDomains3; if (wkspDomains.get_CanDeleteDomain("NumberOfFibers") && wkspDomains.get_CanDeleteDomain("NumberOfBuffers")) { wkspDomains.DeleteDomain("NumberOfFibers"); wkspDomains.DeleteDomain("NumberOfBuffers"); MessageBox.Show("Domains successfully deleted"); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Domains successfully deleted", "NumberOfFibers + NumberOfBuffers"); } else { MessageBox.Show("Upgrade failed. \nCould not get exclusive access to this database. \nPLEASE RESTORE FROM YOUR BACKUP"); _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Cannot delete domains.", "Non-Exclusive access?"); return(false); } // ---------------------------------------------------- // Recalculate the fields based on the count of actual // related objects found. We'll use this code later // for integrity checking. // ---------------------------------------------------- IRelationshipClass bufferRelationship = GdbUtils.GetRelationshipClass(cableFc, ConfigUtil.FiberCableToBufferRelClassName); IRelationshipClass strandRelationship = GdbUtils.GetRelationshipClass(cableFc, ConfigUtil.FiberCableToFiberRelClassName); IFeature ft; int bufferIdx = cableFc.Fields.FindField(ConfigUtil.NumberOfBuffersFieldName); int strandIdx = cableFc.Fields.FindField(ConfigUtil.NumberOfFibersFieldName); if (bufferIdx == -1 || strandIdx == -1) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Cannot find buffer or strand fields.", ConfigUtil.NumberOfBuffersFieldName + " " + ConfigUtil.NumberOfFibersFieldName); MessageBox.Show("Upgrade failed. \nCould not find appropriate fields based on current config settings. \nPLEASE RESTORE FROM YOUR BACKUP."); return(false); } _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Recalculating buffer and strand counts..."); // Start edit session do the updates.... ArcMap.Editor.StartEditing(wksp); IFeatureCursor cables = cableFc.Update(null, false); int count = cableFc.FeatureCount(null); //ProgressBar ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); // Set the properties of the Step Progressor ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, ArcMap.Application.hWnd); stepProgressor.MinRange = 1; stepProgressor.MaxRange = count; stepProgressor.StepValue = 1; stepProgressor.Message = "Updating cable config for " + count + " cables"; // Create the ProgressDialog. This automatically displays the dialog ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog.CancelEnabled = false; progressDialog.Description = ""; progressDialog.Title = "Workspace Upgrade"; progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; progressDialog.ShowDialog(); int i = 1; while ((ft = cables.NextFeature()) != null) { progressDialog.Description = string.Format("Updating cable {0} of {1}", i, count); stepProgressor.Step(); ISet buffers = bufferRelationship.GetObjectsRelatedToObject(ft); ft.set_Value(bufferIdx, buffers.Count); ISet strands = strandRelationship.GetObjectsRelatedToObject(ft); ft.set_Value(strandIdx, strands.Count); ft.Store(); i++; } progressDialog.HideDialog(); ArcMap.Editor.StopEditing(true); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Upgrade Completed Successfully."); MessageBox.Show("Upgrade Completed Successfully."); } catch (Exception e) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "RemoveFiberCableConfigDomains", e.Message); result = false; } return(result); }