コード例 #1
0
        /// <summary>
        /// Set the current element's content from the current XML node
        /// </summary>
        /// <param name="node"></param>
        /// <param name="mgr"></param>
        public void ReadXml(XmlNode node, XmlNamespaceManager mgr)
        {
            if (!node.Name.Equals("fdo:DataStore"))                                                           //NOXLATE
            {
                throw new Exception(string.Format(Strings.ErrorBadDocumentExpectedElement, "fdo:DataStore")); //NOXLATE
            }
            _spatialContexts.Clear();
            _schemas.Clear();

            XmlNodeList csNodes = node.SelectNodes("gml:DerivedCRS", mgr); //NOXLATE

            foreach (XmlNode cs in csNodes)
            {
                var context = new FdoSpatialContextListSpatialContext();
                context.ReadXml(cs, mgr);

                AddSpatialContext(context);
            }

            XmlNodeList schemaNodes = node.SelectNodes("xs:schema", mgr); //NOXLATE

            foreach (XmlNode sn in schemaNodes)
            {
                FeatureSchema fs = new FeatureSchema();
                fs.ReadXml(sn, mgr);
                AddSchema(fs);
            }

            ReadSchemaMappings(node, mgr);
        }
コード例 #2
0
        internal string[] AddClassesToSchema(string schemaName, ClassCollection classCollection)
        {
            List <string> notAdded = new List <string>();
            FeatureSchema fsc      = null;
            var           fidx     = _schemas.IndexOf(schemaName);

            if (fidx >= 0)
            {
                fsc = _schemas[fidx];
            }
            else
            {
                fsc = new FeatureSchema(schemaName, "");
                AddSchema(fsc);
            }

            foreach (ClassDefinition cls in classCollection)
            {
                var cidx = fsc.Classes.IndexOf(cls.Name);
                if (cidx >= 0)
                {
                    notAdded.Add(cls.Name);
                }
                else
                {
                    ClassDefinition copy = FdoSchemaUtil.CloneClass(cls, false);
                    AddClass(fsc.Name, copy);
                }
            }

            return(notAdded.ToArray());
        }
コード例 #3
0
ファイル: TableToFlatFile.cs プロジェクト: beritec/fdotoolbox
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        protected override void Initialize()
        {
            SendMessage("Creating target data source");
            if (!ExpressUtility.CreateFlatFileDataSource(_outputFile))
            {
                throw new FdoETLException(ResourceUtil.GetStringFormatted("ERR_CANNOT_CREATE_DATA_FILE", _outputFile));
            }

            _outConn = ExpressUtility.CreateFlatFileConnection(_outputFile);
            _outConn.Open();

            ClassDefinition cd = _table.CreateClassDefinition(true);

            using (FdoFeatureService service = _outConn.CreateFeatureService())
            {
                SendMessage("Applying schema to target");
                FeatureSchema schema = new FeatureSchema("Schema1", "Default schema");
                schema.Classes.Add(cd);
                service.ApplySchema(schema);
            }

            SendMessage("Copying any attached spatial contexts");
            ExpressUtility.CopyAllSpatialContexts(_table.SpatialContexts, _outConn, true);

            Register(new FdoFeatureTableInputOperation(_table));
            Register(new FdoOutputOperation(_outConn, cd.Name));
        }
コード例 #4
0
        public virtual void TestDeleteFeatures()
        {
            Skip.If(_fixture.Skip, _fixture.SkipReason);

            var             conn   = _fixture.CreateTestConnection();
            var             fsId   = "Library://UnitTests/Data/Test" + GetTestPrefix() + "DeleteFeatures.FeatureSource";
            ClassDefinition cls    = null;
            FeatureSchema   schema = null;

            PopulateTestDataStore(conn, fsId, ref schema, ref cls);

            IDeleteFeatures delete = (IDeleteFeatures)conn.CreateCommand((int)CommandType.DeleteFeatures);

            delete.ClassName       = cls.Name;
            delete.FeatureSourceId = fsId;
            delete.Filter          = "NAME = 'Test4'";

            Assert.Equal(1, delete.Execute());

            int count = 0;

            using (var rdr = conn.FeatureService.QueryFeatureSource(fsId, cls.Name))
            {
                while (rdr.ReadNext())
                {
                    count++;
                }
            }

            Assert.Equal(3, count);
        }
コード例 #5
0
        public void WriteXmlTest()
        {
            var fs = new FeatureSchema("Foo", "Bar");

            Assert.AreEqual("Foo", fs.Name);
            Assert.AreEqual("Bar", fs.Description);
            Assert.AreEqual(0, fs.Classes.Count);

            var cls = new ClassDefinition("Class1", "Test Class");
            var id  = new DataPropertyDefinition("ID", "");

            id.DataType        = DataPropertyType.Int32;
            id.IsAutoGenerated = true;
            var name = new DataPropertyDefinition("Name", "");

            cls.AddProperty(id, true);
            cls.AddProperty(name);
            fs.AddClass(cls);

            var doc = new XmlDocument();

            fs.WriteXml(doc, doc);

            string xml = doc.ToXmlString();

            Assert.False(String.IsNullOrEmpty(xml));
        }
コード例 #6
0
        public virtual void TestCreateDataStore()
        {
            Skip.If(_fixture.Skip, _fixture.SkipReason);

            var             conn   = _fixture.CreateTestConnection();
            var             fsId   = "Library://UnitTests/Data/Test" + GetTestPrefix() + "CreateDataStore.FeatureSource";
            ClassDefinition cls    = null;
            FeatureSchema   schema = null;

            CreateTestDataStore(conn, fsId, ref schema, ref cls);

            ClassDefinition cls2 = conn.FeatureService.GetClassDefinition(fsId, "Class1");

            Assert.NotNull(cls2);
            Assert.False(ClassDefinition.ReferenceEquals(cls, cls2));

            Assert.Equal(cls.Name, cls2.Name);
            Assert.Equal(cls.DefaultGeometryPropertyName, cls2.DefaultGeometryPropertyName);
            Assert.Equal(cls.Properties.Count, cls2.Properties.Count);
            Assert.Equal(cls.IdentityProperties.Count, cls2.IdentityProperties.Count);
            foreach (var prop in cls.Properties)
            {
                var prop2 = cls2.FindProperty(prop.Name);
                Assert.Equal(prop.Name, prop2.Name);
                Assert.Equal(prop.Type, prop2.Type);
            }
        }
コード例 #7
0
        public void CloneTest()
        {
            var fs = new FeatureSchema("Foo", "Bar");

            Assert.AreEqual("Foo", fs.Name);
            Assert.AreEqual("Bar", fs.Description);
            Assert.AreEqual(0, fs.Classes.Count);

            var cls = new ClassDefinition("Class1", "Test Class");
            var id  = new DataPropertyDefinition("ID", "");

            id.DataType        = DataPropertyType.Int32;
            id.IsAutoGenerated = true;
            var name = new DataPropertyDefinition("Name", "");

            cls.AddProperty(id, true);
            cls.AddProperty(name);
            fs.AddClass(cls);

            var fs2 = FeatureSchema.Clone(fs);

            Assert.AreEqual(fs.Name, fs2.Name);
            Assert.AreEqual(fs.Description, fs2.Description);
            Assert.AreEqual(fs.Classes.Count, fs2.Classes.Count);
            Assert.AreNotSame(fs, fs2);
        }
コード例 #8
0
        protected void CreateTestDataStore(IServerConnection conn, string fsId, ref FeatureSchema schema, ref ClassDefinition cls)
        {
            schema = new FeatureSchema("Default", "");
            cls    = new ClassDefinition("Class1", "");

            try
            {
                if (conn.ResourceService.ResourceExists(fsId))
                {
                    conn.ResourceService.DeleteResource(fsId);
                }

                cls.DefaultGeometryPropertyName = "GEOM";
                cls.AddProperty(new DataPropertyDefinition("KEY", "")
                {
                    DataType        = DataPropertyType.Int32,
                    IsAutoGenerated = true,
                    IsReadOnly      = true,
                    IsNullable      = false
                }, true);

                cls.AddProperty(new DataPropertyDefinition("NAME", "")
                {
                    DataType   = DataPropertyType.String,
                    Length     = 255,
                    IsNullable = true,
                    IsReadOnly = false
                });

                cls.AddProperty(new GeometricPropertyDefinition("GEOM", "")
                {
                    GeometricTypes            = FeatureGeometricType.Point,
                    SpatialContextAssociation = "Default"
                });

                schema.AddClass(cls);

                ICreateDataStore create = (ICreateDataStore)conn.CreateCommand((int)CommandType.CreateDataStore);
                CoordinateSystemDefinitionBase coordSys = conn.CoordinateSystemCatalog.FindCoordSys("LL84");
                create.FeatureSourceId     = fsId;
                create.CoordinateSystemWkt = coordSys.WKT;
                create.Name        = "Default";
                create.ExtentType  = OSGeo.MapGuide.ObjectModels.Common.FdoSpatialContextListSpatialContextExtentType.Dynamic;
                create.FileName    = "Test.sdf";
                create.Provider    = "OSGeo.SDF";
                create.Schema      = schema;
                create.XYTolerance = 0.001;
                create.ZTolerance  = 0.001;

                create.Execute();
            }
            catch
            {
                schema = null;
                cls    = null;
                throw;
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
ファイル: FdoSchemaView.cs プロジェクト: morkl/fdotoolbox
 private TreeNode CreateSchemaNode(FeatureSchema schema)
 {
     return(new TreeNode()
     {
         Name = schema.Name,
         Text = schema.Name,
         Tag = schema,
         ImageIndex = IDX_SCHEMA,
         SelectedImageIndex = IDX_SCHEMA,
         ContextMenuStrip = ctxSchema
     });
 }
コード例 #11
0
        internal void AddSchema(FeatureSchema schema)
        {
            _schemas.Add(schema);
            //Broadcast

            var handler = this.SchemaAdded;

            if (handler != null)
            {
                handler(schema);
            }
        }
コード例 #12
0
        public void TestSchemaCannotBeApplied()
        {
            FeatureSchema schema = new FeatureSchema("Default", "");
            FeatureClass  fc     = new FeatureClass("Class1", "");

            DataPropertyDefinition id = new DataPropertyDefinition("ID", "");

            id.DataType        = DataType.DataType_Int32;
            id.IsAutoGenerated = true;

            fc.Properties.Add(id);
            fc.IdentityProperties.Add(id);

            //Unsupported property in SHP
            DataPropertyDefinition d1 = new DataPropertyDefinition("Unsupported", "");

            d1.DataType = DataType.DataType_Int64;
            d1.Nullable = true;

            fc.Properties.Add(d1);

            GeometricPropertyDefinition geom = new GeometricPropertyDefinition("Geometry", "");

            geom.GeometryTypes = (int)GeometryType.GeometryType_Point;

            fc.Properties.Add(geom);
            schema.Classes.Add(fc);

            /*
             * IConnection conn = FeatureAccessManager.GetConnectionManager().CreateConnection("OSGeo.SHP");
             * conn.ConnectionString = "DefaultFileLocation=" + AppGateway.RunningApplication.AppPath;
             * using (conn)
             * {
             *  conn.Open();
             *  using (FeatureService service = new FeatureService(conn))
             *  {
             *      IncompatibleSchema incSchema = null;
             *      bool result = service.CanApplySchema(schema, out incSchema);
             *      Assert.IsNotNull(incSchema);
             *      Assert.IsFalse(result);
             *
             *      foreach (IncompatibleClass incClass in incSchema.Classes)
             *      {
             *          foreach (IncompatibleProperty incProp in incClass.Properties)
             *          {
             *              Assert.AreEqual(incProp.Reasons.Count, incProp.ReasonCodes.Count);
             *          }
             *      }
             *  }
             *  conn.Close();
             * }*/
        }
コード例 #13
0
        public void AddClassTest()
        {
            var fs = new FeatureSchema("Foo", "Bar");

            Assert.Equal("Foo", fs.Name);
            Assert.Equal("Bar", fs.Description);
            Assert.Empty(fs.Classes);

            var cls = new ClassDefinition("Class1", "Test Class");

            fs.AddClass(cls);
            Assert.Single(fs.Classes);
        }
コード例 #14
0
ファイル: FdoSchemaView.cs プロジェクト: morkl/fdotoolbox
            internal void AddSchema()
            {
                string name = _context.GenerateName("Schema");

                while (_context.SchemaNameExists(name))
                {
                    name = _context.GenerateName("Schema");
                }

                FeatureSchema schema = new FeatureSchema(name, "");

                _context.AddSchema(schema);
            }
コード例 #15
0
        public void FeatureSchemaTest()
        {
            var fs = new FeatureSchema("Foo", "");

            Assert.Equal("Foo", fs.Name);
            Assert.True(String.IsNullOrEmpty(fs.Description));
            Assert.Empty(fs.Classes);

            fs = new FeatureSchema("Foo", "Bar");
            Assert.Equal("Foo", fs.Name);
            Assert.Equal("Bar", fs.Description);
            Assert.Empty(fs.Classes);
        }
コード例 #16
0
        public void AddClassTest()
        {
            var fs = new FeatureSchema("Foo", "Bar");

            Assert.AreEqual("Foo", fs.Name);
            Assert.AreEqual("Bar", fs.Description);
            Assert.AreEqual(0, fs.Classes.Count);

            var cls = new ClassDefinition("Class1", "Test Class");

            fs.AddClass(cls);
            Assert.AreEqual(1, fs.Classes.Count);
        }
コード例 #17
0
        public override void Run()
        {
            TreeNode node = Workbench.Instance.ObjectExplorer.GetSelectedNode();

            if (node.Level == 2) //Schema
            {
                TreeNode             schemaNode = node;
                TreeNode             connNode   = node.Parent;
                FdoConnectionManager mgr        = ServiceManager.Instance.GetService <FdoConnectionManager>();
                FdoConnection        conn       = mgr.GetConnection(connNode.Name);
                using (FdoFeatureService service = conn.CreateFeatureService())
                {
                    FeatureSchema schema = service.GetSchemaByName(schemaNode.Name);
                    if (schema != null)
                    {
                        PartialSchemaSaveDialog dialog = new PartialSchemaSaveDialog(schema);
                        dialog.ShowDialog();
                    }
                }
            }


            //string path = FileService.SaveFile(Res.GetString("TITLE_SAVE_SCHEMA"), Res.GetString("FILTER_SCHEMA_FILE"));
            //if (!string.IsNullOrEmpty(path))
            //{
            //    TreeNode node = Workbench.Instance.ObjectExplorer.GetSelectedNode();
            //    if (node.Level == 1) //Connection
            //    {
            //        TreeNode connNode = node;
            //        FdoConnectionManager mgr = ServiceManager.Instance.GetService<FdoConnectionManager>();
            //        FdoConnection conn = mgr.GetConnection(connNode.Name);
            //        using (FdoFeatureService service = conn.CreateFeatureService())
            //        {
            //            service.WriteSchemaToXml(path);
            //            Log.InfoFormatted(Res.GetString("LOG_SCHEMA_SAVED"), path);
            //        }
            //    }
            //    else if (node.Level == 2) //Schema
            //    {
            //        TreeNode schemaNode = node;
            //        TreeNode connNode = node.Parent;
            //        FdoConnectionManager mgr = ServiceManager.Instance.GetService<FdoConnectionManager>();
            //        FdoConnection conn = mgr.GetConnection(connNode.Name);
            //        using (FdoFeatureService service = conn.CreateFeatureService())
            //        {
            //            service.WriteSchemaToXml(schemaNode.Name, path);
            //            Log.InfoFormatted(Res.GetString("LOG_SCHEMA_SAVED_2"), connNode.Name, path);
            //        }
            //    }
            //}
        }
コード例 #18
0
ファイル: AssertHelper.cs プロジェクト: beritec/fdotoolbox
        public static void EqualSchemas(FeatureSchema schema, FeatureSchema schema2)
        {
            Assert.AreEqual(schema.Name, schema2.Name);
            Assert.AreEqual(schema.Classes.Count, schema2.Classes.Count);

            foreach (ClassDefinition classDef in schema.Classes)
            {
                int idx = schema2.Classes.IndexOf(classDef.Name);
                Assert.IsTrue(idx >= 0);

                ClassDefinition cd = schema2.Classes[idx];
                EqualClass(classDef, cd);
            }
        }
コード例 #19
0
ファイル: AssertHelper.cs プロジェクト: stophun/fdotoolbox
        public static void EqualSchemas(FeatureSchema schema, FeatureSchema schema2)
        {
            Assert.AreEqual(schema.Name, schema2.Name);
            Assert.AreEqual(schema.Classes.Count, schema2.Classes.Count);

            foreach (ClassDefinition classDef in schema.Classes)
            {
                int idx = schema2.Classes.IndexOf(classDef.Name);
                Assert.IsTrue(idx >= 0);

                ClassDefinition cd = schema2.Classes[idx];
                EqualClass(classDef, cd);
            }
        }
コード例 #20
0
ファイル: FdoSchemaView.cs プロジェクト: morkl/fdotoolbox
            void OnSchemaAdded(FeatureSchema item)
            {
                var node = CreateSchemaNode(item);

                _view.schemaTree.Nodes.Add(node);

                foreach (ClassDefinition cd in item.Classes)
                {
                    OnClassAdded(cd);
                }

                _view.EvaluateStates();
                _view.FlagUpdateState();
            }
コード例 #21
0
 public override void ExecuteAction()
 {
     using (var svc = _conn.CreateFeatureService())
     {
         IncompatibleSchema schema;
         if (!svc.CanApplySchema(_schema, out schema))
         {
             Info("Fixing incompatibilities in schema");
             _schema = svc.AlterSchema(_schema, schema);
         }
         Info("Applying schema");
         svc.ApplySchema(_schema);
         Info("Schema applied");
     }
 }
コード例 #22
0
 public override void ExecuteAction()
 {
     using (var svc = _conn.CreateFeatureService())
     {
         IncompatibleSchema schema;
         if (!svc.CanApplySchema(_schema, out schema))
         {
             Info("Fixing incompatibilities in schema");
             _schema = svc.AlterSchema(_schema, schema);
         }
         Info("Applying schema");
         svc.ApplySchema(_schema);
         Info("Schema applied");
     }
 }
コード例 #23
0
ファイル: FdoSchemaView.cs プロジェクト: morkl/fdotoolbox
            private void OnSchemaSelected(TreeNode node)
            {
                FeatureSchema schema = (FeatureSchema)node.Tag;
                //C# Lambdas, making code and design compact and elegant since 2007
                NodeUpdateHandler update = () =>
                {
                    node.Text = schema.Name;
                    node.Name = schema.Name;
                };
                var c = new SchemaCtrl(new FeatureSchemaDecorator(schema), update);

                _view.SetLogicalControl(c);
                _view.PhysicalMappingsVisible = false;
                _view.RightPaneVisible        = true;
            }
コード例 #24
0
        public override int Execute()
        {
            IConnection conn = null;

            try
            {
                conn = CreateConnection(_provider, _connstr);
                conn.Open();
            }
            catch (OSGeo.FDO.Common.Exception ex)
            {
                WriteException(ex);
                return((int)CommandStatus.E_FAIL_CONNECT);
            }

            using (FdoFeatureService service = new FdoFeatureService(conn))
            {
                FeatureSchema fs = service.GetSchemaByName(_schema);
                if (fs != null)
                {
                    using (fs)
                    {
                        Console.WriteLine("\nClasses in schema {0}: {1}\n", fs.Name, fs.Classes.Count);
                        foreach (ClassDefinition cd in fs.Classes)
                        {
                            Console.WriteLine("Name: {0} ({1})\n\n\tQualified Name: {2}", cd.Name, cd.ClassType, cd.QualifiedName);
                            Console.WriteLine("\tDescription: {0}", cd.Description);
                            Console.WriteLine("\tIs Abstract: {0}\n\tIs Computed: {1}", cd.IsAbstract, cd.IsComputed);
                            if (cd.BaseClass != null)
                            {
                                Console.WriteLine("\tBase Class: {0}", cd.BaseClass.Name);
                            }
                            Console.WriteLine("\tAttributes:");
                            WriteAttributes(cd.Attributes);
                            Console.WriteLine("");
                        }
                    }
                }
                else
                {
                    Console.Error.WriteLine("Could not find schema: {0}", _schema);
                    return((int)CommandStatus.E_FAIL_SCHEMA_NOT_FOUND);
                }
            }

            conn.Close();
            return((int)CommandStatus.E_OK);
        }
コード例 #25
0
        public void IndexOfTest()
        {
            var fs = new FeatureSchema("Foo", "Bar");

            Assert.AreEqual("Foo", fs.Name);
            Assert.AreEqual("Bar", fs.Description);
            Assert.AreEqual(0, fs.Classes.Count);

            var cls = new ClassDefinition("Class1", "Test Class");

            fs.AddClass(cls);

            Assert.GreaterOrEqual(fs.IndexOf(cls), 0);
            Assert.True(fs.RemoveClass(cls));
            Assert.Less(fs.IndexOf(cls), 0);
        }
コード例 #26
0
        void GetClassNodesFull(FeatureSchema schema, TreeNode schemaNode)
        {
            //Pre-sort
            SortedList <string, ClassDefinition> sorted = new SortedList <string, ClassDefinition>();

            foreach (ClassDefinition classDef in schema.Classes)
            {
                sorted.Add(classDef.Name, classDef);
            }

            foreach (ClassDefinition classDef in sorted.Values)
            {
                TreeNode classNode = CreateClassNode(classDef);
                schemaNode.Nodes.Add(classNode);
            }
        }
コード例 #27
0
        public void IndexOfTest()
        {
            var fs = new FeatureSchema("Foo", "Bar");

            Assert.Equal("Foo", fs.Name);
            Assert.Equal("Bar", fs.Description);
            Assert.Empty(fs.Classes);

            var cls = new ClassDefinition("Class1", "Test Class");

            fs.AddClass(cls);

            Assert.True(fs.IndexOf(cls) >= 0);
            Assert.True(fs.RemoveClass(cls));
            Assert.True(fs.IndexOf(cls) < 0);
        }
コード例 #28
0
        public virtual void TestApplySchema()
        {
            Skip.If(_fixture.Skip, _fixture.SkipReason);

            var fsId = "Library://UnitTests/Data/TestMaestro" + GetTestPrefix() + "ApplySchema.FeatureSource";
            var conn = _fixture.CreateTestConnection();

            if (conn.ResourceService.ResourceExists(fsId))
            {
                conn.ResourceService.DeleteResource(fsId);
            }

            ClassDefinition cls    = null;
            FeatureSchema   schema = null;

            CreateTestDataStore(conn, fsId, ref schema, ref cls);

            cls.AddProperty(new DataPropertyDefinition("ExtraProp", "")
            {
                DataType   = DataPropertyType.String,
                IsNullable = false,
                Length     = 255
            });

            //Apply changes
            IApplySchema cmd = (IApplySchema)conn.CreateCommand((int)CommandType.ApplySchema);

            cmd.Schema          = schema;
            cmd.FeatureSourceId = fsId;
            cmd.Execute();

            ClassDefinition cls2 = conn.FeatureService.GetClassDefinition(cmd.FeatureSourceId, "Class1");

            Assert.NotNull(cls2);
            Assert.False(ClassDefinition.ReferenceEquals(cls, cls2));

            Assert.Equal(cls.Name, cls2.Name);
            Assert.Equal(cls.DefaultGeometryPropertyName, cls2.DefaultGeometryPropertyName);
            Assert.Equal(cls.Properties.Count, cls2.Properties.Count);
            Assert.Equal(cls.IdentityProperties.Count, cls2.IdentityProperties.Count);
            foreach (var prop in cls.Properties)
            {
                var prop2 = cls2.FindProperty(prop.Name);
                Assert.Equal(prop.Name, prop2.Name);
                Assert.Equal(prop.Type, prop2.Type);
            }
        }
コード例 #29
0
        private TreeNode CreateSchemaNode(FeatureSchema schema)
        {
            var node = new TreeNode();

            node.Name = schema.Name;
            node.Text = schema.Name;

            foreach (ClassDefinition cls in schema.Classes)
            {
                var clsNode = CreateClassNode(cls);
                node.Nodes.Add(clsNode);
            }

            node.Tag = schema;

            return(node);
        }
コード例 #30
0
ファイル: SchemaWalker.cs プロジェクト: morkl/fdotoolbox
        public override ClassDefinition GetClassDefinition(string schemaName, string className)
        {
            EnsureSchemaRetrieved();

            if (_schemas.IndexOf(schemaName) >= 0)
            {
                FeatureSchema   fs      = _schemas[schemaName];
                ClassCollection classes = fs.Classes;

                if (classes.IndexOf(className) >= 0)
                {
                    return(classes[className]);
                }
            }

            return(null);
        }
コード例 #31
0
        public void GetItemTest()
        {
            var fs = new FeatureSchema("Foo", "Bar");

            Assert.AreEqual("Foo", fs.Name);
            Assert.AreEqual("Bar", fs.Description);
            Assert.AreEqual(0, fs.Classes.Count);

            var cls = new ClassDefinition("Class1", "Test Class");

            fs.AddClass(cls);

            Assert.Throws <ArgumentOutOfRangeException>(() => fs.GetItem(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => fs.GetItem(1));
            Assert.NotNull(fs.GetItem(0));
            Assert.True(fs.RemoveClass(cls));
            Assert.Throws <ArgumentOutOfRangeException>(() => fs.GetItem(0));
        }
コード例 #32
0
ファイル: SchemaWalker.cs プロジェクト: morkl/fdotoolbox
        public override ClassDescriptor[] GetClassNames(string schemaName)
        {
            EnsureSchemaRetrieved();

            List <ClassDescriptor> classNames = new List <ClassDescriptor>();

            if (_schemas.IndexOf(schemaName) >= 0)
            {
                FeatureSchema   fs      = _schemas[schemaName];
                ClassCollection classes = fs.Classes;

                for (int i = 0; i < classes.Count; i++)
                {
                    classNames.Add(new ClassDescriptor(fs.Name, classes[i].Name));
                }
            }

            return(classNames.ToArray());
        }
コード例 #33
0
ファイル: FdoSchemaUtil.cs プロジェクト: stophun/fdotoolbox
 public static int SetDefaultSpatialContextAssociation(FeatureSchema fs, string name)
 {
     int modified = 0;
     foreach (ClassDefinition cls in fs.Classes)
     {
         foreach (PropertyDefinition prop in cls.Properties)
         {
             if (prop.PropertyType == PropertyType.PropertyType_GeometricProperty)
             {
                 GeometricPropertyDefinition geom = (GeometricPropertyDefinition)prop;
                 if (!geom.SpatialContextAssociation.Equals(name))
                 {
                     geom.SpatialContextAssociation = name;
                     modified++;
                 }
             }
         }
     }
     return modified;
 }
コード例 #34
0
ファイル: FdoSchemaUtil.cs プロジェクト: stophun/fdotoolbox
 /// <summary>
 /// Utility method to clone a feature schema
 /// </summary>
 /// <param name="fs"></param>
 /// <returns></returns>
 public static FeatureSchema CloneSchema(FeatureSchema fs)
 {
     return CloneSchema(fs, false);
 }
コード例 #35
0
        internal string[] AddClassesToSchema(string schemaName, ClassCollection classCollection)
        {
            List<string> notAdded = new List<string>();
            FeatureSchema fsc = null;
            var fidx = _schemas.IndexOf(schemaName);
            if (fidx >= 0)
            {
                fsc = _schemas[fidx];
            }
            else
            {
                fsc = new FeatureSchema(schemaName, "");
                AddSchema(fsc);
            }

            foreach (ClassDefinition cls in classCollection)
            {
                var cidx = fsc.Classes.IndexOf(cls.Name);
                if (cidx >= 0)
                {
                    notAdded.Add(cls.Name);
                }
                else
                {
                    ClassDefinition copy = FdoSchemaUtil.CloneClass(cls, false);
                    AddClass(fsc.Name, copy);
                }
            }

            return notAdded.ToArray();
        }
コード例 #36
0
        internal void AddSchema(FeatureSchema schema)
        {
            _schemas.Add(schema);
            //Broadcast

            var handler = this.SchemaAdded;
            if (handler != null)
                handler(schema);
        }
コード例 #37
0
        public void TestAlterSchemaBaseClass()
        {
            MockRepository mocks = new MockRepository();
            FeatureSchema schema = new FeatureSchema("Default", "");
            IConnection conn = mocks.DynamicMock<IConnection>();
            ISchemaCapabilities caps = mocks.DynamicMock<ISchemaCapabilities>();

            using (mocks.Record())
            {
                SetupResult.For(conn.ConnectionState).Return(ConnectionState.ConnectionState_Open);
                SetupResult.For(conn.SchemaCapabilities).Return(caps);
                SetupResult.For(caps.ClassTypes).Return((ClassType[])Enum.GetValues(typeof(ClassType)));
                SetupResult.For(caps.DataTypes).Return((DataType[])Enum.GetValues(typeof(DataType)));
                SetupResult.For(caps.MaximumDecimalPrecision).Return(20);
                SetupResult.For(caps.MaximumDecimalScale).Return(20);
                SetupResult.For(caps.ReservedCharactersForName).Return(string.Empty);
                SetupResult.For(caps.SupportedAutoGeneratedTypes).Return(new DataType[] { DataType.DataType_Int32, DataType.DataType_Int64 });
                SetupResult.For(caps.SupportedIdentityPropertyTypes).Return(new DataType[] { DataType.DataType_Int32, DataType.DataType_Int64 });
                SetupResult.For(caps.SupportsAssociationProperties).Return(false);
                SetupResult.For(caps.SupportsAutoIdGeneration).Return(true);
                SetupResult.For(caps.SupportsCompositeId).Return(false);
                SetupResult.For(caps.SupportsCompositeUniqueValueConstraints).Return(false);
                SetupResult.For(caps.SupportsDataStoreScopeUniqueIdGeneration).Return(false);
                SetupResult.For(caps.SupportsDefaultValue).Return(true);
                SetupResult.For(caps.SupportsExclusiveValueRangeConstraints).Return(false);
                SetupResult.For(caps.SupportsInclusiveValueRangeConstraints).Return(false);
                SetupResult.For(caps.SupportsMultipleSchemas).Return(false);
                SetupResult.For(caps.SupportsNetworkModel).Return(false);
                SetupResult.For(caps.SupportsNullValueConstraints).Return(true);
                SetupResult.For(caps.SupportsObjectProperties).Return(false);
                SetupResult.For(caps.SupportsSchemaModification).Return(true);
                SetupResult.For(caps.SupportsSchemaOverrides).Return(false);
                SetupResult.For(caps.SupportsUniqueValueConstraints).Return(false);
                SetupResult.For(caps.SupportsValueConstraintsList).Return(false);

                SetupResult.For(caps.SupportsInheritance).Return(false);
            }
            FdoFeatureService service = mocks.DynamicMock<FdoFeatureService>(conn);
            mocks.ReplayAll();

            ClassDefinition baseClass = new Class("Base", "");

            //ID
            DataPropertyDefinition id = new DataPropertyDefinition("ID", "");
            id.DataType = DataType.DataType_Int64;
            id.Nullable = false;

            baseClass.Properties.Add(id);
            baseClass.IdentityProperties.Add(id);

            //Name
            DataPropertyDefinition name = new DataPropertyDefinition("Name", "");
            name.DataType = DataType.DataType_String;
            name.Nullable = true;
            name.Length = 100;

            baseClass.Properties.Add(name);

            ClassDefinition derivedClass = new Class("Derived", "");
            derivedClass.BaseClass = baseClass;

            //DOB
            DataPropertyDefinition dob = new DataPropertyDefinition("DOB", "");
            dob.DataType = DataType.DataType_DateTime;
            dob.Nullable = true;

            derivedClass.Properties.Add(dob);

            schema.Classes.Add(baseClass);
            schema.Classes.Add(derivedClass);

            IncompatibleSchema incSchema = null;
            bool canApply = service.CanApplySchema(schema, out incSchema);
            Assert.IsFalse(canApply);
            Assert.IsNotNull(incSchema);

            FeatureSchema newSchema = service.AlterSchema(schema, incSchema);

            ClassDefinition newClass = newSchema.Classes[newSchema.Classes.IndexOf("Derived")];

            //Base class properties should be copied to derived class
            Assert.AreEqual("BASE_ID", newClass.IdentityProperties[0].Name);
            Assert.AreEqual(3, newClass.Properties.Count);
            Assert.IsTrue(newClass.Properties.IndexOf("BASE_ID") >= 0);
            Assert.IsTrue(newClass.Properties.IndexOf("BASE_Name") >= 0);
        }
コード例 #38
0
ファイル: FdoSchemaView.cs プロジェクト: stophun/fdotoolbox
 private TreeNode CreateSchemaNode(FeatureSchema schema)
 {
     return new TreeNode()
     {
         Name = schema.Name,
         Text = schema.Name,
         Tag = schema,
         ImageIndex = IDX_SCHEMA,
         SelectedImageIndex = IDX_SCHEMA,
         ContextMenuStrip = ctxSchema
     };
 }
コード例 #39
0
ファイル: FdoSchemaView.cs プロジェクト: stophun/fdotoolbox
            internal void AddSchema()
            {
                string name = _context.GenerateName("Schema");
                while(_context.SchemaNameExists(name))
                {
                    name = _context.GenerateName("Schema");
                }

                FeatureSchema schema = new FeatureSchema(name, "");
                _context.AddSchema(schema);
            }
コード例 #40
0
 public PartialSchemaSaveDialog(FeatureSchema schema)
     : this()
 {
     _schema = FdoSchemaUtil.CloneSchema(schema); //Operate on a clone
     InitTree();
 }
コード例 #41
0
ファイル: FdoJoin.cs プロジェクト: jumpinjackie/fdotoolbox
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        protected override void Initialize()
        {
            var sw = new Stopwatch();
            sw.Start();
            _options.Validate();

            SendMessage("Setting up left and right sides of the join");

            // Abstract:
            //
            // The current built-in join infrastructure is very naive as it uses nested
            // loops. Being a O(m*n) operation, the slowdown becomes readily apparent
            // as the size of the data you're working with increases. As such, the
            // current infrastructure is woefully inadequate for large datasets.
            //
            // How can we fix this problem? We could try to implement various join
            // algorithms for different scenarios, which would be a laborious exercise
            // in itself.
            //
            // Or, we can just delegate this problem to the universal swiss army-knife of
            // databases, SQLite.
            //
            // SQLite has many things going for it, including:
            //  - Support for common types of joins (important!)
            //  - LIGHTING FAST insert performance. The current FdoInputOperation is already optimised for SQLite
            //  - LIGHTING FAST read performance
            //  - Ability to use SQL to modify the database internals, such as creating indexes (FDO provider supports SQL commands)
            //
            // As such, SQLite is the perfect candidate for a temp data store to merge two
            // disparate data sources. The time spent setting up this temp SQLite database (ie. Copying "left" and
            // "right" side data into it) is negligible in the grand scheme of things.
            //
            // Process Overview:
            //
            // 1. Create temp SQLite database
            // 2. Pump left and right sides into this database
            // 3. Create indexes on join columns of both tables (IMPORTANT)
            // 4. Create a view encapsulating our join
            // 5. Copy this view out to our target
            //
            // Additional Notes:
            //
            // We will have to change our supported join types to line up with what SQLite supports, which
            // are:
            //  - INNER JOIN
            //  - LEFT OUTER JOIN
            //
            // SQLite does not support RIGHT OUTER JOINs but these could be emulated by inverting the
            // "left" and "right" tables for the LEFT OUTER JOIN. FULL OUTER JOIN is not supporte by
            // SQLite so this will be removed from our API.
            //
            // Since this SQLite database is temporary, we don't bother with putting
            // the right spatial context in there. Spatial contexts do not (should not) affect
            // the underlying coordinates of any geometries moving to and from the data store.
            //
            // SQLite views by default are represented as non-Feature classes. Geometry properties
            // default to BLOB data types. To "fix" this we need to add a new entry to the geometry_columns
            // metadata table. This may produce an incorrect feature class (ie. Has 1-n geometry properties
            // but no designated one), this is okay as we only care that the properties are there and the
            // temp-target property mappings check out.
            //
            // Although the implementation will change, the requirements remain the same, which are:
            //
            // 1. The target class must not already exist (as it will be created)
            // 2. If no designated geometry is specified, then the class definition will be FdoClass and not FdoFeatureClass

            ClassDefinition leftCls = null;
            ClassDefinition rightCls = null;
            ClassDefinition mergedCls = null;

            using (var leftSvc = _options.Left.Connection.CreateFeatureService())
            using (var rightSvc = _options.Right.Connection.CreateFeatureService())
            {
                leftCls = leftSvc.GetClassByName(_options.Left.SchemaName, _options.Left.ClassName);
                rightCls = rightSvc.GetClassByName(_options.Right.SchemaName, _options.Right.ClassName);

                if (leftCls == null)
                    throw new FdoETLException("Left class not found " + _options.Left.SchemaName + ":" + _options.Left.ClassName);

                if (rightCls == null)
                    throw new FdoETLException("Right class not found " + _options.Right.SchemaName + ":" + _options.Right.ClassName);

                var leftJoinProps = new List<string>(_options.JoinPairs.AllKeys);
                var rightJoinProps = new List<string>();
                foreach (var p in leftJoinProps)
                {
                    rightJoinProps.Add(_options.JoinPairs[p]);
                }

                var leftGeom = (!string.IsNullOrEmpty(_options.GeometryProperty) && _options.Side == JoinSide.Left) ? _options.GeometryProperty : null;
                var rightGeom = (!string.IsNullOrEmpty(_options.GeometryProperty) && _options.Side == JoinSide.Right) ? _options.GeometryProperty : null;

                PrepareClass(leftCls, _options.LeftProperties, leftJoinProps, _options.LeftPrefix, leftGeom);
                PrepareClass(rightCls, _options.RightProperties, rightJoinProps, _options.RightPrefix, rightGeom);

                mergedCls = CreateMergedClass(leftCls, rightCls);
            }

            var dprops = new NameValueCollection();
            dprops["File"] = Path.GetTempFileName();

            var tempSchema = new FeatureSchema("Default", "");
            var leftCopy = FdoSchemaUtil.CloneClass(leftCls);
            var rightCopy = FdoSchemaUtil.CloneClass(rightCls);

            string leftClassName = "LEFT_SIDE";
            string rightClassName = "RIGHT_SIDE";

            leftCopy.Name = leftClassName;
            rightCopy.Name = rightClassName;

            tempSchema.Classes.Add(leftCopy);
            tempSchema.Classes.Add(rightCopy);

            //Create SQLite database
            Register(new FdoCreateDataStoreOperation("OSGeo.SQLite", dprops, null));

            //Apply temp schema
            var tempConn = new FdoConnection("OSGeo.SQLite", "File=" + dprops["File"]);
            Register(new FdoApplySchemaOperation(tempConn, tempSchema));

            #if DEBUG
            Register(new FdoSingleActionOperation(() => { SendMessage("Temp db created in: " + dprops["File"]); }));
            #endif

            //Prep property mappings for bulk copy
            var leftMaps = new NameValueCollection();
            var rightMaps = new NameValueCollection();

            var leftQuery = new FeatureQueryOptions(leftCls.Name);
            var rightQuery = new FeatureQueryOptions(rightCls.Name);

            foreach (var leftp in _options.LeftProperties)
            {
                if (string.IsNullOrEmpty(_options.LeftPrefix))
                    leftMaps.Add(leftp, leftp);
                else
                    leftMaps.Add(leftp, _options.LeftPrefix + leftp);
                leftQuery.AddFeatureProperty(leftp);
            }
            foreach (var rightp in _options.RightProperties)
            {
                if (string.IsNullOrEmpty(_options.RightPrefix))
                    rightMaps.Add(rightp, rightp);
                else
                    rightMaps.Add(rightp, _options.RightPrefix + rightp);
                rightQuery.AddFeatureProperty(rightp);
            }

            if (!string.IsNullOrEmpty(_options.LeftFilter))
                leftQuery.Filter = _options.LeftFilter;

            if (!string.IsNullOrEmpty(_options.RightFilter))
                rightQuery.Filter = _options.RightFilter;

            //don't forget join keys
            foreach (string l in _options.JoinPairs.Keys)
            {
                string r = _options.JoinPairs[l];

                if (!_options.LeftProperties.Contains(l))
                {
                    leftQuery.AddFeatureProperty(l);

                    if (string.IsNullOrEmpty(_options.LeftPrefix))
                        leftMaps.Add(l, l);
                    else
                        leftMaps.Add(l, _options.LeftPrefix + l);
                }

                if (!_options.RightProperties.Contains(r))
                {
                    rightQuery.AddFeatureProperty(r);

                    if (string.IsNullOrEmpty(_options.RightPrefix))
                        rightMaps.Add(r, r);
                    else
                        rightMaps.Add(r, _options.RightPrefix + r);
                }

            }

            //don't forget geometry!
            if (!string.IsNullOrEmpty(_options.GeometryProperty))
            {
                if (_options.Side == JoinSide.Left)
                {
                    if (!leftQuery.PropertyList.Contains(_options.GeometryProperty))
                    {
                        leftQuery.AddFeatureProperty(_options.GeometryProperty);

                        if (string.IsNullOrEmpty(_options.LeftPrefix))
                            leftMaps.Add(_options.GeometryProperty, _options.GeometryProperty);
                        else
                            leftMaps.Add(_options.GeometryProperty, _options.LeftPrefix + _options.GeometryProperty);
                    }
                }
                else
                {
                    if (!rightQuery.PropertyList.Contains(_options.GeometryProperty))
                    {
                        rightQuery.AddFeatureProperty(_options.GeometryProperty);

                        if (string.IsNullOrEmpty(_options.RightPrefix))
                            rightMaps.Add(_options.GeometryProperty, _options.GeometryProperty);
                        else
                            rightMaps.Add(_options.GeometryProperty, _options.RightPrefix + _options.GeometryProperty);
                    }
                }
            }

            var copyLeftErrors = new List<Exception>();
            var copyRightErrors = new List<Exception>();
            var copyTargetErrors = new List<Exception>();

            //Copy left source
            ParameterlessAction copyLeft = () =>
            {
                SendMessage("Copying left source with filter: " + _options.LeftFilter);
                var copy = ExpressUtility.CreateBulkCopy(
                    _options.Left.Connection,
                    tempConn,
                    _options.Left.SchemaName,
                    leftQuery,
                    tempSchema.Name,    //temp sqlite schema name
                    leftClassName,      //sqlite "left" class name
                    leftMaps);

                copy.ProcessMessage += delegate(object sender, MessageEventArgs e)
                {
                    SendMessage(e.Message);
                };
                copy.Execute();
                copyLeftErrors.AddRange(copy.GetAllErrors());
            };
            Register(new FdoSingleActionOperation(copyLeft));

            //Register(new FdoInputOperation(_options.Left.Connection, leftQuery));
            //Register(new FdoOutputOperation(tempConn, leftClassName, leftMaps));

            //Copy right source
            ParameterlessAction copyRight = () =>
            {
                SendMessage("Copying right source with filter: " + _options.RightFilter);
                var copy = ExpressUtility.CreateBulkCopy(
                    _options.Right.Connection,
                    tempConn,
                    _options.Right.SchemaName,
                    rightQuery,
                    tempSchema.Name,    //temp sqlite schema name
                    rightClassName,      //sqlite "right" class name
                    rightMaps);

                copy.ProcessMessage += delegate(object sender, MessageEventArgs e)
                {
                    SendMessage(e.Message);
                };
                copy.Execute();
                copyRightErrors.AddRange(copy.GetAllErrors());
            };
            Register(new FdoSingleActionOperation(copyRight));

            //Register(new FdoInputOperation(_options.Right.Connection, rightQuery));
            //Register(new FdoOutputOperation(tempConn, rightClassName, rightMaps));

            string srcClass = "VIEW_INPUT";

            //Create indexes on left and right sides to optimize read performance
            ParameterlessAction indexLeft = () =>
            {
                using (var svc = tempConn.CreateFeatureService())
                {
                    SendMessage("Creating left side index in temp db");
                    string sql = "CREATE INDEX IDX_LEFT_ID ON " + leftClassName + "(";
                    var tokens = new List<string>();
                    foreach (string p in _options.JoinPairs.Keys)
                    {
                        if (!string.IsNullOrEmpty(_options.LeftPrefix))
                            tokens.Add(_options.LeftPrefix + p);
                        else
                            tokens.Add(p);
                    }
                    sql = sql + string.Join(", ", tokens.ToArray()) + ")";
                    SendMessage("Executing SQL: " + sql);
                    svc.ExecuteSQLNonQuery(sql);
                }
            };
            ParameterlessAction indexRight = () =>
            {
                using (var svc = tempConn.CreateFeatureService())
                {
                    SendMessage("Creating right side index in temp db");
                    string sql = "CREATE INDEX IDX_RIGHT_ID ON " + rightClassName + "(";
                    var tokens = new List<string>();
                    foreach (string p in _options.JoinPairs.Keys)
                    {
                        string prop = _options.JoinPairs[p];
                        if (!string.IsNullOrEmpty(_options.RightPrefix))
                            tokens.Add(_options.RightPrefix + prop);
                        else
                            tokens.Add(prop);
                    }
                    sql = sql + string.Join(", ", tokens.ToArray()) + ")";
                    SendMessage("Executing SQL: " + sql);
                    svc.ExecuteSQLNonQuery(sql);
                }
            };
            Register(new FdoSingleActionOperation(indexLeft));
            Register(new FdoSingleActionOperation(indexRight));

            //Create view
            ParameterlessAction createView = () =>
            {
                using (var svc = tempConn.CreateFeatureService())
                {
                    SendMessage("Creating view in temp db");
                    StringBuilder sql = new StringBuilder("CREATE VIEW ");
                    sql.Append(srcClass + " AS SELECT ");
                    foreach (var p in _options.LeftProperties)
                    {
                        if (!string.IsNullOrEmpty(_options.LeftPrefix))
                            sql.Append("l." + _options.LeftPrefix + p + ", ");
                        else
                            sql.Append("l." + p + ", ");
                    }

                    if (!string.IsNullOrEmpty(_options.GeometryProperty))
                    {
                        if (_options.Side == JoinSide.Left)
                        {
                            if (!_options.LeftProperties.Contains(_options.GeometryProperty))
                            {
                                if (!string.IsNullOrEmpty(_options.LeftPrefix))
                                    sql.Append("l." + _options.LeftPrefix + _options.GeometryProperty + ", ");
                                else
                                    sql.Append("l." + _options.GeometryProperty + ", ");
                            }
                        }
                        else
                        {
                            if (!_options.RightProperties.Contains(_options.GeometryProperty))
                            {
                                if (!string.IsNullOrEmpty(_options.RightPrefix))
                                    sql.Append("r." + _options.RightPrefix + _options.GeometryProperty + ", ");
                                else
                                    sql.Append("r." + _options.GeometryProperty + ", ");
                            }
                        }
                    }

                    int rc = _options.RightProperties.Count;
                    int i = 0;
                    foreach (var p in _options.RightProperties)
                    {
                        string pn = p;
                        if (!string.IsNullOrEmpty(_options.RightPrefix))
                            pn = _options.RightPrefix + pn;

                        if (i == rc - 1)
                            sql.Append("r." + pn + " FROM ");
                        else
                            sql.Append("r." + pn + ", ");
                        i++;
                    }
                    sql.Append(leftClassName + " l ");

                    switch (_options.JoinType)
                    {
                        case FdoJoinType.Inner:
                            sql.Append("INNER JOIN " + rightClassName + " r ON ");
                            break;
                        case FdoJoinType.Left:
                            sql.Append("LEFT OUTER JOIN " + rightClassName + " r ON ");
                            break;
                        default:
                            throw new FdoETLException("Unsupported join type: " + _options.JoinType);
                    }

                    rc = _options.JoinPairs.Count;
                    i = 0;
                    foreach (string l in _options.JoinPairs.Keys)
                    {
                        string r = _options.JoinPairs[l];

                        string left = l;
                        string right = r;

                        if (!string.IsNullOrEmpty(_options.LeftPrefix))
                            left = _options.LeftPrefix + left;

                        if (!string.IsNullOrEmpty(_options.RightPrefix))
                            right = _options.RightPrefix + right;

                        if (i == rc - 1)
                            sql.Append("l." + left + " = r." + right);
                        else
                            sql.Append("l." + left + " = r." + right + " AND ");

                        i++;
                    }
                    SendMessage("Executing SQL: " + sql.ToString());
                    svc.ExecuteSQLNonQuery(sql.ToString());
                }
            };
            Register(new FdoSingleActionOperation(createView));

            //Hack FDO metadata to make this a feature class
            if (!string.IsNullOrEmpty(_options.GeometryProperty))
            {
                ParameterlessAction reg = () =>
                {
                    using (var svc = tempConn.CreateFeatureService())
                    {
                        SendMessage("Exposing view as a FDO feature class");
                        string sql = "INSERT INTO geometry_columns(f_table_name, f_geometry_column, geometry_type, geometry_dettype, coord_dimension, srid, geometry_format) VALUES('" + srcClass + "','" + _options.GeometryProperty + "',15,7743,0,0,'FGF')";
                        SendMessage("Executing SQL: " + sql.ToString());
                        svc.ExecuteSQLNonQuery(sql);
                    }
                };
                Register(new FdoSingleActionOperation(reg));
            }

            //Copy view to target
            ParameterlessAction applyTarget = () =>
            {
                using (var svc = _options.Target.Connection.CreateFeatureService())
                {
                    SendMessage("Fetching target schema");
                    var schema = svc.GetSchemaByName(_options.Target.SchemaName);

                    IncompatibleClass cls;
                    if (!svc.CanApplyClass(mergedCls, out cls))
                    {
                        SendMessage("Fixing incompatibilities in merged class");
                        mergedCls = svc.AlterClassDefinition(mergedCls, cls);
                    }

                    SendMessage("Adding merged class to target schema");
                    schema.Classes.Add(mergedCls);
                    SendMessage("Applying modified target schema");
                    svc.ApplySchema(schema);
                }
            };
            Register(new FdoSingleActionOperation(applyTarget));

            var tempQuery = new FeatureQueryOptions("VIEW_INPUT");
            var targetMapping = new NameValueCollection();
            foreach(PropertyDefinition p in mergedCls.Properties)
            {
                tempQuery.AddFeatureProperty(p.Name);
                //Target class is a replica of the temp one, so all properties
                //have the same name in both source and target
                targetMapping[p.Name] = p.Name;
            }

            ParameterlessAction copyToTarget = () =>
            {
                var copy = ExpressUtility.CreateBulkCopy(
                    tempConn,
                    _options.Target.Connection,
                    tempSchema.Name,
                    tempQuery,
                    _options.Target.SchemaName,
                    _options.Target.ClassName,
                    targetMapping);

                copy.ProcessMessage += delegate(object sender, MessageEventArgs e)
                {
                    SendMessage(e.Message);
                };
                copy.Execute();
                copyTargetErrors.AddRange(copy.GetAllErrors());
                sw.Stop();
            };
            Register(new FdoSingleActionOperation(copyToTarget));

            //Log all errors
            ParameterlessAction logErrors = () =>
            {
                SendMessage(copyLeftErrors.Count + " errors encountered copying left source to temp db");
                _allErrors.AddRange(copyLeftErrors);
                SendMessage(copyRightErrors.Count + " errors encountered copying right source to temp db");
                _allErrors.AddRange(copyRightErrors);
                SendMessage(copyTargetErrors.Count + " errors encountered copying merged source to target");
                _allErrors.AddRange(copyTargetErrors);
                SendMessage("Join Operation completed in " + sw.Elapsed.ToString());
            };
            Register(new FdoSingleActionOperation(logErrors));
        }
コード例 #42
0
ファイル: ExpressUtility.cs プロジェクト: stophun/fdotoolbox
        /// <summary>
        /// Utility method to create a feature class dump bulk copy
        /// </summary>
        /// <param name="source"></param>
        /// <param name="schemaName"></param>
        /// <param name="className"></param>
        /// <param name="provider"></param>
        /// <param name="savePath"></param>
        /// <returns></returns>
        public static FdoBulkCopy CreateBulkCopy(FdoConnection source, string schemaName, string className, string provider, string savePath)
        {
            if (!ExpressUtility.CreateFlatFileDataSource(provider, savePath))
                throw new FdoException("Could not create " + savePath);

            ClassDefinition srcClass = null;
            using (var svc = source.CreateFeatureService())
            {
                srcClass = svc.GetClassByName(schemaName, className);
            }

            //Apply a copy of the source class to target
            ClassDefinition clone = FdoSchemaUtil.CloneClass(srcClass, true);
            FeatureSchema fs = null;

            FdoConnection target = ExpressUtility.CreateFlatFileConnection(provider, savePath);
            using (var svc = target.CreateFeatureService())
            {
                var schemas = svc.DescribeSchema();
                if (schemas != null && schemas.Count == 1)
                    fs = schemas[0];

                if (fs == null)
                    fs = new FeatureSchema("Default", "");

                var classes = fs.Classes;
                classes.Add(clone);

                svc.ApplySchema(fs, null, true);
            }

            //Setup mappings
            var mappings = new NameValueCollection();
            foreach (PropertyDefinition prop in srcClass.Properties)
            {
                if (prop.PropertyType == PropertyType.PropertyType_DataProperty ||
                    prop.PropertyType == PropertyType.PropertyType_GeometricProperty)
                {
                    mappings.Add(prop.Name, prop.Name);
                }
            }

            //Compile query
            var query = new FeatureQueryOptions(className);

            var bcp = CreateBulkCopy(source, target, schemaName, query, fs.Name, clone.Name, mappings);

            //The target connection needs to be cleaned up when done
            bcp.Options.MarkOwnerOfConnection("TARGET");

            return bcp;
        }
コード例 #43
0
        void RunExport(string fileName)
        {
            CadastralMapModel mapModel = CadastralMapModel.Current;

            using (ICreateDataStore cmd = m_Connection.CreateCommand(CommandType.CommandType_CreateDataStore) as ICreateDataStore)
            {
                try
                {
                    cmd.DataStoreProperties.SetProperty("File", fileName);
                    cmd.Execute();
                }
                catch (OSGeo.FDO.Common.Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // The connection after the created is ConnectionState_Closed, so open it!
            m_Connection.ConnectionInfo.ConnectionProperties.SetProperty("File", fileName);
            m_Connection.Open();

            // Define coordinate system
            using (ICreateSpatialContext cmd = m_Connection.CreateCommand(CommandType.CommandType_CreateSpatialContext) as ICreateSpatialContext)
            {
                ISpatialSystem ss = mapModel.SpatialSystem;
                cmd.CoordinateSystem = ss.Name; // CSMap key name
                cmd.ExtentType = SpatialContextExtentType.SpatialContextExtentType_Static;
                IWindow mapExtent = mapModel.Extent;
                IDirectPosition minxy = m_Factory.CreatePositionXY(mapExtent.Min.X, mapExtent.Min.Y);
                IDirectPosition maxxy = m_Factory.CreatePositionXY(mapExtent.Max.X, mapExtent.Max.Y);
                IEnvelope extent = m_Factory.CreateEnvelope(minxy, maxxy);
                IGeometry gx = m_Factory.CreateGeometry(extent);
                cmd.Extent = m_Factory.GetFgf(gx);
                cmd.XYTolerance = 0.000001; // resolution?
                cmd.CoordinateSystemWkt = EditingController.Current.GetCoordinateSystemText();
                cmd.Execute();
            }

            // Define feature schema
            FeatureSchema fs = new FeatureSchema("Steve", "This is a test");

            FeatureClass fc = new FeatureClass("FC", "Test feature class");
            fs.Classes.Add(fc);
            GeometricPropertyDefinition gp = new GeometricPropertyDefinition("Geometry", "Polygon property");

            // When you stick more than one geometric type into the output, you can't
            // convert to SHP (not with FDO Toolbox anyway).
            //gp.GeometryTypes = (int)GeometricType.GeometricType_Surface;
            gp.GeometryTypes = (int)GeometricType.GeometricType_All;
            fc.Properties.Add(gp);
            fc.GeometryProperty = gp;

            // c.f. FdoToolbox ExpressUtility
            DataPropertyDefinition dp = new DataPropertyDefinition("ID", "Test ID");
            dp.DataType = DataType.DataType_Int32;
            dp.Nullable = false;
            dp.ReadOnly = true;
            dp.IsAutoGenerated = true;
            fc.Properties.Add(dp);

            // Feature class requires an identity column for the insert
            fc.IdentityProperties.Add(dp);

            using (IApplySchema cmd = m_Connection.CreateCommand(CommandType.CommandType_ApplySchema) as IApplySchema)
            {
                cmd.FeatureSchema = fs;
                cmd.Execute();
            }

            mapModel.Index.QueryWindow(null, SpatialType.Polygon | SpatialType.Point, ExportFeature);

            m_Connection.Flush();
            m_Connection.Close();
        }
コード例 #44
0
ファイル: FdoSchemaUtil.cs プロジェクト: stophun/fdotoolbox
        /// <summary>
        /// Utility method to clone a feature schema
        /// </summary>
        /// <param name="fs"></param>
        /// <param name="ignoreDeleted"></param>
        /// <returns></returns>
        public static FeatureSchema CloneSchema(FeatureSchema fs, bool ignoreDeleted)
        {
            if (fs == null)
                throw new ArgumentNullException("fs");

            /*
             * This method is BIG. So it needs some explanation.
             * 
             * Because Association and Object Properties reference other classes, the classes
             * containing such properties are processed *last*. Everything else is assumed to
             * be cloned (without problems) and cached in a temp dictionary for processing these
             * classes w/ Association/Object properties.
             * 
             * When processing these remaining classes, we iteratively attempt to clone each class.
             * Each successfully cloned class will be added to the temp dictionary. Eventually all
             * references will be satisfied, that's when we can finally return the cloned schema.
             */

            Dictionary<string, ClassDefinition> cloned = new Dictionary<string,ClassDefinition>();
            List<ClassDefinition> classesWithReferences = new List<ClassDefinition>();
            
            FeatureSchema fsc = new FeatureSchema(fs.Name, fs.Description);
            CopyElementAttributes(fs.Attributes, fsc.Attributes);

            if (ignoreDeleted)
            {
                foreach (ClassDefinition cls in fs.Classes)
                {
                    if (cls.ElementState != SchemaElementState.SchemaElementState_Deleted)
                    {
                        ICollection<string> refs = GetReferencedClasses(cls);
                        if (refs.Count == 0)
                        {
                            var klass = CloneClass(cls, ignoreDeleted);
                            fsc.Classes.Add(klass);
                            cloned.Add(klass.QualifiedName, klass);
                        }
                        else
                        {
                            //Check for self-references
                            classesWithReferences.Add(cls);
                        }
                    }
                }
            }
            else
            {
                foreach (ClassDefinition cls in fs.Classes)
                {
                    ICollection<string> refs = GetReferencedClasses(cls);
                    if (refs.Count == 0)
                    {
                        var klass = CloneClass(cls, ignoreDeleted);
                        fsc.Classes.Add(klass);
                        cloned.Add(klass.QualifiedName, klass);
                    }
                    else
                    {
                        //Check for self-references
                        classesWithReferences.Add(cls);
                    }
                }
            }

            //TODO: Does the FDO spec allow self-referenced Association/Object
            //properties? If not, it would simplify this code greatly.

            //Repeat until all references satisfied
            while (classesWithReferences.Count > 0)
            {
                List<ClassDefinition> successfullyCloned = new List<ClassDefinition>();
                foreach (ClassDefinition cls in classesWithReferences)
                {
                    bool bSuccess = false;

                    ClassDefinition klass = null;
                    switch (cls.ClassType)
                    {
                        case ClassType.ClassType_Class:
                            klass = new Class(cls.Name, cls.Description);
                            break;
                        case ClassType.ClassType_FeatureClass:
                            klass = new FeatureClass(cls.Name, cls.Description);
                            break;
                    }

                    Dictionary<AssociationPropertyDefinition, AssociationPropertyDefinition> processAp = new Dictionary<AssociationPropertyDefinition, AssociationPropertyDefinition>();
                    Dictionary<ObjectPropertyDefinition, ObjectPropertyDefinition> processOp = new Dictionary<ObjectPropertyDefinition, ObjectPropertyDefinition>();
                    var props = cls.Properties;
                    for (int i = 0; i < props.Count; i++)
                    {
                        var prop = props[i];
                        if (prop.PropertyType == PropertyType.PropertyType_AssociationProperty)
                        {
                            var ap = (AssociationPropertyDefinition)prop;
                            var apClone = new AssociationPropertyDefinition(ap.Name, ap.Description);

                            ClassDefinition associatedClass = null;
                            associatedClass = cloned[ap.AssociatedClass.QualifiedName];
                            if (associatedClass == null)
                            { 
                                //could be a self-reference
                                if (klass.Name.Equals(ap.AssociatedClass.Name))
                                    associatedClass = klass;
                            }

                            if (associatedClass != null)
                            {
                                apClone.AssociatedClass = associatedClass;
                                apClone.DeleteRule = ap.DeleteRule;
                                //Process identity properties. Shelve for later processing if
                                //any property can't be found
                                var idProps = ap.IdentityProperties;
                                bool foundAll = true;
                                foreach (DataPropertyDefinition dp in idProps)
                                {
                                    if (!props.Contains(dp))
                                        foundAll = false;
                                }
                                if (foundAll)
                                {
                                    foreach (DataPropertyDefinition dp in idProps)
                                    {
                                        apClone.IdentityProperties.Add((DataPropertyDefinition)props[dp.Name]);
                                    }
                                }
                                else
                                {
                                    processAp.Add(apClone, ap);
                                }

                                apClone.LockCascade = ap.LockCascade;
                                apClone.Multiplicity = ap.Multiplicity;
                                //Process reverse identity properties. Shelve for later processing if
                                //any property can't be found
                                var ridProps = ap.ReverseIdentityProperties;
                                foundAll = true;
                                foreach (DataPropertyDefinition dp in ridProps)
                                {
                                    if (!props.Contains(dp))
                                        foundAll = false;
                                }
                                if (foundAll)
                                {
                                    foreach (DataPropertyDefinition dp in ridProps)
                                    {
                                        apClone.ReverseIdentityProperties.Add((DataPropertyDefinition)apClone.AssociatedClass.Properties[dp.Name]);
                                    }
                                }
                                else
                                {
                                    processAp.Add(apClone, ap);
                                }

                                apClone.ReverseMultiplicity = ap.ReverseMultiplicity;
                                apClone.ReverseName = ap.ReverseName;

                                klass.Properties.Add(apClone);
                            }
                            else 
                            {
                                break;
                            }
                        }
                        else if (prop.PropertyType == PropertyType.PropertyType_ObjectProperty)
                        {
                            var op = (ObjectPropertyDefinition)prop;
                            var opClone = new ObjectPropertyDefinition(op.Name, op.Description);

                            if (cloned.ContainsKey(op.Class.QualifiedName))
                            {
                                ClassDefinition associatedClass = cloned[op.Class.QualifiedName];
                                opClone.Class = associatedClass;
                                //Process identity property. Shelve for later processing if none found
                                if (props.Contains(op.IdentityProperty.Name))
                                {
                                    opClone.IdentityProperty = (DataPropertyDefinition)op.Class.Properties[op.IdentityProperty.Name];
                                }
                                else
                                {
                                    processOp.Add(opClone, op);
                                }
                                opClone.ObjectType = op.ObjectType;
                                opClone.OrderType = op.OrderType;
                                klass.Properties.Add(opClone);
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            bool identity = false;
                            bool geometry = false;
                            var dp = prop as DataPropertyDefinition;
                            var gp = prop as GeometricPropertyDefinition;
                            identity = (dp != null && cls.IdentityProperties.Contains(dp));
                            geometry = (gp != null && cls.ClassType == ClassType.ClassType_FeatureClass && ((FeatureClass)cls).GeometryProperty == gp);

                            //Clone property and add to cloned class
                            var cp = CloneProperty(prop);
                            klass.Properties.Add(cp);
                            if (identity)
                            {
                                Debug.Assert(cp.PropertyType == PropertyType.PropertyType_DataProperty);
                                klass.IdentityProperties.Add((DataPropertyDefinition)cp);
                            }
                            if (geometry)
                            {
                                Debug.Assert(cp.PropertyType == PropertyType.PropertyType_GeometricProperty);
                                Debug.Assert(klass.ClassType == ClassType.ClassType_FeatureClass);
                                ((FeatureClass)klass).GeometryProperty = (GeometricPropertyDefinition)cp;
                            }
                        }
                    }

                    if (processAp.Count > 0)
                    {
                        foreach (AssociationPropertyDefinition apClone in processAp.Keys)
                        {
                            var ap = processAp[apClone];
                            //Retry identity properties
                            apClone.IdentityProperties.Clear();
                            var idProps = ap.IdentityProperties;
                            foreach (DataPropertyDefinition dp in idProps)
                            {
                                apClone.IdentityProperties.Add((DataPropertyDefinition)props[dp.Name]);
                            }
                            //Retry reverse identity properties
                            apClone.ReverseIdentityProperties.Clear();
                            var ridProps = ap.ReverseIdentityProperties;
                            foreach (DataPropertyDefinition dp in ridProps)
                            {
                                apClone.ReverseIdentityProperties.Add((DataPropertyDefinition)apClone.AssociatedClass.Properties[dp.Name]);
                            }
                        }
                    }

                    if (processOp.Count > 0)
                    {
                        foreach (ObjectPropertyDefinition opClone in processOp.Keys)
                        {
                            var op = processOp[opClone];
                            //Retry identity property
                            opClone.IdentityProperty = (DataPropertyDefinition)op.Class.Properties[op.IdentityProperty.Name];
                        }
                    }

                    //All properties accounted for
                    if (klass.Properties.Count == cls.Properties.Count &&
                        klass.IdentityProperties.Count == cls.IdentityProperties.Count)
                    {
                        bSuccess = true;
                    }

                    if (bSuccess)
                    {
                        fsc.Classes.Add(klass);
                        successfullyCloned.Add(cls);
                    }
                }

                //Purge successfully cloned entries
                foreach (ClassDefinition cls in successfullyCloned)
                {
                    int ridx = classesWithReferences.IndexOf(cls);
                    if (ridx >= 0)
                        classesWithReferences.RemoveAt(ridx);
                }
            }

            return fsc;
        }
コード例 #45
0
ファイル: FdoSchemaView.cs プロジェクト: stophun/fdotoolbox
            void OnSchemaAdded(FeatureSchema item)
            {
                var node = CreateSchemaNode(item);
                _view.schemaTree.Nodes.Add(node);

                foreach (ClassDefinition cd in item.Classes)
                {
                    OnClassAdded(cd);
                }

                _view.EvaluateStates();
                _view.FlagUpdateState();
            }
コード例 #46
0
        void GetClassNodesFull(FeatureSchema schema, TreeNode schemaNode)
        {
            //Pre-sort
            SortedList<string, ClassDefinition> sorted = new SortedList<string, ClassDefinition>();
            foreach (ClassDefinition classDef in schema.Classes)
                sorted.Add(classDef.Name, classDef);

            foreach (ClassDefinition classDef in sorted.Values)
            {
                TreeNode classNode = CreateClassNode(classDef);
                schemaNode.Nodes.Add(classNode);
            }
        }
コード例 #47
0
        public void TestAlterSchemaPassValueConstraints()
        {
            MockRepository mocks = new MockRepository();
            IConnection conn = mocks.DynamicMock<IConnection>();
            ISchemaCapabilities caps = mocks.DynamicMock<ISchemaCapabilities>();

            using (mocks.Record())
            {
                SetupResult.For(conn.ConnectionState).Return(ConnectionState.ConnectionState_Open);
                SetupResult.For(conn.SchemaCapabilities).Return(caps);
                SetupResult.For(caps.ClassTypes).Return((ClassType[])Enum.GetValues(typeof(ClassType)));
                SetupResult.For(caps.DataTypes).Return((DataType[])Enum.GetValues(typeof(DataType)));
                SetupResult.For(caps.MaximumDecimalPrecision).Return(20);
                SetupResult.For(caps.MaximumDecimalScale).Return(20);
                SetupResult.For(caps.ReservedCharactersForName).Return(string.Empty);
                SetupResult.For(caps.SupportedAutoGeneratedTypes).Return(new DataType[] { DataType.DataType_Int64 });
                SetupResult.For(caps.SupportedIdentityPropertyTypes).Return(new DataType[] { DataType.DataType_Int32, DataType.DataType_Int64 });
                SetupResult.For(caps.SupportsAssociationProperties).Return(false);
                SetupResult.For(caps.SupportsAutoIdGeneration).Return(true);
                SetupResult.For(caps.SupportsCompositeId).Return(false);
                SetupResult.For(caps.SupportsCompositeUniqueValueConstraints).Return(false);
                SetupResult.For(caps.SupportsDataStoreScopeUniqueIdGeneration).Return(false);
                SetupResult.For(caps.SupportsDefaultValue).Return(true);
                //--
                SetupResult.For(caps.SupportsExclusiveValueRangeConstraints).Return(false);
                SetupResult.For(caps.SupportsInclusiveValueRangeConstraints).Return(false);
                //--
                SetupResult.For(caps.SupportsMultipleSchemas).Return(false);
                SetupResult.For(caps.SupportsNetworkModel).Return(false);
                SetupResult.For(caps.SupportsNullValueConstraints).Return(true);
                SetupResult.For(caps.SupportsObjectProperties).Return(false);
                SetupResult.For(caps.SupportsSchemaModification).Return(true);
                SetupResult.For(caps.SupportsSchemaOverrides).Return(false);
                SetupResult.For(caps.SupportsUniqueValueConstraints).Return(false);
                //--
                SetupResult.For(caps.SupportsValueConstraintsList).Return(false);
                //--
                SetupResult.For(caps.SupportsInheritance).Return(false);
            }
            FdoFeatureService service = mocks.StrictMock<FdoFeatureService>(conn);
            mocks.ReplayAll();

            FeatureSchema schema = new FeatureSchema("Default", "");

            ClassDefinition cls = new Class("Test", "");

            //ID
            DataPropertyDefinition id = new DataPropertyDefinition("ID", "");
            id.DataType = DataType.DataType_Int64;
            id.IsAutoGenerated = true; //Should be converted to int64
            id.ReadOnly = true;
            id.Nullable = false;

            cls.Properties.Add(id);
            cls.IdentityProperties.Add(id);

            //Age
            DataPropertyDefinition age = new DataPropertyDefinition("Age", "");
            PropertyValueConstraintRange range = new PropertyValueConstraintRange();
            range.MinValue = new Int32Value(0);
            range.MinInclusive = true;
            range.MaxValue = new Int32Value(100);
            range.MaxInclusive = true;
            age.ValueConstraint = range;
            age.DataType = DataType.DataType_Int32;
            age.Nullable = true;

            cls.Properties.Add(age);

            //Gender
            DataPropertyDefinition gender = new DataPropertyDefinition("Gender", "");
            PropertyValueConstraintList list = new PropertyValueConstraintList();
            list.ConstraintList.Add(new StringValue("M"));
            list.ConstraintList.Add(new StringValue("F"));
            gender.ValueConstraint = list;
            age.DataType = DataType.DataType_String;
            age.Nullable = false;
            age.Length = 1;

            cls.Properties.Add(gender);

            schema.Classes.Add(cls);

            IncompatibleSchema incSchema = null;
            bool canApply = service.CanApplySchema(schema, out incSchema);
            Assert.IsFalse(canApply);
            Assert.IsNotNull(incSchema);

            FeatureSchema newSchema = service.AlterSchema(schema, incSchema);

            ClassDefinition newClass = newSchema.Classes[0];

            DataPropertyDefinition age2 = newClass.Properties[newClass.Properties.IndexOf("Age")] as DataPropertyDefinition;

            //Should have constraint removed
            Assert.IsNull(age2.ValueConstraint);

            DataPropertyDefinition gender2 = newClass.Properties[newClass.Properties.IndexOf("Gender")] as DataPropertyDefinition;
            //Should have constraint removed
            Assert.IsNull(gender2.ValueConstraint);
        }
コード例 #48
0
        public void TestSchemaCannotBeApplied()
        {
            FeatureSchema schema = new FeatureSchema("Default", "");
            FeatureClass fc = new FeatureClass("Class1", "");

            DataPropertyDefinition id = new DataPropertyDefinition("ID", "");
            id.DataType = DataType.DataType_Int32;
            id.IsAutoGenerated = true;

            fc.Properties.Add(id);
            fc.IdentityProperties.Add(id);

            //Unsupported property in SHP
            DataPropertyDefinition d1 = new DataPropertyDefinition("Unsupported", "");
            d1.DataType = DataType.DataType_Int64;
            d1.Nullable = true;

            fc.Properties.Add(d1);

            GeometricPropertyDefinition geom = new GeometricPropertyDefinition("Geometry", "");
            geom.GeometryTypes = (int)GeometryType.GeometryType_Point;

            fc.Properties.Add(geom);
            schema.Classes.Add(fc);

            /*
            IConnection conn = FeatureAccessManager.GetConnectionManager().CreateConnection("OSGeo.SHP");
            conn.ConnectionString = "DefaultFileLocation=" + AppGateway.RunningApplication.AppPath;
            using (conn)
            {
                conn.Open();
                using (FeatureService service = new FeatureService(conn))
                {
                    IncompatibleSchema incSchema = null;
                    bool result = service.CanApplySchema(schema, out incSchema);
                    Assert.IsNotNull(incSchema);
                    Assert.IsFalse(result);

                    foreach (IncompatibleClass incClass in incSchema.Classes)
                    {
                        foreach (IncompatibleProperty incProp in incClass.Properties)
                        {
                            Assert.AreEqual(incProp.Reasons.Count, incProp.ReasonCodes.Count);
                        }
                    }
                }
                conn.Close();
            }*/
        }
コード例 #49
0
        public void TestAlterSchemaPassIdentityType()
        {
            MockRepository mocks = new MockRepository();
            IConnection conn = mocks.DynamicMock<IConnection>();
            ISchemaCapabilities caps = mocks.DynamicMock<ISchemaCapabilities>();

            using (mocks.Record())
            {
                SetupResult.For(conn.ConnectionState).Return(ConnectionState.ConnectionState_Open);
                SetupResult.For(conn.SchemaCapabilities).Return(caps);
                SetupResult.For(caps.ClassTypes).Return((ClassType[])Enum.GetValues(typeof(ClassType)));
                SetupResult.For(caps.DataTypes).Return((DataType[])Enum.GetValues(typeof(DataType)));
                SetupResult.For(caps.MaximumDecimalPrecision).Return(20);
                SetupResult.For(caps.MaximumDecimalScale).Return(20);
                SetupResult.For(caps.ReservedCharactersForName).Return(string.Empty);
                SetupResult.For(caps.SupportedAutoGeneratedTypes).Return(new DataType[] { DataType.DataType_Int64 });
                //--
                SetupResult.For(caps.SupportedIdentityPropertyTypes).Return(new DataType[] { DataType.DataType_Int32, DataType.DataType_Int64, DataType.DataType_String });
                //--
                SetupResult.For(caps.SupportsAssociationProperties).Return(false);
                SetupResult.For(caps.SupportsAutoIdGeneration).Return(true);
                SetupResult.For(caps.SupportsCompositeId).Return(false);
                SetupResult.For(caps.SupportsCompositeUniqueValueConstraints).Return(false);
                SetupResult.For(caps.SupportsDataStoreScopeUniqueIdGeneration).Return(false);
                SetupResult.For(caps.SupportsDefaultValue).Return(true);
                SetupResult.For(caps.SupportsExclusiveValueRangeConstraints).Return(false);
                SetupResult.For(caps.SupportsInclusiveValueRangeConstraints).Return(false);
                SetupResult.For(caps.SupportsMultipleSchemas).Return(false);
                SetupResult.For(caps.SupportsNetworkModel).Return(false);
                SetupResult.For(caps.SupportsNullValueConstraints).Return(true);
                SetupResult.For(caps.SupportsObjectProperties).Return(false);
                SetupResult.For(caps.SupportsSchemaModification).Return(true);
                SetupResult.For(caps.SupportsSchemaOverrides).Return(false);
                SetupResult.For(caps.SupportsUniqueValueConstraints).Return(false);
                SetupResult.For(caps.SupportsValueConstraintsList).Return(false);

                SetupResult.For(caps.SupportsInheritance).Return(false);
            }
            FdoFeatureService service = mocks.StrictMock<FdoFeatureService>(conn);
            mocks.ReplayAll();

            FeatureSchema schema = new FeatureSchema("Default", "");

            ClassDefinition cls = new Class("Test", "");

            //ID - float
            DataPropertyDefinition id = new DataPropertyDefinition("ID", "");
            id.DataType = DataType.DataType_Single;
            id.Nullable = false;

            cls.Properties.Add(id);
            cls.IdentityProperties.Add(id);

            //Name
            DataPropertyDefinition name = new DataPropertyDefinition("Name", "");
            name.DataType = DataType.DataType_String;
            name.Nullable = true;
            name.Length = 100;

            cls.Properties.Add(name);

            schema.Classes.Add(cls);

            IncompatibleSchema incSchema = null;
            bool canApply = service.CanApplySchema(schema, out incSchema);
            Assert.IsFalse(canApply);
            Assert.IsNotNull(incSchema);

            FeatureSchema newSchema = service.AlterSchema(schema, incSchema);

            ClassDefinition newClass = newSchema.Classes[0];

            //Should have been "promoted" to string
            Assert.AreEqual(DataType.DataType_String, newClass.IdentityProperties[0].DataType);
        }
コード例 #50
0
        public void TestSchemaCanBeApplied()
        {
            FeatureSchema schema = new FeatureSchema("Default", "");
            FeatureClass fc = new FeatureClass("Class1", "");

            DataPropertyDefinition id = new DataPropertyDefinition("ID", "");
            id.DataType = DataType.DataType_Int32;
            id.IsAutoGenerated = true;

            fc.Properties.Add(id);
            fc.IdentityProperties.Add(id);

            GeometricPropertyDefinition geom = new GeometricPropertyDefinition("Geometry", "");
            geom.GeometryTypes = (int)GeometryType.GeometryType_Point;

            fc.Properties.Add(geom);
            schema.Classes.Add(fc);

            /*
            IConnection conn = FeatureAccessManager.GetConnectionManager().CreateConnection("OSGeo.SHP");
            conn.ConnectionString = "DefaultFileLocation=" + AppGateway.RunningApplication.AppPath;
            using (conn)
            {
                conn.Open();
                using (FeatureService service = new FeatureService(conn))
                {
                    IncompatibleSchema incSchema = null;
                    bool result = service.CanApplySchema(schema, out incSchema);
                    Assert.IsNull(incSchema);
                    Assert.IsTrue(result);
                }
                conn.Close();
            }*/
        }
コード例 #51
0
 public FdoApplySchemaOperation(FdoConnection conn, FeatureSchema schema)
 {
     _conn = conn;
     _schema = schema;
 }
コード例 #52
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        protected override void Initialize()
        {
            SendMessage("Creating target data source");
            if (!ExpressUtility.CreateFlatFileDataSource(_outputFile))
                throw new FdoETLException(ResourceUtil.GetStringFormatted("ERR_CANNOT_CREATE_DATA_FILE", _outputFile));

            _outConn = ExpressUtility.CreateFlatFileConnection(_outputFile);
            _outConn.Open();

            ClassDefinition cd = _table.CreateClassDefinition(true);

            using (FdoFeatureService service = _outConn.CreateFeatureService())
            {
                SendMessage("Applying schema to target");
                FeatureSchema schema = new FeatureSchema("Schema1", "Default schema");
                schema.Classes.Add(cd);
                service.ApplySchema(schema);
            }

            SendMessage("Copying any attached spatial contexts");
            ExpressUtility.CopyAllSpatialContexts(_table.SpatialContexts, _outConn, true);

            Register(new FdoFeatureTableInputOperation(_table));
            Register(new FdoOutputOperation(_outConn, cd.Name));
        }