/// <summary> /// Gets the index of the display field for the feature's layer, if it is on the map /// </summary> /// <param name="feature">IFeature to look for</param> /// <returns>int</returns> //public int GetDisplayIndex(ESRI.ArcGIS.Geodatabase.IFeature feature) //{ // if (null == feature) // { // throw new ArgumentNullException("feature"); // } // else if (null == feature.Class) // { // throw new InvalidOperationException("feature.Class cannot be null"); // } // int result = -1; // int key = feature.Class.ObjectClassID; // if (_displayIndices.ContainsKey(key)) // { // result = _displayIndices[key]; // } // else // { // ESRI.ArcGIS.Geodatabase.IDataset dataset = feature.Class as ESRI.ArcGIS.Geodatabase.IDataset; // if (null != dataset) // { // string className = GdbUtils.ParseTableName(dataset); // ESRI.ArcGIS.Carto.IFeatureLayer ftLayer = this.FindFeatureLayer(className); // if (null != ftLayer) // { // result = feature.Fields.FindField(ftLayer.DisplayField); // } // } // _displayIndices[key] = result; // Putting it here means that we may store -1 even if the layer was undiscoverable // // even one time...we could move it into where result is assigned if we wanted // // it to recheck every time this is called // } // return result; //} /// <summary> /// Creates a new Progress Dialog in the hook, with a given ITrackCancel /// </summary> /// <param name="trackCancel">Tracks cancel</param> /// <param name="message">The message</param> /// <param name="min">Minimum progress</param> /// <param name="max">Maximum progress</param> /// <param name="step">Progress per step</param> /// <param name="desc">Description</param> /// <param name="title">Title</param> /// <returns>IProgressDialog2</returns> public ESRI.ArcGIS.Framework.IProgressDialog2 CreateProgressDialog(ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel, string message, int min, int max, int step, string desc, string title) { int?hWnd = this.hWnd; if (null == hWnd) { throw new InvalidOperationException("Unable to determine hWnd of Hook"); } //ProgressBar ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); // Set the properties of the Step Progressor ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, (int)hWnd); stepProgressor.MinRange = min; stepProgressor.MaxRange = max; stepProgressor.StepValue = step; stepProgressor.Message = message; // 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 = true; progressDialog.Description = desc; progressDialog.Title = title; progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; return(progressDialog); }
public static void ShowProgressDialog(string message, Delegate action, params object[] args) { // Create a CancelTracker ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); // Set the properties of the Step Progressor var int32_hWnd = ArcMap.Application.hWnd; var stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.Hide(); // Create the ProgressDialog. This automatically displays the dialog var progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Set the properties of the ProgressDialog progressDialog2.CancelEnabled = false; progressDialog2.Description = message; progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; progressDialog2.ShowDialog(); progressDialog2.CancelEnabled = false; action.DynamicInvoke(args); progressDialog2.CancelEnabled = false; trackCancel = null; stepProgressor = null; progressDialog2.HideDialog(); progressDialog2 = null; }
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; }
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); }
/// <summary> /// Gets the index of the display field for the feature's layer, if it is on the map /// </summary> /// <param name="feature">IFeature to look for</param> /// <returns>int</returns> //public int GetDisplayIndex(ESRI.ArcGIS.Geodatabase.IFeature feature) //{ // if (null == feature) // { // throw new ArgumentNullException("feature"); // } // else if (null == feature.Class) // { // throw new InvalidOperationException("feature.Class cannot be null"); // } // int result = -1; // int key = feature.Class.ObjectClassID; // if (_displayIndices.ContainsKey(key)) // { // result = _displayIndices[key]; // } // else // { // ESRI.ArcGIS.Geodatabase.IDataset dataset = feature.Class as ESRI.ArcGIS.Geodatabase.IDataset; // if (null != dataset) // { // string className = GdbUtils.ParseTableName(dataset); // ESRI.ArcGIS.Carto.IFeatureLayer ftLayer = this.FindFeatureLayer(className); // if (null != ftLayer) // { // result = feature.Fields.FindField(ftLayer.DisplayField); // } // } // _displayIndices[key] = result; // Putting it here means that we may store -1 even if the layer was undiscoverable // // even one time...we could move it into where result is assigned if we wanted // // it to recheck every time this is called // } // return result; //} /// <summary> /// Creates a new Progress Dialog in the hook, with a given ITrackCancel /// </summary> /// <param name="trackCancel">Tracks cancel</param> /// <param name="message">The message</param> /// <param name="min">Minimum progress</param> /// <param name="max">Maximum progress</param> /// <param name="step">Progress per step</param> /// <param name="desc">Description</param> /// <param name="title">Title</param> /// <returns>IProgressDialog2</returns> public ESRI.ArcGIS.Framework.IProgressDialog2 CreateProgressDialog(ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel, string message, int min, int max, int step, string desc, string title) { int? hWnd = this.hWnd; if (null == hWnd) { throw new InvalidOperationException("Unable to determine hWnd of Hook"); } //ProgressBar ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); // Set the properties of the Step Progressor ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, (int)hWnd); stepProgressor.MinRange = min; stepProgressor.MaxRange = max; stepProgressor.StepValue = step; stepProgressor.Message = message; // 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 = true; progressDialog.Description = desc; progressDialog.Title = title; progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; return progressDialog; }