private double GetValueInterval(string controlName) { double valueInterval = (maxValueInput.Value - minValueInput.Value) / levelInput.Value; if (m_Layer == null || m_Layer.FeatureClass == null || controlName == "minValueInput" || controlName == "maxValueInput") { return(valueInterval); } ESRI.ArcGIS.Geodatabase.ITable pTable = m_Layer.FeatureClass as ESRI.ArcGIS.Geodatabase.ITable; if (pTable.FindField(cmbField.Text) < 0) { return(valueInterval); } ESRI.ArcGIS.Geodatabase.ICursor pCursor = pTable.Search(null, false); ESRI.ArcGIS.Geodatabase.IDataStatistics dataStatistics = new ESRI.ArcGIS.Geodatabase.DataStatisticsClass(); dataStatistics.Field = cmbField.Text; dataStatistics.Cursor = pCursor; ESRI.ArcGIS.esriSystem.IStatisticsResults statisticsResults = dataStatistics.Statistics; valueInterval = (statisticsResults.Maximum - statisticsResults.Minimum) / levelInput.Value; flag = true; minValueInput.Value = statisticsResults.Minimum; maxValueInput.Value = statisticsResults.Maximum; flag = false; System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor); System.Runtime.InteropServices.Marshal.ReleaseComObject(statisticsResults); return(valueInterval); }
/// <summary> /// 删除记录 /// </summary> /// <param name="PFeatureclass"></param> /// <param name="whereClause"></param> public static void DeleteAeFeature(ESRI.ArcGIS.Geodatabase.ITable pTable, string whereClause) { ESRI.ArcGIS.Geodatabase.IQueryFilter pQueryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); pQueryFilter.WhereClause = whereClause; pTable.DeleteSearchedRows(pQueryFilter); System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter); }
/// <summary> /// Gets a list of all strand numbers from a cable that are spliced 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> GetSplicedStrands(FiberCableWrapper cable, bool isFromEnd) { if (null == cable) { throw new ArgumentNullException("cable"); } List <int> result = new List <int>(); using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = TelecomWorkspaceHelper.Instance().FindTable(ConfigUtil.FiberSpliceTableName); // ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = GdbUtils.GetTable(cable.Feature.Class, ConfigUtil.FiberSpliceTableName); ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); filter.WhereClause = string.Format("{0}='{1}' AND {2}='{3}'", ConfigUtil.ACableIdFieldName, cable.IPID, ConfigUtil.IsAFromEndFieldName, (isFromEnd ? "T" : "F")); ESRI.ArcGIS.Geodatabase.ICursor spliceCursor = fiberSpliceTable.Search(filter, true); ESRI.ArcGIS.Geodatabase.IRow spliceRow = spliceCursor.NextRow(); int fiberIdIdx = fiberSpliceTable.FindField(ConfigUtil.AFiberNumberFieldName); while (null != spliceRow) { result.Add((int)spliceRow.get_Value(fiberIdIdx)); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceRow); spliceRow = spliceCursor.NextRow(); } ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceCursor); filter.WhereClause = string.Format("{0}='{1}' AND {2}='{3}'", ConfigUtil.BCableIdFieldName, cable.IPID, ConfigUtil.IsBFromEndFieldName, (isFromEnd ? "T" : "F")); spliceCursor = fiberSpliceTable.Search(filter, true); spliceRow = spliceCursor.NextRow(); fiberIdIdx = fiberSpliceTable.FindField(ConfigUtil.BFiberNumberFieldName); while (null != spliceRow) { result.Add((int)spliceRow.get_Value(fiberIdIdx)); ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceRow); spliceRow = spliceCursor.NextRow(); } ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceCursor); } return(result); }
public static ESRI.ArcGIS.Geodatabase.ICursor obterCursor(ESRI.ArcGIS.Geodatabase.ITable table, string subFields, string whereClause, string order) { ESRI.ArcGIS.Geodatabase.IQueryFilter queryFilter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); queryFilter.SubFields = subFields; queryFilter.WhereClause = whereClause; ESRI.ArcGIS.Geodatabase.IQueryFilterDefinition queryFilterDef = (ESRI.ArcGIS.Geodatabase.IQueryFilterDefinition)queryFilter; queryFilterDef.PostfixClause = order; return(table.Search(queryFilter, true)); }
/// <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> /// Checks the database to see if the splice Type field has a domain; if it does load the choices, otherwise /// enable free text editing on the column /// </summary> /// <param name="helper">Helper class</param> private void LoadTypeDropdown(FiberSpliceHelper helper) { try { ESRI.ArcGIS.Geodatabase.IFeatureClass ftClass = _wkspHelper.FindFeatureClass(ConfigUtil.FiberCableFtClassName); // ESRI.ArcGIS.Geodatabase.IFeatureClass ftClass = helper.FindFeatureClass(ConfigUtil.FiberCableFtClassName); ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = _wkspHelper.FindTable(ConfigUtil.FiberSpliceTableName); // ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = GdbUtils.GetTable(ftClass, ConfigUtil.FiberSpliceTableName); ESRI.ArcGIS.Geodatabase.IField typeField = fiberSpliceTable.Fields.get_Field(fiberSpliceTable.FindField(ConfigUtil.TypeFieldName)); ESRI.ArcGIS.Geodatabase.ICodedValueDomain domain = typeField.Domain as ESRI.ArcGIS.Geodatabase.ICodedValueDomain; if (null != domain) { colType.Items.Clear(); colType.Items.Add(string.Empty); // For DBNull for (int codeIdx = 0; codeIdx < domain.CodeCount; codeIdx++) { colType.Items.Add(domain.get_Name(codeIdx)); } } else { // Change to a text column System.Windows.Forms.DataGridViewTextBoxColumn colTypeText = new DataGridViewTextBoxColumn(); colTypeText.HeaderText = colType.HeaderText; colTypeText.Name = colType.Name; grdSplices.Columns.Remove(colType); grdSplices.Columns.Add(colTypeText); } } catch (Exception e) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Splice Connection Window (LoadTypeDropdown): ", e.Message); } }
/* * 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); }
void OnBeforeRemoveFeature(ISchematicInMemoryFeature inMemoryFeature, ref bool canRemove) { if (State != ESRI.ArcGIS.Desktop.AddIns.ExtensionState.Enabled) { return; } ESRI.ArcGIS.Geodatabase.IDataset esriData = (ESRI.ArcGIS.Geodatabase.IDataset)inMemoryFeature.SchematicDiagram.SchematicDiagramClass.SchematicDataset; // Remove only elements contained in a specific Schematic dataset if (esriData.Name != SampleDatasetName) { return; } // Remove only elements contained in a specific type of diagram if (inMemoryFeature.SchematicDiagram.SchematicDiagramClass.Name != DiagramClassName) { return; } canRemove = false; // can't remove SubStation if (inMemoryFeature.SchematicElementClass.Name == "InsidePlant_SubStation") { return; } ISchematicDiagramClass schemDiagramClass; schemDiagramClass = (ISchematicDiagramClass)inMemoryFeature.SchematicDiagram.SchematicDiagramClass; // For this specific diagram type, we retrieve the datasource // and the tables where the elements are stored ISchematicDataSource schemDataSource = schemDiagramClass.SchematicDataSource; string tableName = ""; switch (inMemoryFeature.SchematicElementClass.SchematicElementType) { case esriSchematicElementType.esriSchematicNodeType: tableName = TableNameNodes; break; case esriSchematicElementType.esriSchematicLinkType: tableName = TableNameLinks; break; case esriSchematicElementType.esriSchematicDrawingType: return; break; } // Retrieve Feature Workspace ESRI.ArcGIS.Geodatabase.IWorkspace esriWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)schemDataSource.Object; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace esriFeatureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)esriWorkspace; // Get Attributes values ISchematicAttributeContainer schemAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass; ISchematicAttributeContainer schemFatherAttribCont = (ISchematicAttributeContainer)inMemoryFeature.SchematicElementClass.Parent; if ((!(schemAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null) || !(schemFatherAttribCont.GetSchematicAttribute(AttributeNameObjectID, false) == null))) { int indField = inMemoryFeature.Fields.FindFieldByAliasName(AttributeNameObjectID); int OID = int.Parse(inMemoryFeature.get_Value(indField).ToString(), System.Globalization.NumberStyles.Integer); //Get table and row ESRI.ArcGIS.Geodatabase.ITable esriTable = esriFeatureWorkspace.OpenTable(tableName); ESRI.ArcGIS.Geodatabase.IRow esriRow = esriTable.GetRow(OID); // When the row is identified in the table, it is deleted and // the CanRemove returns True so that the associated // schematic element is graphically removed from the active diagram if (!(esriRow == null)) { esriRow.Delete(); canRemove = true; } } }
/// <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); }
/// <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> /// Get the existing splice ranges between two cables at an existing closure /// </summary> /// <param name="cableA">One cable</param> /// <param name="cableB">Other cable</param> /// <param name="splice">Splice Closure</param> /// <returns>List of FiberSplice</returns> /// <remarks>Currently only checks A/B as passed, does not check the reverse B/A combination</remarks> public static List <FiberSplice> GetSplicedRanges(FiberCableWrapper cableA, FiberCableWrapper cableB, SpliceClosureWrapper splice) { List <FiberSplice> result = new List <FiberSplice>(); string spliceWhere = string.Format("{0}='{1}' AND {2}='{3}' AND {4}='{5}'", ConfigUtil.ACableIdFieldName, cableA.IPID, ConfigUtil.BCableIdFieldName, cableB.IPID, ConfigUtil.SpliceClosureIpidFieldName, splice.IPID); using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser()) { ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = TelecomWorkspaceHelper.Instance().FindTable(ConfigUtil.FiberSpliceTableName); // ESRI.ArcGIS.Geodatabase.ITable fiberSpliceTable = GdbUtils.GetTable(cableA.Feature.Class, ConfigUtil.FiberSpliceTableName); ESRI.ArcGIS.Geodatabase.IQueryFilter filter = new ESRI.ArcGIS.Geodatabase.QueryFilterClass(); releaser.ManageLifetime(filter); filter.WhereClause = spliceWhere; ((ESRI.ArcGIS.Geodatabase.IQueryFilterDefinition)filter).PostfixClause = string.Format("ORDER BY {0}", ConfigUtil.AFiberNumberFieldName); int aUnitIdx = fiberSpliceTable.FindField(ConfigUtil.AFiberNumberFieldName); int bUnitIdx = fiberSpliceTable.FindField(ConfigUtil.BFiberNumberFieldName); int lossIdx = fiberSpliceTable.FindField(ConfigUtil.LossFieldName); int typeIdx = fiberSpliceTable.FindField(ConfigUtil.TypeFieldName); ESRI.ArcGIS.Geodatabase.IField typeField = fiberSpliceTable.Fields.get_Field(typeIdx); ESRI.ArcGIS.Geodatabase.ICodedValueDomain typeDomain = typeField.Domain as ESRI.ArcGIS.Geodatabase.ICodedValueDomain; ESRI.ArcGIS.Geodatabase.ICursor splices = fiberSpliceTable.Search(filter, true); releaser.ManageLifetime(splices); ESRI.ArcGIS.Geodatabase.IRow spliceRow = splices.NextRow(); int lastAUnit = -1; int lastBUnit = -1; double?lastLoss = null; object lastType = Type.Missing; int aLow = -1; int bLow = -1; while (null != spliceRow) { // These are not-null columns int aUnit = (int)spliceRow.get_Value(aUnitIdx); int bUnit = (int)spliceRow.get_Value(bUnitIdx); object lossObj = spliceRow.get_Value(lossIdx); double?loss = null; if (DBNull.Value != lossObj) { loss = (double)lossObj; } object type = spliceRow.get_Value(typeIdx); if (aUnit != (lastAUnit + 1) || bUnit != (lastBUnit + 1) || loss != lastLoss || !type.Equals(lastType)) { if (-1 != lastAUnit) { string typeString = string.Empty; if (null != typeString) { if (null != typeDomain) { typeString = GdbUtils.GetDomainNameForValue(typeDomain, lastType); } else { typeString = lastType.ToString(); // DBNull.Value will return string.Empty } } result.Add(new FiberSplice(new Range(aLow, lastAUnit), new Range(bLow, lastBUnit), lastLoss, typeString)); } aLow = aUnit; bLow = bUnit; } lastAUnit = aUnit; lastBUnit = bUnit; lastLoss = loss; lastType = type; ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(spliceRow); spliceRow = splices.NextRow(); } if (-1 < aLow) { string typeString = string.Empty; if (null != typeString) { if (null != typeDomain) { typeString = GdbUtils.GetDomainNameForValue(typeDomain, lastType); } else { typeString = lastType.ToString(); // DBNull.Value will return string.Empty } } result.Add(new FiberSplice(new Range(aLow, lastAUnit), new Range(bLow, lastBUnit), lastLoss, typeString)); } } 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); }