private void _exportFieldSchema(string path, JMSMLConfigETLConfigSchemaContainerSchemasSchema schema, bool isSubTyped)
        {
            // Export a single field schema to the given path.

            using (var w = new StreamWriter(path + "\\" + _filePrefix + schema.Label + ".csv"))
            {
                _writeHeaders(w, _headers);

                FieldType[] fields = _buildFieldArray(schema);

                foreach (FieldType field in fields)
                {
                    if (isSubTyped)
                    {
                        // If this schema is subtyped we need to check to see if this is one of the fields that is subtyped and treat it special if it is.

                        if (field.Subtypes != null)
                        {
                            foreach (FieldTypeSubtype subtype in field.Subtypes)
                            {
                                _writeSubtypedField(w, field, subtype);
                            }
                        }
                        else
                        {
                            _writeField(w, field);
                        }
                    }
                    else
                    {
                        _writeField(w, field);
                    }
                }
            }
        }
        private FieldType[] _buildFieldArray(JMSMLConfigETLConfigSchemaContainerSchemasSchema schema)
        {
            // Build an order-sorted array of fields for the given schema.

            FieldType[] fields = {};

            string[] schemaTypes = schema.SchemaTypeIDs.Split(' ');

            // For each schema type in the schema, fined that type and fetch its fields.
            // Then concatenate the fields.

            foreach (string id in schemaTypes)
            {
                JMSMLConfigETLConfigSchemaType schemaType = _findSchemaType(id);

                if (schemaType != null)
                {
                    fields = fields.Concat(schemaType.Fields).ToArray();
                }
            }

            // Now concat the fields that are unique to this schema.

            fields = fields.Concat(schema.Fields).ToArray();

            // Now sort the array of fields based on their Order property.

            fields = fields.OrderBy(x => int.Parse(x.Order)).ToArray();

            return(fields);
        }
        private bool _exportSchema(string path, JMSMLConfigETLConfigSchemaContainerSchemasSchema schema, bool isFirst)
        {
            // Export the base definition of a schema to a list of schemas

            bool firstTime = isFirst;

            using (var w = new StreamWriter(path + "\\" + _schemaListFile, !firstTime))
            {
                if (firstTime)
                {
                    _writeHeaders(w, _schemaHeaders);

                    firstTime = false;
                }

                string line = string.Format("{0}", "Schema," +
                                            schema.Label + "," +
                                            schema.GeometryType + "," +
                                            '"' + schema.LabelAlias + '"' + "," +
                                            '"' + schema.Metadata.Label + '"' + "," +
                                            schema.Metadata.Thumbnail + "," +
                                            schema.Metadata.Tags + "," +
                                            '"' + schema.Metadata.Summary + '"' + "," +
                                            '"' + schema.Metadata.Description + '"' + "," +
                                            (schema.Metadata.Credits != null ? '"' + schema.Metadata.Credits + '"' : "") + "," +
                                            '"' + schema.Metadata.Use + '"' + "," +
                                            (schema.Metadata.Extent != null ? Convert.ToString(schema.Metadata.Extent.East) : "") + "," +
                                            (schema.Metadata.Extent != null ? Convert.ToString(schema.Metadata.Extent.West) : "") + "," +
                                            (schema.Metadata.Extent != null ? Convert.ToString(schema.Metadata.Extent.North) : "") + "," +
                                            (schema.Metadata.Extent != null ? Convert.ToString(schema.Metadata.Extent.South) : "") + "," +
                                            schema.Metadata.MaximumScale + "," +
                                            schema.Metadata.MinimumScale + "," +
                                            schema.SpatialReference);
                w.WriteLine(line);
                w.Flush();
            }

            return(firstTime);
        }
        private bool _exportSubtypeSchema(string path, JMSMLConfigETLConfigSchemaContainerSchemasSchema schema)
        {
            // Export a single subtype schema to the given path.

            bool isSubtyped = false;

            if (schema.Subtypes != null)
            {
                isSubtyped = true;

                using (var w = new StreamWriter(path + "\\" + _schemaFilePrefix + schema.Label + ".csv"))
                {
                    _writeHeaders(w, _subtypeHeaders);

                    foreach (SubtypeType subtype in schema.Subtypes)
                    {
                        _writeSubtype(w, subtype);
                    }
                }
            }

            return(isSubtyped);
        }
        private bool _exportSchema(string path, JMSMLConfigETLConfigSchemaContainerSchemasSchema schema, bool isFirst)
        {
            // Export the base definition of a schema to a list of schemas

            bool firstTime = isFirst;

            using (var w = new StreamWriter(path + "\\" + _schemaListFile, !firstTime))
            {
                if (firstTime)
                {
                    _writeHeaders(w, _schemaHeaders);

                    firstTime = false;
                }

                string line = string.Format("{0}",  "Schema," + 
                                                    schema.Label + "," +
                                                    schema.GeometryType + "," +
                                                    '"' + schema.LabelAlias + '"' + "," +
                                                    '"' + schema.Metadata.Label + '"' + "," +
                                                    schema.Metadata.Thumbnail + "," +
                                                    schema.Metadata.Tags + "," +
                                                    '"' + schema.Metadata.Summary + '"' + "," +
                                                    '"' + schema.Metadata.Description + '"' + "," +
                                                    (schema.Metadata.Credits != null ? '"' + schema.Metadata.Credits + '"' : "") + "," +
                                                    '"' + schema.Metadata.Use + '"' + "," +
                                                    (schema.Metadata.Extent != null ? Convert.ToString(schema.Metadata.Extent.East) : "") + "," +
                                                    (schema.Metadata.Extent != null ? Convert.ToString(schema.Metadata.Extent.West) : "") + "," +
                                                    (schema.Metadata.Extent != null ? Convert.ToString(schema.Metadata.Extent.North) : "") + "," +
                                                    (schema.Metadata.Extent != null ? Convert.ToString(schema.Metadata.Extent.South) : "") + "," +
                                                    schema.Metadata.MaximumScale + "," +
                                                    schema.Metadata.MinimumScale + "," +
                                                    schema.SpatialReference);
                w.WriteLine(line);
                w.Flush();
            }

            return firstTime;
        }
        private bool _exportSubtypeSchema(string path, JMSMLConfigETLConfigSchemaContainerSchemasSchema schema)
        {
            // Export a single subtype schema to the given path.

            bool isSubtyped = false;

            if (schema.Subtypes != null)
            {
                isSubtyped = true;

                using(var w = new StreamWriter(path + "\\" + _schemaFilePrefix + schema.Label + ".csv"))
                {
                    _writeHeaders(w, _subtypeHeaders);

                    foreach (SubtypeType subtype in schema.Subtypes)
                    {
                        _writeSubtype(w, subtype);
                    }
                }
            }

            return isSubtyped;
        }
        private void _exportFieldSchema(string path, JMSMLConfigETLConfigSchemaContainerSchemasSchema schema, bool isSubTyped)
        {
            // Export a single field schema to the given path.

            using (var w = new StreamWriter(path + "\\" + _filePrefix + schema.Label + ".csv"))
            {
                _writeHeaders(w, _headers);

                FieldType[] fields = _buildFieldArray(schema);

                foreach (FieldType field in fields)
                {
                    if (isSubTyped)
                    {
                        // If this schema is subtyped we need to check to see if this is one of the fields that is subtyped and treat it special if it is.

                        if (field.Subtypes != null)
                        {
                            foreach (FieldTypeSubtype subtype in field.Subtypes)
                            {
                                _writeSubtypedField(w, field, subtype);
                            }
                        }
                        else
                        {
                            _writeField(w, field);
                        }
                    }
                    else 
                    {
                        _writeField(w, field);
                    }
                }
            }
        }
        private FieldType[] _buildFieldArray(JMSMLConfigETLConfigSchemaContainerSchemasSchema schema)
        {
            // Build an order-sorted array of fields for the given schema.

            FieldType[] fields = {};

            string[] schemaTypes = schema.SchemaTypeIDs.Split(' ');

            // For each schema type in the schema, fined that type and fetch its fields.
            // Then concatenate the fields.

            foreach (string id in schemaTypes)
            {
                JMSMLConfigETLConfigSchemaType schemaType = _findSchemaType(id);

                if(schemaType != null)
                    fields = fields.Concat(schemaType.Fields).ToArray();
            }

            // Now concat the fields that are unique to this schema.

            fields = fields.Concat(schema.Fields).ToArray();

            // Now sort the array of fields based on their Order property.

            fields = fields.OrderBy(x => int.Parse(x.Order)).ToArray();

            return fields;
        }