/// <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);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
 /// <summary>
 /// 新建服务
 /// </summary>
 public static int InsertService(CustomServices cusser, int createID)
 {
     cusser.CSState      = 1;
     cusser.CSCreateDate = DateTime.Now;
     cusser.CSCreateID   = createID;
     return(BaseDAL.Insert(cusser));
 }
        public IWebHookStore GetWebHookStore()
        {
            if (_webHookStore == null)
            {
                _webHookStore = CustomServices.GetStore();
            }

            return(_webHookStore);
        }
        public void It_Is_EpiWebHookStore()
        {
            HttpConfiguration config = new HttpConfiguration();

            config.InitializeCustomWebHooksEPiServerStorage();
            IWebHookStore actual = CustomServices.GetStore();

            Assert.IsInstanceOf <EpiWebHookStore>(actual);
        }
        /// <summary>
        /// Gets the set of <see cref="IWebHookFilterProvider"/> instances registered with the Dependency Injection engine
        /// or an empty collection if none are registered.
        /// </summary>
        /// <param name="services">The <see cref="IDependencyScope"/> implementation.</param>
        /// <returns>An <see cref="IEnumerable{T}"/> containing the registered instances.</returns>
        public static IEnumerable <IWebHookFilterProvider> GetFilterProviders(this IDependencyScope services)
        {
            IEnumerable <IWebHookFilterProvider> filterProviders = services.GetServices <IWebHookFilterProvider>();

            if (filterProviders == null || !filterProviders.Any())
            {
                filterProviders = CustomServices.GetFilterProviders();
            }
            return(filterProviders);
        }
Esempio n. 7
0
        private static IWebHookStore CreateStore()
        {
            HttpConfiguration config = new HttpConfiguration();

            config.InitializeCustomWebHooksAzureStorage();
            IWebHookStore store = CustomServices.GetStore();

            Assert.IsType <AzureWebHookStore>(store);
            return(store);
        }
        /// <summary>
        /// Gets an <see cref="IWebHookFilterManager"/> implementation registered with the Dependency Injection engine
        /// or a default implementation if none are registered.
        /// </summary>
        /// <param name="services">The <see cref="IDependencyScope"/> implementation.</param>
        /// <returns>The registered <see cref="IWebHookFilterManager"/> instance or a default implementation if none are registered.</returns>
        public static IWebHookFilterManager GetFilterManager(this IDependencyScope services)
        {
            IWebHookFilterManager filterManager = services.GetService <IWebHookFilterManager>();

            if (filterManager == null)
            {
                IEnumerable <IWebHookFilterProvider> filterProviders = services.GetFilterProviders();
                filterManager = CustomServices.GetFilterManager(filterProviders);
            }
            return(filterManager);
        }
        public static IWebHookSender GetSender(this IDependencyScope services)
        {
            IWebHookSender sender = services.GetService <IWebHookSender>();

            if (sender == null)
            {
                ILogger logger = services.GetLogger();
                sender = CustomServices.GetSender(logger);
            }
            return(sender);
        }
Esempio n. 10
0
        public static IWebHookManager GetManager(this IDependencyResolver services)
        {
            IWebHookManager manager = services.GetService <IWebHookManager>();

            if (manager == null)
            {
                IWebHookStore store  = services.GetStore();
                ILogger       logger = services.GetLogger();
                manager = CustomServices.GetManager(store, logger);
            }
            return(manager);
        }
Esempio n. 11
0
        public void InitializeStore_SetsStore()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();

            // Act
            config.InitializeCustomWebHooksAzureStorage();
            IWebHookStore actual = CustomServices.GetStore();

            // Assert
            Assert.IsType <AzureWebHookStore>(actual);
        }
Esempio n. 12
0
 public int InsertService(CustomServices cusser)
 {
     if (Session["user"] == null)
     {
         return(-1000);
     }
     if (!PowerDAL.HasPower((Session["user"] as Users).RoleID.Value, 10))
     {
         return(-1001);
     }
     return(CustomServicesDAL.InsertService(cusser, (Session["user"] as Users).UserID));
 }
Esempio n. 13
0
        public void Initialize_SetsStore_WithCustomSettings(string nameOrConnectionString, string schemaName, string tableName)
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();

            // Act
            config.InitializeCustomWebHooksSqlStorage(true, nameOrConnectionString, schemaName, tableName);
            IWebHookStore actual = CustomServices.GetStore();

            // Assert
            Assert.IsType <SqlWebHookStore>(actual);
        }
        public IWebHookManager GetHookManager()
        {
            if (_webHookManager == null || _webHookStore.GetType() != typeof(SqlWebHookStore))
            {
                ILogger logger = new TraceLogger();
                _webHookStore = CustomServices.GetStore();
                IWebHookSender sender = new ApiWebHookSender(logger);

                _webHookManager = new WebHookManager(_webHookStore, sender, logger);
            }

            return(_webHookManager);
        }
        public void Initialize_SetSender()
        {
            //Arrange
            HttpConfiguration config = new HttpConfiguration();
            ILogger           logger = new TraceLogger();

            //Act
            config.InitializeAuthenticatedWebHooksSender();
            IWebHookSender actual = CustomServices.GetSender(logger);

            //Assert
            Assert.IsInstanceOfType(actual, typeof(AuthorizedWebHookSender));
        }
Esempio n. 16
0
        public void InitializeSender_SetsSender()
        {
            // Arrange
            ILogger           logger = new Mock <ILogger>().Object;
            HttpConfiguration config = new HttpConfiguration();

            // Act
            config.InitializeCustomWebHooksAzureQueueSender();
            IWebHookSender actual = CustomServices.GetSender(logger);

            // Assert
            Assert.IsType <AzureWebHookSender>(actual);
        }
Esempio n. 17
0
        public IWebHookManager GetHookManager()
        {
            if (_webHookManager == null)
            {
                ILogger        logger = new TraceLogger();
                IWebHookStore  store  = CustomServices.GetStore();
                IWebHookSender sender = new ApiWebHookSender(logger);

                _webHookManager = new WebHookManager(store, sender, logger);
            }

            return(_webHookManager);
        }
Esempio n. 18
0
        /// <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);
        }
Esempio n. 19
0
        public static IWebHookRegistrationsManager GetRegistrationsManager(this IDependencyScope services)
        {
            IWebHookRegistrationsManager registrationsManager = services.GetService <IWebHookRegistrationsManager>();

            if (registrationsManager == null)
            {
                IWebHookManager       manager       = services.GetManager();
                IWebHookStore         store         = services.GetStore();
                IWebHookFilterManager filterManager = services.GetFilterManager();
                IWebHookUser          userManager   = services.GetUser();
                registrationsManager = CustomServices.GetRegistrationsManager(manager, store, filterManager, userManager);
            }
            return(registrationsManager);
        }
Esempio n. 20
0
        /// <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 InitializeCustomWebHooksAzureQueueSender(this HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            ILogger            logger   = config.DependencyResolver.GetLogger();
            SettingsDictionary settings = config.DependencyResolver.GetSettings();

            IStorageManager storageManager = StorageManager.GetInstance(logger);
            IWebHookSender  sender         = new AzureWebHookSender(storageManager, settings, logger);

            CustomServices.SetSender(sender);
        }
Esempio n. 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        public static void InitializeAuthenticatedWebHooksSender(this HttpConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            WebHooksConfig.Initialize(config);

            ILogger    logger = config.DependencyResolver.GetLogger();
            HttpClient client = config.DependencyResolver.GetService <HttpClient>();

            // setting the custom sender
            IWebHookSender sender = new AuthorizedWebHookSender(logger, client);

            CustomServices.SetSender(sender);
        }
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            var controllerType = typeof(WebHookReceiversController);

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new
            {
                id = RouteParameter.Optional
            }
                );

            // Load Azure Storage or SQL for persisting subscriptions
            // config.InitializeCustomWebHooksAzureStorage();
            // config.InitializeCustomWebHooksSqlStorage();

            // Load Azure Queued Sender for enqueueing outgoing WebHooks to an Azure Storage Queue
            // config.InitializeCustomWebHooksAzureQueueSender();

            // Uncomment the following to set a custom WebHook sender where you can control how you want
            // the outgoing WebHook request to look.
            ILogger        logger = CommonServices.GetLogger();
            IWebHookSender sender = new TestWebhookSender(logger);

            CustomServices.SetSender(sender);

            // Load basic support for sending WebHooks
            config.InitializeCustomWebHooks();

            // Load Web API controllers for managing subscriptions
            config.InitializeCustomWebHooksApis();

            config.InitializeReceiveCustomWebHooks();

            config.EnsureInitialized();

            var webhookRoutes = config.Routes;

            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/octet-stream"));
        }
        public IWebHookStore GetWebHookStore()
        {
            if (_webHookStore == null)
            {
                var dataSettings = _configManagerHelper.DataSettings;
                Microsoft.AspNet.WebHooks.Config.SettingsDictionary settings = new Microsoft.AspNet.WebHooks.Config.SettingsDictionary();
                settings.Add("MS_SqlStoreConnectionString", dataSettings.DataConnectionString);
                settings.Connections.Add("MS_SqlStoreConnectionString", new Microsoft.AspNet.WebHooks.Config.ConnectionSettings("MS_SqlStoreConnectionString", dataSettings.DataConnectionString));

                Microsoft.AspNet.WebHooks.IWebHookStore store = new Microsoft.AspNet.WebHooks.SqlWebHookStore(settings, _logger);

                Microsoft.AspNet.WebHooks.Services.CustomServices.SetStore(store);

                _webHookStore = CustomServices.GetStore();
            }

            return(_webHookStore);
        }
Esempio n. 24
0
        /// <summary>
        /// 更改分配人
        /// </summary>
        public static int UpdateCSDueMan(int?csDueID, int csID)
        {
            CustomServices cs = BaseDAL.Find <CustomServices>(csID);

            if (csDueID == null)
            {
                cs.CSState   = 1;
                cs.CSDueID   = null;
                cs.CSDueDate = null;
            }
            else
            {
                cs.CSState   = 2;
                cs.CSDueID   = csDueID;
                cs.CSDueDate = DateTime.Now;
            }

            return(BaseDAL.Update(cs));
        }
Esempio n. 25
0
        /// <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);
        }
Esempio n. 26
0
        private static IWebHookStore CreateStore()
        {
            // Delete any existing DB
            string connectionString = ConfigurationManager.ConnectionStrings[WebHookStoreContext.ConnectionStringName].ConnectionString;

            Database.Delete(connectionString);

            // Initialize DB using code first migration
            var dbConfig = new EF.Configuration();
            var migrator = new DbMigrator(dbConfig);

            migrator.Update();

            HttpConfiguration config = new HttpConfiguration();

            config.InitializeCustomWebHooksSqlStorage(encryptData: false);
            IWebHookStore store = CustomServices.GetStore();

            Assert.IsType <SqlWebHookStore>(store);
            return(store);
        }
Esempio n. 27
0
        /// <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);
        }
Esempio n. 28
0
        /// <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>
        /// Gets an <see cref="IWebHookUser"/> implementation registered with the Dependency Injection engine
        /// or a default implementation if none are registered.
        /// </summary>
        /// <param name="services">The <see cref="IDependencyScope"/> implementation.</param>
        /// <returns>The registered <see cref="IWebHookUser"/> instance or a default implementation if none are registered.</returns>
        public static IWebHookUser GetUser(this IDependencyScope services)
        {
            IWebHookUser userId = services.GetService <IWebHookUser>();

            return(userId ?? CustomServices.GetUser());
        }
        /// <summary>
        /// Gets an <see cref="IWebHookStore"/> implementation registered with the Dependency Injection engine
        /// or a default implementation if none are registered.
        /// </summary>
        /// <param name="services">The <see cref="IDependencyScope"/> implementation.</param>
        /// <returns>The registered <see cref="IWebHookStore"/> instance or a default implementation if none are registered.</returns>
        public static IWebHookStore GetStore(this IDependencyScope services)
        {
            IWebHookStore store = services.GetService <IWebHookStore>();

            return(store ?? CustomServices.GetStore());
        }