public static void Main(string[] args) { // Set up default WebHook logger ILogger logger = new TraceLogger(); // Set the WebHook Store we want to get WebHook subscriptions from. Azure store requires // a valid Azure Storage connection string named MS_AzureStoreConnectionString. IWebHookStore store = AzureWebHookStore.CreateStore(logger); // Set the sender we want to actually send out the WebHooks. We could also // enqueue messages for scale out. IWebHookSender sender = new DataflowWebHookSender(logger); // Set up WebHook manager which we use for creating notifications. Manager = new WebHookManager(store, sender, logger); // Initialize WebJob var listener = ConfigurationManager.ConnectionStrings["WebHookListener"].ConnectionString; JobHostConfiguration config = new JobHostConfiguration { StorageConnectionString = listener }; JobHost host = new JobHost(config); host.RunAndBlock(); }
public static IWebHookRegistrationsManager GetRegistrationsManager(IWebHookManager manager, IWebHookStore store, IWebHookFilterManager filterManager, IWebHookUser userManager) { if (_registrationsManager != null) { return(_registrationsManager); } if (manager == null) { throw new ArgumentNullException(nameof(manager)); } if (store == null) { throw new ArgumentNullException(nameof(store)); } if (filterManager == null) { throw new ArgumentNullException(nameof(filterManager)); } if (userManager == null) { throw new ArgumentNullException(nameof(userManager)); } IWebHookRegistrationsManager instance = new WebHookRegistrationsManager(manager, store, filterManager, userManager); Interlocked.CompareExchange(ref _registrationsManager, instance, null); return(_registrationsManager); }
public WebHookRegistrationsController(IWebHookManager manager, IWebHookStore store, ILogger <WebHookRegistrationsController> logger, IEnumerable <IWebHookFilterProvider> providers) { if (manager == null) { throw new ArgumentNullException("manager"); } if (store == null) { throw new ArgumentNullException("store"); } if (logger == null) { throw new ArgumentNullException("logger"); } if (providers == null) { throw new ArgumentNullException("providers"); } _manager = manager; _store = store; _logger = logger; _providers = providers; }
public WebHookRegistrationsController(IJsonFieldsSerializer jsonFieldsSerializer, IAclService aclService, ICustomerService customerService, IStoreMappingService storeMappingService, IStoreService storeService, IDiscountService discountService, ICustomerActivityService customerActivityService, ILocalizationService localizationService, IPictureService pictureService, IStoreContext storeContext, IWebHookService webHookService, IHttpContextAccessor httpContextAccessor, IClientStore clientStore) : base(jsonFieldsSerializer, aclService, customerService, storeMappingService, storeService, discountService, customerActivityService, localizationService, pictureService) { _storeContext = storeContext; _manager = webHookService.GetWebHookManager(); _store = webHookService.GetWebHookStore(); _filterManager = webHookService.GetWebHookFilterManager(); _httpContextAccessor = httpContextAccessor; _clientStore = clientStore; }
static void Main(string[] args) { Console.WriteLine("Hit ENTER to create a RequestBin for your callback url"); Console.ReadLine(); System.Diagnostics.Process.Start("http://requestb.in"); Console.WriteLine("\nPaste the bin url for your RequestBin below:"); myRequestBin = Console.ReadLine(); whStore = new MemoryWebHookStore(); /// A WebHookManager is used to send a webhook request. /// WebHookManager requires a WebHookStore for tracking subscriptions. /// WebHookManager also uses an ILogger-type object as a diagnostics logger. whManager = new WebHookManager(whStore, new TraceLogger()); Console.WriteLine("\n\nRegistering a Subscriber with WebHookManager"); registerWebhook(); Console.WriteLine("\nHit ENTER to fire your webhook"); Console.ReadLine(); fireWebhook().Wait(); Console.WriteLine("\nTracelog is at " + new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName + "\\trace.log"); Console.WriteLine("Hit ENTER to view the notification in RequestBin"); Console.ReadLine(); System.Diagnostics.Process.Start(myRequestBin + "?inspect"); }
/// <summary> /// For testing purposes /// </summary> internal static void Reset() { _filterManager = null; _manager = null; _filterProviders = null; _store = null; }
/// <summary> /// Submits a notification to all matching registered WebHooks. To match, the <see cref="WebHook"/> must be registered by the /// current <see cref="ControllerBase.User"/> and have a filter that matches one or more of the actions provided for the notification. /// </summary> /// <param name="controller">The <see cref="ControllerBase"/> instance.</param> /// <param name="notifications">The set of notifications to include in the WebHook.</param> /// <param name="predicate">A function to test each <see cref="WebHook"/> to see whether it fulfills the condition. The /// predicate is passed the <see cref="WebHook"/> and the user who registered it. If the predicate returns <c>true</c> then /// the <see cref="WebHook"/> is included; otherwise it is not.</param> /// <returns>The number of <see cref="WebHook"/> instances that were selected and subsequently notified about the actions.</returns> public static async Task <int> NotifyAsync(this ControllerBase controller, IEnumerable <NotificationDictionary> notifications, Func <WebHook, string, bool> predicate) { if (controller == null) { throw new ArgumentNullException(nameof(controller)); } if (notifications == null) { throw new ArgumentNullException(nameof(notifications)); } if (!notifications.Any()) { return(0); } // Get the User ID from the User principal IWebHookUser user = controller.HttpContext.RequestServices.GetUser(); string userId = await user.GetUserIdAsync(controller.User); // Send a notification to registered WebHooks with matching filters IWebHookManager manager = controller.HttpContext.RequestServices.GetManager(); return(await manager.NotifyAsync(userId, notifications, predicate)); }
/// <summary> /// Submits a notification to all matching registered WebHooks across all users. To match, the <see cref="WebHook"/> must /// have a filter that matches one or more of the actions provided for the notification. /// </summary> /// <param name="manager">The <see cref="IWebHookManager"/> instance.</param> /// <param name="notifications">The set of notifications to include in the WebHook.</param> /// <returns>The number of <see cref="WebHook"/> instances that were selected and subsequently notified about the actions.</returns> public static Task <int> NotifyAllAsync(this IWebHookManager manager, params NotificationDictionary[] notifications) { if (manager == null) { throw new ArgumentNullException(nameof(manager)); } return(manager.NotifyAllAsync(notifications, predicate: null)); }
public void GetManager_ReturnsDefaultInstance_IfNoneRegistered() { // Act IWebHookManager actual = _resolverMock.Object.GetManager(); // Assert Assert.IsType <WebHookManager>(actual); }
/// <inheritdoc /> protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); _manager = Configuration.DependencyResolver.GetManager(); _store = Configuration.DependencyResolver.GetStore(); _user = Configuration.DependencyResolver.GetUser(); }
public WebHookEventConsumer() { IWebHookService webHookService = EngineContext.Current.ContainerManager.Resolve <IWebHookService>(); _customerApiService = EngineContext.Current.ContainerManager.Resolve <ICustomerApiService>(); _dtoHelper = EngineContext.Current.ContainerManager.Resolve <IDTOHelper>(); _webHookManager = webHookService.GetHookManager(); }
/// <summary> /// For testing purposes /// </summary> internal static void Reset() { _filterManager = null; _store = null; _sender = null; _manager = null; _registrationsManager = null; _user = null; }
public IWebHookManager GetWebHookManager() { if (_webHookManager == null) { _webHookManager = new WebHookManager(GetWebHookStore(), GetWebHookSender(), _logger); } return(_webHookManager); }
static void Main(string[] args) { _whStore = new MemoryWebHookStore(); _whManager = new WebHookManager(_whStore, new TraceLogger()); SubscribeNewUser(); SendWebhookAsync().Wait(); Console.ReadLine(); }
/// <summary> /// Submits a notification to all matching registered WebHooks across all users. To match, the <see cref="WebHook"/> must /// have a filter that matches one or more of the actions provided for the notification. /// </summary> /// <param name="manager">The <see cref="IWebHookManager"/> instance.</param> /// <param name="action">The action describing the notification.</param> /// <param name="data">Optional additional data to include in the WebHook request.</param> /// <param name="predicate">A function to test each <see cref="WebHook"/> to see whether it fulfills the condition. The /// predicate is passed the <see cref="WebHook"/> and the user who registered it. If the predicate returns <c>true</c> then /// the <see cref="WebHook"/> is included; otherwise it is not.</param> /// <returns>The number of <see cref="WebHook"/> instances that were selected and subsequently notified about the actions.</returns> public static Task <int> NotifyAllAsync(this IWebHookManager manager, string action, object data, Func <WebHook, string, bool> predicate) { if (manager == null) { throw new ArgumentNullException(nameof(manager)); } var notifications = new NotificationDictionary[] { new NotificationDictionary(action, data) }; return(manager.NotifyAllAsync(notifications, predicate)); }
/// <inheritdoc /> protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); // The Microsoft.AspNet.WebHooks library registeres an extension method for the DependencyResolver. // Sadly we cannot access these properties by using out Autofac dependency injection. // In order to access them we have to resolve them through the Configuration. _manager = Configuration.DependencyResolver.GetManager(); _store = Configuration.DependencyResolver.GetStore(); _user = Configuration.DependencyResolver.GetUser(); }
public void GetManager_ReturnsDefaultInstance_IfNoneRegistered() { // Arrange _config.InitializeCustomWebHooks(); // Act IWebHookManager actual = _resolverMock.Object.GetManager(); // Assert Assert.IsType <WebHookManager>(actual); }
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); }
/// <summary> /// Send Notification to register clients /// </summary> /// <param name="product">product code</param> /// <param name="productName"> New Product Name</param> /// <returns></returns> private static async Task SendWebhookContentChangedAsync(string product, string productName) { string eventName = "contentschanged"; var notifications = new List <NotificationDictionary> { new NotificationDictionary(eventName, new { id = product, name = productName }) }; // Send a notification to registered WebHooks with matching filters IWebHookManager manager = DependencyResolver.Current.GetManager(); //ToDo: get all subscribers var x = await manager.NotifyAsync("admin", notifications); }
public void GetManager_ReturnsSameInstance_IfNoneRegistered() { // Arrange _config.InitializeCustomWebHooks(); // Act IWebHookManager actual1 = _resolverMock.Object.GetManager(); IWebHookManager actual2 = _resolverMock.Object.GetManager(); // Assert Assert.Same(actual1, actual2); }
public void GetManager_ReturnsSingleInstance() { // Arrange ILogger logger = CommonServices.GetLogger(); IWebHookStore store = CustomServices.GetStore(); // Act IWebHookManager actual1 = CustomServices.GetManager(store, logger); IWebHookManager actual2 = CustomServices.GetManager(store, logger); // Assert Assert.Same(actual1, actual2); }
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 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); }
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); }
public WebHookRegistrationsController( IJsonFieldsSerializer jsonFieldsSerializer, IAclService aclService, IUserService userService, ITenantMappingService tenantMappingService, ITenantService tenantService, IUserActivityService userActivityService, IWebHookService webHookService, IHttpContextAccessor httpContextAccessor) : base(jsonFieldsSerializer, aclService, userService, tenantMappingService, tenantService, userActivityService) { _manager = webHookService.GetWebHookManager(); _store = webHookService.GetWebHookStore(); _filterManager = webHookService.GetWebHookFilterManager(); _httpContextAccessor = httpContextAccessor; }
public WebHooksController(IWebHookSearchService webHookSearchService, IWebHookFeedSearchService webHookFeedSearchService, IWebHookService webHookService, IWebHookManager webHookManager, IRegisteredEventStore registeredEventStore, IWebHookFeedService webHookFeedService, IWebHookFeedReader webHookFeedReader) { _webHookSearchService = webHookSearchService; _webHookFeedSearchService = webHookFeedSearchService; _webHookService = webHookService; _webHookManager = webHookManager; _registeredEventStore = registeredEventStore; _webHookFeedService = webHookFeedService; _webHookFeedReader = webHookFeedReader; }
public void GetManager_ReturnsDependencyInstance_IfRegistered() { // Arrange Mock <IWebHookManager> instanceMock = new Mock <IWebHookManager>(); _resolverMock.Setup(r => r.GetService(typeof(IWebHookManager))) .Returns(instanceMock.Object) .Verifiable(); // Act IWebHookManager actual = _resolverMock.Object.GetManager(); // Assert Assert.Same(instanceMock.Object, actual); instanceMock.Verify(); }
public WebHookEventConsumer(IStoreService storeService) { IWebHookService webHookService = EngineContext.Current.ContainerManager.Resolve <IWebHookService>(); _customerApiService = EngineContext.Current.ContainerManager.Resolve <ICustomerApiService>(); _categoryApiService = EngineContext.Current.ContainerManager.Resolve <ICategoryApiService>(); _productApiService = EngineContext.Current.ContainerManager.Resolve <IProductApiService>(); _dtoHelper = EngineContext.Current.ContainerManager.Resolve <IDTOHelper>(); _storeService = EngineContext.Current.ContainerManager.Resolve <IStoreService>(); _productService = EngineContext.Current.ContainerManager.Resolve <IProductService>(); _categoryService = EngineContext.Current.ContainerManager.Resolve <ICategoryService>(); _storeMappingService = EngineContext.Current.ContainerManager.Resolve <IStoreMappingService>(); _storeContext = EngineContext.Current.ContainerManager.Resolve <IStoreContext>(); _webHookManager = webHookService.GetHookManager(); }
static void Main(string[] args) { _whStore = new MemoryWebHookStore(); _whManager = new WebHookManager(_whStore, new TraceLogger()); //Alloy site URL string receiverUrl = "http://localhost:51481"; //Subscribe alloy site in Memory of server var wh = SubscribeNewUser(receiverUrl); // Send Notification to all subscribers SendWebhookAsync("alloy-plan", "Alloy Plan").Wait(); //verify the webhook var verify = _whManager.VerifyWebHookAsync(wh); Console.ReadLine(); }
static void Main(string[] args) { _whStore = new MemoryWebHookStore(); _whManager = new WebHookManager(_whStore, new MyWebHookSender(new TraceLogger()), new TraceLogger()); //Alloy site URL string receiverUrl = "http://localhost:50028"; //Subscribe alloy site in Memory of server var wh = SubscribeNewUser(receiverUrl); // Send Notification to all subscribers SendWebhookAsync("alloy-plan", "Alloy Plan").Wait(); //verify the webhook var verify = _whManager.VerifyWebHookAsync(wh); Console.ReadLine(); }
/// <summary> /// Submits a notification to all matching registered WebHooks across all users. To match, the <see cref="WebHook"/> must /// have a filter that matches one or more of the actions provided for the notification. /// </summary> /// <param name="controller">The <see cref="Controller"/> instance.</param> /// <param name="notifications">The set of notifications to include in the WebHook.</param> /// <param name="predicate">A function to test each <see cref="WebHook"/> to see whether it fulfills the condition. The /// predicate is passed the <see cref="WebHook"/> and the user who registered it. If the predicate returns <c>true</c> then /// the <see cref="WebHook"/> is included; otherwise it is not.</param> /// <returns>The number of <see cref="WebHook"/> instances that were selected and subsequently notified about the actions.</returns> public static async Task <int> NotifyAllAsync(this Controller controller, IEnumerable <NotificationDictionary> notifications, Func <WebHook, string, bool> predicate) { if (controller == null) { throw new ArgumentNullException(nameof(controller)); } if (notifications == null) { throw new ArgumentNullException(nameof(notifications)); } if (!notifications.Any()) { return(0); } // Send a notification to registered WebHooks across all users with matching filters IWebHookManager manager = controller.Configuration.DependencyResolver.GetManager(); return(await manager.NotifyAllAsync(notifications, predicate)); }
/// <summary> /// For testing purposes /// </summary> internal static void Reset() { _filterManager = null; _filterProviders = null; _store = null; _sender = null; _manager = null; _user = null; }