/// <summary> /// Creates a clone of the specified instance /// </summary> /// <param name="fsd">The instance to clone</param> /// <returns></returns> public static FeatureSourceDescription Clone(FeatureSourceDescription fsd) { var schemas = new List <FeatureSchema>(); foreach (var fs in fsd.Schemas) { schemas.Add(FeatureSchema.Clone(fs)); } return(new FeatureSourceDescription(schemas, fsd.IsPartial)); }
protected override void OnLoad(EventArgs e) { if (_cachedDesc == null) _cachedDesc = _edsvc.FeatureService.DescribeFeatureSource(txtFeatureSource.Text); //Init cached schemas and selected class if (!string.IsNullOrEmpty(txtFeatureClass.Text)) { var cls = _cachedDesc.GetClass(txtFeatureClass.Text); if (cls != null) { _selectedClass = cls; } } else { SetFeatureClass(_cachedDesc.Schemas[0].Classes[0]); } }
public override FeatureSchema DescribeFeatureSourcePartial(string resourceID, string schema, string[] classNames) { ResourceIdentifier.Validate(resourceID, ResourceTypes.FeatureSource); string req = m_reqBuilder.DescribeSchemaPartial(resourceID, schema, classNames); try { var fsd = new FeatureSourceDescription(this.OpenRead(req)); return fsd.Schemas[0]; } catch (Exception ex) { if (typeof(WebException).IsAssignableFrom(ex.GetType())) LogFailedRequest((WebException)ex); try { if (this.IsSessionExpiredException(ex) && this.AutoRestartSession && this.RestartSession(false)) return this.DescribeFeatureSourcePartial(resourceID, schema, classNames); } catch { //Throw the original exception, not the secondary one } Exception ex2 = Utility.ThrowAsWebException(ex); if (ex2 != ex) throw ex2; else throw; } }
protected override ClassDefinition GetClassDefinitionInternal(string resourceId, string schemaName, string className) { var req = m_reqBuilder.GetClassDefinition(resourceId, schemaName, className); using (var s = this.OpenRead(req)) { var fsd = new FeatureSourceDescription(s); //We can't just assume first class item is the one, as ones that do not take //class name hints will return the full schema var schema = fsd.GetSchema(schemaName); if (schema != null) { if (schema.Classes.Count > 1) { //Since we have the full schema anyway, let's cache these other classes ClassDefinition ret = null; foreach (var cls in schema.Classes) { string key = resourceId + "!" + cls.QualifiedName; m_classDefinitionCache[key] = cls; if (cls.Name == className) ret = cls; } return ret; } else { return schema.GetClass(className); } } else { return null; } } }
/// <summary> /// Creates a clone of the specified instance /// </summary> /// <param name="fsd">The instance to clone</param> /// <returns></returns> public static FeatureSourceDescription Clone(FeatureSourceDescription fsd) { var schemas = new List<FeatureSchema>(); foreach (var fs in fsd.Schemas) { schemas.Add(FeatureSchema.Clone(fs)); } return new FeatureSourceDescription(schemas, fsd.IsPartial); }
public void TestBidirectional() { FeatureSchema schema = new FeatureSchema("Default", "Default Schema"); ClassDefinition cls = new ClassDefinition("Class1", "Test Class"); cls.AddProperty(new DataPropertyDefinition("ID", "ID Property") { IsAutoGenerated = true, DataType = DataPropertyType.Int64, IsNullable = false, }, true); var prop = cls.FindProperty("ID") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(1, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.Int64, prop.DataType); Assert.IsTrue(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); cls.AddProperty(new DataPropertyDefinition("Name", "The name") { DataType = DataPropertyType.String, Length = 255 }); prop = cls.FindProperty("Name") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(2, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.String, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); cls.AddProperty(new DataPropertyDefinition("Date", "The date") { DataType = DataPropertyType.DateTime, IsNullable = true }); prop = cls.FindProperty("Date") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.DateTime, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsTrue(prop.IsNullable); schema.AddClass(cls); Assert.AreEqual(1, schema.Classes.Count); XmlDocument doc = new XmlDocument(); schema.WriteXml(doc, doc); string path = Path.GetTempFileName(); doc.Save(path); FeatureSourceDescription fsd = new FeatureSourceDescription(File.OpenRead(path)); Assert.AreEqual(1, fsd.Schemas.Length); schema = fsd.Schemas[0]; Assert.NotNull(schema); cls = schema.GetClass("Class1"); Assert.NotNull(cls); prop = cls.FindProperty("ID") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.Int64, prop.DataType); Assert.IsTrue(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); prop = cls.FindProperty("Name") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.String, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsFalse(prop.IsNullable); prop = cls.FindProperty("Date") as DataPropertyDefinition; Assert.AreEqual(1, cls.IdentityProperties.Count); Assert.AreEqual(3, cls.Properties.Count); Assert.NotNull(prop); Assert.AreEqual(DataPropertyType.DateTime, prop.DataType); Assert.IsFalse(prop.IsAutoGenerated); Assert.IsFalse(prop.IsReadOnly); Assert.IsTrue(prop.IsNullable); }
public void TestMySqlSchema() { var fds = new FeatureSourceDescription(File.OpenRead("UserTestData\\gen_default1_MySql_master.xml")); Assert.AreEqual(1, fds.Schemas.Length); var fs = fds.GetSchema("AutoGen"); Assert.IsNotNull(fs); Assert.AreEqual(12, fs.Classes.Count); var c1 = fds.GetClass("AutoGen:rtable1"); var c2 = fds.GetClass("AutoGen:rtable2"); var c3 = fds.GetClass("AutoGen:rtable5"); var c4 = fds.GetClass("AutoGen:rtable6"); var c5 = fds.GetClass("AutoGen:rtable7"); var c6 = fds.GetClass("AutoGen:table1"); var c7 = fds.GetClass("AutoGen:table3"); var c8 = fds.GetClass("AutoGen:table4"); var c9 = fds.GetClass("AutoGen:table5"); var c10 = fds.GetClass("AutoGen:table6"); var c11 = fds.GetClass("AutoGen:table7"); var c12 = fds.GetClass("AutoGen:view1"); Assert.NotNull(c1); Assert.NotNull(c2); Assert.NotNull(c3); Assert.NotNull(c4); Assert.NotNull(c5); Assert.NotNull(c6); Assert.NotNull(c7); Assert.NotNull(c8); Assert.NotNull(c9); Assert.NotNull(c10); Assert.NotNull(c11); Assert.NotNull(c12); Assert.AreEqual(1, c1.IdentityProperties.Count); Assert.AreEqual(1, c2.IdentityProperties.Count); Assert.AreEqual(1, c3.IdentityProperties.Count); Assert.AreEqual(1, c4.IdentityProperties.Count); Assert.AreEqual(1, c5.IdentityProperties.Count); Assert.AreEqual(1, c6.IdentityProperties.Count); Assert.AreEqual(2, c7.IdentityProperties.Count); Assert.AreEqual(1, c8.IdentityProperties.Count); Assert.AreEqual(1, c9.IdentityProperties.Count); Assert.AreEqual(2, c10.IdentityProperties.Count); Assert.AreEqual(1, c11.IdentityProperties.Count); Assert.AreEqual(0, c12.IdentityProperties.Count); Assert.AreEqual(c1.Properties.Count, 3); Assert.AreEqual(c2.Properties.Count, 5); Assert.AreEqual(c3.Properties.Count, 3); Assert.AreEqual(c4.Properties.Count, 4); Assert.AreEqual(c5.Properties.Count, 3); Assert.AreEqual(c6.Properties.Count, 47); Assert.AreEqual(c7.Properties.Count, 3); Assert.AreEqual(c8.Properties.Count, 4); Assert.AreEqual(c9.Properties.Count, 2); Assert.AreEqual(c10.Properties.Count, 3); Assert.AreEqual(c11.Properties.Count, 2); Assert.AreEqual(c12.Properties.Count, 3); Assert.AreEqual(c1, fds.GetClass("AutoGen", "rtable1")); Assert.AreEqual(c2, fds.GetClass("AutoGen", "rtable2")); Assert.AreEqual(c3, fds.GetClass("AutoGen", "rtable5")); Assert.AreEqual(c4, fds.GetClass("AutoGen", "rtable6")); Assert.AreEqual(c5, fds.GetClass("AutoGen", "rtable7")); Assert.AreEqual(c6, fds.GetClass("AutoGen", "table1")); Assert.AreEqual(c7, fds.GetClass("AutoGen", "table3")); Assert.AreEqual(c8, fds.GetClass("AutoGen", "table4")); Assert.AreEqual(c9, fds.GetClass("AutoGen", "table5")); Assert.AreEqual(c10, fds.GetClass("AutoGen", "table6")); Assert.AreEqual(c11, fds.GetClass("AutoGen", "table7")); Assert.AreEqual(c12, fds.GetClass("AutoGen", "view1")); Assert.IsTrue(string.IsNullOrEmpty(c1.DefaultGeometryPropertyName)); Assert.IsTrue(string.IsNullOrEmpty(c2.DefaultGeometryPropertyName)); Assert.IsTrue(string.IsNullOrEmpty(c3.DefaultGeometryPropertyName)); Assert.IsTrue(string.IsNullOrEmpty(c4.DefaultGeometryPropertyName)); Assert.IsTrue(string.IsNullOrEmpty(c5.DefaultGeometryPropertyName)); //Though this feature class has geometries, the XML schema says none //are designated Assert.IsTrue(string.IsNullOrEmpty(c6.DefaultGeometryPropertyName)); Assert.IsTrue(string.IsNullOrEmpty(c7.DefaultGeometryPropertyName)); Assert.IsFalse(string.IsNullOrEmpty(c8.DefaultGeometryPropertyName)); Assert.IsTrue(string.IsNullOrEmpty(c9.DefaultGeometryPropertyName)); Assert.IsTrue(string.IsNullOrEmpty(c10.DefaultGeometryPropertyName)); Assert.IsTrue(string.IsNullOrEmpty(c11.DefaultGeometryPropertyName)); Assert.IsTrue(string.IsNullOrEmpty(c12.DefaultGeometryPropertyName)); }