public void TestSchemaClone()
        {
            FeatureSchemaCollection schemas = new FeatureSchemaCollection(null);
            schemas.ReadXml(Path.Combine(TestHelper.CurrentPath, "Test.xml"));

            FeatureSchema cloned = FdoSchemaUtil.CloneSchema(schemas[0]);
            AssertHelper.EqualSchemas(schemas[0], cloned);
        }
        public void TestSchemaClone()
        {
            FeatureSchemaCollection schemas = new FeatureSchemaCollection(null);

            schemas.ReadXml(Path.Combine(TestHelper.CurrentPath, "Test.xml"));

            FeatureSchema cloned = FdoSchemaUtil.CloneSchema(schemas[0]);

            AssertHelper.EqualSchemas(schemas[0], cloned);
        }
        /// <summary>
        /// Loads a FDO XML configuration document
        /// </summary>
        /// <param name="xmlFile"></param>
        /// <returns></returns>
        public static FdoDataStoreConfiguration FromFile(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
                using (var ios = new IoFileStream(xmlFile, "r"))
                {
                    using (var reader = new XmlReader(ios))
                    {
                        List <SpatialContextInfo> contexts = new List <SpatialContextInfo>();
                        using (var scReader = new XmlSpatialContextReader(reader))
                        {
                            while (scReader.ReadNext())
                            {
                                var sc = new SpatialContextInfo();
                                sc.CoordinateSystem    = scReader.GetCoordinateSystem();
                                sc.CoordinateSystemWkt = scReader.GetCoordinateSystemWkt();
                                sc.Description         = scReader.GetDescription();
                                sc.ExtentType          = scReader.GetExtentType();
                                if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Static)
                                {
                                    using (var geom = fact.CreateGeometryFromFgf(scReader.GetExtent()))
                                    {
                                        sc.ExtentGeometryText = geom.Text;
                                    }
                                }
                                sc.IsActive    = scReader.IsActive();
                                sc.Name        = scReader.GetName();
                                sc.XYTolerance = scReader.GetXYTolerance();
                                sc.ZTolerance  = scReader.GetZTolerance();

                                contexts.Add(sc);
                            }
                        }

                        ios.Reset();

                        var schemas = new FeatureSchemaCollection(null);
                        schemas.ReadXml(ios);

                        ios.Reset();

                        var mappings = new PhysicalSchemaMappingCollection();
                        mappings.ReadXml(ios);

                        ios.Close();

                        return(new FdoDataStoreConfiguration(schemas, contexts.ToArray(), mappings));
                    }
                }
        }
        private void ApplySchemas(FdoConnection conn)
        {
            using (var svc = conn.CreateFeatureService())
            {
                using (FeatureSchemaCollection fsc = new FeatureSchemaCollection(null))
                {
                    fsc.ReadXml(_view.SchemaFile);
                    int modified = FdoSchemaUtil.SetDefaultSpatialContextAssociation(fsc, "Default");

                    List <FeatureSchema> schemas = new List <FeatureSchema>();
                    if (_view.FixSchema)
                    {
                        foreach (FeatureSchema fs in fsc)
                        {
                            IncompatibleSchema inc;
                            if (!svc.CanApplySchema(fs, out inc))
                            {
                                FeatureSchema mod = svc.AlterSchema(fs, inc);
                                schemas.Add(mod);
                            }
                            else
                            {
                                schemas.Add(fs);
                            }
                        }
                    }
                    else
                    {
                        foreach (FeatureSchema fs in fsc)
                        {
                            schemas.Add(fs);
                        }
                    }

                    foreach (FeatureSchema fs in schemas)
                    {
                        svc.ApplySchema(fs);
                    }
                }
            }
        }
        /// <summary>
        /// Loads a FDO XML configuration document
        /// </summary>
        /// <param name="xmlFile"></param>
        /// <returns></returns>
        public static FdoDataStoreConfiguration FromFile(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
            using (var ios = new IoFileStream(xmlFile, "r"))
            {
                using (var reader = new XmlReader(ios))
                {
                    List<SpatialContextInfo> contexts = new List<SpatialContextInfo>();
                    using (var scReader = new XmlSpatialContextReader(reader))
                    {
                        while (scReader.ReadNext())
                        {
                            var sc = new SpatialContextInfo();
                            sc.CoordinateSystem = scReader.GetCoordinateSystem();
                            sc.CoordinateSystemWkt = scReader.GetCoordinateSystemWkt();
                            sc.Description = scReader.GetDescription();
                            sc.ExtentType = scReader.GetExtentType();
                            if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Static)
                            {
                                using (var geom = fact.CreateGeometryFromFgf(scReader.GetExtent()))
                                {
                                    sc.ExtentGeometryText = geom.Text;
                                }
                            }
                            sc.IsActive = scReader.IsActive();
                            sc.Name = scReader.GetName();
                            sc.XYTolerance = scReader.GetXYTolerance();
                            sc.ZTolerance = scReader.GetZTolerance();

                            contexts.Add(sc);
                        }
                    }

                    ios.Reset();

                    var schemas = new FeatureSchemaCollection(null);
                    schemas.ReadXml(ios);

                    ios.Reset();

                    var mappings = new PhysicalSchemaMappingCollection();
                    mappings.ReadXml(ios);

                    ios.Close();

                    return new FdoDataStoreConfiguration(schemas, contexts.ToArray(), mappings);
                }
            }
        }
        private void ApplySchemas(FdoConnection conn)
        {
            using (var svc = conn.CreateFeatureService())
            {
                using (FeatureSchemaCollection fsc = new FeatureSchemaCollection(null))
                {
                    fsc.ReadXml(_view.SchemaFile);
                    int modified = FdoSchemaUtil.SetDefaultSpatialContextAssociation(fsc, "Default");

                    List<FeatureSchema> schemas = new List<FeatureSchema>();
                    if (_view.FixSchema)
                    {
                        foreach (FeatureSchema fs in fsc)
                        {
                            IncompatibleSchema inc;
                            if (!svc.CanApplySchema(fs, out inc))
                            {
                                FeatureSchema mod = svc.AlterSchema(fs, inc);
                                schemas.Add(mod);
                            }
                            else
                            {
                                schemas.Add(fs);
                            }
                        }
                    }
                    else
                    {
                        foreach (FeatureSchema fs in fsc)
                        {
                            schemas.Add(fs);
                        }
                    }

                    foreach (FeatureSchema fs in schemas)
                    {
                        svc.ApplySchema(fs);
                    }
                }
            }
        }