コード例 #1
0
        public static void Run(AddClientCertArgs args, Func <ILogger> getLogger)
        {
            args.Validate();
            var settings = RunnerHelper.GetSettings(args.Configfile);
            var clientCertificateProvider = new ClientCertificateProvider(settings);

            var item = clientCertificateProvider.GetClientCertificate(args.PackageSource);

            if (item != null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          Strings.Error_ClientCertificateAlreadyExist,
                                                          args.PackageSource));
            }

            if (args.IsFileCertSettingsProvided())
            {
                item = new FileClientCertItem(args.PackageSource,
                                              args.Path,
                                              args.Password,
                                              args.StorePasswordInClearText,
                                              args.Configfile);
            }
            else if (args.IsStoreCertSettingsProvided())
            {
                item = new StoreClientCertItem(args.PackageSource,
                                               args.FindValue,
                                               args.GetStoreLocation(),
                                               args.GetStoreName(),
                                               args.GetFindBy());
            }
            else
            {
                throw new CommandLineArgumentCombinationException(string.Format(CultureInfo.CurrentCulture,
                                                                                Strings.Error_UnknownClientCertificateStoreType));
            }

            try
            {
                var certificates = item.Search();
                if (!certificates.Any())
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.Error_ClientCertificatesNotFound));
                }
            }
            catch
            {
                if (!args.Force)
                {
                    throw;
                }
            }


            clientCertificateProvider.AddOrUpdate(item);

            getLogger().LogInformation(string.Format(CultureInfo.CurrentCulture, Strings.ClientCertificateSuccessfullyAdded, args.PackageSource));
        }
コード例 #2
0
        public static void Validate(this AddClientCertArgs args)
        {
            if (!args.IsPackageSourceSettingProvided())
            {
                throw new CommandLineArgumentCombinationException(string.Format(CultureInfo.CurrentCulture,
                                                                                Strings.Error_PropertyCannotBeNullOrEmpty,
                                                                                nameof(PackageSource)));
            }

            if (args.IsFileCertSettingsProvided() == args.IsStoreCertSettingsProvided())
            {
                throw new CommandLineArgumentCombinationException(string.Format(CultureInfo.CurrentCulture,
                                                                                Strings.Error_CouldNotUpdateClientCertificate,
                                                                                Strings.Error_InvalidCombinationOfArguments));
            }
        }