public void TestConnection()
        {
            FdoProviderInfo provider = _view.SelectedProvider;
            string          connStr  = ExpressUtility.ConvertFromNameValueCollection(_view.ConnectProperties);

            FdoConnection conn = new FdoConnection(provider.Name, connStr);

            try
            {
                FdoConnectionState state = conn.Open();
                if (state == FdoConnectionState.Open || state == FdoConnectionState.Pending)
                {
                    _view.ShowMessage(null, "Test successful");
                    conn.Close();
                }
                else
                {
                    _view.ShowError("Connection test failed");
                }
            }
            catch (FdoException ex)
            {
                _view.ShowError(ex.InnerException.Message);
            }
            finally
            {
                conn.Dispose();
            }
        }
        public bool CreateDataStore()
        {
            FdoProviderInfo prov = _view.SelectedProvider;

            if (prov != null)
            {
                NameValueCollection dp = _view.DataStoreProperties;
                NameValueCollection cp = _view.ConnectProperties;
                FdoFeatureService.CreateDataStore(prov.Name, dp, cp);
                _view.ShowMessage(ResourceService.GetString("TITLE_CREATE_DATA_STORE"), ResourceService.GetString("MSG_DATA_STORE_CREATED"));
                return(true);
            }
            return(false);
        }
        public void ProviderChanged()
        {
            FdoProviderInfo prov = _view.SelectedProvider;

            if (prov != null)
            {
                _view.ResetGrid();
                _pendingProperties.Clear();
                IList <DictionaryProperty> props = FdoFeatureService.GetConnectProperties(prov.Name);
                if (props != null)
                {
                    foreach (DictionaryProperty p in props)
                    {
                        if (p.Enumerable)
                        {
                            EnumerableDictionaryProperty ep = p as EnumerableDictionaryProperty;
                            if (!ep.RequiresConnection)
                            {
                                _view.AddEnumerableProperty(ep.Name, ep.DefaultValue, ep.Values);
                            }
                            else
                            {
                                _pendingProperties.Add(ep);
                            }
                        }
                        else
                        {
                            _view.AddProperty(p);
                        }
                    }
                }

                using (var conn = FeatureAccessManager.GetConnectionManager().CreateConnection(prov.Name))
                {
                    _view.ConfigEnabled = conn.ConnectionCapabilities.SupportsConfiguration();
                }
            }
        }
        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);
        }
        public void ProviderChanged()
        {
            FdoProviderInfo prov = _view.SelectedProvider;

            if (prov != null)
            {
                _view.ResetDataStoreGrid();

                IList <DictionaryProperty> dprops = FdoFeatureService.GetCreateDataStoreProperties(prov.Name);
                if (dprops != null)
                {
                    foreach (DictionaryProperty p in dprops)
                    {
                        if (p.Enumerable)
                        {
                            EnumerableDictionaryProperty ep = p as EnumerableDictionaryProperty;
                            if (!ep.RequiresConnection)
                            {
                                _view.AddEnumerableDataStoreProperty(ep.Name, ep.DefaultValue, ep.Values);
                            }
                        }
                        else
                        {
                            _view.AddDataStoreProperty(p);
                        }
                    }
                    _view.CreateEnabled = true;
                }
                else
                {
                    _view.ShowError("Selected provider does not support creation of data stores");
                    _view.ResetDataStoreGrid();
                    _view.ResetConnectGrid();
                    _view.CreateEnabled = false;
                    return;
                }

                if (!prov.IsFlatFile)
                {
                    _view.ResetConnectGrid();
                    IList <DictionaryProperty> cprops = FdoFeatureService.GetConnectProperties(prov.Name);
                    if (cprops != null)
                    {
                        foreach (DictionaryProperty p in cprops)
                        {
                            if (p.Enumerable)
                            {
                                EnumerableDictionaryProperty ep = p as EnumerableDictionaryProperty;
                                if (!ep.RequiresConnection)
                                {
                                    _view.AddEnumerableConnectProperty(ep.Name, ep.DefaultValue, ep.Values);
                                }
                            }
                            else
                            {
                                _view.AddConnectProperty(p);
                            }
                        }
                    }
                }
            }
        }