FdoToolbox.Core.Feature.FdoDataStoreConfiguration.Save C# (CSharp) Method

Save() public method

Saves this out to a FDO XML configuration document
public Save ( string xmlFile ) : void
xmlFile string
return void
        public void Save(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
            using (var ws = new IoFileStream(xmlFile, "w"))
            {
                using (var writer = new XmlWriter(ws, true, XmlWriter.LineFormat.LineFormat_Indent))
                {
                    //Write spatial contexts
                    if (this.SpatialContexts != null && this.SpatialContexts.Length > 0)
                    {
                        var flags = new XmlSpatialContextFlags();
                        using (var scWriter = new XmlSpatialContextWriter(writer))
                        {
                            foreach (var sc in this.SpatialContexts)
                            {
                                //XmlSpatialContextWriter forbids writing dynamically calculated extents
                                if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Dynamic)
                                    continue;

                                scWriter.CoordinateSystem = sc.CoordinateSystem;
                                scWriter.CoordinateSystemWkt = sc.CoordinateSystemWkt;
                                scWriter.Description = sc.Description;

                                scWriter.ExtentType = sc.ExtentType;

                                using (var geom = fact.CreateGeometry(sc.ExtentGeometryText))
                                {
                                    byte[] fgf = fact.GetFgf(geom);
                                    scWriter.Extent = fgf;
                                }

                                scWriter.Name = sc.Name;
                                scWriter.XYTolerance = sc.XYTolerance;
                                scWriter.ZTolerance = sc.ZTolerance;

                                scWriter.WriteSpatialContext();
                            }
                        }
                    }

                    //Write logical schema
                    if (this.Schemas != null)
                    {
                        var schemas = CloneSchemas(this.Schemas);

                        schemas.WriteXml(writer);
                    }

                    //Write physical mappings
                    if (this.Mappings != null)
                    {
                        this.Mappings.WriteXml(writer);
                    }

                    writer.Close();
                }
                ws.Close();
            }
        }

Usage Example

Exemplo n.º 1
0
        public override void Run()
        {
            string path = FileService.SaveFile(Res.GetString("TITLE_EXPORT_DATASTORE_XML"), Res.GetString("FILTER_XML_FILES"));
            if (!string.IsNullOrEmpty(path))
            {
                TreeNode connNode = Workbench.Instance.ObjectExplorer.GetSelectedNode();
                FdoConnectionManager mgr = ServiceManager.Instance.GetService<FdoConnectionManager>();
                FdoConnection conn = mgr.GetConnection(connNode.Name);

                using (new TempCursor(Cursors.WaitCursor))
                {
                    using (var svc = conn.CreateFeatureService())
                    {
                        var scs = new List<SpatialContextInfo>(svc.GetSpatialContexts()).ToArray();
                        var schemas = svc.DescribeSchema();
                        var mappings = svc.DescribeSchemaMapping(true);

                        var dstore = new FdoDataStoreConfiguration(schemas, scs, mappings);
                        dstore.Save(path);

                        Log.InfoFormatted("Connection saved to: {0}", path);
                    }
                }
            }
        }