/// <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);
        }
        /*
         * 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);
        }
Пример #4
0
        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;
                }
            }
        }
Пример #5
0
 public void Save(ESRI.ArcGIS.Geodatabase.IWorkspace Workspace, ESRI.ArcGIS.Geodatabase.IRow Row, BaseModel BaseModel, ModelProperty Property)
 {
     this.Save(Workspace, BaseModel, Property);
 }
        /// <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);
        }