Esempio n. 1
0
        /// <summary>
        ///     Shows the SQL server.
        /// </summary>
        private void ShowSqlServer( )
        {
            var properties = new DatabaseProperties( );

            properties.ShowDialog( );

            var vm = properties.DataContext as DatabasePropertiesViewModel;

            if (vm != null && vm.OkClicked)
            {
                DatabaseSettings databaseSettings = vm.DatabaseInfo;

                var manager = new DatabaseManager(databaseSettings);

                if (!manager.TestConnection( ))
                {
                    MessageBox.Show("Selected server/database does not appear to be compatible with ReadiMon", "Invalid settings", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (databaseSettings.ServerName != Settings.Default.DatabaseServer ||
                    databaseSettings.CatalogName != Settings.Default.DatabaseCatalog ||
                    databaseSettings.UseIntegratedSecurity != Settings.Default.DatabaseUseIntegratedSecurity ||
                    databaseSettings.Username != Settings.Default.DatabaseUsername ||
                    databaseSettings.Password != Settings.Default.DatabasePassword)
                {
                    DatabaseSettings = databaseSettings;

                    PluginSettings.DatabaseSettings = DatabaseSettings;

                    Settings.Default.DatabaseServer  = databaseSettings.ServerName;
                    Settings.Default.DatabaseCatalog = databaseSettings.CatalogName;
                    Settings.Default.DatabaseUseIntegratedSecurity = databaseSettings.UseIntegratedSecurity;
                    Settings.Default.DatabaseUsername = databaseSettings.Username;
                    Settings.Default.DatabasePassword = databaseSettings.Password;
                    Settings.Default.Save( );

                    OnPropertyChanged("DatabaseStatusText");
                    OnPropertyChanged("CatalogStatusText");

                    foreach (PluginWrapper plugin in PluginManager.Plugins)
                    {
                        plugin.Plugin.OnUpdateSettings(PluginSettings);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Gets the database settings.
        /// </summary>
        /// <returns></returns>
        private static DatabaseSettings GetDatabaseSettings( )
        {
            string username = null;
            string password = null;

            string server  = Settings.Default.DatabaseServer;
            string catalog = Settings.Default.DatabaseCatalog;
            bool   useIntegratedSecurity = Settings.Default.DatabaseUseIntegratedSecurity;

            if (!useIntegratedSecurity)
            {
                username = Settings.Default.DatabaseUsername;
                password = Settings.Default.DatabasePassword;
            }

            if (string.IsNullOrEmpty(server))
            {
                server = "localhost";
            }

            if (string.IsNullOrEmpty(catalog))
            {
                catalog = "SoftwarePlatform";
            }

            var databaseSettings = new DatabaseSettings(server, catalog, username, password, useIntegratedSecurity);

            var manager = new DatabaseManager(databaseSettings);

            bool modified = false;

            while (!manager.TestConnection( ))
            {
                modified         = true;
                databaseSettings = null;

                var properties = new DatabaseProperties( );
                properties.ShowDialog( );

                var vm = properties.DataContext as DatabasePropertiesViewModel;

                if (vm != null && vm.OkClicked)
                {
                    databaseSettings = vm.DatabaseInfo;

                    manager = new DatabaseManager(databaseSettings);
                }
                else
                {
                    break;
                }
            }

            if (modified && databaseSettings != null)
            {
                Settings.Default.DatabaseServer  = databaseSettings.ServerName;
                Settings.Default.DatabaseCatalog = databaseSettings.CatalogName;
                Settings.Default.DatabaseUseIntegratedSecurity = databaseSettings.UseIntegratedSecurity;
                Settings.Default.DatabaseUsername = databaseSettings.Username;
                Settings.Default.DatabasePassword = databaseSettings.Password;
                Settings.Default.Save( );
            }

            return(databaseSettings);
        }