/// <summary> /// Gets a list of all port numbers from a device that are not connected on the given end /// </summary> /// <param name="device">Device to check</param> /// <param name="portType">Check input or output ports</param> /// <returns>List of int</returns> private static List <int> GetOpenPorts(DeviceWrapper device, PortType portType) { #region Validation if (null == device) { throw new ArgumentNullException("device"); } if (null == device.Feature) { throw new ArgumentException("device.Class cannot be null"); } #endregion List <int> result = new List <int>(); using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IFeatureClass deviceFtClass = device.Feature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass; ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship(deviceFtClass); if (null != deviceHasPorts) { ESRI.ArcGIS.Geodatabase.ITable portTable = deviceHasPorts.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable; if (null != portTable) { ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); filter.WhereClause = string.Format("{0}='{1}' AND {2} IS NULL AND {3}='{4}'", deviceHasPorts.OriginForeignKey, device.Feature.get_Value(deviceFtClass.FindField(deviceHasPorts.OriginPrimaryKey)), ConfigUtil.ConnectedCableFieldName, ConfigUtil.PortTypeFieldName, (PortType.Input == portType ? "1" : "2")); ESRI.ArcGIS.Geodatabase.ICursor portCursor = portTable.Search(filter, true); ESRI.ArcGIS.Geodatabase.IRow portRow = portCursor.NextRow(); int portIdIdx = portTable.FindField(ConfigUtil.PortIdFieldName); while (null != portRow) { result.Add((int)portRow.get_Value(portIdIdx)); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(portRow); portRow = portCursor.NextRow(); } ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(portCursor); } } } return(result); }
/// <summary> /// Returns the device class related to a given port table /// </summary> /// <param name="deviceClassName">Port Table</param> /// <returns>IFeatureClass</returns> public static ESRI.ArcGIS.Geodatabase.IFeatureClass GetDeviceClass(ESRI.ArcGIS.Geodatabase.ITable portTable) { if (null == portTable) { throw new ArgumentNullException("portTable"); } ESRI.ArcGIS.Geodatabase.IRelationshipClass relationshipClass = GetDeviceRelationship(portTable); if (null == relationshipClass) { throw new Exception("Could not find port relationship class."); } ESRI.ArcGIS.Geodatabase.IFeatureClass result = relationshipClass.OriginClass as ESRI.ArcGIS.Geodatabase.IFeatureClass; if (null == result) { throw new Exception("OriginClass from port relationship null or does not implement ITable."); } return(result); }
/// <summary> /// Returns the port table related to a given device feature class /// </summary> /// <param name="deviceClassName">Device class</param> /// <returns>ITable</returns> public static ESRI.ArcGIS.Geodatabase.ITable GetPortTable(ESRI.ArcGIS.Geodatabase.IFeatureClass deviceFtClass) { if (null == deviceFtClass) { throw new ArgumentNullException("deviceFtClass"); } ESRI.ArcGIS.Geodatabase.IRelationshipClass relationshipClass = GetPortRelationship(deviceFtClass); if (null == relationshipClass) { throw new Exception("Could not find port relationship class."); } ESRI.ArcGIS.Geodatabase.ITable result = relationshipClass.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable; if (null == result) { throw new Exception("DestinationClass from port relationship null or does not implement ITable."); } return(result); }
/// <summary> /// Finds the Device to Port relationship class for a given port table /// </summary> /// <param name="deviceClass">port table</param> /// <returns>ESRI.ArcGIS.Geodatabase.IRelationshipClass</returns> public static ESRI.ArcGIS.Geodatabase.IRelationshipClass GetDeviceRelationship(ESRI.ArcGIS.Geodatabase.ITable portTable) { // TODO: Currently returns the first relationship class found whose name ends with "Ports". Should probably make the relationship classes part of the configuration ESRI.ArcGIS.Geodatabase.IRelationshipClass result = null; if (null == portTable) { throw new ArgumentNullException("portTable"); } using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IEnumRelationshipClass relClasses = ((ESRI.ArcGIS.Geodatabase.IObjectClass)portTable).get_RelationshipClasses(ESRI.ArcGIS.Geodatabase.esriRelRole.esriRelRoleDestination); releaser.ManageLifetime(relClasses); relClasses.Reset(); result = relClasses.Next(); while (null != result) { ESRI.ArcGIS.Geodatabase.IDataset relationshipDataset = result as ESRI.ArcGIS.Geodatabase.IDataset; if (relationshipDataset.Name.EndsWith("Ports", StringComparison.CurrentCultureIgnoreCase)) { break; } result = relClasses.Next(); } } if (null == result) { throw new Exception("Relationship class from device to port was not found."); } return(result); }
/* * private String fiberOrBufferColorLookup(int number) * { * switch (number) * { * case 1: * return "Blue"; * case 2: * return "Orange"; * case 3: * return "Green"; * case 4: * return "Brown"; * case 5: * return "Slate"; * case 6: * return "White"; * case 7: * return "Red"; * case 8: * return "Black"; * case 9: * return "Yellow"; * case 10: * return "Violet"; * case 11: * return "Rose"; * case 12: * return "Aqua"; * default: * return string.Empty; * } * } */ /// <summary> /// Generates a number of buffer tubes and fiber records for a fiber cable, given a configuration. /// </summary> /// <param name="feature">IFeature to generate for</param> /// <param name="configuration">Specification of buffer and fiber counts</param> /// <param name="progressDialog">Progress dialog for user notification</param> /// <param name="trackCancel">TrackCancel used in the progress dialog</param> /// <returns>Success</returns> private bool GenerateUnits(ESRI.ArcGIS.Geodatabase.IFeature feature, FiberCableConfiguration configuration, ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog, ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel) { bool isComplete = false; bool isCancelled = false; Guid g; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = (ESRI.ArcGIS.esriSystem.IStepProgressor)progressDialog; ESRI.ArcGIS.Geodatabase.IObjectClass ftClass = feature.Class; using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IRelationshipClass cableHasBuffer = GdbUtils.GetRelationshipClass(ftClass, ConfigUtil.FiberCableToBufferRelClassName); releaser.ManageLifetime(cableHasBuffer); ESRI.ArcGIS.Geodatabase.IRelationshipClass cableHasFiber = GdbUtils.GetRelationshipClass(ftClass, ConfigUtil.FiberCableToFiberRelClassName); releaser.ManageLifetime(cableHasFiber); ESRI.ArcGIS.Geodatabase.IRelationshipClass bufferHasFiber = GdbUtils.GetRelationshipClass(ftClass, ConfigUtil.BufferToFiberRelClassName); releaser.ManageLifetime(bufferHasFiber); ESRI.ArcGIS.Geodatabase.ITable bufferTable = cableHasBuffer.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable; ESRI.ArcGIS.Geodatabase.ITable fiberTable = cableHasFiber.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable; // Fields to populate on buffer int bufferIpidIdx = bufferTable.Fields.FindField(ConfigUtil.IpidFieldName); int fiberCountIdx = bufferTable.Fields.FindField(ConfigUtil.NumberOfFibersFieldName); int bufferToCableIdx = bufferTable.Fields.FindField(cableHasBuffer.OriginForeignKey); object bufferToCableValue = feature.get_Value(feature.Fields.FindField(cableHasBuffer.OriginPrimaryKey)); // Fields to populate on fiber int fiberIpidIdx = fiberTable.Fields.FindField(ConfigUtil.IpidFieldName); int fiberNumberIdx = fiberTable.Fields.FindField(ConfigUtil.Fiber_NumberFieldName); int fiberColorIdx = fiberTable.Fields.FindField(ConfigUtil.Fiber_ColorFieldName); int fiberToCableIdx = fiberTable.Fields.FindField(cableHasFiber.OriginForeignKey); object fiberToCableValue = feature.get_Value(feature.Fields.FindField(cableHasFiber.OriginPrimaryKey)); int fiberToBufferIdx = fiberTable.Fields.FindField(bufferHasFiber.OriginForeignKey); int fiberToBufferValueIdx = bufferTable.Fields.FindField(bufferHasFiber.OriginPrimaryKey); // Research using InsertCursor for speed. int fiberNumber = 0; for (int bufferIdx = 1; bufferIdx <= configuration.BufferCount; bufferIdx++) { g = Guid.NewGuid(); string bufferId = g.ToString("B").ToUpper(); ESRI.ArcGIS.Geodatabase.IRow row = bufferTable.CreateRow(); releaser.ManageLifetime(row); row.set_Value(bufferIpidIdx, bufferId); row.set_Value(fiberCountIdx, configuration.FibersPerTube); row.set_Value(bufferToCableIdx, bufferToCableValue); row.Store(); object fiberToBufferValue = row.get_Value(fiberToBufferValueIdx); // Research using InsertCursor for speed. for (int fiberIdx = 1; fiberIdx <= configuration.FibersPerTube; fiberIdx++) { fiberNumber++; progressDialog.Description = string.Format("Creating fiber {0} of {1}", fiberNumber, configuration.TotalFiberCount); stepProgressor.Step(); g = Guid.NewGuid(); ESRI.ArcGIS.Geodatabase.IRow fiberRow = fiberTable.CreateRow(); releaser.ManageLifetime(fiberRow); fiberRow.set_Value(fiberIpidIdx, g.ToString("B").ToUpper()); fiberRow.set_Value(fiberNumberIdx, fiberNumber); // Dangerous if coded values are altered but while // domain type is int Rather than string coded, this // is quickest way to add this // Dont do for fiber groupings of more than 12 if (configuration.FibersPerTube <= 12) { fiberRow.set_Value(fiberColorIdx, fiberIdx); } fiberRow.set_Value(fiberToBufferIdx, fiberToBufferValue); fiberRow.set_Value(fiberToCableIdx, fiberToCableValue); fiberRow.Store(); if (!trackCancel.Continue()) { isCancelled = true; break; } } if (!trackCancel.Continue()) { isCancelled = true; break; } } if (!isCancelled) { isComplete = true; } } return(isComplete); }
/// <summary> /// Gets a list of all strand numbers from a cable that are connected on the given end /// </summary> /// <param name="cable">Cable to check</param> /// <param name="isFromEnd">True to check from end, False to check to end</param> /// <returns>List of int</returns> private static List <int> GetConnectedStrands(FiberCableWrapper cable, bool isFromEnd) { #region Validation if (null == cable) { throw new ArgumentNullException("cable"); } #endregion List <int> result = new List <int>(); using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = cable.Feature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass; string[] deviceClassNames = ConfigUtil.DeviceFeatureClassNames; for (int i = 0; i < deviceClassNames.Length; i++) { string deviceClassName = deviceClassNames[i]; ESRI.ArcGIS.Geodatabase.IFeatureClass deviceFtClass = TelecomWorkspaceHelper.Instance().FindFeatureClass(deviceClassName); // ESRI.ArcGIS.Geodatabase.IFeatureClass deviceFtClass = GdbUtils.GetFeatureClass(cableFtClass, deviceClassName); if (null != deviceFtClass) { ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship(deviceFtClass); if (null != deviceHasPorts) { ESRI.ArcGIS.Geodatabase.ITable portTable = deviceHasPorts.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable; if (null != portTable) { ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); filter.WhereClause = string.Format("{0}='{1}' AND {2}='{3}' AND {4} IS NOT NULL", ConfigUtil.ConnectedCableFieldName, cable.IPID, ConfigUtil.ConnectedEndFieldName, (isFromEnd ? "T" : "F"), ConfigUtil.ConnectedFiberFieldName); ESRI.ArcGIS.Geodatabase.ICursor portCursor = portTable.Search(filter, true); ESRI.ArcGIS.Geodatabase.IRow portRow = portCursor.NextRow(); int fiberIdIdx = portTable.FindField(ConfigUtil.ConnectedFiberFieldName); while (null != portRow) { result.Add((int)portRow.get_Value(fiberIdIdx)); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(portRow); portRow = portCursor.NextRow(); } ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(portCursor); } } } } } return(result); }
/// <summary> /// Determines if all the ranges fall between 1 to port count /// </summary> /// <param name="ranges">Ranges to check</param> /// <param name="device">Device to check on</param> /// <param name="portType">Port type</param> /// <returns>True if valid ranges</returns> public static bool AreRangesWithinPortCount(List <Range> ranges, DeviceWrapper device, PortType portType) { bool result = false; // Default to false in case we can't even find the port relationship class #region Validation if (null == ranges) { throw new ArgumentNullException("ranges"); } if (null == device) { throw new ArgumentNullException("device"); } #endregion ESRI.ArcGIS.Geodatabase.IFeatureClass ftClass = device.Feature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass; if (null != ftClass) { using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.IRelationshipClass deviceHasPorts = ConfigUtil.GetPortRelationship(ftClass); if (null != deviceHasPorts) { ESRI.ArcGIS.Geodatabase.ITable portTable = deviceHasPorts.DestinationClass as ESRI.ArcGIS.Geodatabase.ITable; int portIdIdx = portTable.FindField(ConfigUtil.PortIdFieldName); if (-1 < portIdIdx) { result = true; // Now that we have the ports, assume we're ok until we find a problem ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); filter.SubFields = ConfigUtil.PortIdFieldName; filter.WhereClause = string.Format("{0}='{1}' AND {2}='{3}' AND {4} IS NOT NULL", deviceHasPorts.OriginForeignKey, device.Feature.get_Value(ftClass.FindField(deviceHasPorts.OriginPrimaryKey)), ConfigUtil.PortTypeFieldName, PortType.Input == portType ? 1 : 2, ConfigUtil.PortIdFieldName); ((ESRI.ArcGIS.Geodatabase.IQueryFilterDefinition)filter).PostfixClause = string.Format("ORDER BY {0}", ConfigUtil.PortIdFieldName); ESRI.ArcGIS.Geodatabase.ICursor cursor = portTable.Search(filter, true); releaser.ManageLifetime(cursor); int minPort = int.MinValue; int maxPort = int.MaxValue; ESRI.ArcGIS.Geodatabase.IRow row = cursor.NextRow(); if (null != row) { minPort = (int)row.get_Value(portIdIdx); while (null != row) { maxPort = (int)row.get_Value(portIdIdx); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(row); row = cursor.NextRow(); } } foreach (Range r in ranges) { if (r.High > maxPort || minPort > r.Low) { result = false; break; } } } } } } return(result); }