Ejemplo n.º 1
0
        /// <summary>
        /// Creates the connection.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="connStr">The conn STR.</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)
        {
            var conn = new FdoConnection(provider, connStr);

            if (!string.IsNullOrEmpty(configPath) && File.Exists(configPath))
            {
                conn.SetConfiguration(configPath);
            }
            return(conn);
        }
Ejemplo n.º 2
0
        private void InitConnection()
        {
            if (_conn == null)
            {
                _conn = new FdoConnection(_view.Provider);
            }

            if (!string.IsNullOrEmpty(_view.ConfigPath) && System.IO.File.Exists(_view.ConfigPath))
            {
                _conn.SetConfiguration(_view.ConfigPath);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        public bool Connect()
        {
            if (string.IsNullOrEmpty(_view.ConnectionName))
            {
                _view.ShowMessage(null, "Name required");
                return(false);
            }

            FdoConnection conn = new FdoConnection("OSGeo.ODBC", string.Format("ConnectionString=\"{0}\"", _view.BuilderObject.ToConnectionString()));

            if (FileService.FileExists(_view.ConfigurationFile))
            {
                conn.SetConfiguration(_view.ConfigurationFile);
            }
            if (conn.Open() == FdoConnectionState.Open)
            {
                IFdoConnectionManager mgr = ServiceManager.Instance.GetService <IFdoConnectionManager>();
                mgr.AddConnection(_view.ConnectionName, conn);
                return(true);
            }

            _view.ShowMessage(null, "Connection test failed");
            return(false);
        }
        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);
        }