//
        // PUBLIC METHODS
        //
        /// <summary>
        /// Validates a table name
        /// </summary>
        /// <param name="name">The table name to validate</param>
        /// <param name="message">If table name fails then this variable will contain a description</param>
        /// <returns>True if passed. False if failed.</returns>
        public bool ValidateTableName(string name, out string message)
        {
            // Check Arguments
            if (string.IsNullOrEmpty(name))
            {
                throw new NullReferenceException("<name> argument cannot be null");
            }

            // Get Table Name
            string tableName = GeodatabaseUtility.GetTableName(name);

            // Validate Table Name
            IFieldChecker fieldChecker = new FieldCheckerClass();

            fieldChecker.ValidateWorkspace = this._workspace;
            string newName = null;
            int    error   = fieldChecker.ValidateTableName(tableName, out newName);

            // Create Message
            switch (error)
            {
            case 0:
                message = null;
                break;

            case 1:
                message = string.Format("Table name [{0}] contains a reserved word.", name);
                break;

            case 2:
                message = string.Format("Table name [{0}] contains an invalid character.", name);
                break;

            case 4:
                message = string.Format("Table name [{0}] has invalid starting character.", name);
                break;

            default:
                message = string.Format("Table name [{0}] is invalid.", name);
                break;
            }

            // Append Recommended Name
            switch (error)
            {
            case 0:
                return(true);

            default:
                if (!(string.IsNullOrEmpty(newName)))
                {
                    if (newName != name)
                    {
                        message += string.Format(" Try [{0}].", newName);
                    }
                }
                return(false);
            }
        }
        public static string ProcessDataObject(DragEventArgs e)
        {
            // If the dropped object is from ArcCatalog then export the geodatabase
            // to XML and return pathname.
            if (e.Data.GetDataPresent("ESRI Names"))
            {
                return(GeodatabaseUtility.ExportXml(e));
            }

            // If a use dropped one or more files then get first file and verify that it
            // has a "xml" or "diagram" extension.
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                object drop = e.Data.GetData(DataFormats.FileDrop);
                if (drop == null)
                {
                    return(null);
                }

                string[] files = drop as string[];
                if (files == null)
                {
                    return(null);
                }
                if (files.Length != 1)
                {
                    return(null);
                }

                string file      = files[0];
                string extension = System.IO.Path.GetExtension(file);
                switch (extension.ToUpper())
                {
                case ".XML":
                case ".DIAGRAM":
                    return(file);

                default:
                    return(null);
                }
            }

            // Invalid DataObject. Return Null.
            return(null);
        }
        public static string ExportXml(DragEventArgs e)
        {
            // Get dropped object
            if (!e.Data.GetDataPresent("ESRI Names"))
            {
                return(null);
            }
            object drop = e.Data.GetData("ESRI Names");

            // Convert to byte array
            MemoryStream memoryStream = (MemoryStream)drop;

            byte[] bytes     = memoryStream.ToArray();
            object byteArray = (object)bytes;

            // Get First WorkpaceName
            INameFactory   nameFactory   = new NameFactoryClass();
            IEnumName      enumName      = nameFactory.UnpackageNames(ref byteArray);
            IName          name          = enumName.Next();
            IWorkspaceName workspaceName = name as IWorkspaceName;

            if (workspaceName != null)
            {
                return(GeodatabaseUtility.ExportWorkspaceXml(workspaceName));
            }
            ;

            MessageBox.Show(
                Resources.TEXT_DROPPED_OBJECT_NOT_VALID_GEODATABASE,
                Resources.TEXT_APPLICATION,
                MessageBoxButtons.OK,
                MessageBoxIcon.Error,
                MessageBoxDefaultButton.Button1,
                MessageBoxOptions.DefaultDesktopOnly);
            return(null);
        }
        private void AddDataset(XmlWriter writer, IDatasetName datasetName)
        {
            // Check Parameters
            if (writer == null)
            {
                return;
            }
            if (datasetName == null)
            {
                return;
            }

            // Open Dataset
            IName name = datasetName as IName;

            if (name == null)
            {
                return;
            }
            object o = null;

            try {
                o = name.Open();
            }
            catch { }
            if (o == null)
            {
                return;
            }
            IDataset dataset = o as IDataset;

            if (dataset == null)
            {
                return;
            }
            IFeatureClass featureClass = dataset as IFeatureClass;

            // <Dataset>
            writer.WriteStartElement("Dataset");

            // <Dataset><Name>
            writer.WriteStartElement("Name");
            writer.WriteValue(dataset.Name);
            writer.WriteEndElement();

            // <Dataset><Type>
            string type = string.Empty;

            switch (dataset.Type)
            {
            case esriDatasetType.esriDTFeatureClass:
                if (featureClass == null)
                {
                    type += "Unknown";
                    break;
                }
                switch (featureClass.FeatureType)
                {
                case esriFeatureType.esriFTAnnotation:
                case esriFeatureType.esriFTDimension:
                case esriFeatureType.esriFTSimple:
                    type += GeodatabaseUtility.GetDescription(esriDatasetType.esriDTFeatureClass);
                    break;

                default:
                    type += GeodatabaseUtility.GetDescription(featureClass.FeatureType);
                    break;
                }
                break;

            default:
                type += GeodatabaseUtility.GetDescription(dataset.Type);
                break;
            }
            writer.WriteStartElement("Type");
            writer.WriteValue(type);
            writer.WriteEndElement();

            // <Dataset><Geometry>
            string geometry = "-";

            if (featureClass != null)
            {
                switch (featureClass.FeatureType)
                {
                case esriFeatureType.esriFTAnnotation:
                case esriFeatureType.esriFTDimension:
                    geometry = GeodatabaseUtility.GetDescription(featureClass.FeatureType);
                    break;

                default:
                    geometry = GeodatabaseUtility.GetDescription(featureClass.ShapeType);
                    break;
                }
            }
            writer.WriteStartElement("Geometry");
            writer.WriteValue(geometry);
            writer.WriteEndElement();

            //if (dataset is IFeatureClass) {
            //    IFeatureClass featureClass = (IFeatureClass)dataset;

            //    // <Dataset><FeatureType>
            //    writer.WriteStartElement("FeatureType");
            //    writer.WriteValue(GeodatabaseUtility.GetDescription(featureClass.FeatureType));
            //    writer.WriteEndElement();

            //    // Add ...<Dataset><ShapeType>
            //    switch (featureClass.FeatureType) {
            //        case esriFeatureType.esriFTAnnotation:
            //        case esriFeatureType.esriFTDimension:
            //            break;
            //        default:
            //            writer.WriteStartElement("ShapeType");
            //            writer.WriteValue(GeodatabaseUtility.GetDescription(featureClass.ShapeType));
            //            writer.WriteEndElement();
            //            break;
            //    }
            //}

            // Get Row Count
            ITable table       = dataset as ITable;
            int    intRowCount = -1;

            if (table != null)
            {
                try {
                    intRowCount = table.RowCount(null);
                }
                catch { }
            }

            // <Dataset><RowCount>
            writer.WriteStartElement("RowCount");
            switch (intRowCount)
            {
            case -1:
                writer.WriteValue("Error");
                break;

            case 0:
            default:
                writer.WriteValue(intRowCount.ToString());
                break;
            }
            writer.WriteEndElement();

            if (intRowCount > 0)
            {
                if (dataset is IGeoDataset)
                {
                    IGeoDataset geoDataset = (IGeoDataset)dataset;
                    IEnvelope   envelope   = geoDataset.Extent;
                    if (envelope != null && !envelope.IsEmpty)
                    {
                        // <Dataset><Extent>
                        writer.WriteStartElement("Extent");

                        // <Dataset><Extent><XMax>
                        writer.WriteStartElement("XMax");
                        writer.WriteValue(envelope.XMax.ToString());
                        writer.WriteEndElement();

                        // <Dataset><Extent><XMin>
                        writer.WriteStartElement("XMin");
                        writer.WriteValue(envelope.XMin.ToString());
                        writer.WriteEndElement();

                        // <Dataset><Extent><YMax>
                        writer.WriteStartElement("YMax");
                        writer.WriteValue(envelope.YMax.ToString());
                        writer.WriteEndElement();

                        // <Dataset><Extent><YMin>
                        writer.WriteStartElement("YMin");
                        writer.WriteValue(envelope.YMin.ToString());
                        writer.WriteEndElement();

                        // <Dataset></Extent>
                        writer.WriteEndElement();

                        // <Dataset><SmallImage>
                        if (DataReportSettings.Default.ShowSmallImage)
                        {
                            string smallImage = System.IO.Path.GetTempFileName();
                            writer.WriteStartElement("SmallImage");
                            writer.WriteValue(smallImage);
                            writer.WriteEndElement();
                            GeodatabaseUtility.CreateBitmap(
                                dataset,
                                DataReportSettings.Default.SmallImageType,
                                DataReportSettings.Default.SmallImageSize,
                                DataReportSettings.Default.SmallImageResolution,
                                DataReportSettings.Default.SmallImageBackgroundColor,
                                smallImage);
                        }

                        // <Dataset><LargeImage>
                        if (DataReportSettings.Default.ShowLargeImage)
                        {
                            string largeImage = System.IO.Path.GetTempFileName();
                            writer.WriteStartElement("LargeImage");
                            writer.WriteValue(largeImage);
                            writer.WriteEndElement();
                            GeodatabaseUtility.CreateBitmap(
                                dataset,
                                DataReportSettings.Default.LargeImageType,
                                DataReportSettings.Default.LargeImageSize,
                                DataReportSettings.Default.LargeImageResolution,
                                DataReportSettings.Default.LargeImageBackgroundColor,
                                largeImage);
                        }
                    }
                }
            }

            ISubtypes subtypes = dataset as ISubtypes;

            if (subtypes != null && subtypes.HasSubtype)
            {
                int          subtypeCode = 0;
                IEnumSubtype enumSubtype = subtypes.Subtypes;
                string       subtypeName = enumSubtype.Next(out subtypeCode);
                while (subtypeName != null)
                {
                    // <Dataset><Sybtype>
                    writer.WriteStartElement("Subtype");

                    // <Dataset><Sybtype><Name>
                    writer.WriteStartElement("Name");
                    writer.WriteValue(subtypeName);
                    writer.WriteEndElement();

                    // Get Row Count
                    IQueryFilter queryFilter = new QueryFilterClass();
                    queryFilter.WhereClause = string.Format("{0} = {1}", subtypes.SubtypeFieldName, subtypeCode.ToString());
                    int rowCount = table.RowCount(queryFilter);

                    // <Dataset><Sybtype><RowCount>
                    writer.WriteStartElement("RowCount");
                    writer.WriteValue(rowCount.ToString());
                    writer.WriteEndElement();

                    // <Dataset></Sybtype>
                    writer.WriteEndElement();

                    // Get Next Subtype
                    subtypeName = enumSubtype.Next(out subtypeCode);
                }
            }

            // </Dataset>
            writer.WriteEndElement();
        }
        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));
                            }
                        }
                    }
                }
            }
        }
        //
        // CONSTRUCTOR
        //
        public NetworkAttribute(IXPathNavigable path) : base(path)
        {
            // Get Navigator
            XPathNavigator navigator = path.CreateNavigator();

            // <ID>
            XPathNavigator navigatorID = navigator.SelectSingleNode("ID");

            if (navigatorID != null)
            {
                this._id = navigatorID.ValueAsInt;
            }

            // <Name>
            XPathNavigator navigatorName = navigator.SelectSingleNode("Name");

            if (navigatorName != null)
            {
                this._name = navigatorName.Value;
            }

            // <Units>
            XPathNavigator navigatorUnits = navigator.SelectSingleNode("Units");

            if (navigatorUnits != null)
            {
                this._units = GeodatabaseUtility.GetNetworkAttributeUnits(navigatorUnits.Value);
            }

            // <DataType>
            XPathNavigator navigatorDataType = navigator.SelectSingleNode("DataType");

            if (navigatorDataType != null)
            {
                this._dataType = (esriNetworkAttributeDataType)Enum.Parse(typeof(esriNetworkAttributeDataType), navigatorDataType.Value, true);
            }

            // <UsageType>
            XPathNavigator navigatorUsageType = navigator.SelectSingleNode("UsageType");

            if (navigatorUsageType != null)
            {
                this._usageType = (esriNetworkAttributeUsageType)Enum.Parse(typeof(esriNetworkAttributeUsageType), navigatorUsageType.Value, true);
            }

            // <UserData><PropertyArray><PropertySetProperty>
            this._userData = new List <Property>();
            XPathNodeIterator interatorProperty = navigator.Select("UserData/PropertyArray/PropertySetProperty");

            while (interatorProperty.MoveNext())
            {
                // Get <PropertySetProperty>
                XPathNavigator navigatorProperty = interatorProperty.Current;

                // Add PropertySetProperty
                Property property = new Property(navigatorProperty);
                this._userData.Add(property);
            }

            // <UseByDefault>
            XPathNavigator navigatorUseByDefault = navigator.SelectSingleNode("UseByDefault");

            if (navigatorUseByDefault != null)
            {
                this._useByDefault = navigatorUseByDefault.ValueAsBoolean;
            }

            // <AttributedParameters><AttributedParameter>
            this._attributeParameters = new List <NetworkAttributeParameter>();
            XPathNodeIterator interatorAttributedParameter = navigator.Select("AttributedParameters/AttributedParameter");

            while (interatorAttributedParameter.MoveNext())
            {
                // Get <AttributedParameter>
                XPathNavigator navigatorAttributedParameter = interatorAttributedParameter.Current;

                // Add AttributedParameter
                NetworkAttributeParameter networkAttributeParameter = new NetworkAttributeParameter(navigatorAttributedParameter);
                this._attributeParameters.Add(networkAttributeParameter);
            }
        }
        protected override void WriteInnerXml(XmlWriter writer)
        {
            // Call Base Method
            base.WriteInnerXml(writer);

            // <ID></ID>
            writer.WriteStartElement("ID");
            writer.WriteValue(this._id);
            writer.WriteEndElement();

            // <Name></Name>
            writer.WriteStartElement("Name");
            writer.WriteValue(this._name);
            writer.WriteEndElement();

            // <Units></Units>
            writer.WriteStartElement("Units");
            writer.WriteValue(GeodatabaseUtility.GetDescription(this._units));
            writer.WriteEndElement();

            // <DataType></DataType>
            writer.WriteStartElement("DataType");
            writer.WriteValue(this._dataType.ToString());
            writer.WriteEndElement();

            // <UsageType></UsageType>
            writer.WriteStartElement("UsageType");
            writer.WriteValue(this._usageType.ToString());
            writer.WriteEndElement();

            if (this._userData.Count == 0)
            {
                // <UserData></UserData>
                writer.WriteStartElement("UserData");
                writer.WriteAttributeString(Xml._XSI, "nil", null, "true");
                writer.WriteEndElement();
            }
            else
            {
                // <UserData>
                writer.WriteStartElement("UserData");
                writer.WriteAttributeString(Xml._XSI, Xml._TYPE, null, "esri:PropertySet");

                // <PropertyArray>
                writer.WriteStartElement("PropertyArray");
                writer.WriteAttributeString(Xml._XSI, Xml._TYPE, null, "esri:PropertyArray");

                // <PropertySetProperty></PropertySetProperty>
                foreach (Property property in this._userData)
                {
                    property.WriteXml(writer);
                }

                // </PropertyArray>
                writer.WriteEndElement();

                // </UserData>
                writer.WriteEndElement();
            }

            // <UseByDefault></UseByDefault>
            writer.WriteStartElement("UseByDefault");
            writer.WriteValue(this._useByDefault);
            writer.WriteEndElement();

            // <AttributeParameters>
            writer.WriteStartElement("AttributeParameters");
            writer.WriteAttributeString(Xml._XSI, Xml._TYPE, null, "esri:ArrayOfNetworkAttributeParameter");

            // <NetworkAttributeParameter></NetworkAttributeParameter>
            foreach (NetworkAttributeParameter networkAttributeParameter in this._attributeParameters)
            {
                networkAttributeParameter.WriteXml(writer);
            }

            // </AttributeParameters>
            writer.WriteEndElement();
        }
        //
        // PROTECTED METHODS
        //
        protected override void WriteInnerXml(XmlWriter writer)
        {
            // Write Inner Xml
            base.WriteInnerXml(writer);

            // <HasOID>
            bool hasOID = !string.IsNullOrEmpty(this._oidFieldName);

            writer.WriteStartElement("HasOID");
            writer.WriteValue(hasOID);
            writer.WriteEndElement();

            // <OIDFieldName>
            writer.WriteStartElement("OIDFieldName");
            writer.WriteValue(this._oidFieldName);
            writer.WriteEndElement();

            // <Fields>
            TableGroup tableGroupField = (TableGroup)base.Groups[0];

            writer.WriteStartElement("Fields");
            writer.WriteAttributeString(Xml._XSI, Xml._TYPE, null, "esri:Fields");

            // <FieldArray>
            writer.WriteStartElement("FieldArray");
            writer.WriteAttributeString(Xml._XSI, Xml._TYPE, null, "esri:ArrayOfField");

            // <Field></Field>
            foreach (Field field in tableGroupField.Rows)
            {
                field.WriteXml(writer);
            }

            // </FieldArray>
            writer.WriteEndElement();

            // </Fields>
            writer.WriteEndElement();

            // <Indexes>
            TableGroup tableGroupIndex = (TableGroup)base.Groups[1];

            writer.WriteStartElement("Indexes");
            writer.WriteAttributeString(Xml._XSI, Xml._TYPE, null, "esri:Indexes");

            // <IndexArray>
            writer.WriteStartElement("IndexArray");
            writer.WriteAttributeString(Xml._XSI, Xml._TYPE, null, "esri:ArrayOfIndex");

            // <Index></Index>
            foreach (Index index in tableGroupIndex.Groups)
            {
                index.WriteXml(writer);
            }

            // </IndexArray>
            writer.WriteEndElement();

            // </Indexes>
            writer.WriteEndElement();

            // <IsInteger>
            writer.WriteStartElement("IsInteger");
            writer.WriteValue(this._isInteger);
            writer.WriteEndElement();

            // <MeanCellHeight>
            writer.WriteStartElement("MeanCellHeight");
            writer.WriteValue(this._meanCellHeight);
            writer.WriteEndElement();

            // <MeanCellWidth>
            writer.WriteStartElement("MeanCellWidth");
            writer.WriteValue(this._meanCellWidth);
            writer.WriteEndElement();

            // <Height>
            writer.WriteStartElement("Height");
            writer.WriteValue(this._height);
            writer.WriteEndElement();

            // <Width>
            writer.WriteStartElement("Width");
            writer.WriteValue(this._width);
            writer.WriteEndElement();

            // <PixelType>
            writer.WriteStartElement("PixelType");
            writer.WriteValue(GeodatabaseUtility.GetDescription(this._pixelType));
            writer.WriteEndElement();

            // <PrimaryField>
            writer.WriteStartElement("PrimaryField");
            writer.WriteValue(this._primaryField);
            writer.WriteEndElement();

            // <TableType>
            writer.WriteStartElement("TableType");
            writer.WriteValue(this._tableType.ToString());
            writer.WriteEndElement();

            // <Extent>
            if (this._extent != null)
            {
                this._extent.WriteXml(writer);
            }

            // <SpatialReference>
            if (this._spatialReference != null)
            {
                this._spatialReference.WriteXml(writer);
            }
        }
        //
        // CONSTRUCTOR
        //
        public RasterBand(IXPathNavigable path) : base(path)
        {
            // Get Navigator
            XPathNavigator navigator = path.CreateNavigator();

            // <OIDFieldName>
            XPathNavigator navigatorOIDFieldName = navigator.SelectSingleNode("OIDFieldName");

            if (navigatorOIDFieldName != null)
            {
                this._oidFieldName = navigatorOIDFieldName.Value;
            }

            // Create Fields Group
            TableGroup tableGroupFields = new TableGroup();

            tableGroupFields.Expanded = true;
            tableGroupFields.Text     = "Fields";
            this.Groups.Add(tableGroupFields);

            XPathNodeIterator interatorField = navigator.Select("Fields/FieldArray/Field");

            while (interatorField.MoveNext())
            {
                // Create Field
                XPathNavigator navigatorField = interatorField.Current;
                Field          field          = new Field(navigatorField, this);

                // Add Field To Group
                tableGroupFields.Rows.Add(field);
            }

            // Create Indexes Group
            TableGroup tableGroupIndexes = new TableGroup();

            tableGroupIndexes.Expanded = true;
            tableGroupIndexes.Text     = "Indexes";
            this.Groups.Add(tableGroupIndexes);

            XPathNodeIterator interatorIndex = navigator.Select("Indexes/IndexArray/Index");

            while (interatorIndex.MoveNext())
            {
                // Add Index
                XPathNavigator navigatorIndex = interatorIndex.Current;
                Index          index          = new Index(navigatorIndex);
                tableGroupIndexes.Groups.Add(index);

                // Add Field Index
                XPathNodeIterator interatorIndexField = navigatorIndex.Select("Fields/FieldArray/Field");
                while (interatorIndexField.MoveNext())
                {
                    XPathNavigator navigatorIndexField = interatorIndexField.Current;
                    IndexField     indexField          = new IndexField(navigatorIndexField);
                    index.Rows.Add(indexField);
                }
            }

            // <IsInteger>
            XPathNavigator navigatorIsInteger = navigator.SelectSingleNode("IsInteger");

            if (navigatorIsInteger != null)
            {
                this._isInteger = navigatorIsInteger.ValueAsBoolean;
            }

            // <MeanCellHeight>
            XPathNavigator navigatorMeanCellHeight = navigator.SelectSingleNode("MeanCellHeight");

            if (navigatorMeanCellHeight != null)
            {
                this._meanCellHeight = navigatorMeanCellHeight.ValueAsDouble;
            }

            // <MeanCellWidth>
            XPathNavigator navigatorMeanCellWidth = navigator.SelectSingleNode("MeanCellWidth");

            if (navigatorMeanCellWidth != null)
            {
                this._meanCellWidth = navigatorMeanCellWidth.ValueAsDouble;
            }

            // <Height>
            XPathNavigator navigatorHeight = navigator.SelectSingleNode("Height");

            if (navigatorHeight != null)
            {
                this._height = navigatorHeight.ValueAsInt;
            }

            // <Width>
            XPathNavigator navigatorWidth = navigator.SelectSingleNode("Width");

            if (navigatorWidth != null)
            {
                this._width = navigatorWidth.ValueAsInt;
            }

            // <PixelType>
            XPathNavigator navigatorPixelType = navigator.SelectSingleNode("PixelType");

            if (navigatorPixelType != null)
            {
                this._pixelType = GeodatabaseUtility.GetPixelType(navigatorPixelType.Value);
            }

            // <PrimaryField>
            XPathNavigator navigatorPrimaryField = navigator.SelectSingleNode("PrimaryField");

            if (navigatorPrimaryField != null)
            {
                this._primaryField = navigatorPrimaryField.ValueAsInt;
            }

            // <TableType>
            XPathNavigator navigatorTableType = navigator.SelectSingleNode("TableType");

            if (navigatorTableType != null)
            {
                this._tableType = (esriRasterTableTypeEnum)Enum.Parse(typeof(esriRasterTableTypeEnum), navigatorTableType.Value, true);
            }

            // <Extent>
            XPathNavigator navigatorExtent = navigator.SelectSingleNode("Extent");

            if (navigatorExtent != null)
            {
                this._extent = new Extent(navigatorExtent);
            }
            else
            {
                this._extent = new Extent();
            }

            // <SpatialReference>
            XPathNavigator navigatorSpatialReference = navigator.SelectSingleNode("SpatialReference");

            if (navigatorSpatialReference != null)
            {
                this._spatialReference = new SpatialReference(navigatorSpatialReference);
            }
            else
            {
                this._spatialReference = new SpatialReference();
            }
        }
        /// <summary>
        /// Create Bitmap From ESRI Dataset
        /// </summary>
        /// <param name="dataset">Dataset to generate an image from</param>
        /// <param name="imageFormat">Output image format</param>
        /// <param name="size">Size of output image</param>
        /// <param name="resolution">Resolution of output image (dpi)</param>
        /// <param name="background">Background color</param>
        /// <param name="filename">Ouput filename</param>
        public static void CreateBitmap(IDataset dataset, esriImageFormat imageFormat, Size size, ushort resolution, Color background, string filename)
        {
            ILayer layer = null;

            switch (dataset.Type)
            {
            case esriDatasetType.esriDTFeatureClass:
                IFeatureClass featureClass = (IFeatureClass)dataset;
                switch (featureClass.FeatureType)
                {
                case esriFeatureType.esriFTDimension:
                    layer = new DimensionLayerClass();
                    break;

                case esriFeatureType.esriFTAnnotation:
                    layer = new FeatureLayerClass();
                    IGeoFeatureLayer geoFeaureLayer = (IGeoFeatureLayer)layer;
                    geoFeaureLayer.DisplayAnnotation = true;
                    break;

                case esriFeatureType.esriFTComplexEdge:
                case esriFeatureType.esriFTComplexJunction:
                case esriFeatureType.esriFTSimple:
                case esriFeatureType.esriFTSimpleEdge:
                case esriFeatureType.esriFTSimpleJunction:
                    layer = new FeatureLayerClass();
                    break;
                }
                if (layer == null)
                {
                    return;
                }

                IFeatureLayer featureLayer = (IFeatureLayer)layer;
                featureLayer.FeatureClass = featureClass;

                break;

            case esriDatasetType.esriDTRasterDataset:
                layer = new RasterLayerClass();
                IRasterLayer rasterLayer = (IRasterLayer)layer;
                rasterLayer.CreateFromDataset((IRasterDataset)dataset);
                break;

            default:
                string message = string.Format("[{0}] is not supported", dataset.Type.ToString());
                throw new Exception(message);
            }
            if (layer == null)
            {
                return;
            }

            // Create In-memory Map
            IMap map = new MapClass();

            map.AddLayer(layer);
            IActiveView activeView = (IActiveView)map;
            IExport     export     = null;
            tagRECT     rect       = new tagRECT();

            // Set Format Specific Properties
            switch (imageFormat)
            {
            case esriImageFormat.esriImageJPG:
                export = new ExportJPEGClass();
                IExportJPEG exportJpeg = (IExportJPEG)export;
                exportJpeg.ProgressiveMode = false;
                exportJpeg.Quality         = 100;

                break;

            default:
                throw new Exception("[" + imageFormat.ToString() + "] is not supported");
            }
            if (export == null)
            {
                throw new Exception("Failed to Created Exporter");
            }

            // Set Background
            if ((export is IExportBMP) ||
                (export is IExportGIF) ||
                (export is IExportJPEG) ||
                (export is IExportPNG) ||
                (export is IExportTIFF))
            {
                IExportImage exportImage = (IExportImage)export;
                exportImage.ImageType       = esriExportImageType.esriExportImageTypeTrueColor;
                exportImage.BackgroundColor = GeodatabaseUtility.ToESRIColor(background);
            }

            // Set Export Frame
            rect        = activeView.ExportFrame;
            rect.left   = 0;
            rect.top    = 0;
            rect.right  = size.Width;
            rect.bottom = size.Height;

            // Set Output Extent
            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords(rect.left, rect.top, rect.right, rect.bottom);
            export.PixelBounds    = envelope;
            export.Resolution     = resolution;
            export.ExportFileName = filename;

            // Export map to image
            int intHdc = export.StartExporting();

            activeView.Output(intHdc, resolution, ref rect, null, null);
            export.FinishExporting();
            export.Cleanup();

            // Clear Layers
            map.ClearLayers();

            // Release COM Objects
            GeodatabaseUtility.ReleaseComObject(layer);
            GeodatabaseUtility.ReleaseComObject(envelope);
            GeodatabaseUtility.ReleaseComObject(map);
            GeodatabaseUtility.ReleaseComObject(activeView);
            GeodatabaseUtility.ReleaseComObject(export);
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Beispiel #11
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;
                }
            }
        }