Ejemplo n.º 1
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());
            }
        }
        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);
        }