public override void Run()
        {
            string path = FileService.SaveFile(Res.GetString("TITLE_EXPORT_DATASTORE_XML"), Res.GetString("FILTER_XML_FILES"));

            if (!string.IsNullOrEmpty(path))
            {
                TreeNode             connNode = Workbench.Instance.ObjectExplorer.GetSelectedNode();
                FdoConnectionManager mgr      = ServiceManager.Instance.GetService <FdoConnectionManager>();
                FdoConnection        conn     = mgr.GetConnection(connNode.Name);

                using (new TempCursor(Cursors.WaitCursor))
                {
                    using (var svc = conn.CreateFeatureService())
                    {
                        var scs      = new List <SpatialContextInfo>(svc.GetSpatialContexts()).ToArray();
                        var schemas  = svc.DescribeSchema();
                        var mappings = svc.DescribeSchemaMapping(true);

                        var dstore = new FdoDataStoreConfiguration(schemas, scs, mappings);
                        dstore.Save(path);

                        Log.InfoFormatted("Connection saved to: {0}", path);
                    }
                }
            }
        }
        public override void Run()
        {
            Workbench wb = Workbench.Instance;

            if (wb != null)
            {
                TreeNode node     = wb.ObjectExplorer.GetSelectedNode();
                TreeNode connNode = wb.ObjectExplorer.GetSelectedNode();
                while (connNode.Level > 1)
                {
                    connNode = connNode.Parent;
                }

                FdoConnectionManager mgr  = ServiceManager.Instance.GetService <FdoConnectionManager>();
                FdoConnection        conn = mgr.GetConnection(connNode.Name);
                FdoDataPreviewCtl    ctl  = null;
                if (node.Level > 1) //Class node
                {
                    ctl = new FdoDataPreviewCtl(conn, node.Parent.Name, node.Name);
                }
                else
                {
                    ctl = new FdoDataPreviewCtl(conn);
                }

                wb.ShowContent(ctl, ViewRegion.Document);
            }
        }
        void OnBeforeConnectionRemove(object sender, ConnectionBeforeRemoveEventArgs e)
        {
            foreach (var name in _taskMgr.GetTaskNames())
            {
                var task = _taskMgr.GetTask(name);
                if (typeof(FdoBulkCopy).IsAssignableFrom(task.GetType()))
                {
                    var bcp   = (FdoBulkCopy)task;
                    var names = new List <string>(bcp.Options.ConnectionNames);
                    if (names.Contains(e.ConnectionName))
                    {
                        MessageService.ShowMessage("Cannot remove connection as the task (" + name + ") depends on this connection");
                        e.Cancel = true;
                        return;
                    }
                }
                else if (typeof(FdoJoin).IsAssignableFrom(task.GetType()))
                {
                    var join = (FdoJoin)task;
                    var conn = _connMgr.GetConnection(e.ConnectionName);

                    var opts = join.Options;
                    if (opts.Left.Connection == conn ||
                        opts.Right.Connection == conn ||
                        opts.Target.Connection == conn)
                    {
                        MessageService.ShowMessage("Cannot remove connection as the task (" + name + ") depends on this connection");
                        e.Cancel = true;
                        return;
                    }
                }
            }
        }
Example #4
0
        private void AddParticipatingConnection(string name)
        {
            FdoConnection conn = _connMgr.GetConnection(name);

            if (conn != null)
            {
                grdConnections.Rows.Add(name, conn.Provider, conn.SafeConnectionString, conn.ConnectionString);
            }
        }
Example #5
0
        /// <summary>
        /// Prompts the user for a currently open connection
        /// </summary>
        /// <returns>The selected FDO connection. Returns null if user cancelled or did not make a selection</returns>
        public static FdoConnection PickConnection()
        {
            string name = ConnectionPicker.GetConnectionName();

            if (!string.IsNullOrEmpty(name))
            {
                return(ConnectionManager.GetConnection(name));
            }

            return(null);
        }
        public override void Run()
        {
            string path = FileService.SaveFile(Res.GetString("TITLE_SAVE_CONNECTION"), Res.GetString("FILTER_CONNECTION_FILE"));

            if (!string.IsNullOrEmpty(path))
            {
                TreeNode             connNode = Workbench.Instance.ObjectExplorer.GetSelectedNode();
                FdoConnectionManager mgr      = ServiceManager.Instance.GetService <FdoConnectionManager>();
                FdoConnection        conn     = mgr.GetConnection(connNode.Name);
                conn.Save(path);
                Log.InfoFormatted("Connection saved to: {0}", path);
            }
        }
        public override void Run()
        {
            Workbench            wb          = Workbench.Instance;
            TreeNode             classNode   = wb.ObjectExplorer.GetSelectedNode();
            string               srcConnName = classNode.Parent.Parent.Name;
            string               schemaName  = classNode.Parent.Name;
            string               className   = classNode.Name;
            FdoConnectionManager mgr         = ServiceManager.Instance.GetService <FdoConnectionManager>();
            FdoConnection        source      = mgr.GetConnection(srcConnName);
            var ctl = new DumpFeatureClassCtl(source, schemaName, className);

            wb.ShowContent(ctl, ViewRegion.Dialog);
        }
        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);
            //        }
            //    }
            //}
        }
        public override void Run()
        {
            Workbench wb   = Workbench.Instance;
            TreeNode  node = wb.ObjectExplorer.GetSelectedNode();

            if (node.Level == 3)
            {
                string name = node.Name;
                FdoConnectionManager mgr  = ServiceManager.Instance.GetService <FdoConnectionManager>();
                FdoConnection        conn = mgr.GetConnection(node.Parent.Parent.Name);
                FdoInsertScaffold    ctl  = new FdoInsertScaffold(conn, name);
                wb.ShowContent(ctl, ViewRegion.Dialog);
            }
        }
        public bool IsValid(object caller, Condition condition)
        {
            IObjectExplorer objectExplorer = caller as IObjectExplorer;

            if (objectExplorer == null)
            {
                return(false);
            }

            TreeNode node = objectExplorer.GetSelectedNode();

            //Might be the one. Check it's root parent
            if (node.Level >= 1)
            {
                TreeNode root = node.Parent;
                while (root.Level > 0)
                {
                    root = root.Parent;
                }

                TreeNode rootCmp = objectExplorer.GetRootNode(FdoObjectExplorerExtender.RootNodeName);
                if (root == rootCmp)
                {
                    TreeNode connNode = node;
                    while (connNode.Level > 1)
                    {
                        connNode = connNode.Parent;
                    }
                    FdoConnectionManager connMgr = ServiceManager.Instance.GetService <FdoConnectionManager>();
                    FdoConnection        conn    = connMgr.GetConnection(connNode.Name);
                    if (conn != null)
                    {
                        try
                        {
                            var applicable                     = (Array.IndexOf <string>(applicableProviders, conn.Provider.ToUpper()) >= 0);
                            var supportsSchemaMappings         = conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsSchemaOverrides);
                            var supportsDescribeSchemaMappings = conn.Capability.GetArrayCapability(CapabilityType.FdoCapabilityType_CommandList).Cast <CommandType>().Contains(CommandType.CommandType_DescribeSchemaMapping);

                            return(supportsSchemaMappings && supportsDescribeSchemaMappings);
                        }
                        catch
                        {
                            return(false);
                        }
                    }
                }
            }
            return(false);
        }
Example #11
0
        /// <summary>
        /// Prepares the specified bulk copy definition (freshly deserialized) before the loading process begins
        /// </summary>
        /// <param name="def">The bulk copy definition.</param>
        protected override NameValueCollection Prepare(FdoToolbox.Core.Configuration.FdoBulkCopyTaskDefinition def)
        {
            /* There is subtle precondition that would've resulted in all connection references being named to a
             * single reference, thus invalidating the whole task when loaded.
             *
             * If the task definition has any connection names to an *already* loaded connection, a rename operation
             * could overwrite a previous rename operation. Consider:
             *
             * Connection A) SDF_Desktop
             * Connection B) SDFConnection0
             *
             * Loaded Connections:
             * - SDFConnection0
             * - SDFConnection1
             *
             * If during loading, SDF_Desktop matches to SDFConnection0, and SDFConnection0 matches to SDFConnection1 the rename operations
             * would then be:
             *
             * 1) Rename SDF_Desktop to SDFConnection0
             * 2) Rename SDF_Connection0 to SDFConnection1
             *
             * As a result, all referenced connections will eventually be renamed to SDFConnection1, which is not what we want.
             *
             * The solution bere is to "fix" the definition by renaming the named connections to something we know is not already a loaded
             * connection. This is done regardless to ensure consistent behaviour. Thsi method performs this solution.
             */

            string prefix  = "Connection";
            int    counter = 0;
            FdoConnectionManager connMgr = ServiceManager.Instance.GetService <FdoConnectionManager>();

            NameValueCollection nameMappings = new NameValueCollection();

            foreach (FdoConnectionEntryElement el in def.Connections)
            {
                string newName = prefix + counter;
                while (connMgr.GetConnection(newName) != null)
                {
                    counter++;
                    newName = prefix + counter;
                }
                string oldName = el.name;
                def.UpdateConnectionReferences(oldName, newName);
                nameMappings.Add(newName, oldName);
                counter++;
            }

            return(nameMappings);
        }
        public override void Run()
        {
            TreeNode             connNode = Workbench.Instance.ObjectExplorer.GetSelectedNode();
            FdoConnectionManager mgr      = ServiceManager.Instance.GetService <FdoConnectionManager>();
            FdoConnection        conn     = mgr.GetConnection(connNode.Name);

            if (!conn.Capability.GetBooleanCapability(CapabilityType.FdoCapabilityType_SupportsSQL))
            {
                MessageService.ShowError(Res.GetString("ERR_UNSUPPORTED_SQL"));
            }
            else
            {
                var dlg = new FdoSqlCommandDialog(conn);
                dlg.ShowDialog();
            }
        }
        public override void Run()
        {
            Workbench wb = Workbench.Instance;

            if (wb != null)
            {
                TreeNode node = wb.ObjectExplorer.GetSelectedNode();
                if (node.Level == 1)
                {
                    FdoConnectionManager mgr  = ServiceManager.Instance.GetService <FdoConnectionManager>();
                    FdoConnection        conn = mgr.GetConnection(node.Name);

                    FdoDataStoreMgrCtl ctl = new FdoDataStoreMgrCtl(conn);

                    wb.ShowContent(ctl, ViewRegion.Document);
                }
            }
        }
        public override void Run()
        {
            Workbench wb   = Workbench.Instance;
            TreeNode  node = wb.ObjectExplorer.GetSelectedNode();

            if (node.Level == 3)
            {
                if (MessageService.AskQuestion("This is a dangerous operation. One false filter could cause irreversible data changes. Do you want to continue?"))
                {
                    string name = node.Name;
                    FdoConnectionManager mgr  = ServiceManager.Instance.GetService <FdoConnectionManager>();
                    FdoConnection        conn = mgr.GetConnection(node.Parent.Parent.Name);

                    FdoBulkUpdateCtl ctl = new FdoBulkUpdateCtl(conn, node.Name);
                    wb.ShowContent(ctl, ViewRegion.Dialog);
                }
            }
        }
        public override void Run()
        {
            Workbench wb   = Workbench.Instance;
            TreeNode  node = wb.ObjectExplorer.GetSelectedNode();

            if (node.Level == 1)
            {
                string name = node.Name;
                FdoConnectionManager mgr  = ServiceManager.Instance.GetService <FdoConnectionManager>();
                FdoConnection        conn = mgr.GetConnection(name);

                if (conn != null)
                {
                    var ctl = new FdoDataStoreCtrl(conn);
                    ctl.DataStoreChanged += delegate
                    {
                        mgr.RefreshConnection(name);
                    };
                    wb.ShowContent(ctl, ViewRegion.Document);
                }
            }
        }
        public void Init()
        {
            FdoConnectionManager connMgr = ServiceManager.Instance.GetService <FdoConnectionManager>();
            FdoConnection        conn    = connMgr.GetConnection(_connName);

            ICapability cap = conn.Capability;

            CapabilityType[]       capTypes = (CapabilityType[])Enum.GetValues(typeof(CapabilityType));
            List <CapabilityEntry> ents     = new List <CapabilityEntry>();

            foreach (CapabilityType ct in capTypes)
            {
                Type t = cap.GetCapabilityValueType(ct);
                if (t != null)
                {
                    CapabilityEntry ent = new CapabilityEntry();
                    ent.Name = ct.ToString();
                    ent.Type = t.ToString();

                    object value = cap.GetObjectCapability(ct);
                    if (t == typeof(Array))
                    {
                        ent.Value = GetArrayValues((Array)value);
                    }
                    else if (t == typeof(FunctionDefinitionCollection))
                    {
                        ent.Value = GetFunctions((FunctionDefinitionCollection)value);
                    }
                    else
                    {
                        ent.Value = value.ToString();
                    }
                    ents.Add(ent);
                }
            }

            _view.Capabilities = ents.ToArray();
        }
        public override void Run()
        {
            TreeNode schemaNode = Workbench.Instance.ObjectExplorer.GetSelectedNode();

            if (schemaNode.Level == 2 && MessageService.AskQuestion("Are you sure you want to delete this schema?"))
            {
                FdoConnectionManager mgr  = ServiceManager.Instance.GetService <FdoConnectionManager>();
                FdoConnection        conn = mgr.GetConnection(schemaNode.Parent.Name);
                using (FdoFeatureService service = conn.CreateFeatureService())
                {
                    try
                    {
                        service.DestroySchema(schemaNode.Name);
                        Msg.ShowMessage(Res.GetString("MSG_SCHEMA_DELETED"), Res.GetString("TITLE_DELETE_SCHEMA"));
                        Log.InfoFormatted(Res.GetString("LOG_SCHEMA_DELETED"), schemaNode.Name, schemaNode.Parent.Name);
                        mgr.RefreshConnection(schemaNode.Parent.Name);
                    }
                    catch (OSGeo.FDO.Common.Exception ex)
                    {
                        Msg.ShowError(ex);
                    }
                }
            }
        }
 internal FdoConnection GetSourceConnection()
 {
     return(_connMgr.GetConnection(_srcConnName));
 }
        void OnAfterNodeExpansion(object sender, TreeViewEventArgs e)
        {
            if (e.Action == TreeViewAction.Expand)
            {
                TreeNode node = e.Node;
                TreeNode root = _explorer.GetRootNode(RootNodeName);
                //Is a FDO data source node
                if (IsChild(root.Nodes, node, NODE_LEVEL_CLASS))
                {
                    //Find the connection node
                    TreeNode connNode = node;
                    while (connNode.Level > 1)
                    {
                        connNode = connNode.Parent;
                    }
                    string connName = connNode.Name;

                    using (new TempCursor(Cursors.WaitCursor))
                    {
                        switch (node.Level)
                        {
                        case NODE_LEVEL_CONNECTION:     //Connection node
                        {
                            if (!(bool)node.Tag)        //Not loaded, load it now
                            {
                                //Clear out dummy node
                                node.Nodes.Clear();
                                CreateSchemaNodes(node);
                                node.Tag = true;         //Schema is loaded
                            }
                        }
                        break;

                        case NODE_LEVEL_SCHEMA:     //Schema Node
                        {
                            bool isPartial = Convert.ToBoolean(node.Tag);
                            if (isPartial)
                            {
                                Debug.Assert(node.Nodes.Count == 1);         //Has a dummy node
                                string        schemaName = node.Name;
                                FdoConnection conn       = _connMgr.GetConnection(connName);

                                using (FdoFeatureService svc = conn.CreateFeatureService())
                                {
                                    Debug.Assert(svc.SupportsPartialSchemaDiscovery());
                                    List <string> classNames = svc.GetClassNames(schemaName);
                                    GetClassNodesPartial(classNames, node);
                                    node.Tag = false;         //This node is no longer partial
                                    node.Expand();
                                }
                            }
                        }
                        break;

                        case NODE_LEVEL_CLASS:     //Class Node
                        {
                            bool isPartial = Convert.ToBoolean(node.Tag);
                            if (isPartial)
                            {
                                Debug.Assert(node.Nodes.Count == 1);         //Has a dummy node
                                string        schemaName = node.Parent.Name;
                                FdoConnection conn       = _connMgr.GetConnection(connName);
                                using (FdoFeatureService svc = conn.CreateFeatureService())
                                {
                                    Debug.Assert(svc.SupportsPartialSchemaDiscovery());
                                    ClassDefinition cd = svc.GetClassByName(schemaName, node.Name);
                                    if (cd != null)
                                    {
                                        UpdateClassNode(node, cd);
                                    }
                                }
                            }
                        }
                        break;
                        }
                    }
                }
            }
        }
Example #20
0
        private FdoFeatureService CreateSourceService()
        {
            FdoConnection conn = _connMgr.GetConnection(cmbSrcConnection.SelectedItem.ToString());

            return(conn.CreateFeatureService());
        }