Esempio n. 1
0
        private bool ExportToFile(string provider, string file, int maxSchemas, int maxSpatialContexts)
        {
            var conf = _context.GetConfiguration();

            if (maxSchemas > 0 && conf.Schemas.Count > maxSchemas)
            {
                ShowError("This provider only allows " + maxSchemas + " feature schema(s)");
                return(false);
            }
            if (maxSpatialContexts > 0 && conf.SpatialContexts.Length > maxSpatialContexts)
            {
                ShowError("This provider only allows " + maxSpatialContexts + " spatial context(s)");
                return(false);
            }

            if (ExpressUtility.CreateFlatFileDataSource(provider, file))
            {
                var conn   = ExpressUtility.CreateFlatFileConnection(provider, file);
                var schema = conf.Schemas[0];
                schema = FdoSchemaUtil.CloneSchema(schema, true);
                using (var svc = conn.CreateFeatureService())
                {
                    IncompatibleSchema incs;
                    if (!svc.CanApplySchema(schema, out incs))
                    {
                        string msg = "This schema has incompatibilities. Attempt to fix it? " + incs.ToString();
                        if (!WrappedMessageBox.Confirm("Incompatible schema", msg, MessageBoxText.YesNo))
                        {
                            return(false);
                        }
                        schema = svc.AlterSchema(schema, incs);
                    }

                    using (var cur = new TempCursor(Cursors.WaitCursor))
                    {
                        foreach (var sc in conf.SpatialContexts)
                        {
                            svc.CreateSpatialContext(sc, true);
                        }

                        //Only for SQLite, but this is general enough
                        var fscs = svc.DescribeSchema();
                        if (fscs.Count == 1)
                        {
                            var fsc = fscs[0];
                            foreach (ClassDefinition cls in schema.Classes)
                            {
                                var klass = FdoSchemaUtil.CloneClass(cls);
                                fsc.Classes.Add(klass);
                            }
                            schema = fsc;
                        }
                        svc.ApplySchema(schema);
                    }
                }
                conn.Close();
            }
            return(true);
        }
Esempio n. 2
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);
        }
 public PartialSchemaSaveDialog(FeatureSchema schema)
     : this()
 {
     _schema = FdoSchemaUtil.CloneSchema(schema); //Operate on a clone
     InitTree();
 }