Example #1
0
        public bool DependsOnConnection(FdoToolbox.Core.Feature.FdoConnection conn)
        {
            IFdoConnectionManager connMgr = ServiceManager.Instance.GetService <IFdoConnectionManager>();
            FdoConnection         left    = connMgr.GetConnection(this.SelectedLeftConnection);
            FdoConnection         right   = connMgr.GetConnection(this.SelectedRightConnection);
            FdoConnection         target  = connMgr.GetConnection(this.SelectedTargetConnection);

            return(conn == left || conn == right || conn == target);
        }
        public void Init()
        {
            List <string> names = new List <string>(_connMgr.GetConnectionNames());

            names.Remove(_view.SourceConnectionName);

            _view.TargetConnectionNames = names;
            FdoConnection conn = _connMgr.GetConnection(_view.SourceConnectionName);

            using (FdoFeatureService service = conn.CreateFeatureService())
            {
                ICollection <SpatialContextInfo> contexts = service.GetSpatialContexts();
                List <string> scn = new List <string>();
                foreach (SpatialContextInfo sc in contexts)
                {
                    scn.Add(sc.Name);
                }
                _view.SpatialContexts = scn;
            }
        }
Example #3
0
        /// <summary>
        /// Creates the connection.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="connStr">The connection string.</param>
        /// <param name="configPath">The configuration path</param>
        /// <param name="name">The name that will be assigned to the connection.</param>
        /// <returns></returns>
        protected override FdoConnection CreateConnection(string provider, string connStr, string configPath, ref string name)
        {
            IFdoConnectionManager connMgr = ServiceManager.Instance.GetService <IFdoConnectionManager>();
            //Try to find by name first
            FdoConnection conn = null;

            conn = connMgr.GetConnection(name);
            //Named connection matches all the details
            if (conn != null)
            {
                if (conn.Provider == provider && conn.ConnectionString == connStr)
                {
                    return(conn);
                }
            }

            //Then to find matching open connection
            foreach (string connName in connMgr.GetConnectionNames())
            {
                FdoConnection c = connMgr.GetConnection(connName);
                if (c.Provider == provider && c.ConnectionString == connStr)
                {
                    name = connName;
                    return(c);
                }
            }

            //Make a new connection
            LoggingService.Info(ResourceService.GetString("INFO_REFERENCED_CONNECTION_NOT_FOUND"));
            conn = new FdoConnection(provider, connStr);
            if (!string.IsNullOrEmpty(configPath) && System.IO.File.Exists(configPath))
            {
                conn.SetConfiguration(configPath);
            }
            connMgr.AddConnection(name, conn);
            return(conn);
        }
Example #4
0
        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;
                    }
                    FdoConnection conn = connMgr.GetConnection(connNode.Name);
                    if (conn != null)
                    {
                        string cmd = "CommandType_" + condition.Properties["command"];
                        try
                        {
                            OSGeo.FDO.Commands.CommandType ctype = (OSGeo.FDO.Commands.CommandType)Enum.Parse(typeof(OSGeo.FDO.Commands.CommandType), cmd);
                            Array commands = conn.Capability.GetArrayCapability(CapabilityType.FdoCapabilityType_CommandList);
                            return(Array.IndexOf(commands, ctype) >= 0);
                        }
                        catch
                        {
                            return(false);
                        }
                    }
                }
            }
            return(false);
        }
Example #5
0
        internal FdoConnection GetConnection(JoinSourceType type)
        {
            switch (type)
            {
            case JoinSourceType.Left:
                return(_connMgr.GetConnection(_view.SelectedLeftConnection));

            case JoinSourceType.Right:
                return(_connMgr.GetConnection(_view.SelectedRightConnection));

            case JoinSourceType.Target:
                return(_connMgr.GetConnection(_view.SelectedTargetConnection));

            default:
                return(null);
            }
        }
Example #6
0
        void OnBeforeRemoveConnection(object sender, ConnectionBeforeRemoveEventArgs e)
        {
            FdoConnection conn = connMgr.GetConnection(e.ConnectionName);
            //Get all views that depend on connection
            List <IConnectionDependentView> matches = _tabs.FindAll(delegate(IConnectionDependentView c) { return(c.DependsOnConnection(conn)); });

            if (matches.Count > 0)
            {
                //Don't close then cancel
                if (!MessageService.AskQuestion(ResourceService.GetStringFormatted("QUESTION_CLOSE_TABS", e.ConnectionName)))
                {
                    e.Cancel = true;
                    return;
                }
                else //Otherwise remove from watch list and close the view
                {
                    foreach (IConnectionDependentView view in matches)
                    {
                        _tabs.Remove(view);
                        view.Close();
                    }
                }
            }
        }
        public bool Connect()
        {
            if (string.IsNullOrEmpty(_view.ConnectionName))
            {
                _view.FlagNameError("Required");
                return(false);
            }

            FdoConnection conn = _manager.GetConnection(_view.ConnectionName);

            if (conn != null)
            {
                _view.FlagNameError("A connection named " + _view.ConnectionName + " already exists");
                return(false);
            }

            FdoProviderInfo provider = _view.SelectedProvider;
            //string connStr = ExpressUtility.ConvertFromNameValueCollection(_view.ConnectProperties);

            NameValueCollection cp = new NameValueCollection(_view.ConnectProperties);

            if (_pendingProperties.Count > 0)
            {
                NameValueCollection extra = new NameValueCollection();
                cp.Add(extra);
            }
            string connStr = ExpressUtility.ConvertFromNameValueCollection(cp);

            conn = new FdoConnection(provider.Name, connStr);
            if (FileService.FileExists(_view.ConfigFile))
            {
                try
                {
                    conn.SetConfiguration(_view.ConfigFile);
                }
                catch (Exception ex)
                {
                    conn.Dispose();
                    _view.FlagConfigError(ex.Message);
                    return(false);
                }
            }

            try
            {
                FdoConnectionState state = conn.Open();
                if (state == FdoConnectionState.Open)
                {
                    _manager.AddConnection(_view.ConnectionName, conn);
                    return(true);
                }
                else if (state == FdoConnectionState.Pending)
                {
                    //Re-query the pending parameters and re-prompt in a new dialog
                    if (_pendingProperties.Count > 0)
                    {
                        List <DictionaryProperty> pend = new List <DictionaryProperty>();
                        foreach (DictionaryProperty p in _pendingProperties)
                        {
                            pend.Add(conn.GetConnectTimeProperty(p.Name));
                        }
                        NameValueCollection extra = PendingParameterDialog.GetExtraParameters(pend);
                        //Cancelled action
                        if (extra == null)
                        {
                            return(false);
                        }

                        cp.Add(extra);
                        conn.ConnectionString = ExpressUtility.ConvertFromNameValueCollection(cp);
                        if (conn.Open() == FdoConnectionState.Open)
                        {
                            _manager.AddConnection(_view.ConnectionName, conn);
                            return(true);
                        }
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                _view.ShowError(ex);
                conn.Dispose();
                return(false);
            }
            return(false);
        }