private void BuildDefaultDocument() { _doc = new OdbcConfigurationDocument(); var xmlDoc = new XmlDocument(); XmlNamespaceManager mgr = new XmlNamespaceManager(xmlDoc.NameTable); mgr.AddNamespace("xs", XmlNamespaces.XS); //NOXLATE mgr.AddNamespace("xsi", XmlNamespaces.XSI); //NOXLATE mgr.AddNamespace("fdo", XmlNamespaces.FDO); //NOXLATE mgr.AddNamespace("gml", XmlNamespaces.GML); //NOXLATE mgr.AddNamespace("xlink", XmlNamespaces.XLINK); //NOXLATE mgr.AddNamespace("fds", XmlNamespaces.FDS); //NOXLATE //This may have changed, so reapply var props = Use64BitDriver ? this.ChildEditor.Get64BitConnectionProperties() : this.ChildEditor.ConnectionProperties; _fs.ApplyConnectionProperties(props); _service.SyncSessionCopy(); try { var schemaName = _service.CurrentConnection.FeatureService.GetSchemas(_fs.ResourceID)[0]; var classNames = _service.CurrentConnection.FeatureService.GetClassNames(_fs.ResourceID, schemaName); var diag = new FilteredLogicalSchemaDialog(classNames); if (diag.ShowDialog() == DialogResult.Cancel) { throw new ApplicationException(Strings.TextNoItemSelected); } var names = diag.ClassNames; BusyWaitDelegate worker = () => { classNames = names.Select(x => x.Contains(":") ? x.Split(':')[1] : x).ToArray(); //NOXLATE var schema = _service.CurrentConnection.FeatureService.DescribeFeatureSourcePartial(_fs.ResourceID, schemaName, classNames); _doc.AddSchema(schema); //Only one schema is supported by ODBC so this is ok var scList = _service.CurrentConnection.FeatureService.GetSpatialContextInfo(_fs.ResourceID, false); foreach (var sc in scList.SpatialContext) { _doc.AddSpatialContext(sc); } return(null); }; BusyWaitDialog.Run(Strings.TextPreparingConfigurationDocument, worker, (obj, ex) => { if (ex != null) { throw ex; } //Done }); } catch (Exception ex) { _doc = null; MessageBox.Show(ex.Message); } }
private IEnumerable <ValidationIssue> ValidateOdbcDoc(IFeatureSource fs, OdbcConfigurationDocument odbcDoc) { foreach (var schema in odbcDoc.Schemas) { var featureClasses = schema .Classes .Where(c => !string.IsNullOrEmpty(c.DefaultGeometryPropertyName) && c.Properties.Any(p => p.Type == Schema.PropertyDefinitionType.Geometry && p.Name == c.DefaultGeometryPropertyName)); foreach (var fc in featureClasses) { var geomProp = fc.Properties.OfType <GeometricPropertyDefinition>().FirstOrDefault(p => p.Name == fc.DefaultGeometryPropertyName); if (geomProp != null) { //Must be point if (geomProp.GeometricTypes != FeatureGeometricType.Point) { yield return(new ValidationIssue(fs, ValidationStatus.Error, ValidationStatusCode.Error_OdbcConfig_InvalidLogicalGeometryProperty, string.Format(Strings.ODBC_InvalidGeometryProperty, fc.Name, geomProp.Name))); } var ovTable = odbcDoc.GetOverride(schema.Name, fc.Name); if (ovTable == null) //If it has geometry, it must have a table override { yield return(new ValidationIssue(fs, ValidationStatus.Error, ValidationStatusCode.Error_OdbcConfig_NoTableOverrideForFeatureClass, string.Format(Strings.ODBC_NoSuchTableOverrideForFeatureClass, fc.Name))); } else if (geomProp.GeometricTypes == FeatureGeometricType.Point) { if (string.IsNullOrEmpty(ovTable.XColumn) || string.IsNullOrEmpty(ovTable.YColumn)) { yield return(new ValidationIssue(fs, ValidationStatus.Error, ValidationStatusCode.Error_OdbcConfig_IncompleteXYZColumnMapping, string.Format(Strings.ODBC_IncompleteXYZColumnMapping, fc.Name))); } } } } } }
public TableConfigurationDialog(IEditorService edSvc, OdbcConfigurationDocument doc, string schemaName) : this() { _edSvc = edSvc; var scNames = doc.GetSpatialContextNames(); tableConfigCtrl.SetSpatialContexts(scNames); var sc = doc.GetSpatialContext(scNames[0]); txtCoordinateSystem.Text = sc.CoordinateSystemWkt; var schema = doc.GetSchema(schemaName); Dictionary <string, TableOverrideItem> tables = new Dictionary <string, TableOverrideItem>(); List <TableOverrideItem> existing = new List <TableOverrideItem>(); foreach (var tbl in doc.GetMappingsForSchema(schemaName)) { var cls = doc.GetClass(schemaName, tbl.ClassName); tables[tbl.ClassName] = new TableOverrideItem() { Override = true, Class = cls, TableName = tbl.ClassName, Key = cls.IdentityProperties.Count > 0 ? cls.IdentityProperties[0].Name : string.Empty, X = tbl.XColumn, Y = tbl.YColumn, Z = tbl.ZColumn }; if (!string.IsNullOrEmpty(cls.DefaultGeometryPropertyName)) { var prop = cls.FindProperty(cls.DefaultGeometryPropertyName) as GeometricPropertyDefinition; if (prop != null) { tables[tbl.ClassName].SpatialContext = prop.SpatialContextAssociation; } } existing.Add(tables[tbl.ClassName]); } foreach (var cls in schema.Classes) { if (!tables.ContainsKey(cls.Name)) { tables[cls.Name] = new TableOverrideItem() { Override = false, Class = cls, TableName = cls.Name, Geometry = false, Key = cls.IdentityProperties.Count > 0 ? cls.IdentityProperties[0].Name : string.Empty }; } } foreach (var tbl in tables.Values) { _tables.Add(tbl); } }
private void btnEditSchema_Click(object sender, EventArgs e) { if (CheckValidConnection()) { if (string.IsNullOrEmpty(_defaultSchemaName)) { var names = _service.CurrentConnection.FeatureService.GetSchemas(_fs.ResourceID); if (names.Length == 1) { _defaultSchemaName = names[0]; } else { MessageBox.Show(Strings.NoSchemasInFeatureSource); return; } } string xml = _fs.GetConfigurationContent(_service.CurrentConnection); if (!string.IsNullOrEmpty(xml)) { _doc = (OdbcConfigurationDocument)ConfigurationDocument.LoadXml(xml); } else { if (_doc == null) { BuildDefaultDocument(); } } var diag = new TableConfigurationDialog(_service, _doc, _defaultSchemaName); if (diag.ShowDialog() == DialogResult.OK) { _doc.ClearMappings(); foreach (var table in diag.ConfiguredTables) { _doc.AddOverride(table); } foreach (var sc in _doc.SpatialContexts) { sc.CoordinateSystemWkt = diag.CoordinateSystemWkt; } string updatedContent = _doc.ToXml(); _fs.SetConfigurationContent(_service.CurrentConnection, updatedContent); OnResourceChanged(); } } }
private void DoDocumentReset() { _fs.SetConfigurationContent(_service.CurrentConnection, null); _fs.ConfigurationDocument = null; _service.SyncSessionCopy(); _doc = null; BuildDefaultDocument(); if (null != _doc) { _fs.ConfigurationDocument = "config.xml"; _fs.SetConfigurationContent(_service.CurrentConnection, _doc.ToXml()); MessageBox.Show(Strings.ConfigurationDocumentReset); } }
public void TestOdbcSaveLoad() { var schema = new FeatureSchema("Default", "Test schema"); var cls = new ClassDefinition("Cities", "Cities class"); cls.AddProperty(new DataPropertyDefinition("ID", "Primary Key") { DataType = DataPropertyType.Int64, IsNullable = false, IsAutoGenerated = true }, true); cls.AddProperty(new DataPropertyDefinition("Name", "City Name") { DataType = DataPropertyType.String, IsNullable = true, IsAutoGenerated = false, Length = 255 }); cls.AddProperty(new GeometricPropertyDefinition("Geometry", "Geometry property") { GeometricTypes = FeatureGeometricType.Point, SpecificGeometryTypes = new SpecificGeometryType[] { SpecificGeometryType.Point }, HasElevation = false, HasMeasure = false, SpatialContextAssociation = "Default" }); cls.AddProperty(new DataPropertyDefinition("Population", "Population") { DataType = DataPropertyType.Int32, IsNullable = true, IsAutoGenerated = false }); cls.DefaultGeometryPropertyName = "Geometry"; schema.AddClass(cls); var sc = new FdoSpatialContextListSpatialContext(); sc.CoordinateSystemName = "LL84"; sc.CoordinateSystemWkt = ""; sc.Description = "Default Spatial Context"; sc.Extent = new FdoSpatialContextListSpatialContextExtent() { LowerLeftCoordinate = new FdoSpatialContextListSpatialContextExtentLowerLeftCoordinate() { X = "-180.0", Y = "-180.0" }, UpperRightCoordinate = new FdoSpatialContextListSpatialContextExtentUpperRightCoordinate() { X = "180.0", Y = "180.0" } }; sc.ExtentType = FdoSpatialContextListSpatialContextExtentType.Static; sc.Name = "Default"; sc.XYTolerance = 0.0001; sc.ZTolerance = 0.0001; var conf = new OdbcConfigurationDocument(); conf.AddSchema(schema); conf.AddSpatialContext(sc); var ov = new OdbcTableItem(); ov.SchemaName = schema.Name; ov.ClassName = cls.Name; ov.SpatialContextName = sc.Name; ov.XColumn = "Lon"; ov.YColumn = "Lat"; conf.AddOverride(ov); string path = "OdbcConfigTest.xml"; Utils.WriteAllText(path, conf.ToXml()); conf = null; string xml = Utils.ReadAllText(path); conf = ConfigurationDocument.LoadXml(xml) as OdbcConfigurationDocument; Assert.NotNull(conf); ov = conf.GetOverride("Default", "Cities"); Assert.NotNull(ov); Assert.AreEqual("Default", ov.SchemaName); Assert.AreEqual("Cities", ov.ClassName); Assert.AreEqual(sc.Name, ov.SpatialContextName); Assert.AreEqual("Lon", ov.XColumn); Assert.AreEqual("Lat", ov.YColumn); }