Esempio n. 1
0
        public Form GetForm(EntranceContext context)
        {
            _context = context ?? throw new ArgumentNullException(nameof(context));

            var certificates = new KeySettingsService(context.UnityContainer).SelectCertificates();

            var step1IncomeValuesWrapper = new RegistrationFormValuesWrapper.Step1
            {
                Control5Certificate = certificates.Select(c => new ListItemContent(c)
                {
                    ImageKey = "Pfx"
                }).ToList()
            };

            _form =
                SubmitFormDisplayHelper.LoadSubmitFormByExtensionId(context.ExtensionManager, ExtensionCatalog.Registration,
                                                                    step1IncomeValuesWrapper.CollectIncomeValues());

            _form.ServiceCommand += (sender, args) =>
            {
                if (args.Command.Equals("BuildConnectionString", StringComparison.OrdinalIgnoreCase))
                {
                    BuildConnectionString((string)args.Argument);
                }
            };

            _form.WorkCallback = (step, list) =>
            {
                switch (step)
                {
                case 0:
                {
                    return(Step1(new RegistrationFormValuesWrapper.Step1(list)).CollectIncomeValues());
                }

                case 1:
                    Step2(new RegistrationFormValuesWrapper.Step2(list));
                    return(new Dictionary <string, object>());

                default:
                    throw new InvalidOperationException("step == " + step);
                }
            };

            return(_form);
        }
Esempio n. 2
0
        private RegistrationFormValuesWrapper.Step2 Step1(RegistrationFormValuesWrapper.Step1 valuesWrapper)
        {
            var entranceService = _context.UnityContainer.Resolve <IEntranceService>();

            switch (valuesWrapper.Control1AuthenticationType)
            {
            case RegistrationFormValuesWrapper.Step1.Control1AuthenticationTypeValueClassic:
            {
                var identifier = long.Parse(valuesWrapper.Control2Identifier);
                var encrypted  = File.ReadAllBytes(valuesWrapper.Control3BackupFile);
                var password   = valuesWrapper.Control4BackupFilePassword;

                byte[] decryptedKey;

                try
                {
                    decryptedKey = entranceService.DecryptKeeperKey(encrypted, identifier, password);
                }
                catch (Exception exception)
                {
                    throw new WrongPasswordException(
                              Resources.RegistrationFormProvider_Step1_Wrong_password_or_WMID_for_kwm_file_, exception);
                }

                _identifier       = identifier;
                _decryptedKey     = decryptedKey;
                _lightCertificate = null;
            }
            break;

            case RegistrationFormValuesWrapper.Step1.Control1AuthenticationTypeValueLight:
                var lightCertificate = (ILightCertificate)valuesWrapper.Control5Certificate;
                _identifier   = lightCertificate.Identifier;
                _decryptedKey = null;

                _lightCertificate = lightCertificate;
                break;

            default:
                throw new InvalidOperationException("valuesWrapper.Control1AuthenticationType == " +
                                                    valuesWrapper.Control1AuthenticationType);
            }

            if (entranceService.CheckRegistration(_identifier))
            {
                var identifierValue = _context.UnityContainer.Resolve <IFormattingService>()
                                      .FormatIdentifier(_identifier);
                throw new DuplicateRegistrationException(string.Format(CultureInfo.InvariantCulture,
                                                                       Resources.RegistrationFormProvider_Step1_WMID__0__already_registered_, identifierValue));
            }

            var connectionString = entranceService.SuggestConnectionString(_identifier) ??
                                   Translator.Instance.Translate(ExtensionCatalog.Registration, "<DB-connection is not supported>");

            var step2Wrapper =
                new RegistrationFormValuesWrapper.Step2 {
                Control5ConnectionString = connectionString
            };

            return(step2Wrapper);
        }