예제 #1
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);
            //        }
            //    }
            //}
        }
예제 #2
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);
        }
예제 #3
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;
        }
예제 #4
0
        /// <summary>
        /// Validates these options
        /// </summary>
        public void Validate()
        {
            if (_Left == null)
            {
                throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_LEFT_UNDEFINED"));
            }

            if (_Right == null)
            {
                throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_RIGHT_UNDEFINED"));
            }

            if (_Target == null)
            {
                throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_TARGET_UNDEFINED"));
            }

            if (string.IsNullOrEmpty(_Target.ClassName))
            {
                throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_TARGET_CLASS_UNDEFINED"));
            }

            if (this.JoinPairs.Count == 0)
            {
                throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_KEYS_UNDEFINED"));
            }

            int count = this.LeftProperties.Count + this.RightProperties.Count;

            if (string.IsNullOrEmpty(_LeftPrefix) && string.IsNullOrEmpty(_RightPrefix))
            {
                ISet <string> set = new HashSet <string>();
                foreach (var prop in this.LeftProperties)
                {
                    set.Add(prop);
                }
                foreach (var prop in this.RightProperties)
                {
                    set.Add(prop);
                }

                //If all properties are unique then the counts should be the same
                if (set.Count < count)
                {
                    throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_PROPERTY_NAME_COLLISION"));
                }
            }

            //Verify left source filter checks out
            if (!string.IsNullOrEmpty(this.LeftFilter))
            {
                try
                {
                    using (var filter = Filter.Parse(this.LeftFilter)) { }
                }
                catch
                {
                    throw new TaskValidationException(ResourceUtil.GetStringFormatted("ERR_INVALID_LEFT_FILTER", this.LeftFilter));
                }
            }

            //Verify right source filter checks out
            if (!string.IsNullOrEmpty(this.RightFilter))
            {
                try
                {
                    using (var filter = Filter.Parse(this.RightFilter)) { }
                }
                catch
                {
                    throw new TaskValidationException(ResourceUtil.GetStringFormatted("ERR_INVALID_RIGHT_FILTER", this.LeftFilter));
                }
            }

            //Create target class. The schema must already exist, but the class must *not* already exist.
            using (FdoFeatureService service = this.Target.Connection.CreateFeatureService())
            {
                if (!service.SupportsCommand(OSGeo.FDO.Commands.CommandType.CommandType_ApplySchema))
                {
                    throw new TaskValidationException(ResourceUtil.GetStringFormatted("ERR_UNSUPPORTED_CMD", OSGeo.FDO.Commands.CommandType.CommandType_ApplySchema));
                }

                //Get target schema
                FeatureSchema schema = service.GetSchemaByName(this.Target.SchemaName);
                if (schema == null)
                {
                    throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_SCHEMA_NOT_FOUND"));
                }

                //Check target class does not exist
                int cidx = schema.Classes.IndexOf(this.Target.ClassName);
                if (cidx >= 0)
                {
                    throw new TaskValidationException(ResourceUtil.GetString("ERR_JOIN_TARGET_EXISTS"));
                }
            }
        }
예제 #5
0
        public override int Execute()
        {
            CommandStatus retCode;

            FdoConnection srcConn  = new FdoConnection(_srcProvider, _srcConnStr);
            FdoConnection destConn = null;

            //Directory given, assume SHP
            if (Directory.Exists(_destPath))
            {
                destConn = new FdoConnection("OSGeo.SHP", "DefaultFileLocation=" + _destPath);
            }
            else
            {
                if (ExpressUtility.CreateFlatFileDataSource(_destPath))
                {
                    destConn = ExpressUtility.CreateFlatFileConnection(_destPath);
                }
                else
                {
                    throw new FdoException("Could not create data source: " + _destPath);
                }
            }

            try
            {
                srcConn.Open();
                destConn.Open();

                string srcName = "SOURCE";
                string dstName = "TARGET";

                FdoBulkCopyOptions options = new FdoBulkCopyOptions();
                options.RegisterConnection(srcName, srcConn);
                options.RegisterConnection(dstName, destConn);
                using (FdoFeatureService srcService = srcConn.CreateFeatureService())
                    using (FdoFeatureService destService = destConn.CreateFeatureService())
                    {
                        //See if spatial context needs to be copied to target
                        if (!string.IsNullOrEmpty(_srcSpatialContext))
                        {
                            SpatialContextInfo srcCtx = srcService.GetSpatialContext(_srcSpatialContext);
                            if (srcCtx != null)
                            {
                                Console.WriteLine("Copying spatial context: " + srcCtx.Name);
                                ExpressUtility.CopyAllSpatialContexts(new SpatialContextInfo[] { srcCtx }, destConn, true);
                            }
                        }
                        else
                        {
                            //Copy all
                            ExpressUtility.CopyAllSpatialContexts(srcConn, destConn, true);
                        }

                        FeatureSchema srcSchema = null;
                        //See if partial class list is needed
                        if (_srcClasses.Count > 0)
                        {
                            WriteLine("Checking if partial schema discovery is supported: " + srcService.SupportsPartialSchemaDiscovery());

                            srcSchema = srcService.PartialDescribeSchema(_srcSchema, _srcClasses);
                        }
                        else //Full copy
                        {
                            WriteLine("No classes specified, reading full source schema");
                            srcSchema = srcService.GetSchemaByName(_srcSchema);
                        }

                        if (srcSchema == null)
                        {
                            WriteError("Could not find source schema: " + _srcSchema);
                            retCode = CommandStatus.E_FAIL_SCHEMA_NOT_FOUND;
                        }
                        else
                        {
                            WriteLine("Checking source schema for incompatibilities");
                            FeatureSchema      targetSchema = null;
                            IncompatibleSchema incSchema;
                            if (destService.CanApplySchema(srcSchema, out incSchema))
                            {
                                int clsCount = srcSchema.Classes.Count;
                                WriteLine("Applying source schema (containing " + clsCount + " classes) to target");
                                destService.ApplySchema(srcSchema, null, true);
                                targetSchema = srcSchema;
                            }
                            else
                            {
                                WriteWarning("Incompatibilities were detected in source schema. Applying a modified version to target");
                                FeatureSchema fixedSchema = destService.AlterSchema(srcSchema, incSchema);
                                int           clsCount    = fixedSchema.Classes.Count;
                                WriteLine("Applying modified source schema (containing " + clsCount + " classes) to target");
                                destService.ApplySchema(fixedSchema, null, true);
                                targetSchema = fixedSchema;
                            }

                            //Now set class copy options
                            foreach (ClassDefinition cd in srcSchema.Classes)
                            {
                                FdoClassCopyOptions copt = new FdoClassCopyOptions(srcName, dstName, srcSchema.Name, cd.Name, targetSchema.Name, cd.Name);
                                copt.FlattenGeometries = _flatten;
                                options.AddClassCopyOption(copt);
                            }

                            if (_flatten)
                            {
                                WriteWarning("The switch -flatten has been defined. Geometries that are copied will have any Z or M coordinates removed");
                            }

                            FdoBulkCopy copy = new FdoBulkCopy(options);
                            copy.ProcessMessage   += new MessageEventHandler(OnMessage);
                            copy.ProcessCompleted += new EventHandler(OnCompleted);
                            Console.WriteLine("Executing bulk copy");
                            copy.Execute();
                            List <Exception> errors = new List <Exception>(copy.GetAllErrors());
                            if (errors.Count > 0)
                            {
                                string file = GenerateLogFileName("bcp-error-");
                                LogErrors(errors, file);
                                base.WriteError("Errors were encountered during bulk copy.");
                                retCode = CommandStatus.E_FAIL_BULK_COPY_WITH_ERRORS;
                            }
                            else
                            {
                                retCode = CommandStatus.E_OK;
                            }
                            retCode = CommandStatus.E_OK;
                        }
                    }
            }
            catch (Exception ex)
            {
                WriteException(ex);
                retCode = CommandStatus.E_FAIL_UNKNOWN;
            }
            finally
            {
                srcConn.Dispose();
                destConn.Dispose();
            }
            return((int)retCode);
        }