Beispiel #1
0
 private void ShowKeysView(MycoKeyCreator.Library.Database.IDatabase iDatabase, MycoKeyCreator.Library.Database.KeyManager keyManager)
 {
     MycoKeyCreator.Application.View.KeysListView keysListView = new View.KeysListView(this);
     ViewModel.KeysListViewModel keysListViewModel             = new ViewModel.KeysListViewModel(iDatabase.Name, keyManager);
     keysListView.DataContext = keysListViewModel;
     keysListViewModel.Load();
     keysListView.WindowStartupLocation = WindowStartupLocation.CenterOwner;
     keysListView.Owner = this;
     keysListView.ShowDialog();
     if (keysListView._datagridKeys.Columns.Count > 0)
     {
         keysListView._datagridKeys.Columns[0].Visibility = Visibility.Collapsed;
     }
     iDatabase.CloseConnection();
 }
Beispiel #2
0
        private bool OpenDatabase(out MycoKeyCreator.Library.Database.IDatabase iDatabase, out MycoKeyCreator.Library.Database.KeyManager keyManager)
        {
            iDatabase  = null;
            keyManager = null;

            OpenControls.Wpf.Serialisation.RegistryItemSerialiser        registryItemSerialiser = new OpenControls.Wpf.Serialisation.RegistryItemSerialiser(_keyPath);
            OpenControls.Wpf.DatabaseDialogs.Model.DatabaseConfiguration databaseConfiguration  = new OpenControls.Wpf.DatabaseDialogs.Model.DatabaseConfiguration(registryItemSerialiser);
            if (registryItemSerialiser.OpenKey())
            {
                databaseConfiguration.Load();
            }

            OpenControls.Wpf.DatabaseDialogs.ViewModel.OpenDatabaseViewModel openDatabaseViewModel = new OpenControls.Wpf.DatabaseDialogs.ViewModel.OpenDatabaseViewModel(databaseConfiguration);
            OpenControls.Wpf.DatabaseDialogs.View.OpenDatabaseView           openDatabaseView      =
                new OpenControls.Wpf.DatabaseDialogs.View.OpenDatabaseView(new OpenControls.Wpf.DatabaseDialogs.Model.Encryption());
            openDatabaseView.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            openDatabaseView.Owner       = this;
            openDatabaseView.DataContext = openDatabaseViewModel;
            if (openDatabaseView.ShowDialog() != true)
            {
                return(false);
            }
            if (!registryItemSerialiser.IsOpen)
            {
                registryItemSerialiser.CreateKey();
            }
            databaseConfiguration.Save();
            registryItemSerialiser.Close();

            try
            {
                OpenControls.Wpf.DatabaseDialogs.Model.Encryption encryption = new OpenControls.Wpf.DatabaseDialogs.Model.Encryption();
                if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.MicrosoftSQLServer)
                {
                    MycoKeyCreator.Library.PetaPocoAdapter.SQLServerDatabaseFactory.OpenDatabase(
                        out iDatabase,
                        openDatabaseViewModel.SQLServer_UseLocalServer,
                        openDatabaseViewModel.SelectedSqlServerInstance,
                        openDatabaseViewModel.SQLServer_IPAddress,
                        openDatabaseViewModel.SQLServer_Port,
                        openDatabaseViewModel.SQLServer_UseWindowsAuthentication,
                        openDatabaseViewModel.SQLServer_UserName,
                        encryption.Decrypt(openDatabaseViewModel.SQLServer_Password),
                        openDatabaseViewModel.SQLServer_DatabaseName);
                }
                else if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.MySQL)
                {
                    MycoKeyCreator.Library.PetaPocoAdapter.MySQLDatabaseFactory.OpenDatabase(
                        out iDatabase,
                        openDatabaseViewModel.MySQL_IPAddress,
                        openDatabaseViewModel.MySQL_Port,
                        openDatabaseViewModel.MySQL_UseWindowsAuthentication,
                        openDatabaseViewModel.MySQL_UserName,
                        encryption.Decrypt(openDatabaseViewModel.MySQL_Password),
                        openDatabaseViewModel.MySQL_DatabaseName);
                }
                else if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.PostGreSQL)
                {
                    MycoKeyCreator.Library.PetaPocoAdapter.PostgreSQLServerDatabaseFactory.OpenDatabase(
                        out iDatabase,
                        openDatabaseViewModel.PostgreSQL_IPAddress,
                        openDatabaseViewModel.PostgreSQL_Port,
                        openDatabaseViewModel.PostgreSQL_UseWindowsAuthentication,
                        openDatabaseViewModel.PostgreSQL_UserName,
                        encryption.Decrypt(openDatabaseViewModel.PostgreSQL_Password),
                        openDatabaseViewModel.PostgreSQL_DatabaseName);
                }
                else if (openDatabaseViewModel.SelectedDatabaseProvider == OpenControls.Wpf.DatabaseDialogs.Model.DatabaseProvider.SQLite)
                {
                    MycoKeyCreator.Library.PetaPocoAdapter.SQLiterDatabaseFactory.OpenDatabase(
                        out iDatabase,
                        openDatabaseViewModel.SQLite_Filename);
                }
                else
                {
                    throw new Exception("Unsupported database type");
                }
            }
            catch (Exception exception)
            {
                System.Windows.Forms.MessageBox.Show(exception.Message);
                return(false);
            }

            keyManager = MycoKeyCreator.Library.PetaPocoAdapter.KeyManagerFactory.BuildKeyManager(iDatabase);

            return(true);
        }