/// <summary> /// Configures a Microsoft SQL Server Storage implementation of <see cref="IWebHookStore"/> /// which provides a persistent store for registered WebHooks used by the custom WebHooks module. /// </summary> /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param> /// <param name="encryptData">Indicates whether the data should be encrypted using <see cref="IDataProtector"/> while persisted.</param> public static void InitializeCustomWebHooksSqlStorage(this HttpConfiguration config, bool encryptData) { if (config == null) { throw new ArgumentNullException(nameof(config)); } WebHooksConfig.Initialize(config); ILogger logger = config.DependencyResolver.GetLogger(); SettingsDictionary settings = config.DependencyResolver.GetSettings(); // We explicitly set the DB initializer to null to avoid that an existing DB is initialized wrongly. Database.SetInitializer <WebHookStoreContext>(null); IWebHookStore store; if (encryptData) { IDataProtector protector = DataSecurity.GetDataProtector(); store = new SqlWebHookStore(settings, protector, logger); } else { store = new SqlWebHookStore(settings, logger); } CustomServices.SetStore(store); }
/// <summary> /// Configures a Microsoft Azure Table Storage implementation of <see cref="IWebHookStore"/> /// which provides a persistent store for registered WebHooks used by the custom WebHooks module. /// </summary> /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param> /// <param name="encryptData">Indicates whether the data should be encrypted using <see cref="IDataProtector"/> while persisted.</param> public static void InitializeCustomWebHooksAzureStorage(this HttpConfiguration config, bool encryptData) { if (config == null) { throw new ArgumentNullException(nameof(config)); } WebHooksConfig.Initialize(config); ILogger logger = config.DependencyResolver.GetLogger(); SettingsDictionary settings = config.DependencyResolver.GetSettings(); IStorageManager storageManager = StorageManager.GetInstance(logger); IWebHookStore store; if (encryptData) { IDataProtector protector = DataSecurity.GetDataProtector(); store = new AzureWebHookStore(storageManager, settings, protector, logger); } else { store = new AzureWebHookStore(storageManager, settings, logger); } CustomServices.SetStore(store); }
/// <summary> /// Configures an EPiServer DDS Storage implementation of <see cref="IWebHookStore"/> /// </summary> /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param> public static void InitializeCustomWebHooksEPiServerStorage(this HttpConfiguration config) { if (config == null) { throw new ArgumentNullException("config"); } WebHooksConfig.Initialize(config); ILogger logger = config.DependencyResolver.GetLogger(); IStorageManager storageManager = new StorageManager(logger); IWebHookStore store = new EpiWebHookStore(storageManager, logger); CustomServices.SetStore(store); }
/// <summary> /// Configures a Microsoft Azure Table Storage implementation of <see cref="IWebHookStore"/> /// which provides a persistent store for registered WebHooks used by the custom WebHooks module. /// </summary> /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param> public static void InitializeCustomWebHooksAzureStorage(this HttpConfiguration config) { if (config == null) { throw new ArgumentNullException("config"); } WebHooksConfig.Initialize(config); ILogger logger = config.DependencyResolver.GetLogger(); SettingsDictionary settings = config.DependencyResolver.GetSettings(); IDataProtectionProvider provider = GetDataProtectionProvider(); IDataProtector protector = provider.CreateProtector(Purpose); IStorageManager storageManager = new StorageManager(logger); IWebHookStore store = new AzureWebHookStore(storageManager, settings, protector, logger); CustomServices.SetStore(store); }
/// <summary> /// Configures a Microsoft SQL Server Storage implementation of <see cref="IWebHookStore"/> /// which provides a persistent store for registered WebHooks used by the custom WebHooks module. /// </summary> /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param> public static void InitializeCustomWebHooksSqlStorage(this HttpConfiguration config) { if (config == null) { throw new ArgumentNullException("config"); } WebHooksConfig.Initialize(config); ILogger logger = config.DependencyResolver.GetLogger(); SettingsDictionary settings = config.DependencyResolver.GetSettings(); // We explicitly set the DB initializer to null to avoid that an existing DB is initialized wrongly. Database.SetInitializer <WebHookStoreContext>(null); IDataProtectionProvider provider = GetDataProtectionProvider(); IDataProtector protector = provider.CreateProtector(Purpose); IWebHookStore store = new SqlWebHookStore(settings, protector, logger); CustomServices.SetStore(store); }
/// <summary> /// Configures the MongoDB Storage implementation of <see cref="IWebHookStore"/> /// which provides a persistent store for registered WebHooks used by the custom WebHooks module. /// </summary> /// <param name="config">The current <see cref="HttpConfiguration"/>config.</param> /// <param name="nameOrConnectionString">The name of the connection string application setting. Used to initialize <see cref="WebHookStoreContext"/>.</param> /// <param name="encryptData">Indicates whether the data should be encrypted using <see cref="IDataProtector"/> while persisted.</param> /// <param name="databaseName">The custom name of database schema. Used to initialize <see cref="WebHookStoreContext"/>.</param> /// <param name="collectionName">The custom name of database table. Used to initialize <see cref="WebHookStoreContext"/>.</param> public static void InitializeCustomWebHooksMongoStorage(this HttpConfiguration config, string nameOrConnectionString, bool encryptData, string databaseName, string collectionName) { if (config == null) { throw new ArgumentNullException(nameof(config)); } IWebHookRepository repository; IWebHookStore store; WebHooksConfig.Initialize(config); ILogger logger = config.DependencyResolver.GetLogger(); SettingsDictionary settings = config.DependencyResolver.GetSettings(); if (!string.IsNullOrEmpty(nameOrConnectionString) && string.IsNullOrEmpty(databaseName) && string.IsNullOrEmpty(collectionName)) { repository = new WebHookRepository(new WebHookStoreContext(nameOrConnectionString)); } else if (!string.IsNullOrEmpty(nameOrConnectionString) && !string.IsNullOrEmpty(databaseName) && (!string.IsNullOrEmpty(collectionName) || string.IsNullOrEmpty(collectionName))) { repository = new WebHookRepository(new WebHookStoreContext(nameOrConnectionString, databaseName, collectionName)); } else { repository = new WebHookRepository(new WebHookStoreContext()); } if (encryptData) { IDataProtector protector = DataSecurity.GetDataProtector(); store = new MongoWebHookStore(protector, logger, repository); } else { store = new MongoWebHookStore(logger, repository); } CustomServices.SetStore(store); }