Ejemplo n.º 1
0
        public override void Errors(List <Error> list)
        {
            // Field Name
            if (string.IsNullOrEmpty(this._name))
            {
                list.Add(new ErrorTableRow(this, "Index Field names can not be empty", ErrorType.Error));
            }
            else
            {
                // Get Parent Index
                Index index = (Index)base.Parent;

                // Get Sibling IndexFields
                List <IndexField> indexFields = index.GetIndexFields();

                // Check for duplicate IndexField names
                foreach (IndexField indexField in indexFields)
                {
                    if (indexField == this)
                    {
                        continue;
                    }
                    if (indexField.Name == this._name)
                    {
                        // Duplicate IndexField Name found
                        string message = string.Format(
                            "Index Field name '{0}' is duplicated in Index {1}",
                            this._name,
                            index.Name);
                        list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                        break;
                    }
                }

                // Find Field
                Field field = null;
                if (this.Table is ObjectClass)
                {
                    ObjectClass objectClass = (ObjectClass)this.Table;
                    field = objectClass.FindField(this._name);
                }
                else if (this.Table is RasterBand)
                {
                    RasterBand rasterBand = (RasterBand)this.Table;
                    field = rasterBand.FindField(this._name);
                }

                // Error if Field not found
                if (field == null)
                {
                    // Field cannot be found in parent ObjectClass/RasterBand
                    string message = string.Format("Index Field '{0}' is missing from parent dataset", this._name);
                    list.Add(new ErrorTableRow(this, message, ErrorType.Error));
                }
            }
        }
Ejemplo n.º 2
0
        public override void WriteXml(XmlWriter writer)
        {
            Field field = null;

            if (this.Table is ObjectClass)
            {
                ObjectClass objectClass = (ObjectClass)this.Table;
                field = objectClass.FindField(this._name);
            }
            else if (this.Table is RasterBand)
            {
                RasterBand rasterBand = (RasterBand)this.Table;
                field = rasterBand.FindField(this._name);
            }
            if (field == null)
            {
                return;
            }
            field.WriteXml(writer);
        }
        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));
            }
        }
Ejemplo n.º 4
0
        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));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        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();
            }
        }