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> /// 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); }
/// <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> /// 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); }