public bool Connect()
        {
            var builder = new System.Data.Common.DbConnectionStringBuilder();

            builder["Username"] = _view.Username;
            builder["Password"] = _view.Password;
            builder["Service"]  = _view.Service;
            if (!string.IsNullOrEmpty(_view.OracleSchema))
            {
                builder["OracleSchema"] = _view.OracleSchema;
            }
            if (!string.IsNullOrEmpty(_view.KingFdoClass))
            {
                builder["KingFdoClass"] = _view.KingFdoClass;
            }
            if (!string.IsNullOrEmpty(_view.SdeSchema))
            {
                builder["SDE Schema"] = _view.SdeSchema;
            }
            FdoConnection conn = new FdoConnection("OSGeo.KingOracle", builder.ToString());

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

            _view.ShowMessage(null, "Connection failed");
            return(false);
        }
        public bool Connect()
        {
            if (string.IsNullOrEmpty(_view.ConnectionName))
            {
                _view.ShowMessage(null, "Name required");
                return(false);
            }

            FdoConnection conn = new FdoConnection("OSGeo.OGR", _view.BuilderObject.ToConnectionString());

            try
            {
                if (conn.Open() == FdoConnectionState.Open)
                {
                    IFdoConnectionManager mgr = ServiceManager.Instance.GetService <IFdoConnectionManager>();
                    mgr.AddConnection(_view.ConnectionName, conn);
                    return(true);
                }
            }
            catch (FdoException ex)
            {
                _view.ShowError(ex);
            }
            return(false);
        }
        public bool Connect()
        {
            InitConnection();
            if (string.IsNullOrEmpty(_view.ConnectionName) || _connMgr.NameExists(_view.ConnectionName))
            {
                _view.ShowError(ResourceService.GetString("ERR_CONNECTION_NAME_EMPTY_OR_EXISTS"));
                return(false);
            }

            try
            {
                _conn.ConnectionString = string.Format("{0}={1};{2}={3};{4}={5};{6}={7}", _view.ServiceParameter, _view.Service, _view.UsernameParameter, _view.Username, _view.PasswordParameter, _view.Password, _view.DataStoreParameter, _view.SelectedDataStore);
                if (_conn.Open() == FdoConnectionState.Open)
                {
                    _connMgr.AddConnection(_view.ConnectionName, _conn);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                _view.ShowError(ex.Message);
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// Handles the file drop
        /// </summary>
        /// <param name="file">The file being dropped</param>
        public void HandleDrop(string file)
        {
            IFdoConnectionManager connMgr = ServiceManager.Instance.GetService<IFdoConnectionManager>();
            NamingService namer = ServiceManager.Instance.GetService<NamingService>();
            FdoConnection conn = null;
            try
            {
                conn = ExpressUtility.CreateFlatFileConnection(file);
            }
            catch (Exception ex)
            {
                LoggingService.Error("Failed to load connection", ex);
                return;
            }

            string name = namer.GetDefaultConnectionName(conn.Provider, System.IO.Path.GetFileNameWithoutExtension(file));
            connMgr.AddConnection(name, conn);
        }
        /// <summary>
        /// Handles the file drop
        /// </summary>
        /// <param name="file">The file being dropped</param>
        public void HandleDrop(string file)
        {
            IFdoConnectionManager connMgr = ServiceManager.Instance.GetService <IFdoConnectionManager>();
            NamingService         namer   = ServiceManager.Instance.GetService <NamingService>();
            FdoConnection         conn    = null;

            try
            {
                conn = FdoConnection.LoadFromFile(file, true);
            }
            catch (Exception ex)
            {
                LoggingService.Error("Failed to load connection", ex);
                return;
            }

            string name = namer.GetDefaultConnectionName(conn.Provider);

            connMgr.AddConnection(name, conn);
        }
Beispiel #6
0
        public void HandleDrop(string file)
        {
            IFdoConnectionManager connMgr = ServiceManager.Instance.GetService <IFdoConnectionManager>();
            NamingService         namer   = ServiceManager.Instance.GetService <NamingService>();
            FdoConnection         conn    = null;

            try
            {
#if X64
                conn = new FdoConnection("OSGeo.ODBC", "ConnectionString=\"Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};Dbq=" + file + "\"");
#else
                conn = new FdoConnection("OSGeo.ODBC", "ConnectionString=\"Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" + file + "\"");
#endif
            }
            catch (Exception ex)
            {
                LoggingService.Error("Failed to load connection", ex);
                return;
            }

            string name = namer.GetDefaultConnectionName(conn.Provider, System.IO.Path.GetFileNameWithoutExtension(file));
            connMgr.AddConnection(name, conn);
        }
Beispiel #7
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);
        }
        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 Create()
        {
            bool          ok      = true;
            FdoConnection conn    = new FdoConnection(_view.Provider, GetBaseConnectionString());
            bool          created = false;
            bool          cleanup = true;

            try
            {
                using (var svc = conn.CreateFeatureService())
                {
                    try
                    {
                        CreateDataStore(svc);
                        created = true;
                    }
                    catch (Exception ex)
                    {
                        _view.ShowError(ex);
                        created = false;
                        ok      = false;
                    }
                }

                if (created)
                {
                    //Amend the connection string to include the data store
                    var builder = new DbConnectionStringBuilder();
                    builder.ConnectionString          = conn.ConnectionString;
                    builder[_view.DataStoreParameter] = _view.DataStoreName;
                    conn.ConnectionString             = builder.ConnectionString;
                    conn.Open();

                    using (var svc = conn.CreateFeatureService())
                    {
                        CreateDefaultSpatialContext(svc);
                    }
                }
            }
            finally
            {
                if (created)
                {
                    if (File.Exists(_view.SchemaFile))
                    {
                        ApplySchemas(conn);
                    }

                    if (_view.ConnectOnCreate)
                    {
                        _connMgr.AddConnection(_view.ConnectionName, conn);
                        cleanup = false;
                    }
                }

                if (cleanup)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }

            return(ok);
        }
        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);
        }