public bool TryConnect(ConfigurationDatabase configurationDatabase, string login, string password)
        {
            Boolean success = false;
            DbConnection connection = this.CreateConnection(configurationDatabase, login, password);
            if (connection != null)
            {
                try
                {

                    connection.Open();
                    success = connection.State == System.Data.ConnectionState.Open;

                }
                catch (Exception ex)
                { }
                finally
                {
                    connection.Close();
                    connection.Dispose();
                }

            }

            return success;
        }
        public void Load()
        {
            this.Databases.Clear();
            RegistryKey companyKey = Registry.LocalMachine.OpenOrCreateCompanyKey();
            RegistryKey geoPatKey = companyKey.OpenOrCreateKey("GeoPatV2");
            RegistryKey configKey = geoPatKey.OpenOrCreateKey("Configuration");
            RegistryKey providersKey = configKey.OpenOrCreateKey("Providers");
            String[] providersKeyNames = providersKey.GetSubKeyNames();
            foreach (String providerKeyName in providersKeyNames)
            {
                RegistryKey providerKey = providersKey.OpenOrCreateKey(providerKeyName);
                String providerTypeFullName = providerKey.GetValue("ProviderTypeFullName").ToString();
                ConfigurationProviderType configurationProviderType = null;
                if (providerTypeFullName.Equals(typeof(ConfigurationProviderTypeMysql).FullName))
                {
                    configurationProviderType = new ConfigurationProviderTypeMysql();

                }
                else if (providerTypeFullName.Equals(typeof(ConfigurationProviderTypeOracle).FullName))
                {
                    configurationProviderType = new ConfigurationProviderTypeMysql();

                }
                else if (providerTypeFullName.Equals(typeof(ConfigurationProviderTypePostgre).FullName))
                {
                    configurationProviderType = new ConfigurationProviderTypeMysql();

                }
                if (configurationProviderType != null)
                {
                    ConfigurationDatabase item = new ConfigurationDatabase();
                    item.DisplayName = providerKey.GetValue("DisplayName").ToString();
                    item.IsDefault = providerKey.GetValue("IsDefault").ToString().ToUpper().Equals("TRUE");
                    item.ProviderTypeFullName = providerTypeFullName;
                    RegistryKey parametersKey = providerKey.OpenOrCreateKey("Parameters");
                    String[] parametersKeyNames = parametersKey.GetSubKeyNames();
                    foreach (String parametersKeyName in parametersKeyNames)
                    {
                        RegistryKey parameterKey = parametersKey.OpenOrCreateKey(parametersKeyName);
                        item.Parameters.Add ( parameterKey.GetValue("Code").ToString(), parameterKey.GetValue("Value").ToString());

                    }
                    this.Databases.Add(item);
                }
            }
        }
Exemple #3
0
        public void CreateConnection(ConfigurationDatabase database, string login, string password)
        {
            if (database != null)
            {

                Type providerType = this.GetType().Assembly.GetType(database.ProviderTypeFullName);
                if (providerType != null)
                {
                     ConfigurationProviderType configurationProviderType = Activator.CreateInstance(providerType) as ConfigurationProviderType;
                     if (configurationProviderType != null)
                     {
                         this.Connection = configurationProviderType.CreateConnection(database, login, password);

                     }

                }
            }
        }
        public override DbConnection CreateConnection(ConfigurationDatabase configurationDatabase, string login, string password)
        {
            Assembly assembly = Assembly.Load("Oracle.DataAccess");
            if (assembly != null)
            {
                Type connectionType = assembly.GetType("Oracle.DataAccess.Client.OracleConnection");
                if (connectionType != null)
                {
                    DbConnection connection = Activator.CreateInstance(connectionType) as DbConnection;
                    String sid = (from p in configurationDatabase.Parameters where p.Key.Equals ("SID") select p.Value).FirstOrDefault();
                    if (sid != null)
                    {
                        connection.ConnectionString = "Data Source=" + sid + ";User Id=" + login + ";Password="******";";
                        return connection;
                    }

                }
            }
            return null;
        }
        public override System.Data.Common.DbConnection CreateConnection(ConfigurationDatabase configurationDatabase, string login, string password)
        {
            string host = (from p in configurationDatabase.Parameters where p.Key.Equals("HOST") select p.Value).FirstOrDefault();
            string port = (from p in configurationDatabase.Parameters where p.Key.Equals("PORT") select p.Value).FirstOrDefault();
            string database = (from p in configurationDatabase.Parameters where p.Key.Equals("DATABASE") select p.Value).FirstOrDefault();
            Assembly assembly = Assembly.Load("Npgsql");
            if (assembly != null)
            {
                Type connectionType = assembly.GetType("Npgsql.NpgsqlConnection");
                if (connectionType != null)
                {
                    DbConnection connection = Activator.CreateInstance(connectionType) as DbConnection;
                    if (host != null && port != null && database != null)
                    {
                        connection.ConnectionString = "HOST=" + host + ";PORT=" + port + ";DATABASE=" + database + ";USER ID=" + login + ";PASSWORD="******";PRELOADREADER=true;";
                        return connection;
                    }

                }
            }
            return null;
        }
 internal string GetPasswordForLogin(ConfigurationDatabase configurationDatabase, string login)
 {
     RegistryKey companyKey = Registry.CurrentUser.OpenOrCreateCompanyKey();
     RegistryKey geoPatKey = companyKey.OpenOrCreateKey("GeoPat");
     RegistryKey configKey = geoPatKey.OpenOrCreateKey("Configuration");
     RegistryKey providersKey = configKey.OpenOrCreateKey("Providers");
     String providerKeyName = configurationDatabase.GetHash();
     RegistryKey keyProvider = providersKey.OpenOrCreateKey(providerKeyName);
     if (keyProvider.GetValueNames().Contains(login))
     { return keyProvider.GetValue(login).ToString(); }
     return null;
 }
 internal void AddDatabase(ConfigurationDatabase model)
 {
     this.Databases.Add(model);
     this.Save();
 }
Exemple #8
0
 public string ShowInputPasswordDialog(ConfigurationDatabase database,string needestLogin)
 {
     LoginDataBaseViewModel viewModel = new LoginDataBaseViewModel();
     viewModel.Login = needestLogin;
     viewModel.Database = database;
     LoginDatabaseDialog dialog = new LoginDatabaseDialog(viewModel);
     Nullable<Boolean> result = dialog.ShowDialog();
     if (result.HasValue && result.Value == true)
     { return viewModel.Password; }
     return null;
 }
Exemple #9
0
 public void SetPasswordForLogin(ConfigurationDatabase database, string login, string password)
 {
     this._container.Resolve<Configuration>().SetPasswordForLogin(database, login, password);
 }
 private void AddDatabaseCommandExecute()
 {
     AddDatabaseDialog dialog = this._container.Resolve<AddDatabaseDialog>();
     dialog.Owner = Application.Current.Windows.Cast<Window>().SingleOrDefault(x => x.IsActive);
     Nullable<Boolean> result = dialog.ShowDialog();
     if (result.HasValue && result.Value == true)
     {
         ConfigurationDatabaseViewModel vm = dialog.ViewModel;
         ConfigurationDatabase model = new ConfigurationDatabase();
         model.ProviderTypeFullName = vm.SelectedProviderType.GetType().FullName;
         model.DisplayName = vm.DisplayName;
         foreach (ConfigurationProviderParameter param in vm.SelectedProviderType.Parameters)
         {model.Parameters.Add(param.Code, param.Value);}
         this._container.Resolve<Configuration>().AddDatabase(model);
         this.Databases.Add(model);
     }
 }
Exemple #11
0
 public bool TryConnect(ConfigurationDatabase database, string login, string password)
 {
     if (database != null)
     {
         Type providerType = this.GetType().Assembly.GetType(database.ProviderTypeFullName);
        if (providerType != null)
        {
            ConfigurationProviderType configurationProviderType = Activator.CreateInstance(providerType) as ConfigurationProviderType;
            if (configurationProviderType != null)
            { return configurationProviderType.TryConnect(database, login, password); }
        }
     }
     return false;
 }
 public abstract DbConnection CreateConnection(ConfigurationDatabase configurationDatabase, string login, string password);
 public override System.Data.Common.DbConnection CreateConnection(ConfigurationDatabase configurationDatabase, string login, string password)
 {
     throw new NotImplementedException();
 }
 private void RemoveDatabaseCommandExecute(ConfigurationDatabase database)
 {
     this._container.Resolve<Configuration>().Databases.Remove(database);
     this.Databases.Remove(database);
     this._container.Resolve<Configuration>().Save();
 }
Exemple #15
0
 internal void SetDefaultDatabase(ConfigurationDatabase selectedDatabase)
 {
     foreach (ConfigurationDatabase db in this.Databases)
     {db.IsDefault = false;}
     selectedDatabase.IsDefault = true;
     this.Save();
 }
Exemple #16
0
 internal void SetPasswordForLogin(ConfigurationDatabase database,string login, string password)
 {
     RegistryKey companyKey = Registry.CurrentUser.OpenOrCreateCompanyKey();
     RegistryKey geoPatKey = companyKey.OpenOrCreateKey("GeoPat");
     RegistryKey configKey = geoPatKey.OpenOrCreateKey("Configuration");
     RegistryKey providersKey = configKey.OpenOrCreateKey("Providers");
     String providerKeyName = database.GetHash();
     RegistryKey keyProvider = providersKey.OpenOrCreateKey(providerKeyName);
     keyProvider.SetValue(login, password);
 }
Exemple #17
0
 public string GetPasswordForLogin(ConfigurationDatabase database, string login)
 {
     return this._container.Resolve<Configuration>().GetPasswordForLogin(database, login);
 }
Exemple #18
0
 public void SetDefaultDatabase(ConfigurationDatabase selectedDatabase)
 {
     this._container.Resolve<Configuration>().SetDefaultDatabase(selectedDatabase);
 }
 private void SelectDatabaseCommandExecute(ConfigurationDatabase database)
 {
     this.SelectedDatabase = database;
     Window Window = Application.Current.Windows.Cast<Window>().SingleOrDefault(x => x.IsActive);
     Window.DialogResult = true;
     Window.Close();
 }