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); } } } }
private void btnImport_Click(object sender, EventArgs e) { string file = FileService.OpenFile("Open XML Configuration", "XML files (*.xml)|*.xml"); if (!string.IsNullOrEmpty(file)) { var conf = FdoDataStoreConfiguration.FromFile(file); if (!_context.IsConnected) { using (var cur = new TempCursor(Cursors.WaitCursor)) { _context.SetConfiguration(conf); schemaView.Reset(); } } else { //Prompt for elements to import var impDiag = new ImportElementsDialog(conf, _context); impDiag.ShowDialog(); } } }
internal void SetConfiguration(FdoDataStoreConfiguration conf) { _schemas = conf.Schemas; _mappings = conf.Mappings; if (_schemas == null) { _schemas = new FeatureSchemaCollection(null); } if (_mappings == null) { _mappings = new PhysicalSchemaMappingCollection(); } _spatialContexts.Clear(); if (conf.SpatialContexts != null && conf.SpatialContexts.Length > 0) { foreach (var sc in conf.SpatialContexts) { _spatialContexts.Add(sc); } } }
public bool CreateSdf() { if (_view.CreateConnection && string.IsNullOrEmpty(_view.ConnectionName)) { _view.ShowError("Specify a connection name"); return(false); } if (ExpressUtility.CreateFlatFileDataSource("OSGeo.SDF", _view.SdfFile)) { FdoDataStoreConfiguration dstore = null; if (FileService.FileExists(_view.FeatureSchemaDefinition)) { dstore = FdoDataStoreConfiguration.FromFile(_view.FeatureSchemaDefinition); //SDF only permits the following: // 1 feature schema // 1 spatial context if (dstore.Schemas.Count > 1) { _view.ShowError("Multiple schemas were found in this document. SDF only allows 1 feature schema"); return(false); } if (dstore.SpatialContexts.Length > 1) { _view.ShowError("Multiple spatial contexts were found in this doucment. SDF only allows 1 spatial context"); return(false); } } FdoConnection conn = ExpressUtility.CreateFlatFileConnection("OSGeo.SDF", _view.SdfFile); if (dstore != null) { using (var svc = conn.CreateFeatureService()) { if (dstore.SpatialContexts.Length == 1) { //Overwrite existing spatial context if it exists var sc = dstore.SpatialContexts[0]; var asc = svc.GetActiveSpatialContext(); if (asc != null) { sc.Name = asc.Name; } svc.CreateSpatialContext(sc, (asc != null)); } var schema = dstore.Schemas[0]; if (_view.FixIncompatibilities) { IncompatibleSchema incS; if (!svc.CanApplySchema(schema, out incS)) { schema = svc.AlterSchema(schema, incS); } } svc.ApplySchema(schema); } } if (_view.CreateConnection) { _connMgr.AddConnection(_view.ConnectionName, conn); } else { conn.Dispose(); } } return(true); }
public ImportElementsDialog(FdoDataStoreConfiguration dataStore, SchemaDesignContext context) : this() { _dataStore = dataStore; _context = context; }
public bool CreateShp() { if (_view.CreateConnection && string.IsNullOrEmpty(_view.ConnectionName)) { _view.ShowError("Specify a connection name"); return(false); } //Creating SHP files is as follows // // 1. Connect to the *parent* directory of the shape file we want to create // 2. Apply the schema to this connection if (FileService.FileExists(_view.FeatureSchemaDefinition)) { try { FdoConnection conn = ExpressUtility.CreateFlatFileConnection("OSGeo.SHP", _view.ShpDirectory); FdoDataStoreConfiguration config = FdoDataStoreConfiguration.FromFile(_view.FeatureSchemaDefinition); //SHP allows the following: // 1 feature schema // Multiple spatial contexts if (config.Schemas.Count > 1) { _view.ShowError("More than 1 feature schema was found in the document. SHP only allows 1 feature schema"); return(false); } var schema = config.Schemas[0]; using (var svc = conn.CreateFeatureService()) { foreach (var sc in config.SpatialContexts) { svc.CreateSpatialContext(sc, true); } if (_view.FixIncompatibilities) { IncompatibleSchema incs; if (!svc.CanApplySchema(schema, out incs)) { schema = svc.AlterSchema(schema, incs); } } svc.ApplySchema(schema); } conn.Dispose(); if (_view.CreateConnection) { conn = ExpressUtility.CreateFlatFileConnection("OSGeo.SHP", _view.ShpDirectory); conn.Open(); _connMgr.AddConnection(_view.ConnectionName, conn); } } catch (OSGeo.FDO.Common.Exception ex) { _view.ShowError(ex); LoggingService.Error("Failed to create SHP", ex); return(false); } } return(true); }