Beispiel #1
0
 public DataImportService(IDatabaseRepository <T> databaseRepository, IXmlRepository fileRepository, T entity)
 {
     this.entityRepository = databaseRepository;
     this.xmlRepository    = fileRepository;
     this.entity           = entity;
     this.MaxNumberOfRowsToBeBulkInserted = 5000;
 }
        /// <summary>
        /// Creates an <see cref="XmlKeyManager"/>.
        /// </summary>
        /// <param name="repository">The repository where keys are stored.</param>
        /// <param name="configuration">Configuration for newly-created keys.</param>
        /// <param name="services">A provider of optional services.</param>
        public XmlKeyManager(
            IXmlRepository repository,
            IAuthenticatedEncryptorConfiguration configuration,
            IServiceProvider services)
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            KeyEncryptor = services.GetService<IXmlEncryptor>(); // optional
            KeyRepository = repository;

            _activator = services.GetActivator(); // returns non-null
            _authenticatedEncryptorConfiguration = configuration;
            _internalKeyManager = services.GetService<IInternalXmlKeyManager>() ?? this;
            _keyEscrowSink = services.GetKeyEscrowSink(); // not required
            _logger = services.GetLogger<XmlKeyManager>(); // not required
            TriggerAndResetCacheExpirationToken(suppressLogging: true);
        }
Beispiel #3
0
        private void ExecuteLoadAsserts(
            IXmlRepository <Person, Guid> repository,
            int totalNumberOfEntities,
            bool isPeterContained,
            bool isGoloContained)
        {
            Assert.That(repository.LoadAll().Count(), Is.EqualTo(totalNumberOfEntities));

            Assert.That(repository.LoadAllBy(p => p.Id == Guid.Empty).Count(), Is.EqualTo(0));
            Assert.That(() => repository.LoadBy(p => p.Id == Guid.Empty), Throws.Exception);

            Assert.That(repository.LoadAllBy(p => p.Id == this._peter.Id).Count(), Is.EqualTo(isPeterContained ? 1 : 0));
            if (isPeterContained)
            {
                Assert.That(repository.LoadBy(p => p.Id == this._peter.Id).LastName, Is.EqualTo(this._peter.LastName));
            }
            else
            {
                Assert.That(() => repository.LoadBy(p => p.Id == this._peter.Id), Throws.Exception);
            }

            Assert.That(repository.LoadAllBy(p => p.Id == this._golo.Id).Count(), Is.EqualTo(isGoloContained ? 1 : 0));
            if (isGoloContained)
            {
                Assert.That(repository.LoadBy(p => p.Id == this._golo.Id).LastName, Is.EqualTo(this._golo.LastName));
            }
            else
            {
                Assert.That(() => repository.LoadBy(p => p.Id == this._golo.Id), Throws.Exception);
            }
        }
        /// <summary>
        /// Creates an <see cref="XmlKeyManager"/>.
        /// </summary>
        /// <param name="repository">The repository where keys are stored.</param>
        /// <param name="configuration">Configuration for newly-created keys.</param>
        /// <param name="services">A provider of optional services.</param>
        public XmlKeyManager(
            IXmlRepository repository,
            IAuthenticatedEncryptorConfiguration configuration,
            IServiceProvider services)
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            KeyEncryptor  = services.GetService <IXmlEncryptor>(); // optional
            KeyRepository = repository;

            _activator = services.GetActivator(); // returns non-null
            _authenticatedEncryptorConfiguration = configuration;
            _internalKeyManager = services.GetService <IInternalXmlKeyManager>() ?? this;
            _keyEscrowSink      = services.GetKeyEscrowSink();          // not required
            _logger             = services.GetLogger <XmlKeyManager>(); // not required
            TriggerAndResetCacheExpirationToken(suppressLogging: true);
        }
Beispiel #5
0
 private void Check()
 {
     KeyRepository = _keyManagementOptions.Value.XmlRepository;
     if (KeyRepository == null)
     {
         KeyRepository = GetFallbackKeyRepositoryEncryptorPair();
     }
 }
Beispiel #6
0
 public XmlController(IXmlRepository xmlRepository)
 {
     if (xmlRepository == null)
     {
         throw new ArgumentNullException("xmlRepository is null");
     }
     _xmlRepository = xmlRepository;
 } 
 public SettingsController(string extPath,
                           IVsProfileDataManager manager,
                           IXmlRepository xmlRepository)
 {
     _fullPath      = Path.Combine(extPath, FileName);
     _manager       = manager;
     _xmlRepository = xmlRepository;
 }
Beispiel #8
0
 public XmlController(IXmlRepository xmlRepository)
 {
     if (xmlRepository == null)
     {
         throw new ArgumentNullException("xmlRepository is null");
     }
     _xmlRepository = xmlRepository;
 }
 public void Setup()
 {
     _manager          = Mock.Create <IVsProfileDataManager>();
     _errorInformation = Mock.Create <IVsSettingsErrorInformation>();
     _files            = Mock.Create <IVsProfileSettingsFileCollection>();
     _xmlRepository    = Mock.Create <IXmlRepository>();
     _settingsFileInfo = Mock.Create <IVsProfileSettingsFileInfo>();
     _sets             = Mock.Create <IVsProfileSettingsTree>();
 }
Beispiel #10
0
        public XmlPolicyStore(string storeName, IXmlRepository repository)
        {
            if (string.IsNullOrEmpty(storeName))
            {
                throw new ArgumentException(string.Empty, "storeName");
            }

            this.storeName = storeName;
            this.repository = repository;
        }
Beispiel #11
0
        public XmlPolicyStore(string storeName, IXmlRepository repository)
        {
            if (string.IsNullOrEmpty(storeName))
            {
                throw new ArgumentException(string.Empty, "storeName");
            }

            this.storeName  = storeName;
            this.repository = repository;
        }
        public HomeController(IKeyManager keyManager, IConfiguration configuration, ILoggerFactory loggerFactory)
        {
            _keyring = new AzureKeyVaultKeyRingRepository(
                keyRingName: configuration["DataProtection:KeyRingName"],
                vaultUrl: configuration["Vault:Url"],
                clientId: configuration["Vault:ClientId"],
                tenantId: configuration["Vault:TenantId"],
                secret: configuration["Vault:Secret"],
                loggerFactory: loggerFactory);

            _keyManager = keyManager;
        }
 public XmlKeyManager(
     [NotNull] IServiceProvider serviceProvider,
     [NotNull] IAuthenticatedEncryptorConfigurationFactory authenticatedEncryptorConfigurationFactory,
     [NotNull] ITypeActivator typeActivator,
     [NotNull] IXmlRepository xmlRepository,
     [NotNull] IXmlEncryptor xmlEncryptor)
 {
     _serviceProvider = serviceProvider;
     _authenticatedEncryptorConfigurationFactory = authenticatedEncryptorConfigurationFactory;
     _typeActivator = typeActivator;
     _xmlRepository = xmlRepository;
     _xmlEncryptor  = xmlEncryptor;
 }
Beispiel #14
0
        private static void ImportStackOverflowEntities(IXmlRepository xmlRepository, DatabaseDetails databaseDetails, Logger logger)
        {
            Import <TagEntity>(xmlRepository, databaseDetails, logger);

            Import <UserEntity>(xmlRepository, databaseDetails, logger);

            Import <BadgeEntity>(xmlRepository, databaseDetails, logger);

            Import <VoteEntity>(xmlRepository, databaseDetails, logger);

            Import <CommentEntity>(xmlRepository, databaseDetails, logger);

            Import <PostEntity>(xmlRepository, databaseDetails, logger);
        }
        public PasswordResetSteps(ScenarioContext context, Settings settings)
        {
            _context  = context;
            _settings = settings;

            _keyRepository = new FileSystemXmlRepository(_keysDirectory, NullLoggerFactory.Instance);
            var provider = DataProtectionProvider.Create(
                _keysDirectory,
                b => b.SetApplicationName(settings.DataProtectionAppName));

            _dataProtectionProvider = new DataProtectorTokenProvider <IdentityUser>(
                provider,
                null,
                new Logger <DataProtectorTokenProvider <IdentityUser> >(NullLoggerFactory.Instance));
        }
Beispiel #16
0
        private static void Import <T>(IXmlRepository xmlRepository, DatabaseDetails databaseConnectionDetails, Logger logger)
            where T : IStackOverflowEntity, new()
        {
            IDatabaseRepository <T> repository =
                new DatabaseRepositoryStrategy <T>(databaseConnectionDetails).GetDatabaseRepository();

            T entity =
                new T();

            IDataImportService <T> dataImportService =
                new DataImportServiceLogger <T>(logger,
                                                new DataImportService <T>(repository, xmlRepository, entity));

            dataImportService.ImportData();
        }
Beispiel #17
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            this._userMappings = new Dictionary <Type, IList <IPropertyMapping> >();

            this._mappedRepository = XmlRepository
                                     .XmlRepository
                                     .Get(
                RepositoryFor <Article>
                .WithIdentity(p => p.Id)
                .WithMappings(this._userMappings)
                .WithDataProvider(new InMemoryDataProvider(this.txtDefault.Text)));

            this.LoadMappingList(true);
        }
Beispiel #18
0
        /// <summary>
        /// 显示城市
        /// </summary>
        /// <param name="pid">省份名称</param>
        /// <returns>城市模型集合</returns>
        public IList <CityModel> DisplayCitys(int pid)
        {
            IList <CityModel> targets = new List <CityModel>();

            IXmlRepository rep = Factory.Factory <IXmlRepository> .GetConcrete();

            foreach (City c in rep.Select("ID", pid.ToString()))
            {
                CityModel model = new CityModel();
                model.CityName = c.Name;

                targets.Add(model);
            }

            return(targets);
        }
Beispiel #19
0
        /// <summary>
        /// 显示省份
        /// </summary>
        /// <returns>省份模型集合</returns>
        public IList <ProvinceModel> DisplayProvinces()
        {
            IList <ProvinceModel> targets = new List <ProvinceModel>();

            IXmlRepository rep = Factory.Factory <IXmlRepository> .GetConcrete();

            var x = rep.FindAll();

            foreach (Province p in x)
            {
                ProvinceModel instance = new ProvinceModel();
                instance.ProvinceName = p.Name;
                instance.ProvinceID   = p.ID;
                targets.Add(instance);
            }

            return(targets);
        }
Beispiel #20
0
 public SponsorRepository(IXmlRepository xmlRepository)
 {
     this.xmlRepository = xmlRepository;
     this.xmlRepository.DataChangedEventHandler += (o, e) => allSponsors = null;
 }
Beispiel #21
0
 public ParcelService(IMailHandlersConfiguration configuration, IXmlRepository repository, ICriteria criteria)
 {
     _repository    = repository;
     _criteria      = criteria;
     _configuration = configuration;
 }
 public DataProtectionOptionsConfigurator(IXmlRepository repository)
 {
     _repository = repository;
 }
        /// <summary>
        /// Configures the data protection system to persist keys to the custom repository configured in the application.
        /// </summary>
        /// <param name="builder">The <see cref="IDataProtectionBuilder"/>.</param>
        /// <param name="repository">Custom repository</param>
        /// <returns>A reference to the <see cref="IDataProtectionBuilder" /> after this operation has completed.</returns>
        public static IDataProtectionBuilder PersistKeysToCustomXmlRepository(this IDataProtectionBuilder builder, IXmlRepository repository)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddSingleton <IConfigureOptions <KeyManagementOptions> >(services =>
            {
                return(new ConfigureOptions <KeyManagementOptions>(options =>
                {
                    options.XmlRepository = repository;
                }));
            });

            return(builder);
        }
Beispiel #24
0
 public MemberRepository(IXmlRepository xmlRepository)
 {
     this.xmlRepository = xmlRepository;
     this.xmlRepository.DataChangedEventHandler += (o, e) => allMembers = null;
 }
Beispiel #25
0
 public FacilityRepository(IXmlRepository xmlRepository)
 {
     this.xmlRepository = xmlRepository;
     this.xmlRepository.DataChangedEventHandler += (o, e) => allFacilities = null;
 }
Beispiel #26
0
 public UbfService(IUbfRepository ubfRepository, IXmlRepository xmlRepository, IMessageRepository <Guid> messageRepository)
 {
     _ubfRepository     = ubfRepository;
     _xmlRepository     = xmlRepository;
     _messageRepository = messageRepository;
 }
Beispiel #27
0
        internal KeyValuePair <IXmlRepository, IXmlEncryptor> GetFallbackKeyRepositoryEncryptorPair()
        {
            IXmlRepository repository = null;
            IXmlEncryptor  encryptor  = null;

            // If we're running in Azure Web Sites, the key repository goes in the %HOME% directory.
            var azureWebSitesKeysFolder = _keyStorageDirectories.GetKeyStorageDirectoryForAzureWebSites();

            if (azureWebSitesKeysFolder != null)
            {
                _logger.UsingAzureAsKeyRepository(azureWebSitesKeysFolder.FullName);

                // Cloud DPAPI isn't yet available, so we don't encrypt keys at rest.
                // This isn't all that different than what Azure Web Sites does today, and we can always add this later.
                repository = new FileSystemXmlRepository(azureWebSitesKeysFolder, _loggerFactory);
            }
            else
            {
                // If the user profile is available, store keys in the user profile directory.
                var localAppDataKeysFolder = _keyStorageDirectories.GetKeyStorageDirectory();
                if (localAppDataKeysFolder != null)
                {
                    if (OSVersionUtil.IsWindows())
                    {
                        Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); // Hint for the platform compatibility analyzer.

                        // If the user profile is available, we can protect using DPAPI.
                        // Probe to see if protecting to local user is available, and use it as the default if so.
                        encryptor = new DpapiXmlEncryptor(
                            protectToLocalMachine: !DpapiSecretSerializerHelper.CanProtectToCurrentUserAccount(),
                            loggerFactory: _loggerFactory);
                    }
                    repository = new FileSystemXmlRepository(localAppDataKeysFolder, _loggerFactory);

                    if (encryptor != null)
                    {
                        _logger.UsingProfileAsKeyRepositoryWithDPAPI(localAppDataKeysFolder.FullName);
                    }
                    else
                    {
                        _logger.UsingProfileAsKeyRepository(localAppDataKeysFolder.FullName);
                    }
                }
                else
                {
                    // Use profile isn't available - can we use the HKLM registry?
                    RegistryKey regKeyStorageKey = null;
                    if (OSVersionUtil.IsWindows())
                    {
                        Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); // Hint for the platform compatibility analyzer.
                        regKeyStorageKey = RegistryXmlRepository.DefaultRegistryKey;
                    }
                    if (regKeyStorageKey != null)
                    {
                        Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); // Hint for the platform compatibility analyzer.
                        regKeyStorageKey = RegistryXmlRepository.DefaultRegistryKey;

                        // If the user profile isn't available, we can protect using DPAPI (to machine).
                        encryptor  = new DpapiXmlEncryptor(protectToLocalMachine: true, loggerFactory: _loggerFactory);
                        repository = new RegistryXmlRepository(regKeyStorageKey, _loggerFactory);

                        _logger.UsingRegistryAsKeyRepositoryWithDPAPI(regKeyStorageKey.Name);
                    }
                    else
                    {
                        // Final fallback - use an ephemeral repository since we don't know where else to go.
                        // This can only be used for development scenarios.
                        repository = new EphemeralXmlRepository(_loggerFactory);

                        _logger.UsingEphemeralKeyRepository();
                    }
                }
            }

            return(new KeyValuePair <IXmlRepository, IXmlEncryptor>(repository, encryptor));
        }
Beispiel #28
0
 public XmlConfigurationService(IXmlRepository configurationRepository)
 {
     _configurationRepository.TraceEventHandler += ConfigurationRepository_EventHandler;
 }
Beispiel #29
0
 public XmlRepositoryController(IXmlRepository xmlRepository)
 {
     _xmlRepository = xmlRepository;
 }