Beispiel #1
0
        public override void Errors(List <Error> list, EsriTable table)
        {
            // Write Base Errors
            base.Errors(list, table);

            // Get Topology
            Topology topology = (Topology)table;

            // Check for duplicate rules
            bool duplicate = false;

            foreach (TopologyRule topologyRule in topology.TopologyRules)
            {
                if (topologyRule == this)
                {
                    continue;
                }
                if (this._allOriginSubtypes == topologyRule.AllOriginSubtypes &&
                    this._originClassId == topologyRule.OriginClassId &&
                    this._originSubtype == topologyRule.OriginSubtype &&
                    this._allDestinationSubtypes == topologyRule.AllDestinationSubtypes &&
                    this._destinationClassId == topologyRule.DestinationClassId &&
                    this._destinationSubtype == topologyRule.DestinationSubtype &&
                    this._topologyRuleType == topologyRule.TopologyRuleType)
                {
                    duplicate = true;
                    break;
                }
            }
            if (duplicate)
            {
                string message = string.Format("Duplicate topology rules found");
                list.Add(new ErrorObject(this, table, message, ErrorType.Error));
            }

            // Duplicate Guids
            bool duplicateGuid = false;

            foreach (TopologyRule topologyRule in topology.TopologyRules)
            {
                if (topologyRule == this)
                {
                    continue;
                }
                if (this._guid == topologyRule.Guid)
                {
                    duplicateGuid = true;
                    break;
                }
            }
            if (duplicateGuid)
            {
                string message = string.Format("Topology Rule Guid [{0}] is not unique", this._guid);
                list.Add(new ErrorObject(this, table, message, ErrorType.Error));
            }

            // Check if rule conflict with rules using "All Subtypes" - Origin
            if (this._allOriginSubtypes)
            {
                bool originSubtypeConflict = false;
                foreach (TopologyRule topologyRule in topology.TopologyRules)
                {
                    if (topologyRule == this)
                    {
                        continue;
                    }
                    if (topologyRule.AllOriginSubtypes == false &&
                        this._originClassId == topologyRule.OriginClassId &&
                        this._allDestinationSubtypes == topologyRule.AllDestinationSubtypes &&
                        this._destinationClassId == topologyRule.DestinationClassId &&
                        this._destinationSubtype == topologyRule.DestinationSubtype &&
                        this._topologyRuleType == topologyRule.TopologyRuleType)
                    {
                        originSubtypeConflict = true;
                        break;
                    }
                }
                if (originSubtypeConflict)
                {
                    string message = string.Format("The Topology Rule [{0}] with an Origin 'AllSubtypes' setting conflicts another rule", this._guid);
                    list.Add(new ErrorObject(this, table, message, ErrorType.Error));
                }
            }

            // Check if rule conflict with rules using "All Subtypes" - Destination
            if (this._allDestinationSubtypes)
            {
                bool destinationSubtypeConflict = false;
                foreach (TopologyRule topologyRule in topology.TopologyRules)
                {
                    if (topologyRule == this)
                    {
                        continue;
                    }
                    if (topologyRule.AllDestinationSubtypes == false &&
                        this._destinationClassId == topologyRule.DestinationClassId &&
                        this._allOriginSubtypes == topologyRule.AllOriginSubtypes &&
                        this._originClassId == topologyRule.OriginClassId &&
                        this._originSubtype == topologyRule.OriginSubtype &&
                        this._topologyRuleType == topologyRule.TopologyRuleType)
                    {
                        destinationSubtypeConflict = true;
                        break;
                    }
                }
                if (destinationSubtypeConflict)
                {
                    string message = string.Format("The Topology Rule [{0}] with an Destination 'AllSubtypes' setting conflicts another rule", this._guid);
                    list.Add(new ErrorObject(this, table, message, ErrorType.Error));
                }
            }

            // Valid rules for Origin/Destination Shape Types
            DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default;
            SchemaModel           schemaModel           = diagrammerEnvironment.SchemaModel;

            // Get Origin and Destination FeatureClasses
            ObjectClass objectClassOrig = schemaModel.FindObjectClass(this._originClassId);
            ObjectClass objectClassDest = schemaModel.FindObjectClass(this._destinationClassId);

            // Check if Origin and Destination ObjectClasses Exist
            if (objectClassOrig == null)
            {
                list.Add(new ErrorObject(this, table, "Origin FeatureClass Does Not Exist", ErrorType.Error));
            }
            if (objectClassDest == null)
            {
                list.Add(new ErrorObject(this, table, "Destination FeatureClass Does Not Exist", ErrorType.Error));
            }

            // Check if Origin and Destination Subypes Exist
            EsriTable tableOrig = schemaModel.FindObjectClassOrSubtype(this._originClassId, this._originSubtype);
            EsriTable tableDest = schemaModel.FindObjectClassOrSubtype(this._destinationClassId, this._destinationSubtype);

            if (tableOrig == null)
            {
                list.Add(new ErrorObject(this, table, "Origin FeatureClass and/or Subtype Does Not Exist", ErrorType.Error));
            }
            if (tableDest == null)
            {
                list.Add(new ErrorObject(this, table, "Destination FeatureClass and/or Subtype Does Not Exist", ErrorType.Error));
            }

            // Get Origin and Destination FeatureClasses
            FeatureClass featureClassOrig = objectClassOrig as FeatureClass;
            FeatureClass featureClassDest = objectClassDest as FeatureClass;

            // These rules MUST have the same origin and destination class/subtype
            if (featureClassOrig != null && featureClassDest != null && tableOrig != null && tableDest != null)
            {
                switch (this._topologyRuleType)
                {
                case esriTopologyRuleType.esriTRTLineNoOverlap:
                case esriTopologyRuleType.esriTRTLineNoIntersection:
                case esriTopologyRuleType.esriTRTLineNoDangles:
                case esriTopologyRuleType.esriTRTLineNoPseudos:
                case esriTopologyRuleType.esriTRTLineNoSelfOverlap:
                case esriTopologyRuleType.esriTRTLineNoSelfIntersect:
                case esriTopologyRuleType.esriTRTLineNoIntersectOrInteriorTouch:
                case esriTopologyRuleType.esriTRTLineNoMultipart:
                case esriTopologyRuleType.esriTRTAreaNoGaps:
                case esriTopologyRuleType.esriTRTAreaNoOverlap:
                    if (this._originClassId != this._destinationClassId ||
                        this._originSubtype != this._destinationSubtype)
                    {
                        list.Add(new ErrorObject(this, table, "This rule must have the same origin and destination FeatureClass and Subtype", ErrorType.Error));
                    }
                    break;

                default:
                    break;
                }
            }

            // Examine Rule Based on Origin and Destination GeometryType
            bool ok = false;

            if (featureClassOrig != null && featureClassDest != null)
            {
                switch (featureClassOrig.ShapeType)
                {
                case esriGeometryType.esriGeometryPoint:
                    switch (featureClassDest.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPoint:
                        // POINT > POINT
                        switch (this._topologyRuleType)
                        {
                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolyline:
                        // POINT > POLYLINE
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTPointCoveredByLine:
                        case esriTopologyRuleType.esriTRTPointCoveredByLineEndpoint:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolygon:
                        // POINT > POLYGON
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTPointCoveredByAreaBoundary:
                        case esriTopologyRuleType.esriTRTPointProperlyInsideArea:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;
                    }
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    switch (featureClassDest.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPoint:
                        // POLYLINE > POINT
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTLineEndpointCoveredByPoint:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolyline:
                        // POLYLINE > POLYLINE
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTLineNoOverlap:
                        case esriTopologyRuleType.esriTRTLineNoIntersection:
                        case esriTopologyRuleType.esriTRTLineNoDangles:
                        case esriTopologyRuleType.esriTRTLineNoPseudos:
                        case esriTopologyRuleType.esriTRTLineCoveredByLineClass:
                        case esriTopologyRuleType.esriTRTLineNoOverlapLine:
                        case esriTopologyRuleType.esriTRTLineNoSelfOverlap:
                        case esriTopologyRuleType.esriTRTLineNoSelfIntersect:
                        case esriTopologyRuleType.esriTRTLineNoIntersectOrInteriorTouch:
                        case esriTopologyRuleType.esriTRTLineNoMultipart:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolygon:
                        // POLYLINE > POLYGON
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTLineCoveredByAreaBoundary:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                    switch (featureClassDest.ShapeType)
                    {
                    case esriGeometryType.esriGeometryPoint:
                        // POLYGON > POINT
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTAreaContainPoint:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolyline:
                        // POLYGON > POLYLINE
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTAreaBoundaryCoveredByLine:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;

                    case esriGeometryType.esriGeometryPolygon:
                        // POLYGON > POLYGON
                        switch (this._topologyRuleType)
                        {
                        case esriTopologyRuleType.esriTRTAreaNoGaps:
                        case esriTopologyRuleType.esriTRTAreaNoOverlap:
                        case esriTopologyRuleType.esriTRTAreaCoveredByAreaClass:
                        case esriTopologyRuleType.esriTRTAreaAreaCoverEachOther:
                        case esriTopologyRuleType.esriTRTAreaCoveredByArea:
                        case esriTopologyRuleType.esriTRTAreaNoOverlapArea:
                        case esriTopologyRuleType.esriTRTAreaBoundaryCoveredByAreaBoundary:
                            ok = true;
                            break;

                        default:
                            ok = false;
                            break;
                        }
                        break;
                    }
                    break;
                }
            }
            if (!ok)
            {
                list.Add(new ErrorObject(this, table, "This rule cannot be added between these FeatureClass geometric types", ErrorType.Error));
            }
        }
        public override void Errors(List <Error> list)
        {
            // Field Name Null or Empty
            if (string.IsNullOrEmpty(this._fieldName))
            {
                list.Add(new ErrorTableRow(this, "Subtype Field names cannot be empty", ErrorType.Error));
            }

            // Get DiagrammerEnvironment Singleton
            DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default;
            SchemaModel           schemaModel           = diagrammerEnvironment.SchemaModel;

            // Get Subtype
            Subtype subtype = (Subtype)this.Table;

            // Get ObjectClass
            ObjectClass objectClass = subtype.GetParent();

            if (objectClass == null)
            {
                // This error is handled by the Subtype class
                return;
            }

            // Get Field
            Field field = objectClass.FindField(this._fieldName);

            if (field == null)
            {
                // Field is missing in parent ObjectClass
                string message = string.Format("The subtype field [{0}] does not exist in the parent objectclass", this._fieldName);
                list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                return;
            }

            // Warning if parent default value and domain are identical
            if (this._defaultValue == field.DefaultValue &&
                this._domainName == field.Domain)
            {
                string message = string.Format("The default values and domain for the subtype field [{0}] are identical to those in the parent objectclass", this._fieldName);
                list.Add(new ErrorTableRow(this, message, ErrorType.Warning));
            }

            // Field can only be small int, long in, single, double, text, date, guid
            switch (field.FieldType)
            {
            case esriFieldType.esriFieldTypeDate:
            case esriFieldType.esriFieldTypeDouble:
            case esriFieldType.esriFieldTypeGUID:
            case esriFieldType.esriFieldTypeInteger:
            case esriFieldType.esriFieldTypeSingle:
            case esriFieldType.esriFieldTypeSmallInteger:
            case esriFieldType.esriFieldTypeString:
                // OK
                break;

            case esriFieldType.esriFieldTypeRaster:
            case esriFieldType.esriFieldTypeBlob:
            case esriFieldType.esriFieldTypeGeometry:
            case esriFieldType.esriFieldTypeOID:
            case esriFieldType.esriFieldTypeGlobalID:
            case esriFieldType.esriFieldTypeXML:
                string message = string.Format("The subtype field [{0}] must use a field of type Date, Double, Guid, Integer, Single, SmallInteger or String", this._fieldName);
                list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                break;
            }

            // Find Domain
            if (!string.IsNullOrEmpty(this._domainName))
            {
                // Get Domain
                Domain domain = schemaModel.FindDomain(this._domainName);

                if (domain == null)
                {
                    // Domain does not exit
                    string message = string.Format("The domain [{0}] for field [{1}] does not exist", this._domainName, field.Name);
                    list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                }
                else
                {
                    // Compare domain and field types
                    if (field.FieldType != domain.FieldType)
                    {
                        string message = string.Format("The field [{0}] and assigned domain [{1}] do not have matching field types.", field.Name, this._domainName);
                        list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                    }

                    // Check Default Value (
                    if (!string.IsNullOrEmpty(this._defaultValue))
                    {
                        string message = null;
                        if (!domain.IsValid(this._defaultValue, out message))
                        {
                            list.Add(new ErrorTableRow(this, message, ErrorType.Warning));
                        }
                    }

                    // Check if a domain value is too long for the text field
                    if (field.FieldType == esriFieldType.esriFieldTypeString &&
                        domain.FieldType == esriFieldType.esriFieldTypeString &&
                        domain.GetType() == typeof(DomainCodedValue))
                    {
                        DomainCodedValue domain2 = (DomainCodedValue)domain;
                        foreach (DomainCodedValueRow x in domain2.CodedValues)
                        {
                            if (string.IsNullOrEmpty(x.Code))
                            {
                                continue;
                            }
                            if (x.Code.Length > field.Length)
                            {
                                string message = string.Format("The domain [{0}] has a value [{1}] that is too long for the field [{2}]", this._domainName, x, this._fieldName);
                                list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                            }
                        }
                    }
                }
            }

            // Check validity of default value against field type
            if (!string.IsNullOrEmpty(this._defaultValue))
            {
                string message;
                if (!GeodatabaseUtility.IsValidateValue(field.FieldType, this._defaultValue, out message))
                {
                    string message2 = string.Format("Default value [{0}] {1}", this._defaultValue, message);
                    list.Add(new ErrorTableRow(this, message2, ErrorType.Error));
                }
            }

            //
            if (!string.IsNullOrEmpty(this._defaultValue))
            {
                if (!string.IsNullOrEmpty(this._domainName))
                {
                    if (!string.IsNullOrEmpty(field.Domain))
                    {
                        if (this._domainName != field.Domain)
                        {
                            Domain domain2 = schemaModel.FindDomain(field.Domain);
                            string message = null;
                            if (!domain2.IsValid(this._defaultValue, out message))
                            {
                                string message2 = string.Format("NIM013605: Field [{0}] - {1}", this._fieldName, message);
                                list.Add(new ErrorTableRow(this, message2, ErrorType.Error));
                            }
                        }
                    }
                }
            }
        }
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if (context == null)
            {
                return(null);
            }
            if (context.Instance == null)
            {
                return(null);
            }

            // FeatureClass::ShapeFieldName, AreaFieldName, LengthFieldName, ShapeFieldName
            // GeometricNetworkControllerMembership::EnabledFieldName, AncillaryRoleFieldName
            // IndexField::Name
            // ObjectClass::OIDFieldName, GlobalIDFieldName, RasterFieldName, SubtypeFieldName, OIDFieldName, GlobalIDFieldName
            // RelationshipClass::OriginPrimary, OriginForeign, DestinationPrimary, DestinationForeign
            // SubtypeField::FieldName
            // NetWeightAssociation::FieldName
            // TerrainDataSource::HeightField, TagValueField

            // Create List
            List <string> list = new List <string>();

            DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default;
            SchemaModel           schemaModel           = diagrammerEnvironment.SchemaModel;

            if (context.PropertyDescriptor.ComponentType == typeof(IndexField))
            {
                IndexField  indexField  = (IndexField)context.Instance;
                ObjectClass objectClass = (ObjectClass)indexField.Table;
                foreach (Field field in objectClass.GetFields())
                {
                    list.Add(field.Name);
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(GeometricNetworkControllerMembership))
            {
                GeometricNetworkControllerMembership geometricNetworkControllerMembership = (GeometricNetworkControllerMembership)context.Instance;
                ObjectClass objectClass = schemaModel.FindParent(geometricNetworkControllerMembership);
                foreach (Field field in objectClass.GetFields())
                {
                    list.Add(field.Name);
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(SubtypeField))
            {
                SubtypeField subtypeField = (SubtypeField)context.Instance;
                Subtype      subtype      = (Subtype)subtypeField.Table;
                ObjectClass  objectClass  = subtype.GetParent();
                foreach (Field field in objectClass.GetFields())
                {
                    list.Add(field.Name);
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(ObjectClass))
            {
                ObjectClass objectClass = (ObjectClass)context.Instance;
                foreach (Field field in objectClass.GetFields())
                {
                    list.Add(field.Name);
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(RelationshipClass))
            {
                RelationshipClass relationshipClass = (RelationshipClass)context.Instance;
                if (relationshipClass.IsAttributed)
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "OIDFieldName":
                    case "GlobalIDFieldName":
                    case "RasterFieldName":
                    case "SubtypeFieldName":
                        foreach (Field field in relationshipClass.GetFields())
                        {
                            list.Add(field.Name);
                        }
                        break;

                    case "OriginPrimary":
                        ObjectClass objectClass1 = schemaModel.FindObjectClass(relationshipClass.OriginClassName);
                        foreach (Field field in objectClass1.GetFields())
                        {
                            list.Add(field.Name);
                        }
                        break;

                    case "OriginForeign":
                    case "DestinationForeign":
                        foreach (Field field in relationshipClass.GetFields())
                        {
                            list.Add(field.Name);
                        }
                        break;

                    case "DestinationPrimary":
                        ObjectClass objectClass2 = schemaModel.FindObjectClass(relationshipClass.DestinationClassName);
                        foreach (Field field in objectClass2.GetFields())
                        {
                            list.Add(field.Name);
                        }
                        break;
                    }
                }
                else
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "OIDFieldName":
                    case "GlobalIDFieldName":
                    case "RasterFieldName":
                    case "SubtypeFieldName":
                        foreach (Field field in relationshipClass.GetFields())
                        {
                            list.Add(field.Name);
                        }
                        break;

                    case "OriginPrimary":
                        ObjectClass objectClass1 = schemaModel.FindObjectClass(relationshipClass.OriginClassName);
                        foreach (Field field in objectClass1.GetFields())
                        {
                            list.Add(field.Name);
                        }
                        break;

                    case "OriginForeign":
                        ObjectClass objectClass2 = schemaModel.FindObjectClass(relationshipClass.DestinationClassName);
                        foreach (Field field in objectClass2.GetFields())
                        {
                            list.Add(field.Name);
                        }
                        break;

                    case "DestinationPrimary":
                    case "DestinationForeign":
                        break;
                    }
                }
            }
            else if (
                context.PropertyDescriptor.ComponentType == typeof(FeatureClass) ||
                context.PropertyDescriptor.ComponentType == typeof(RasterCatalog))
            {
                FeatureClass featureClass = (FeatureClass)context.Instance;
                foreach (Field field in featureClass.GetFields())
                {
                    list.Add(field.Name);
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(NetWeightAssociation))
            {
                NetWeightAssociation netWeightAssociation = (NetWeightAssociation)context.Instance;
                if (netWeightAssociation != null)
                {
                    if (!string.IsNullOrEmpty(netWeightAssociation.TableName))
                    {
                        ObjectClass objectClass = schemaModel.FindObjectClass(netWeightAssociation.TableName);
                        if (objectClass != null)
                        {
                            foreach (Field field in objectClass.GetFields())
                            {
                                list.Add(field.Name);
                            }
                        }
                    }
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(TerrainDataSource))
            {
                TerrainDataSource terrainDataSource = (TerrainDataSource)context.Instance;
                if (terrainDataSource != null)
                {
                    if (!string.IsNullOrEmpty(terrainDataSource.FeatureClassName))
                    {
                        ObjectClass objectClass = schemaModel.FindObjectClass(terrainDataSource.FeatureClassName);
                        if (objectClass != null)
                        {
                            foreach (Field field in objectClass.GetFields())
                            {
                                list.Add(field.Name);
                            }
                        }
                    }
                }
            }

            // Sort field name list and insert "None" item
            list.Sort();
            list.Insert(0, Resources.TEXT_NONE_BR);

            // Return sort field name list
            StandardValuesCollection svc = new StandardValuesCollection(list);

            return(svc);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (context == null)
            {
                return(null);
            }
            if (context.Instance == null)
            {
                return(null);
            }

            if (value.GetType() == typeof(string))
            {
                string text = Convert.ToString(value);

                if (context.PropertyDescriptor.ComponentType == typeof(RelationshipClass))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "OriginClassName":
                    case "DestinationClassName":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(string.Empty);
                        }
                        return(text);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(EdgeConnectivityRule))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "DefaultJunctionID":
                    case "FromClassID":
                    case "ToClassID":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(-1);
                        }
                        DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
                        SchemaModel           model       = de.SchemaModel;
                        ObjectClass           objectClass = model.FindObjectClass(text);
                        if (objectClass == null)
                        {
                            return(-1);
                        }
                        return(objectClass.DSID);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(JunctionSubtype))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "ClassID":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(-1);
                        }
                        DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
                        SchemaModel           model       = de.SchemaModel;
                        ObjectClass           objectClass = model.FindObjectClass(text);
                        if (objectClass == null)
                        {
                            return(-1);
                        }
                        return(objectClass.DSID);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(RelationshipRule))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "OriginClass":
                    case "DestinationClass":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(-1);
                        }
                        DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
                        SchemaModel           model       = de.SchemaModel;
                        ObjectClass           objectClass = model.FindObjectClass(text);
                        if (objectClass == null)
                        {
                            return(-1);
                        }
                        return(objectClass.DSID);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(JunctionConnectivityRule))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "EdgeClassID":
                    case "JunctionClassID":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(-1);
                        }
                        DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
                        SchemaModel           model       = de.SchemaModel;
                        ObjectClass           objectClass = model.FindObjectClass(text);
                        if (objectClass == null)
                        {
                            return(-1);
                        }
                        return(objectClass.DSID);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "OriginClassId":
                    case "DestinationClassId":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(-1);
                        }
                        DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
                        SchemaModel           model       = de.SchemaModel;
                        ObjectClass           objectClass = model.FindObjectClass(text);
                        if (objectClass == null)
                        {
                            return(-1);
                        }
                        return(objectClass.DSID);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(NetWeightAssociation))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "TableName":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(string.Empty);
                        }
                        return(text);
                    }
                }
                else if (context.PropertyDescriptor.ComponentType == typeof(TerrainDataSource))
                {
                    switch (context.PropertyDescriptor.Name)
                    {
                    case "FeatureClassName":
                        if (text == string.Empty ||
                            text == Resources.TEXT_NONE_BR)
                        {
                            return(string.Empty);
                        }
                        return(text);
                    }
                }
            }

            return(base.ConvertFrom(context, culture, value));
        }
        protected override void WriteInnerXml(XmlWriter writer)
        {
            base.WriteInnerXml(writer);

            // Get Model
            Subtype     subtype     = (Subtype)this.Table;
            ObjectClass objectClass = subtype.GetParent();

            // <FieldName></FieldName>
            writer.WriteStartElement("FieldName");
            writer.WriteValue(this._fieldName);
            writer.WriteEndElement();

            if (!string.IsNullOrEmpty(this._domainName))
            {
                // <DomainName></DomainName>
                writer.WriteStartElement("DomainName");
                writer.WriteValue(this._domainName);
                writer.WriteEndElement();
            }

            // Get Field
            Field field = objectClass.FindField(this._fieldName);

            //
            if (!string.IsNullOrEmpty(this._defaultValue))
            {
                // Get correct data type value
                string dataType = string.Empty;
                switch (field.FieldType)
                {
                case esriFieldType.esriFieldTypeSmallInteger:
                    dataType = "xs:short";
                    break;

                case esriFieldType.esriFieldTypeInteger:
                    dataType = "xs:int";
                    break;

                case esriFieldType.esriFieldTypeSingle:
                    dataType = "xs:float";
                    break;

                case esriFieldType.esriFieldTypeDouble:
                    dataType = "xs:double";
                    break;

                case esriFieldType.esriFieldTypeString:
                    dataType = "xs:string";
                    break;

                case esriFieldType.esriFieldTypeDate:
                    dataType = "xs:dateTime";
                    break;
                }

                // <DefaultValue></DefaultValue>
                writer.WriteStartElement("DefaultValue");
                writer.WriteAttributeString(Xml._XSI, Xml._TYPE, null, dataType);
                writer.WriteValue(this._defaultValue);
                writer.WriteEndElement();
            }
        }
        private void Model_ElementInvalid(object sender, ElementEventArgs e)
        {
            // Check Relationship
            if (this._relationshipClass == null)
            {
                return;
            }

            // Get Element
            Element element = e.Value;

            if (element == null)
            {
                return;
            }
            EsriLine <RelationshipRule> line = element as EsriLine <RelationshipRule>;

            if (line == null)
            {
                return;
            }

            // Get Rule
            RelationshipRule rule = line.Parent;

            // Suspend Rule Events
            rule.Suspend();

            //
            Element elementStart = line.Start.Shape;
            Element elementEnd   = line.End.Shape;

            // Update Origin Class/Subtype
            if (elementStart == null)
            {
                rule.OriginClass   = -1;
                rule.OriginSubtype = -1;
            }
            else if (elementStart is EsriShape <ObjectClass> )
            {
                EsriShape <ObjectClass> shape       = (EsriShape <ObjectClass>)elementStart;
                ObjectClass             objectClass = shape.Parent;
                rule.OriginClass   = objectClass.DSID;
                rule.OriginSubtype = 0;
            }
            else if (elementStart is EsriShape <FeatureClass> )
            {
                EsriShape <FeatureClass> shape        = (EsriShape <FeatureClass>)elementStart;
                FeatureClass             featureClass = shape.Parent;
                rule.OriginClass   = featureClass.DSID;
                rule.OriginSubtype = 0;
            }
            else if (elementStart is EsriShape <Subtype> )
            {
                EsriShape <Subtype> shape       = (EsriShape <Subtype>)elementStart;
                Subtype             subtype     = shape.Parent;
                ObjectClass         objectClass = subtype.GetParent();
                if (objectClass != null)
                {
                    rule.OriginClass   = objectClass.DSID;
                    rule.OriginSubtype = subtype.SubtypeCode;
                }
            }

            // Update Destination Class/Subtype
            if (elementEnd == null)
            {
                rule.DestinationClass   = -1;
                rule.DestinationSubtype = -1;
            }
            else if (elementEnd is EsriShape <ObjectClass> )
            {
                EsriShape <ObjectClass> shape       = (EsriShape <ObjectClass>)elementEnd;
                ObjectClass             objectClass = shape.Parent;
                rule.DestinationClass   = objectClass.DSID;
                rule.DestinationSubtype = 0;
            }
            else if (elementEnd is EsriShape <FeatureClass> )
            {
                EsriShape <FeatureClass> shape        = (EsriShape <FeatureClass>)elementEnd;
                FeatureClass             featureClass = shape.Parent;
                rule.DestinationClass   = featureClass.DSID;
                rule.DestinationSubtype = 0;
            }
            else if (elementEnd is EsriShape <Subtype> )
            {
                EsriShape <Subtype> shape       = (EsriShape <Subtype>)elementEnd;
                Subtype             subtype     = shape.Parent;
                ObjectClass         objectClass = subtype.GetParent();
                if (objectClass != null)
                {
                    rule.DestinationClass   = objectClass.DSID;
                    rule.DestinationSubtype = subtype.SubtypeCode;
                }
            }

            // Resume Rule Events
            rule.Resume();
        }
        private void AddSubtypes(ObjectClass objectClass, IXPathNavigable path) {
            // Get Navigator
            XPathNavigator navigator = path.CreateNavigator();

            // Check if Subtypes Exist
            XPathNavigator navigatorSubtypeField = navigator.SelectSingleNode("SubtypeFieldName");
            if (navigatorSubtypeField != null) {
                // Get Default Subtype
                XPathNavigator navigatorDefaultSubtypeCode = navigator.SelectSingleNode("DefaultSubtypeCode");

                // Get Subtypes
                XPathNodeIterator iteratorSubtype = navigator.Select("Subtypes/Subtype");

                // Loop for each Subtype
                while (iteratorSubtype.MoveNext()) {
                    // Create Subtype
                    XPathNavigator navigatorSubtype = iteratorSubtype.Current;
                    Subtype subtype = new Subtype(navigatorSubtype);

                    // Update Default Subtype Property
                    subtype.Default = (subtype.SubtypeCode == navigatorDefaultSubtypeCode.ValueAsInt);

                    // Add Subtype to Model
                    this.Shapes.Add(this.Shapes.CreateKey(), subtype);

                    // Add Link From ObjectClass to Subtype
                    Link link = new Link(objectClass, subtype);
                    link.BorderColor = ModelSettings.Default.EnabledLines;
                    link.BorderStyle = DashStyle.Solid;
                    link.BorderWidth = 1f;
                    link.End.Marker.BorderColor = ModelSettings.Default.EnabledLines;
                    this.Lines.Add(this.Lines.CreateKey(), link);
                }
            }
        }
        private void LoadModel()
        {
            // Store Selected EsriTable (if any)
            EsriTable table = null;

            if (this.treeView1.SelectedNode != null)
            {
                TreeNodeTable treeNodeTable = this.treeView1.SelectedNode as TreeNodeTable;
                if (treeNodeTable != null)
                {
                    if (treeNodeTable.Table != null)
                    {
                        table = treeNodeTable.Table;
                    }
                }
            }

            // Clear TreeView
            this.treeView1.Nodes.Clear();

            // Exit if No Model
            if (this._model == null)
            {
                return;
            }

            // Get Datasets
            List <Dataset> datasets = this._model.GetDatasets();

            // Get Domains
            List <Domain> domains = this._model.GetDomains();

            // Start TreeView Update
            this.treeView1.BeginUpdate();
            this.treeView1.Sorted = false;

            // Add Geodatabase Node
            TreeNodeGeodatabase treeNode = new TreeNodeGeodatabase(this._model);

            treeNode.ImageKey         = Catalog.GEODATABASE;
            treeNode.SelectedImageKey = Catalog.GEODATABASE;
            treeNode.Text             = this._model.Title;
            this.treeView1.Nodes.Add(treeNode);

            if (this.buttonItemCatalog.Checked)
            {
                // Sort Datasets
                datasets.Sort();

                // Loop Throught Datasets
                foreach (Dataset dataset in datasets)
                {
                    if (dataset is FeatureDataset)
                    {
                        // Get FeatureDataset
                        FeatureDataset featureDataset = (FeatureDataset)dataset;

                        // Add FeatureDataset Node
                        TreeNode treeNode2 = this.CreateCatalogNode(treeNode, featureDataset);

                        // Get Child Datasets
                        List <Dataset> datasets2 = featureDataset.GetChildren();
                        datasets2.Sort();

                        foreach (Dataset dataset2 in datasets2)
                        {
                            TreeNode treeNode3 = this.CreateCatalogNode(treeNode2, dataset2);

                            // Add Subtypes if ObjectClass
                            if (dataset2 is ObjectClass)
                            {
                                // Get ObjectClass
                                ObjectClass objectClass = (ObjectClass)dataset2;

                                // Get Subtypes
                                List <Subtype> subtypes = objectClass.GetSubtypes();
                                subtypes.Sort();

                                // Add Subtypes Nodes
                                foreach (Subtype subtype in subtypes)
                                {
                                    TreeNode treeNodeSubtype = this.CreateCatalogNode(treeNode3, subtype);
                                }
                            }
                        }
                    }
                }

                // Add Everything Else
                foreach (Dataset dataset in datasets)
                {
                    // Skip FeatureDataset and FeatureDataset Objects
                    if (dataset is FeatureDataset ||
                        dataset is GeometricNetwork ||
                        dataset is Network ||
                        dataset is RasterBand ||
                        dataset is Terrain ||
                        dataset is Topology)
                    {
                        continue;
                    }

                    // Skip Objects that Belong to a FeatureDataset
                    if (dataset is FeatureClass ||
                        dataset is RelationshipClass)
                    {
                        Dataset parent = dataset.GetParent();
                        if (parent != null)
                        {
                            continue;
                        }
                    }

                    // Create Node
                    TreeNode treeNode2 = this.CreateCatalogNode(treeNode, dataset);

                    // Add Subtypes if ObjectClass
                    if (dataset is ObjectClass)
                    {
                        // Get ObjectClass
                        ObjectClass objectClass = (ObjectClass)dataset;

                        // Get Subtypes
                        List <Subtype> subtypes = objectClass.GetSubtypes();
                        subtypes.Sort();

                        // Add Subtypes Nodes
                        foreach (Subtype subtype in subtypes)
                        {
                            TreeNode treeNodeSubtype = this.CreateCatalogNode(treeNode2, subtype);
                        }
                    }

                    // Add Raster Bands
                    if (dataset.GetType() == typeof(RasterDataset))
                    {
                        // Get RasterDataset
                        RasterDataset rasterDataset = (RasterDataset)dataset;

                        // Get RasterBands
                        List <Dataset> rasterBands = rasterDataset.GetChildren();

                        // Add RasterBands
                        foreach (Dataset datasetRasterBand in rasterBands)
                        {
                            if (datasetRasterBand.GetType() == typeof(RasterBand))
                            {
                                RasterBand rasterBand         = (RasterBand)datasetRasterBand;
                                TreeNode   treeNodeRasterBand = this.CreateCatalogNode(treeNode2, rasterBand);
                            }
                        }
                    }
                }

                // Sort Domains
                domains.Sort();

                // Add Domains
                foreach (Domain domain in domains)
                {
                    TreeNode treeNodeDomain = this.CreateCatalogNode(treeNode, domain);
                }

                // Expand Geodatabase Node
                treeNode.Expand();
            }
            else if (this.buttonItemCategorized.Checked)
            {
                // Loop for each Dataset
                foreach (Dataset dataset in datasets)
                {
                    // Get Group Node Name
                    string key = string.Empty;
                    if (dataset.GetType() == typeof(FeatureDataset))
                    {
                        key = Resources.TEXT_FEATURE_DATASET;
                    }
                    else if (dataset.GetType() == typeof(FeatureClass))
                    {
                        key = Resources.TEXT_FEATURE_CLASS;
                    }
                    else if (dataset.GetType() == typeof(GeometricNetwork))
                    {
                        key = Resources.TEXT_GEOMETRIC_NETWORK;
                    }
                    else if (dataset.GetType() == typeof(ObjectClass))
                    {
                        key = Resources.TEXT_TABLE;
                    }
                    else if (dataset.GetType() == typeof(RasterBand))
                    {
                        key = Resources.TEXT_RASTER_BAND;
                    }
                    else if (dataset.GetType() == typeof(RasterCatalog))
                    {
                        key = Resources.TEXT_RASTER_CATALOG;
                    }
                    else if (dataset.GetType() == typeof(RasterDataset))
                    {
                        key = Resources.TEXT_RASTER_DATASET;
                    }
                    else if (dataset.GetType() == typeof(RelationshipClass))
                    {
                        key = Resources.TEXT_RELATIONSHIP;
                    }
                    else if (dataset.GetType() == typeof(Terrain))
                    {
                        key = Resources.TEXT_TERRAIN;
                    }
                    else if (dataset.GetType() == typeof(Topology))
                    {
                        key = Resources.TEXT_TOPOLOGY;
                    }
                    if (string.IsNullOrEmpty(key))
                    {
                        continue;
                    }

                    // Get Group Node (create if it does not exist)
                    TreeNodeGroup treeNodeGroup = null;
                    foreach (TreeNodeGroup group in treeNode.Nodes)
                    {
                        if (group.Type == dataset.GetType())
                        {
                            treeNodeGroup = group;
                            break;
                        }
                    }
                    if (treeNodeGroup == null)
                    {
                        treeNodeGroup                  = new TreeNodeGroup(dataset.GetType());
                        treeNodeGroup.ImageKey         = Catalog.FOLDER_CLOSED;
                        treeNodeGroup.SelectedImageKey = Catalog.FOLDER_CLOSED;
                        treeNodeGroup.Text             = key;
                        treeNode.Nodes.Add(treeNodeGroup);
                    }

                    // Create New Dataset Node
                    TreeNode treeNodeDataset = this.CreateCatalogNode(treeNodeGroup, dataset);
                }

                // Append Subtypes Nodes
                foreach (Dataset dataset in datasets)
                {
                    // Is ObjectClass?
                    if (dataset is ObjectClass)
                    {
                        // Cast to ObjectClass
                        ObjectClass objectClass = (ObjectClass)dataset;

                        // Get Subtypes
                        List <Subtype> subtypes = objectClass.GetSubtypes();
                        if (subtypes.Count == 0)
                        {
                            continue;
                        }

                        // Find Subtype Group Node
                        TreeNodeGroup treeNodeGroup = null;
                        foreach (TreeNodeGroup group in treeNode.Nodes)
                        {
                            if (group.Type == typeof(Subtype))
                            {
                                treeNodeGroup = group;
                                break;
                            }
                        }
                        if (treeNodeGroup == null)
                        {
                            treeNodeGroup                  = new TreeNodeGroup(typeof(Subtype));
                            treeNodeGroup.ImageKey         = Catalog.FOLDER_CLOSED;
                            treeNodeGroup.SelectedImageKey = Catalog.FOLDER_CLOSED;
                            treeNodeGroup.Text             = Resources.TEXT_SUBTYPE;
                            treeNode.Nodes.Add(treeNodeGroup);
                        }

                        // Add Each Subtype
                        foreach (Subtype subtype in subtypes)
                        {
                            TreeNode treeNodeSubtype = this.CreateCatalogNode(treeNodeGroup, subtype);
                        }
                    }
                }

                // Loop for each Domain
                foreach (Domain domain in domains)
                {
                    // Get Group Node Name
                    string key = string.Empty;
                    if (domain.GetType() == typeof(DomainCodedValue))
                    {
                        key = Resources.TEXT_CODED_VALUE;
                    }
                    else if (domain.GetType() == typeof(DomainRange))
                    {
                        key = Resources.TEXT_RANGE_DOMAIN;
                    }
                    if (string.IsNullOrEmpty(key))
                    {
                        continue;
                    }

                    // Get Group Node (create if it does not exist)
                    TreeNodeGroup treeNodeGroup = null;
                    foreach (TreeNodeGroup group in treeNode.Nodes)
                    {
                        if (group.Type == domain.GetType())
                        {
                            treeNodeGroup = group;
                            break;
                        }
                    }
                    if (treeNodeGroup == null)
                    {
                        treeNodeGroup                  = new TreeNodeGroup(domain.GetType());
                        treeNodeGroup.ImageKey         = Catalog.FOLDER_CLOSED;
                        treeNodeGroup.SelectedImageKey = Catalog.FOLDER_CLOSED;
                        treeNodeGroup.Text             = key;
                        treeNode.Nodes.Add(treeNodeGroup);
                    }

                    // Create New Dataset Node
                    TreeNode treeNodeDomain = this.CreateCatalogNode(treeNodeGroup, domain);
                }

                // Expand Geodatabase Node
                treeNode.Expand();

                // Traditional Text Sort
                this.treeView1.Sort();
            }
            else if (this.buttonItemAlphabetical.Checked)
            {
                // Loop for each Dataset
                foreach (Dataset dataset in datasets)
                {
                    // Create New Dataset Node
                    TreeNode treeNodeDataset = this.CreateCatalogNode(treeNode, dataset);

                    if (dataset is ObjectClass)
                    {
                        // Cast to ObjectClass
                        ObjectClass objectClass = (ObjectClass)dataset;

                        // Get and Add Subtypes
                        List <Subtype> subtypes = objectClass.GetSubtypes();
                        foreach (Subtype subtype in subtypes)
                        {
                            TreeNode treeNodeSubtype = this.CreateCatalogNode(treeNode, subtype);
                        }
                    }
                }

                // Loop for each Domain
                foreach (Domain domain in domains)
                {
                    TreeNode treeNodeDomain = this.CreateCatalogNode(treeNode, domain);
                }

                // Expand Geodatabase Node
                treeNode.Expand();

                // Traditional Text Sort
                this.treeView1.Sort();
            }

            // Reselect Previous EsriTable (if any)
            if (table != null)
            {
                if (this.treeView1.Nodes.Count == 1)
                {
                    //TreeNode treeNode = this.treeView1.Nodes[0];
                    TreeNode treeNodeFind = this.FindNode(treeNode, table);
                    if (treeNodeFind != null)
                    {
                        treeNodeFind.EnsureVisible();
                        treeNodeFind.TreeView.SelectedNode = treeNodeFind;
                    }
                }
            }

            // End TreeView Update
            this.treeView1.EndUpdate();
        }
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (context == null)
            {
                return(null);
            }
            if (context.Instance == null)
            {
                return(null);
            }
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }

            if (destinationType == typeof(string))
            {
                if (value.GetType() == typeof(int))
                {
                    int         id          = Convert.ToInt32(value);
                    ObjectClass objectClass = this.GetObjectClass(context);
                    if (objectClass == null)
                    {
                        return(Resources.TEXT_NONE_BR);
                    }
                    List <Subtype> subtypes = objectClass.GetSubtypes();
                    if (subtypes.Count == 0)
                    {
                        if (id == -1)
                        {
                            return(Resources.TEXT_NONE_BR);
                        }
                        return(Resources.TEXT_CLASS_BR);
                    }

                    if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule))
                    {
                        TopologyRule topologyRule = (TopologyRule)context.Instance;
                        switch (context.PropertyDescriptor.Name)
                        {
                        case "OriginSubtype":
                            if (topologyRule.OriginSubtype == 0 && topologyRule.AllOriginSubtypes)
                            {
                                return(Resources.TEXT_NONE_BR);
                            }
                            break;

                        case "DestinationSubtype":
                            if (topologyRule.DestinationSubtype == 0 && topologyRule.AllDestinationSubtypes)
                            {
                                return(Resources.TEXT_NONE_BR);
                            }
                            break;
                        }
                    }

                    Subtype subtype = objectClass.FindSubtype(id);
                    if (subtype == null)
                    {
                        return(Resources.TEXT_NONE_BR);
                    }
                    return(subtype.SubtypeName);
                }
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
        private void Model_ElementInvalid(object sender, ElementEventArgs e)
        {
            // Exit if Topology Does not Exist
            if (this._topology == null)
            {
                return;
            }

            // Get Element
            Element element = e.Value;

            if (element == null)
            {
                return;
            }
            EsriLine <TopologyRule> line = element as EsriLine <TopologyRule>;

            if (line == null)
            {
                return;
            }

            // Get TopologyRule
            TopologyRule rule = line.Parent;

            // Suspend Rule Events
            rule.Suspend();

            // Get Start and End Elements
            Element elementStart = line.Start.Shape;
            Element elementEnd   = line.End.Shape;

            // Update Start Class/Subtype
            if (elementStart == null)
            {
                rule.AllOriginSubtypes = false;
                rule.OriginClassId     = -1;
                rule.OriginSubtype     = -1;
            }
            else if (elementStart is EsriShape <FeatureClass> )
            {
                EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementStart;
                ObjectClass objectClass        = shape.Parent;
                rule.AllOriginSubtypes = true;
                rule.OriginClassId     = objectClass.DSID;
                rule.OriginSubtype     = 0;
            }
            else if (elementStart is EsriShape <Subtype> )
            {
                EsriShape <Subtype> shape       = (EsriShape <Subtype>)elementStart;
                Subtype             subtype     = shape.Parent;
                ObjectClass         objectClass = subtype.GetParent();
                rule.AllOriginSubtypes = false;
                if (objectClass == null)
                {
                    rule.OriginClassId = -1;
                    rule.OriginSubtype = -1;
                }
                else
                {
                    rule.OriginClassId = objectClass.DSID;
                    rule.OriginSubtype = subtype.SubtypeCode;
                }
            }

            // Update End Class/Subtype
            if (elementEnd == null)
            {
                rule.AllDestinationSubtypes = false;
                rule.DestinationClassId     = -1;
                rule.DestinationSubtype     = -1;
            }
            else if (elementEnd is EsriShape <FeatureClass> )
            {
                EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementEnd;
                ObjectClass objectClass        = shape.Parent;
                rule.AllDestinationSubtypes = true;
                rule.DestinationClassId     = objectClass.DSID;
                rule.DestinationSubtype     = 0;
            }
            else if (elementEnd is EsriShape <Subtype> )
            {
                EsriShape <Subtype> shape       = (EsriShape <Subtype>)elementEnd;
                Subtype             subtype     = shape.Parent;
                ObjectClass         objectClass = subtype.GetParent();
                rule.AllDestinationSubtypes = false;
                if (objectClass == null)
                {
                    rule.DestinationClassId = -1;
                    rule.DestinationSubtype = -1;
                }
                else
                {
                    rule.DestinationClassId = objectClass.DSID;
                    rule.DestinationSubtype = subtype.SubtypeCode;
                }
            }

            // Resume Rule Events
            rule.Resume();
        }
Beispiel #11
0
        private TreeNode CreateCatalogNode(TreeNode node, EsriTable table)
        {
            if (table.GetType() == typeof(DomainCodedValue))
            {
                // Get Coded Value Domain
                DomainCodedValue domainCodedValue = (DomainCodedValue)table;

                // Add Coded Value Domain
                TreeNodeTable treeNode = new TreeNodeTable(domainCodedValue);
                treeNode.ImageKey         = Catalog.CODED_VALUE_DOMAIN;
                treeNode.SelectedImageKey = Catalog.CODED_VALUE_DOMAIN;
                treeNode.Text             = domainCodedValue.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(DomainRange))
            {
                // Get Range Domain
                DomainRange domainRange = (DomainRange)table;

                // Add Range Domain
                TreeNodeTable treeNode = new TreeNodeTable(domainRange);
                treeNode.ImageKey         = Catalog.RANGE_DOMAIN;
                treeNode.SelectedImageKey = Catalog.RANGE_DOMAIN;
                treeNode.Text             = domainRange.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(FeatureClass))
            {
                // Get FeatureClass
                FeatureClass featureClass = (FeatureClass)table;

                // Add FeatureClass Node
                string imageKey = null;
                switch (featureClass.FeatureType)
                {
                case ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTAnnotation:
                    imageKey = Catalog.ANNOTATION_FEATURE_CLASS;
                    break;

                case ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTDimension:
                    imageKey = Catalog.DIMENSION_FEATURE_CLASS;
                    break;

                case ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple:
                    switch (featureClass.ShapeType)
                    {
                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultipoint:
                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                        imageKey = Catalog.POINT_FEATURE_CLASS;
                        break;

                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                        imageKey = Catalog.POLYGON_FEATURE_CLASS;
                        break;

                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                        imageKey = Catalog.POLYLINE_FEATURE_CLASS;
                        break;

                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryMultiPatch:
                        imageKey = Catalog.MULTIPATCH_FEATURE_CLASS;
                        break;

                    default:
                        imageKey = Catalog.POINT_FEATURE_CLASS;
                        break;
                    }
                    break;

                default:
                    imageKey = POINT_FEATURE_CLASS;
                    break;
                }
                TreeNodeTable treeNode = new TreeNodeTable(featureClass);
                treeNode.ImageKey         = imageKey;
                treeNode.SelectedImageKey = imageKey;
                treeNode.Text             = featureClass.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(FeatureDataset))
            {
                // Get FeatureDataset
                FeatureDataset featureDataset = (FeatureDataset)table;

                // Add FeatureDataset Node
                TreeNodeTable treeNode = new TreeNodeTable(featureDataset);
                treeNode.ImageKey         = Catalog.FEATURE_DATASET;
                treeNode.SelectedImageKey = Catalog.FEATURE_DATASET;
                treeNode.Text             = featureDataset.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(GeometricNetwork))
            {
                // Get GeometricNetwork
                GeometricNetwork geometricNetwork = (GeometricNetwork)table;

                // Add GeometricNetwork Node
                TreeNodeTable treeNode = new TreeNodeTable(geometricNetwork);
                treeNode.ImageKey         = Catalog.GEOMETRIC_NETWORK;
                treeNode.SelectedImageKey = Catalog.GEOMETRIC_NETWORK;
                treeNode.Text             = geometricNetwork.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(Network))
            {
                // Get Network
                Network network = (Network)table;

                // Add Network TreeNode
                TreeNodeTable treeNode = new TreeNodeTable(network);
                treeNode.ImageKey         = Catalog.NETWORK_DATASET;
                treeNode.SelectedImageKey = Catalog.NETWORK_DATASET;
                treeNode.Text             = network.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(ObjectClass))
            {
                // Get ObjectClass
                ObjectClass objectClass = (ObjectClass)table;

                // Add ObjectClass TreeNode
                TreeNodeTable treeNode = new TreeNodeTable(objectClass);
                treeNode.ImageKey         = Catalog.TABLE;
                treeNode.SelectedImageKey = Catalog.TABLE;
                treeNode.Text             = objectClass.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(RasterBand))
            {
                // Get RasterBand
                RasterBand rasterBand = (RasterBand)table;

                // Add RasterBand TreeNode
                TreeNodeTable treeNode = new TreeNodeTable(rasterBand);
                treeNode.ImageKey         = Catalog.RASTER_BAND;
                treeNode.SelectedImageKey = Catalog.RASTER_BAND;
                treeNode.Text             = rasterBand.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(RasterCatalog))
            {
                // Get RasterCatalog
                RasterCatalog rasterCatalog = (RasterCatalog)table;

                // Add RasterCatalog TreeNode
                TreeNodeTable treeNode = new TreeNodeTable(rasterCatalog);
                treeNode.ImageKey         = Catalog.RASTER_CATALOG;
                treeNode.SelectedImageKey = Catalog.RASTER_CATALOG;
                treeNode.Text             = rasterCatalog.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(RasterDataset))
            {
                // Get RasterDataset
                RasterDataset rasterDataset = (RasterDataset)table;

                // Add RasterDataset TreeNode
                TreeNodeTable treeNode = new TreeNodeTable(rasterDataset);
                treeNode.ImageKey         = Catalog.RASTER_DATASET;
                treeNode.SelectedImageKey = Catalog.RASTER_DATASET;
                treeNode.Text             = rasterDataset.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(RelationshipClass))
            {
                // Get RelationshipClass
                RelationshipClass relationshipClass = (RelationshipClass)table;

                // Add RelationshipClass TreeNode
                TreeNodeTable treeNode = new TreeNodeTable(relationshipClass);
                treeNode.ImageKey         = Catalog.RELATIONSHIP_CLASS;
                treeNode.SelectedImageKey = Catalog.RELATIONSHIP_CLASS;
                treeNode.Text             = relationshipClass.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(Subtype))
            {
                // Get Subtype
                Subtype subtype = (Subtype)table;

                // Add Subtype TreeNode
                TreeNodeTable treeNode = new TreeNodeTable(subtype);
                treeNode.ImageKey         = Catalog.SUBTYPE;
                treeNode.SelectedImageKey = Catalog.SUBTYPE;
                treeNode.Text             = subtype.SubtypeName;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(Terrain))
            {
                // Get Terrain
                Terrain terrain = (Terrain)table;

                // Add Terrain TreeNode
                TreeNodeTable treeNode = new TreeNodeTable(terrain);
                treeNode.ImageKey         = Catalog.TERRAIN;
                treeNode.SelectedImageKey = Catalog.TERRAIN;
                treeNode.Text             = terrain.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            if (table.GetType() == typeof(Topology))
            {
                // Get Topology
                Topology topology = (Topology)table;

                // Add Topology TreeNode
                TreeNodeTable treeNode = new TreeNodeTable(topology);
                treeNode.ImageKey         = Catalog.TOPOLOGY;
                treeNode.SelectedImageKey = Catalog.TOPOLOGY;
                treeNode.Text             = topology.Name;
                node.Nodes.Add(treeNode);

                return(treeNode);
            }

            return(null);
        }
        private void Model_ElementInvalid(object sender, ElementEventArgs e)
        {
            // Exit if GeometricNetwork Does not Exist
            if (this._geometricNetwork == null)
            {
                return;
            }

            // Get Element
            Element element = e.Value;

            if (element == null)
            {
                return;
            }
            EsriLine <JunctionConnectivityRule> line = element as EsriLine <JunctionConnectivityRule>;

            if (line == null)
            {
                return;
            }

            // Get EdgeConnectivityRule
            JunctionConnectivityRule rule = line.Parent;

            // Suspend Rule Events
            rule.Suspend();

            // Get Start and End Elements
            Element elementStart = line.Start.Shape;
            Element elementEnd   = line.End.Shape;

            // Update Start Class/Subtype
            if (elementStart == null)
            {
                rule.EdgeClassID     = -1;
                rule.EdgeSubtypeCode = -1;
            }
            else if (elementStart is EsriShape <FeatureClass> )
            {
                EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementStart;
                ObjectClass objectClass        = shape.Parent;
                rule.EdgeClassID     = objectClass.DSID;
                rule.EdgeSubtypeCode = 0;
            }
            else if (elementStart is EsriShape <Subtype> )
            {
                EsriShape <Subtype> shape       = (EsriShape <Subtype>)elementStart;
                Subtype             subtype     = shape.Parent;
                ObjectClass         objectClass = subtype.GetParent();
                if (objectClass == null)
                {
                    rule.EdgeClassID     = -1;
                    rule.EdgeSubtypeCode = -1;
                }
                else
                {
                    rule.EdgeClassID     = objectClass.DSID;
                    rule.EdgeSubtypeCode = subtype.SubtypeCode;
                }
            }

            // Update End Class/Subtype
            if (elementEnd == null)
            {
                rule.JunctionClassID = -1;
                rule.SubtypeCode     = -1;
            }
            else if (elementEnd is EsriShape <FeatureClass> )
            {
                EsriShape <FeatureClass> shape = (EsriShape <FeatureClass>)elementEnd;
                ObjectClass objectClass        = shape.Parent;
                rule.JunctionClassID = objectClass.DSID;
                rule.SubtypeCode     = 0;
            }
            else if (elementEnd is EsriShape <Subtype> )
            {
                EsriShape <Subtype> shape       = (EsriShape <Subtype>)elementEnd;
                Subtype             subtype     = shape.Parent;
                ObjectClass         objectClass = subtype.GetParent();
                if (objectClass == null)
                {
                    rule.JunctionClassID = -1;
                    rule.SubtypeCode     = -1;
                }
                else
                {
                    rule.JunctionClassID = objectClass.DSID;
                    rule.SubtypeCode     = subtype.SubtypeCode;
                }
            }

            // Resume Rule Events
            rule.Resume();
        }
        public ObjectClass(ObjectClass prototype) : base(prototype) {
            this._oidFieldName = prototype.OIDFieldName;
            this._clsid = prototype.CLSID;
            this._extClsid = prototype.EXTCLSID;
            this._aliasName = prototype.AliasName;
            this._modelName = prototype.ModelName;
            this._globalIDFieldName = prototype.GlobalIDFieldName;
            this._rasterFieldName = prototype.RasterFieldName;

            // Add Cloned Properites
            this._extensionProperties = new List<Property>();
            foreach (Property property in prototype.ExtensionProperties) {
                this._extensionProperties.Add((Property)property.Clone());
            }

            this._subtypeFieldName = prototype.SubtypeFieldName;

            // Add Cloned Controller Memberships
            this._controllerMemberships = new List<ControllerMembership>();
            foreach (ControllerMembership controllerMembership in prototype.ControllerMemberships) {
                this._controllerMemberships.Add((ControllerMembership)controllerMembership.Clone());
            }
        }
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (context == null)
            {
                return(null);
            }
            if (context.Instance == null)
            {
                return(null);
            }
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }

            if (context.PropertyDescriptor.ComponentType == typeof(RelationshipClass))
            {
                switch (context.PropertyDescriptor.Name)
                {
                case "OriginClassName":
                case "DestinationClassName":
                    if (value.GetType() == typeof(string))
                    {
                        string text = Convert.ToString(value);
                        if (string.IsNullOrEmpty(text))
                        {
                            return(Resources.TEXT_NONE_BR);
                        }
                    }
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(EdgeConnectivityRule))
            {
                switch (context.PropertyDescriptor.Name)
                {
                case "DefaultJunctionID":
                case "FromClassID":
                case "ToClassID":
                    if (value.GetType() == typeof(int))
                    {
                        int id = Convert.ToInt32(value);
                        if (id == -1)
                        {
                            return(Resources.TEXT_NONE_BR);
                        }
                        ObjectClass objectClasss = DiagrammerEnvironment.Default.SchemaModel.FindObjectClass(id);
                        if (objectClasss == null)
                        {
                            return(string.Empty);
                        }
                        return(objectClasss.Name);
                    }
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(JunctionSubtype))
            {
                switch (context.PropertyDescriptor.Name)
                {
                case "ClassID":
                    if (value.GetType() == typeof(int))
                    {
                        int id = Convert.ToInt32(value);
                        if (id == -1)
                        {
                            return(Resources.TEXT_NONE_BR);
                        }
                        ObjectClass objectClasss = DiagrammerEnvironment.Default.SchemaModel.FindObjectClass(id);
                        if (objectClasss == null)
                        {
                            return(string.Empty);
                        }
                        return(objectClasss.Name);
                    }
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(RelationshipRule))
            {
                switch (context.PropertyDescriptor.Name)
                {
                case "OriginClass":
                case "DestinationClass":
                    if (value.GetType() == typeof(int))
                    {
                        int id = Convert.ToInt32(value);
                        if (id == -1)
                        {
                            return(Resources.TEXT_NONE_BR);
                        }
                        ObjectClass objectClasss = DiagrammerEnvironment.Default.SchemaModel.FindObjectClass(id);
                        if (objectClasss == null)
                        {
                            return(string.Empty);
                        }
                        return(objectClasss.Name);
                    }
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(JunctionConnectivityRule))
            {
                switch (context.PropertyDescriptor.Name)
                {
                case "EdgeClassID":
                case "JunctionClassID":
                    if (value.GetType() == typeof(int))
                    {
                        int id = Convert.ToInt32(value);
                        if (id == -1)
                        {
                            return(Resources.TEXT_NONE_BR);
                        }
                        ObjectClass objectClasss = DiagrammerEnvironment.Default.SchemaModel.FindObjectClass(id);
                        if (objectClasss == null)
                        {
                            return(string.Empty);
                        }
                        return(objectClasss.Name);
                    }
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule))
            {
                switch (context.PropertyDescriptor.Name)
                {
                case "OriginClassId":
                case "DestinationClassId":
                    if (value.GetType() == typeof(int))
                    {
                        int id = Convert.ToInt32(value);
                        if (id == -1)
                        {
                            return(Resources.TEXT_NONE_BR);
                        }
                        ObjectClass objectClasss = DiagrammerEnvironment.Default.SchemaModel.FindObjectClass(id);
                        if (objectClasss == null)
                        {
                            return(string.Empty);
                        }
                        return(objectClasss.Name);
                    }
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(NetWeightAssociation))
            {
                switch (context.PropertyDescriptor.Name)
                {
                case "TableName":
                    if (value.GetType() == typeof(string))
                    {
                        string text = Convert.ToString(value);
                        if (string.IsNullOrEmpty(text))
                        {
                            return(Resources.TEXT_NONE_BR);
                        }
                    }
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(TerrainDataSource))
            {
                switch (context.PropertyDescriptor.Name)
                {
                case "FeatureClassName":
                    if (value.GetType() == typeof(string))
                    {
                        string text = Convert.ToString(value);
                        if (string.IsNullOrEmpty(text))
                        {
                            return(Resources.TEXT_NONE_BR);
                        }
                    }
                    break;
                }
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
        private void Model_ElementInvalid(object sender, ElementEventArgs e)
        {
            // Exit if GeometricNetwork Does not Exist
            if (this._geometricNetwork == null)
            {
                return;
            }

            // Get Element
            Element element = e.Value;

            if (element == null)
            {
                return;
            }
            EsriLine <GeometricNetworkControllerMembership> line = element as EsriLine <GeometricNetworkControllerMembership>;

            if (line == null)
            {
                return;
            }

            // Get Controller
            GeometricNetworkControllerMembership controller = line.Parent;

            // Suspend Rule Events
            controller.Suspend();

            // Get Start and End Elements
            Element elementStart = line.Start.Shape;
            Element elementEnd   = line.End.Shape;

            // Update GeometricNetwork Name Property
            if (elementStart == null)
            {
                controller.GeometricNetworkName = string.Empty;
            }
            else if (elementStart is EsriShape <GeometricNetwork> )
            {
                EsriShape <GeometricNetwork> shape            = (EsriShape <GeometricNetwork>)elementStart;
                GeometricNetwork             geometricNetwork = shape.Parent;
                controller.GeometricNetworkName = geometricNetwork.Name;
            }

            //
            DiagrammerEnvironment diagrammerEnvironment = DiagrammerEnvironment.Default;
            SchemaModel           schemaModel           = diagrammerEnvironment.SchemaModel;
            ObjectClass           objectClass           = schemaModel.FindParent(controller);

            if (objectClass != null)
            {
                objectClass.ControllerMemberships.Remove(controller);
            }

            if (elementEnd == null)
            {
                controller.AncillaryRoleFieldName = string.Empty;
                controller.EnabledFieldName       = string.Empty;
            }
            else if (elementEnd is EsriShape <FeatureClass> )
            {
                EsriShape <FeatureClass> es           = (EsriShape <FeatureClass>)elementEnd;
                FeatureClass             featureClass = es.Parent;
                featureClass.ControllerMemberships.Add(controller);
            }

            // Resume Controller Events
            controller.Resume();
        }
        private ObjectClass GetObjectClass(ITypeDescriptorContext context)
        {
            DiagrammerEnvironment de          = DiagrammerEnvironment.Default;
            SchemaModel           model       = de.SchemaModel;
            ObjectClass           objectClass = null;

            if (context.PropertyDescriptor.ComponentType == typeof(EdgeConnectivityRule))
            {
                EdgeConnectivityRule edgeConnectivityRule = (EdgeConnectivityRule)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "FromEdgeSubtypeCode":
                    objectClass = model.FindObjectClass(edgeConnectivityRule.FromClassID);
                    break;

                case "ToEdgeSubtypeCode":
                    objectClass = model.FindObjectClass(edgeConnectivityRule.ToClassID);
                    break;

                case "DefaultJunctionSubtypeCode":
                    objectClass = model.FindObjectClass(edgeConnectivityRule.DefaultJunctionID);
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(JunctionSubtype))
            {
                JunctionSubtype junctionSubtype = (JunctionSubtype)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "SubtypeCode":
                    objectClass = model.FindObjectClass(junctionSubtype.ClassID);
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(RelationshipRule))
            {
                RelationshipRule relationshipRule = (RelationshipRule)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "OriginSubtype":
                    objectClass = model.FindObjectClass(relationshipRule.OriginClass);
                    break;

                case "DestinationSubtype":
                    objectClass = model.FindObjectClass(relationshipRule.DestinationClass);
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(JunctionConnectivityRule))
            {
                JunctionConnectivityRule junctionConnectivityRule = (JunctionConnectivityRule)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "EdgeSubtypeCode":
                    objectClass = model.FindObjectClass(junctionConnectivityRule.EdgeClassID);
                    break;

                case "SubtypeCode":
                    objectClass = model.FindObjectClass(junctionConnectivityRule.JunctionClassID);
                    break;
                }
            }
            else if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule))
            {
                TopologyRule topologyRule = (TopologyRule)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "OriginSubtype":
                    objectClass = model.FindObjectClass(topologyRule.OriginClassId);
                    break;

                case "DestinationSubtype":
                    objectClass = model.FindObjectClass(topologyRule.DestinationClassId);
                    break;
                }
            }
            return(objectClass);
        }
        public override void Errors(List <Error> list)
        {
            // Write Base Errors
            base.Errors(list);

            // Origin Class Name
            ObjectClass origin = null;

            if (string.IsNullOrEmpty(this._originClassNames))
            {
                list.Add(new ErrorTable(this, "The 'OriginClassName' field cannot be empty", ErrorType.Error));
            }
            else
            {
                origin = DiagrammerEnvironment.Default.SchemaModel.FindObjectClass(this._originClassNames);
                if (origin == null)
                {
                    list.Add(new ErrorTable(this, "The 'OriginClassName' is not a valid table or feature class", ErrorType.Error));
                }
            }

            // Destination Class Name
            ObjectClass destination = null;

            if (string.IsNullOrEmpty(this._destinationClassNames))
            {
                list.Add(new ErrorTable(this, "The 'DestinationClassName' field cannot be empty", ErrorType.Error));
            }
            else
            {
                destination = DiagrammerEnvironment.Default.SchemaModel.FindObjectClass(this._destinationClassNames);
                if (destination == null)
                {
                    list.Add(new ErrorTable(this, "The 'DestinationClassName' is not a valid table or feature class", ErrorType.Error));
                }
            }

            // OriginPrimary
            if (string.IsNullOrEmpty(this._originPrimary))
            {
                list.Add(new ErrorTable(this, "The 'OriginPrimary' field cannot be empty", ErrorType.Error));
            }
            else
            {
                if (origin != null)
                {
                    Field field = origin.FindField(this._originPrimary);
                    if (field == null)
                    {
                        list.Add(new ErrorTable(this, "The 'OriginPrimary' does not exist in the origin table", ErrorType.Error));
                    }
                }
            }

            // Origin Foreign
            if (string.IsNullOrEmpty(this._originForeign))
            {
                list.Add(new ErrorTable(this, "The 'OriginForeign' field cannot be empty", ErrorType.Error));
            }
            else
            {
                if (this.IsAttributed)
                {
                    Field field = this.FindField(this._originForeign);
                    if (field == null)
                    {
                        list.Add(new ErrorTable(this, "The 'OriginForeign' does not exist in the relationship table", ErrorType.Error));
                    }
                }
                else
                {
                    if (destination != null)
                    {
                        Field field = destination.FindField(this._originForeign);
                        if (field == null)
                        {
                            list.Add(new ErrorTable(this, "The 'OriginForeign' does not exist in the destination table", ErrorType.Error));
                        }
                    }
                }
            }

            // Destination Primary
            if (string.IsNullOrEmpty(this._destinationPrimary))
            {
                if (this.IsAttributed)
                {
                    list.Add(new ErrorTable(this, "The 'DestinationPrimary' field cannot be empty in attributed relationships", ErrorType.Error));
                }
                else
                {
                    // OK
                }
            }
            else
            {
                if (this.IsAttributed)
                {
                    if (destination != null)
                    {
                        Field field = destination.FindField(this._destinationPrimary);
                        if (field == null)
                        {
                            list.Add(new ErrorTable(this, "The 'DestinationPrimary' does not exist in the destination table", ErrorType.Error));
                        }
                    }
                }
                else
                {
                    list.Add(new ErrorTable(this, "The 'DestinationPrimary' must be empty in non-attributed relationships", ErrorType.Error));
                }
            }

            // Destination Foreign
            if (string.IsNullOrEmpty(this._destinationForeign))
            {
                if (this.IsAttributed)
                {
                    list.Add(new ErrorTable(this, "The 'DestinationForeign' field cannot be empty in attributed relationships", ErrorType.Error));
                }
                else
                {
                    // OK
                }
            }
            else
            {
                if (this.IsAttributed)
                {
                    Field field = this.FindField(this._destinationForeign);
                    if (field == null)
                    {
                        list.Add(new ErrorTable(this, "The 'DestinationForeign' does not exist in the relationship table", ErrorType.Error));
                    }
                }
                else
                {
                    list.Add(new ErrorTable(this, "The 'DestinationForeign' must be empty in non-attributed relationships", ErrorType.Error));
                }
            }

            // CLSID
            if (this.IsAttributed)
            {
                // CLSID must be 'EsriRegistry.CLSID_ATTRIBUTED_RELATIONSHIP' if attributed
                if (string.IsNullOrEmpty(this._clsid))
                {
                    list.Add(new ErrorTable(this, string.Format("Attributed relationships must have a CLSID set to '{0}'.", EsriRegistry.CLASS_ATTRIBUTED_RELATIONSHIP), ErrorType.Error));
                }
                else
                {
                    Guid guid = Guid.Empty;
                    try {
                        guid = new Guid(this._clsid);
                    }
                    catch (FormatException) { }
                    catch (OverflowException) { }
                    if (guid == Guid.Empty)
                    {
                        list.Add(new ErrorTable(this, "CLSID is not a valid guid {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", ErrorType.Error));
                    }
                    else
                    {
                        if (guid.ToString("B").ToUpper() != EsriRegistry.CLASS_ATTRIBUTED_RELATIONSHIP)
                        {
                            list.Add(new ErrorTable(this, string.Format("Attributed relationships must have a CLSID set to '{0}'.", EsriRegistry.CLASS_ATTRIBUTED_RELATIONSHIP), ErrorType.Error));
                        }
                    }
                }
            }
            else
            {
                // CLSID must be blank if not attributed
                if (!string.IsNullOrEmpty(this._clsid))
                {
                    list.Add(new ErrorTable(this, "Non-attributes relationships must have be empty CLSID", ErrorType.Error));
                }
            }

            // EXTCLSID
            if (!string.IsNullOrEmpty(this.EXTCLSID))
            {
                list.Add(new ErrorTable(this, "EXTCLSID is must be empty for relationship classes", ErrorType.Error));
            }
        }
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            if (context == null)
            {
                return(null);
            }
            if (context.Instance == null)
            {
                return(null);
            }

            // Get Model
            DiagrammerEnvironment de = DiagrammerEnvironment.Default;

            if (de == null)
            {
                return(null);
            }
            SchemaModel model = de.SchemaModel;

            if (model == null)
            {
                return(null);
            }

            // Create List
            List <string> list = new List <string>();

            // In some cases do not display list of subtypes
            bool skip = false;

            if (context.PropertyDescriptor.ComponentType == typeof(TopologyRule))
            {
                // If "All Subtypes" then do not show dropdown
                TopologyRule topologyRule = (TopologyRule)context.Instance;
                switch (context.PropertyDescriptor.Name)
                {
                case "OriginSubtype":
                    skip = topologyRule.AllOriginSubtypes;
                    break;

                case "DestinationSubtype":
                    skip = topologyRule.AllDestinationSubtypes;
                    break;
                }
            }

            //
            if (!skip)
            {
                ObjectClass objectClass = this.GetObjectClass(context);
                if (objectClass != null)
                {
                    List <Subtype> subtypes = objectClass.GetSubtypes();
                    foreach (Subtype subtype in subtypes)
                    {
                        list.Add(subtype.SubtypeName);
                    }
                    if (subtypes.Count == 0)
                    {
                        list.Add(Resources.TEXT_CLASS_BR);
                    }
                }
            }

            // Sort List
            list.Sort();
            list.Insert(0, Resources.TEXT_NONE_BR);

            // Return List
            StandardValuesCollection svc = new StandardValuesCollection(list);

            return(svc);
        }
        //
        // PUBLIC METHODS
        //
        public override void OpenModel()
        {
            EsriShape <ObjectClass>     orig                = null;
            EsriShape <ObjectClass>     dest                = null;
            List <EsriShape <Subtype> > originSubtypes      = new List <EsriShape <Subtype> >();
            List <EsriShape <Subtype> > destinationSubtypes = new List <EsriShape <Subtype> >();

            // Exit if invalid
            if (this._relationshipClass == null)
            {
                return;
            }

            // Suspend Model
            if (ModelSettings.Default.EnableUndoRedo)
            {
                this.UndoList.Suspend();
            }
            this.Suspend();
            this.SuspendEvents = true;

            // Get Schema Model
            SchemaModel schemaModel = (SchemaModel)this._relationshipClass.Container;

            // Get Origin and Destination ObjectClasses
            ObjectClass objectClassOrig = schemaModel.FindObjectClass(this._relationshipClass.OriginClassName);
            ObjectClass objectClassDest = schemaModel.FindObjectClass(this._relationshipClass.DestinationClassName);

            // Add ObjectClasses
            orig = new EsriShape <ObjectClass>(objectClassOrig);
            dest = new EsriShape <ObjectClass>(objectClassDest);
            this.Shapes.Add(this.Shapes.CreateKey(), orig);
            this.Shapes.Add(this.Shapes.CreateKey(), dest);

            // Get Subtypes
            List <Subtype> subtypesOrig = objectClassOrig.GetSubtypes();
            List <Subtype> subtypesDest = objectClassDest.GetSubtypes();

            // Add Subtypes
            foreach (Subtype subtype in subtypesOrig)
            {
                EsriShape <Subtype> sub = new EsriShape <Subtype>(subtype);
                this.Shapes.Add(this.Shapes.CreateKey(), sub);

                Arrow arrow = new Arrow();
                arrow.BorderColor    = ModelSettings.Default.DisabledLined;
                arrow.DrawBackground = false;

                Line line = new Line(orig, sub);
                line.BorderColor     = ModelSettings.Default.DisabledLined;
                line.End.AllowMove   = false;
                line.End.Marker      = arrow;
                line.Start.AllowMove = false;
                this.Lines.Add(this.Lines.CreateKey(), line);

                originSubtypes.Add(sub);
            }
            foreach (Subtype subtype in subtypesDest)
            {
                EsriShape <Subtype> sub = new EsriShape <Subtype>(subtype);
                this.Shapes.Add(this.Shapes.CreateKey(), sub);

                Arrow arrow = new Arrow();
                arrow.BorderColor    = ModelSettings.Default.DisabledLined;
                arrow.DrawBackground = false;

                Line line = new Line(sub, dest);
                line.BorderColor     = ModelSettings.Default.DisabledLined;
                line.End.AllowMove   = false;
                line.Start.AllowMove = false;
                line.Start.Marker    = arrow;
                this.Lines.Add(this.Lines.CreateKey(), line);

                destinationSubtypes.Add(sub);
            }

            // Get Rules
            List <RelationshipRule> rules = this._relationshipClass.RelationshipRules;

            foreach (RelationshipRule rule in rules)
            {
                Shape shapeOrign = null;
                if (subtypesOrig.Count == 0)
                {
                    shapeOrign = orig;
                }
                else
                {
                    foreach (EsriShape <Subtype> subtype in originSubtypes)
                    {
                        if (subtype.Parent.SubtypeCode == rule.OriginSubtype)
                        {
                            shapeOrign = subtype;
                            break;
                        }
                    }
                }

                Shape shapeDestination = null;
                if (subtypesDest.Count == 0)
                {
                    shapeDestination = dest;
                }
                else
                {
                    foreach (EsriShape <Subtype> subtype in destinationSubtypes)
                    {
                        if (subtype.Parent.SubtypeCode == rule.DestinationSubtype)
                        {
                            shapeDestination = subtype;
                            break;
                        }
                    }
                }
                if (shapeOrign == null || shapeDestination == null)
                {
                    continue;
                }
                //
                EsriLine <RelationshipRule> line = new EsriLine <RelationshipRule>(rule, shapeOrign, shapeDestination);
                this.Lines.Add(this.Lines.CreateKey(), line);
            }

            // Perform Layout
            this.ExecuteLayout(typeof(HierarchicalLayout), true);

            // Resume and Refresh Model
            this.SuspendEvents = false;
            this.Resume();
            if (ModelSettings.Default.EnableUndoRedo)
            {
                this.UndoList.Resume();
            }
            this.Refresh();
        }
Beispiel #20
0
        //
        // CONSTRUCTOR
        //
        public EsriShape(T parent) : base()
        {
            this._parent = parent;

            //
            this.SuspendEvents = true;

            // Get a stencil containing some basic shapes
            BasicStencil stencil = (BasicStencil)Crainiate.ERM4.Component.Instance.GetStencil(typeof(BasicStencil));

            this.BorderWidth   = 2f;
            this.Size          = new Size(100, 40);
            this.SmoothingMode = SmoothingMode.HighQuality;
            this.StencilItem   = stencil[BasicStencilType.RoundedRectangle];
            this.Label         = new TextLabel();
            this.Label.Color   = ModelSettings.Default.TextColor;

            if (typeof(T) == typeof(DomainCodedValue))
            {
                DomainCodedValue domainCodedValue = this._parent as DomainCodedValue;
                this.BorderColor   = ColorSettings.Default.CodedValueDomainColor;
                this.GradientColor = ColorSettings.Default.CodedValueDomainColor;
                this.Label.Text    = domainCodedValue.Name;
                this.Tooltip       = domainCodedValue.Name;
            }
            else if (typeof(T) == typeof(DomainRange))
            {
                DomainRange domainRange = this._parent as DomainRange;
                this.BorderColor   = ColorSettings.Default.RangeDomainColor;
                this.GradientColor = ColorSettings.Default.RangeDomainColor;
                this.Label.Text    = domainRange.Name;
                this.Tooltip       = domainRange.Name;
            }
            else if (typeof(T) == typeof(FeatureClass))
            {
                FeatureClass featureClass = this._parent as FeatureClass;
                this.BorderColor   = ColorSettings.Default.FeatureClassColor;
                this.GradientColor = ColorSettings.Default.FeatureClassColor;
                this.Label.Text    = featureClass.Name;
                this.Tooltip       = featureClass.Name;
            }
            else if (typeof(T) == typeof(ObjectClass))
            {
                ObjectClass objectClass = this._parent as ObjectClass;
                this.BorderColor   = ColorSettings.Default.ObjectClassColor;
                this.GradientColor = ColorSettings.Default.ObjectClassColor;
                this.Label.Text    = objectClass.Name;
                this.Tooltip       = objectClass.Name;
            }
            else if (typeof(T) == typeof(RelationshipClass))
            {
                RelationshipClass relationship = this._parent as RelationshipClass;
                this.BorderColor   = ColorSettings.Default.RelationshipColor;
                this.GradientColor = ColorSettings.Default.RelationshipColor;
                this.Label.Text    = relationship.Name;
                this.Tooltip       = relationship.Name;
            }
            else if (typeof(T) == typeof(Subtype))
            {
                Subtype subtype = this._parent as Subtype;
                this.BorderColor   = ColorSettings.Default.SubtypeColor;
                this.GradientColor = ColorSettings.Default.SubtypeColor;
                this.Label.Text    = subtype.SubtypeName;
                this.Tooltip       = subtype.SubtypeName;
            }
            else if (typeof(T) == typeof(Field))
            {
                Field field = this._parent as Field;
                this.BorderColor   = ColorSettings.Default.FieldColor;
                this.GradientColor = ColorSettings.Default.FieldColor;
                this.Label.Text    = field.Name;
                this.Tooltip       = field.Name;
            }
            else if (typeof(T) == typeof(SubtypeField))
            {
                SubtypeField subtypeField = this._parent as SubtypeField;
                this.BorderColor   = ColorSettings.Default.SubtypeFieldColor;
                this.GradientColor = ColorSettings.Default.SubtypeFieldColor;
                this.Label.Text    = subtypeField.FieldName;
                this.Tooltip       = subtypeField.FieldName;
            }
            else if (typeof(T) == typeof(FeatureDataset))
            {
                FeatureDataset featureDataset = this._parent as FeatureDataset;
                this.BorderColor   = ColorSettings.Default.FeatureDatasetColor;
                this.GradientColor = ColorSettings.Default.FeatureDatasetColor;
                this.Label.Text    = featureDataset.Name;
                this.Tooltip       = featureDataset.Name;
            }
            else if (typeof(T) == typeof(GeometricNetwork))
            {
                GeometricNetwork geometricNetwork = this._parent as GeometricNetwork;
                this.BorderColor   = ColorSettings.Default.GeometricNetworkColor;
                this.GradientColor = ColorSettings.Default.GeometricNetworkColor;
                this.Label.Text    = geometricNetwork.Name;
                this.Tooltip       = geometricNetwork.Name;
            }
            else if (typeof(T) == typeof(Network))
            {
                Network network = this._parent as Network;
                this.BorderColor   = ColorSettings.Default.NetworkColor;
                this.GradientColor = ColorSettings.Default.NetworkColor;
                this.Label.Text    = network.Name;
                this.Tooltip       = network.Name;
            }
            else if (typeof(T) == typeof(Topology))
            {
                Topology topology = this._parent as Topology;
                this.BorderColor   = ColorSettings.Default.TopologyColor;
                this.GradientColor = ColorSettings.Default.TopologyColor;
                this.Label.Text    = topology.Name;
                this.Tooltip       = topology.Name;
            }
            else if (typeof(T) == typeof(Terrain))
            {
                Terrain terrain = this._parent as Terrain;
                this.BorderColor   = ColorSettings.Default.TerrainColor;
                this.GradientColor = ColorSettings.Default.TerrainColor;
                this.Label.Text    = terrain.Name;
                this.Tooltip       = terrain.Name;
            }

            //
            this.SuspendEvents = false;
        }
        //
        // PUBLIC METHODS
        //
        public override void OpenModel(string filename) {
            // Exit if FileName is invalid
            if (string.IsNullOrEmpty(filename)) { return; }

            // Exit if File does not exist
            if (!File.Exists(filename)) { return; }

            // Open XML Workspace
            XPathDocument document = null;
            try {
                document = new XPathDocument(filename, XmlSpace.None);
            }
            catch (XmlException ex) {
                MessageBox.Show(
                    "The XML file failed to load. Please select 'View > Exceptions' to view a detailed explanation.",
                    Resources.TEXT_APPLICATION,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly);

                // Add Exception
                ExceptionDialog.HandleException(ex);
            }
            if (document == null) { return; }

            // Get XPathNavigator (IXPathNavigable::CreateNavigator)
            XPathNavigator navigator = document.CreateNavigator();

            // Get <esri:Workspace>
            if (!navigator.MoveToFirstChild()) {
                MessageBox.Show(
                    "This file is not a valid ESRI xml workspace document",
                    Resources.TEXT_APPLICATION,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly);
                return;
            }

            // Check Node Name
            if (navigator.Name != "esri:Workspace") {
                MessageBox.Show(
                    "This file is not a valid ESRI xml workspace document",
                    Resources.TEXT_APPLICATION,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly);
                return;
            }

            // Create Xml Namespace Manager
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(navigator.NameTable);
            namespaceManager.AddNamespace(Xml._XSI, Xml.XMLSCHEMAINSTANCE);

            // Suspend Model
            this.Suspend();
            this.SuspendEvents = true;
            if (ModelSettings.Default.EnableUndoRedo) {
                this.UndoList.Suspend();
            }

            // Select Domains
            XPathNodeIterator iteratorDomain = navigator.Select("WorkspaceDefinition/Domains/Domain");

            // Add Domains
            while (iteratorDomain.MoveNext()) {
                XPathNavigator domain = iteratorDomain.Current;
                XPathNavigator type = domain.SelectSingleNode(Xml._XSITYPE, namespaceManager);
                switch (type.Value) {
                    case Xml._RANGEDOMAIN:
                        DomainRange domainRange = new DomainRange(domain);
                        this.Shapes.Add(this.Shapes.CreateKey(), domainRange);
                        break;
                    case Xml._CODEDVALUEDOMAIN:
                        DomainCodedValue domainCodedValue = new DomainCodedValue(domain);
                        this.Shapes.Add(this.Shapes.CreateKey(), domainCodedValue);
                        break;
                }
            }

            // Select Root DataElements
            XPathNodeIterator iteratorDataElement = navigator.Select("WorkspaceDefinition/DatasetDefinitions/DataElement");
            while (iteratorDataElement.MoveNext()) {
                XPathNavigator dataElement = iteratorDataElement.Current;
                XPathNavigator type = dataElement.SelectSingleNode(Xml._XSITYPE, namespaceManager);
                switch (type.Value) {
                    case Xml._DEFEATUREDATASET:
                        // Create FeatureDataset
                        FeatureDataset featureDataset = new FeatureDataset(dataElement);
                        this.Shapes.Add(this.Shapes.CreateKey(), featureDataset);

                        // Loop for Child DataElements
                        XPathNodeIterator iteratorDataElement2 = dataElement.Select("Children/DataElement");
                        while (iteratorDataElement2.MoveNext()) {
                            XPathNavigator dataElement2 = iteratorDataElement2.Current;
                            XPathNavigator type2 = dataElement2.SelectSingleNode(Xml._XSITYPE, namespaceManager);
                            switch (type2.Value) {
                                case Xml._DEFEATURECLASS:
                                    // Create FeatureClass
                                    FeatureClass featureClass2 = new FeatureClass(dataElement2);
                                    this.Shapes.Add(this.Shapes.CreateKey(), featureClass2);

                                    // Create Link to FeatureDataset
                                    Link link1 = new Link(featureDataset, featureClass2);
                                    link1.BorderColor = ModelSettings.Default.EnabledLines;
                                    link1.BorderStyle = DashStyle.Solid;
                                    link1.BorderWidth = 1f;
                                    link1.End.Marker.BorderColor = ModelSettings.Default.EnabledLines;
                                    this.Lines.Add(this.Lines.CreateKey(), link1);

                                    // Add Subtypes
                                    this.AddSubtypes(featureClass2, dataElement2);

                                    break;
                                case Xml._DEGEOMETRICNETWORK:
                                    // Create GeometricNetwork
                                    GeometricNetwork geometricNetwork = new GeometricNetwork(dataElement2);
                                    this.Shapes.Add(this.Shapes.CreateKey(), geometricNetwork);

                                    // Create Link to FeatureDataset
                                    Link link2 = new Link(featureDataset, geometricNetwork);
                                    link2.BorderColor = ModelSettings.Default.EnabledLines;
                                    link2.BorderStyle = DashStyle.Solid;
                                    link2.BorderWidth = 1f;
                                    link2.End.Marker.BorderColor = ModelSettings.Default.EnabledLines;
                                    this.Lines.Add(this.Lines.CreateKey(), link2);

                                    break;
                                case Xml._DERELATIONSHIPCLASS:
                                    // Create Relationship
                                    RelationshipClass relationshipClass = new RelationshipClass(dataElement2);
                                    this.Shapes.Add(this.Shapes.CreateKey(), relationshipClass);

                                    // Create Link to FeatureDataset
                                    Link link3 = new Link(featureDataset, relationshipClass);
                                    link3.BorderColor = ModelSettings.Default.EnabledLines;
                                    link3.BorderStyle = DashStyle.Solid;
                                    link3.BorderWidth = 1f;
                                    link3.End.Marker.BorderColor = ModelSettings.Default.EnabledLines;
                                    this.Lines.Add(this.Lines.CreateKey(), link3);

                                    break;
                                case Xml._DETOPOLOGY:
                                    // Create Topology
                                    Topology topology = new Topology(dataElement2);
                                    this.Shapes.Add(this.Shapes.CreateKey(), topology);

                                    // Create Link to FeatureDataset
                                    Link link4 = new Link(featureDataset, topology);
                                    link4.BorderColor = ModelSettings.Default.EnabledLines;
                                    link4.BorderStyle = DashStyle.Solid;
                                    link4.BorderWidth = 1f;
                                    link4.End.Marker.BorderColor = ModelSettings.Default.EnabledLines;
                                    this.Lines.Add(this.Lines.CreateKey(), link4);

                                    break;
                                case Xml._DENETWORKDATASET:
                                    // Create Network Dataset
                                    Network network = new Network(dataElement2);
                                    this.Shapes.Add(this.Shapes.CreateKey(), network);

                                    // Create Link to FeatureDataset
                                    Link link5 = new Link(featureDataset, network);
                                    link5.BorderColor = ModelSettings.Default.EnabledLines;
                                    link5.BorderStyle = DashStyle.Solid;
                                    link5.BorderWidth = 1f;
                                    link5.End.Marker.BorderColor = ModelSettings.Default.EnabledLines;
                                    this.Lines.Add(this.Lines.CreateKey(), link5);

                                    break;
                                case Xml._DETERRAIN:
                                    // Create Network Dataset
                                    Terrain terrain = new Terrain(dataElement2);
                                    this.Shapes.Add(this.Shapes.CreateKey(), terrain);

                                    // Create Link to FeatureDataset
                                    Link link6 = new Link(featureDataset, terrain);
                                    link6.BorderColor = ModelSettings.Default.EnabledLines;
                                    link6.BorderStyle = DashStyle.Solid;
                                    link6.BorderWidth = 1f;
                                    link6.End.Marker.BorderColor = ModelSettings.Default.EnabledLines;
                                    this.Lines.Add(this.Lines.CreateKey(), link6);

                                    break;
                            }
                        }

                        break;
                    case Xml._DEFEATURECLASS:
                        // Create FeatureClass
                        FeatureClass featureClass = new FeatureClass(dataElement);
                        this.Shapes.Add(this.Shapes.CreateKey(), featureClass);

                        // Add Subtypes
                        this.AddSubtypes(featureClass, dataElement);

                        break;
                    case Xml._DETABLE:
                        // Create Table
                        ObjectClass objectClass = new ObjectClass(dataElement);
                        this.Shapes.Add(this.Shapes.CreateKey(), objectClass);

                        // Add Subtypes
                        this.AddSubtypes(objectClass, dataElement);

                        break;
                    case Xml._DERASTERCATALOG:
                        // Create Table
                        RasterCatalog rasterCatalog = new RasterCatalog(dataElement);
                        this.Shapes.Add(this.Shapes.CreateKey(), rasterCatalog);

                        break;
                    case Xml._DERELATIONSHIPCLASS:
                        // Create Relationship
                        RelationshipClass relationshipClass2 = new RelationshipClass(dataElement);
                        this.Shapes.Add(this.Shapes.CreateKey(), relationshipClass2);

                        break;
                    case Xml._DERASTERDATASET:
                        // Create RasterDataset
                        RasterDataset rasterDataset = new RasterDataset(dataElement);
                        this.Shapes.Add(this.Shapes.CreateKey(), rasterDataset);

                        // Loop for Child DataElements
                        XPathNodeIterator iteratorDataElement3 = dataElement.Select("Children/DataElement");
                        while (iteratorDataElement3.MoveNext()) {
                            XPathNavigator dataElement2 = iteratorDataElement3.Current;
                            XPathNavigator type2 = dataElement2.SelectSingleNode(Xml._XSITYPE, namespaceManager);
                            switch (type2.Value) {
                                case Xml._DERASTERBAND:
                                    // Create FeatureClass
                                    RasterBand rasterBand = new RasterBand(dataElement2);
                                    this.Shapes.Add(this.Shapes.CreateKey(), rasterBand);

                                    // Create Link to FeatureDataset
                                    Link link = new Link(rasterDataset, rasterBand);
                                    link.BorderColor = ModelSettings.Default.EnabledLines;
                                    link.BorderStyle = DashStyle.Solid;
                                    link.BorderWidth = 1f;
                                    link.End.Marker.BorderColor = ModelSettings.Default.EnabledLines;
                                    this.Lines.Add(this.Lines.CreateKey(), link);

                                    break;
                            }
                        }

                        break;
                }
            }

            // <esri:Workspace><WorkspaceDefinition><Metadata><XmlDoc>
            XPathNavigator navigatorMetadata = navigator.SelectSingleNode("WorkspaceDefinition/Metadata/XmlDoc");
            if (navigatorMetadata != null) {
                this._metadata = navigatorMetadata.Value;
            }

            // <WorkspaceType>
            XPathNavigator navigatorWorkspaceType = navigator.SelectSingleNode("WorkspaceDefinition/WorkspaceType");
            if (navigatorWorkspaceType != null) {
                this._workspaceType = (esriWorkspaceType)Enum.Parse(typeof(esriWorkspaceType), navigatorWorkspaceType.Value, true);
            }

            // <Version>
            XPathNavigator navigatorVersion = navigator.SelectSingleNode("WorkspaceDefinition/Version");
            if (navigatorVersion != null) {
                this._version = navigatorVersion.Value;
            }

            // Close XML Document
            document = null;

            // Perform Layout
            this.ExecuteLayout(typeof(HierarchicalLayout), true);

            // Resume and Refresh Model
            if (ModelSettings.Default.EnableUndoRedo) {
                this.UndoList.Resume();
            }
            this.SuspendEvents = false;
            this.Resume();
            this.Refresh();

            // Make Dirty
            this._dirty = true;
        }
Beispiel #22
0
        public override void Errors(List <Error> list)
        {
            // Get Parent ObjectClass
            ObjectClass objectClass = (ObjectClass)this.Table;

            // Get ObjectClass Fields
            List <Field> fields = objectClass.GetFields();

            // Get Schema Model
            SchemaModel model = (SchemaModel)objectClass.Container;

            // Add GeometryDef Errors
            if (this._geometryDef != null)
            {
                this._geometryDef.Errors(list, (EsriTable)this.Table);
            }

            // GeometryDef only valid for Geometry Fields
            switch (this._fieldType)
            {
            case esriFieldType.esriFieldTypeGeometry:
                if (this._geometryDef == null)
                {
                    list.Add(new ErrorTableRow(this, "Geometry Fields Must have a GeometryDef defined.", ErrorType.Error));
                }
                break;

            case esriFieldType.esriFieldTypeBlob:
            case esriFieldType.esriFieldTypeDate:
            case esriFieldType.esriFieldTypeDouble:
            case esriFieldType.esriFieldTypeGlobalID:
            case esriFieldType.esriFieldTypeGUID:
            case esriFieldType.esriFieldTypeInteger:
            case esriFieldType.esriFieldTypeOID:
            case esriFieldType.esriFieldTypeRaster:
            case esriFieldType.esriFieldTypeSingle:
            case esriFieldType.esriFieldTypeSmallInteger:
            case esriFieldType.esriFieldTypeString:
            case esriFieldType.esriFieldTypeXML:
                if (this._geometryDef != null)
                {
                    list.Add(new ErrorTableRow(this, "Only Geometry Fields can have a GeometryDef defined.", ErrorType.Error));
                }
                break;
            }

            // Raster Fields can have a RasterDef
            switch (this._fieldType)
            {
            case esriFieldType.esriFieldTypeRaster:
                if (this._rasterDef == null)
                {
                    string message = string.Format("The raster field [{0}] does not have a RasterDef assigned", this._name);
                    list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                }
                break;

            case esriFieldType.esriFieldTypeBlob:
            case esriFieldType.esriFieldTypeDate:
            case esriFieldType.esriFieldTypeDouble:
            case esriFieldType.esriFieldTypeGeometry:
            case esriFieldType.esriFieldTypeGUID:
            case esriFieldType.esriFieldTypeInteger:
            case esriFieldType.esriFieldTypeOID:
            case esriFieldType.esriFieldTypeSingle:
            case esriFieldType.esriFieldTypeSmallInteger:
            case esriFieldType.esriFieldTypeString:
            case esriFieldType.esriFieldTypeGlobalID:
            case esriFieldType.esriFieldTypeXML:
                if (this._rasterDef != null)
                {
                    string message = string.Format("The field [{0}] is invalid. Only raster fields can have a RasterDef", this._name);
                    list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                }
                break;
            }

            // Field Name Null or Empty
            if (string.IsNullOrEmpty(this._name))
            {
                list.Add(new ErrorTableRow(this, "Field names cannot be empty", ErrorType.Error));
            }

            // Validate Field Name
            if (!string.IsNullOrEmpty(this._name))
            {
                // Get Validator
                Validator validator = WorkspaceValidator.Default.Validator;
                string    message   = null;
                if (!validator.ValidateFieldName(this._name, out message))
                {
                    string message2 = string.Format("Field [{0}] {1}", this._name, message);
                    list.Add(new ErrorTableRow(this, message2, ErrorType.Error));
                }
            }

            // Alias name more than 255 characters long
            if (!string.IsNullOrEmpty(this._aliasName))
            {
                if (this._aliasName.Length > 255)
                {
                    string message = string.Format("Field [{0}]. Alias name cannot be longer than 255 characters", this._name);
                    list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                }
            }

            // Find Domain
            Domain domain = null;

            if (!string.IsNullOrEmpty(this._domain))
            {
                domain = model.FindDomain(this._domain);

                if (domain == null)
                {
                    // Domain does not exit
                    string message = string.Format("The domain [{0}] for field [{1}] does not exist", this._domain, this._name);
                    list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                }
                else
                {
                    // Compare domain and field types
                    if (this._fieldType != domain.FieldType)
                    {
                        string message = string.Format("The field [{0}] and assigned domain [{1}] do not have matching field types", this._name, this._domain);
                        list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                    }

                    // Check Default Value
                    if (!string.IsNullOrEmpty(this._defaultValue))
                    {
                        string message = null;
                        if (!domain.IsValid(this._defaultValue, out message))
                        {
                            list.Add(new ErrorTableRow(this, message, ErrorType.Warning));
                        }
                    }

                    // Check if a domain value is too long for the text field
                    if (this._fieldType == esriFieldType.esriFieldTypeString &&
                        domain.FieldType == esriFieldType.esriFieldTypeString &&
                        domain.GetType() == typeof(DomainCodedValue))
                    {
                        DomainCodedValue domain2 = (DomainCodedValue)domain;
                        foreach (DomainCodedValueRow x in domain2.CodedValues)
                        {
                            if (string.IsNullOrEmpty(x.Code))
                            {
                                continue;
                            }
                            if (x.Code.Length > this._length)
                            {
                                string message = string.Format("The domain [{0}] has a value [{1}] that is too long for the field [{2}]", this._domain, x, this._name);
                                list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                            }
                        }
                    }
                }
            }

            // Check validity of default value against field type
            if (!string.IsNullOrEmpty(this._defaultValue))
            {
                string message;
                if (!GeodatabaseUtility.IsValidateValue(this._fieldType, this._defaultValue, out message))
                {
                    string message2 = string.Format("Default value '{0}' {1}", this._defaultValue, message);
                    list.Add(new ErrorTableRow(this, message2, ErrorType.Error));
                }
            }

            // Check for unsupported field types
            switch (this._fieldType)
            {
            case esriFieldType.esriFieldTypeBlob:
            case esriFieldType.esriFieldTypeDate:
            case esriFieldType.esriFieldTypeDouble:
            case esriFieldType.esriFieldTypeGeometry:
            case esriFieldType.esriFieldTypeGUID:
            case esriFieldType.esriFieldTypeInteger:
            case esriFieldType.esriFieldTypeOID:
            case esriFieldType.esriFieldTypeRaster:
            case esriFieldType.esriFieldTypeSingle:
            case esriFieldType.esriFieldTypeSmallInteger:
            case esriFieldType.esriFieldTypeString:
            case esriFieldType.esriFieldTypeGlobalID:
                break;

            case esriFieldType.esriFieldTypeXML:
                string message = string.Format("Field type '{0}' is unsupported", this._fieldType.ToString());
                list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                break;
            }

            // Length must be > 0
            if (this._length < 0)
            {
                list.Add(new ErrorTableRow(this, "Field length cannot be less than zero", ErrorType.Error));
            }

            // ModelName cannot be longer than 255 characters
            if (!(string.IsNullOrEmpty(this._modelName)))
            {
                if (this._modelName.Length > 255)
                {
                    list.Add(new ErrorTableRow(this, "Model name cannot be greater than 255 characters long", ErrorType.Error));
                }
            }

            // Precision must be > 0
            if (this._precision < 0)
            {
                list.Add(new ErrorTableRow(this, "Field precision cannot be less than zero", ErrorType.Error));
            }

            // Scale must be > 0
            if (this._scale < 0)
            {
                list.Add(new ErrorTableRow(this, "Field scake cannot be less than zero", ErrorType.Error));
            }

            // IsNullable
            if (this._isNullable)
            {
                switch (this._fieldType)
                {
                case esriFieldType.esriFieldTypeBlob:
                case esriFieldType.esriFieldTypeDate:
                case esriFieldType.esriFieldTypeDouble:
                case esriFieldType.esriFieldTypeGeometry:
                case esriFieldType.esriFieldTypeGUID:
                case esriFieldType.esriFieldTypeInteger:
                case esriFieldType.esriFieldTypeRaster:
                case esriFieldType.esriFieldTypeSingle:
                case esriFieldType.esriFieldTypeSmallInteger:
                case esriFieldType.esriFieldTypeString:
                case esriFieldType.esriFieldTypeXML:
                    break;

                case esriFieldType.esriFieldTypeGlobalID:
                case esriFieldType.esriFieldTypeOID:
                    string message = string.Format("Field type '{0}' cannot have IsNullable = True", this._fieldType.ToString());
                    list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                    break;
                }
            }
        }