コード例 #1
0
        internal static IConnectionSettings ExtractConnectionSettings(DbSettingsFormValuesWrapper valuesWrapper)
        {
            if (null == valuesWrapper)
            {
                throw new ArgumentNullException(nameof(valuesWrapper));
            }

            switch (valuesWrapper.Control1Provider)
            {
            case DbSettingsFormValuesWrapper.Control1ProviderValueSystemDataSqlserverce40:
            {
                var connectionBuilder = new StringBuilder();

                connectionBuilder.Append($"Data Source={valuesWrapper.Control2PathToDatabase};");

                if (valuesWrapper.Control3UsePassword)
                {
                    connectionBuilder.Append($" Password={valuesWrapper.Control4Password};");
                }

                return(new ConnectionSettings(valuesWrapper.Control1Provider, connectionBuilder.ToString()));
            }

            case DbSettingsFormValuesWrapper.Control1ProviderValueSystemDataSqlclient:
            case DbSettingsFormValuesWrapper.Control1ProviderValueMysqlDataMysqlclient:
            case DbSettingsFormValuesWrapper.Control1ProviderValueNpgsql:
            case DbSettingsFormValuesWrapper.Control1ProviderValueOracleManageddataaccessClient:
                return(new ConnectionSettings(valuesWrapper.Control1Provider,
                                              valuesWrapper.Control6ConnectionString));

            default:
                throw new InvalidOperationException("valuesWrapper.Control1Provider == " +
                                                    valuesWrapper.Control1Provider);
            }
        }
コード例 #2
0
        private void BuildConnectionString(string connectionStringWithProvider)
        {
            var connectionSettings = DbSettingsService.ParseConnectionSettings(connectionStringWithProvider);
            var inputValuesWrapper = DbSettingsService.MapToValuesWrapper(connectionSettings);

            var dbSettingsForm = SubmitFormDisplayHelper.LoadSubmitFormByExtensionId(_context.ExtensionManager,
                                                                                     ExtensionCatalog.DbSettings, inputValuesWrapper.CollectIncomeValues());

            dbSettingsForm.WorkCallback = (step, list) =>
            {
                var valuesWrapper = new DbSettingsFormValuesWrapper(list);
                connectionSettings = DbSettingsService.ExtractConnectionSettings(valuesWrapper);

                var dbSettingsService = new DbSettingsService(_context.UnityContainer);
                dbSettingsService.CheckConnectionSettings(connectionSettings);

                connectionStringWithProvider =
                    DbSettingsService.ToConnectionStringWithProvider(connectionSettings);

                return(new Dictionary <string, object>());
            };

            if (DialogResult.OK == dbSettingsForm.ShowDialog(_form))
            {
                var step2 =
                    new RegistrationFormValuesWrapper.Step2
                {
                    Control5ConnectionString = connectionStringWithProvider
                };

                _form.ApplyValues(step2.CollectIncomeValues());
            }
        }
コード例 #3
0
        public Form GetForm(SessionContext context)
        {
            if (null == context)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var dbSettingsService = new DbSettingsService(context.UnityContainer);

            var connectionSettings = context.Session.AuthenticationService.GetConnectionSettings();

            DbSettingsFormValuesWrapper incomeValuesWrapper = null;

            if (null != connectionSettings)
            {
                incomeValuesWrapper = DbSettingsService.MapToValuesWrapper(connectionSettings);
            }

            var form = SubmitFormDisplayHelper.LoadSubmitFormByExtensionId(context.ExtensionManager, ExtensionCatalog.DbSettings,
                                                                           incomeValuesWrapper?.CollectIncomeValues());

            form.Closed += (sender, args) =>
            {
                if (DialogResult.OK == form.DialogResult)
                {
                    EventBroker.OnDatabaseChanged();
                }
            };

            form.WorkCallback = (step, list) =>
            {
                var valuesWrapper = new DbSettingsFormValuesWrapper(list);
                connectionSettings = DbSettingsService.ExtractConnectionSettings(valuesWrapper);

                dbSettingsService.CheckConnectionSettings(connectionSettings);

                context.Session.AuthenticationService.SetConnectionSettings(connectionSettings);

                return(new Dictionary <string, object>());
            };

            return(form);
        }