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; }
/// <summary> /// For testing purposes /// </summary> internal static void Reset() { _filterManager = null; _manager = null; _filterProviders = null; _store = null; }
protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); _webHookStore = Configuration.DependencyResolver.GetStore(); _filterProvider = Configuration.DependencyResolver.GetFilterProviders().FirstOrDefault(); }
protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); _logger = Configuration.DependencyResolver.GetLogger(); _store = Configuration.DependencyResolver.GetStore(); }
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(); }
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"); }
public WebHookManager(IWebHookSender sender, IWebHookStore store, ILogger <WebHookManager> logger) { _sender = sender; _store = store; Logger = logger; }
public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); config.InitializeCustomWebHooks(); config.InitializeCustomWebHooksSqlStorage(); config.InitializeCustomWebHooksApis(); ILogger logger = config.DependencyResolver.GetLogger(); IWebHookStore store = config.DependencyResolver.GetStore(); IWebHookSender sender = new ScionWebHookSender(logger); IWebHookManager manager = new ScionWebhookManager(store, sender, logger); ContainerBuilder builder = new ContainerBuilder(); builder.RegisterInstance(manager).As <IWebHookManager>().SingleInstance(); builder.RegisterInstance(sender).As <IWebHookSender>().SingleInstance(); Assembly currentAssembly = Assembly.GetExecutingAssembly(); builder.RegisterApiControllers(currentAssembly); builder.RegisterControllers(currentAssembly); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); }
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; }
protected WebHookStoreTest(IWebHookStore store) { if (store == null) { throw new ArgumentNullException("store"); } _store = store; }
protected WebHookStoreTest(IWebHookStore store) { if (store == null) { throw new ArgumentNullException("store"); } _store = store; }
/// <summary> /// Initialize a new instance of the <see cref="WebHookManager"/> with the given <paramref name="httpClient"/>. This /// constructor is intended for unit testing purposes. /// </summary> internal WebHookManager(IWebHookStore webHookStore, IWebHookSender webHookSender, ILogger logger, HttpClient httpClient) { _webHookStore = webHookStore ?? throw new ArgumentNullException(nameof(webHookStore)); _webHookSender = webHookSender ?? throw new ArgumentNullException(nameof(webHookSender)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _httpClient = httpClient ?? new HttpClient(); }
public void GetStore_ReturnsDefaultInstance_IfNoneRegistered() { // Act IWebHookStore actual = _resolverMock.Object.GetStore(); // Assert Assert.IsType <MemoryWebHookStore>(actual); }
/// <summary> /// For testing purposes /// </summary> internal static void Reset() { _filterManager = null; _store = null; _sender = null; _manager = null; _registrationsManager = null; _user = null; }
public void It_Is_EpiWebHookStore() { HttpConfiguration config = new HttpConfiguration(); config.InitializeCustomWebHooksEPiServerStorage(); IWebHookStore actual = CustomServices.GetStore(); Assert.IsInstanceOf <EpiWebHookStore>(actual); }
public void GetStore_ReturnsSingleInstance() { // Act IWebHookStore actual1 = CustomServices.GetStore(); IWebHookStore actual2 = CustomServices.GetStore(); // Assert Assert.Same(actual1, actual2); }
public IWebHookStore GetWebHookStore() { if (_webHookStore == null) { _webHookStore = new NopWebHookStore(); } return(_webHookStore); }
public IWebHookStore GetWebHookStore() { if (_webHookStore == null) { _webHookStore = CustomServices.GetStore(); } return(_webHookStore); }
public WebHookRegistrationsControllerTests() { _resolverMock = new Mock <IDependencyResolver>(); _managerMock = new Mock <IWebHookManager>(); _resolverMock.Setup(r => r.GetService(typeof(IWebHookManager))) .Returns(_managerMock.Object) .Verifiable(); _store = new MemoryWebHookStore(); _resolverMock.Setup(r => r.GetService(typeof(IWebHookStore))) .Returns(_store) .Verifiable(); _user = new WebHookUser(); _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser))) .Returns(_user) .Verifiable(); _filterProviderMock = new Mock <IWebHookFilterProvider>(); _filterManager = new WebHookFilterManager(new[] { new WildcardWebHookFilterProvider(), _filterProviderMock.Object }); _resolverMock.Setup(r => r.GetService(typeof(IWebHookFilterManager))) .Returns(_filterManager) .Verifiable(); _config = new HttpConfiguration(); _config.DependencyResolver = _resolverMock.Object; ClaimsIdentity identity = new ClaimsIdentity(); Claim claim = new Claim(ClaimTypes.Name, TestUser); identity.AddClaim(claim); IPrincipal principal = new ClaimsPrincipal(identity); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Address); request.SetConfiguration(_config); HttpRequestContext requestContext = new HttpRequestContext() { Configuration = _config, Principal = principal, Url = new UrlHelper(request), }; _controllerContext = new HttpControllerContext() { Configuration = _config, Request = new HttpRequestMessage(), RequestContext = requestContext, }; _controller = new WebHookRegistrationsControllerMock(); _controller.Initialize(_controllerContext); }
static void Main(string[] args) { _whStore = new MemoryWebHookStore(); _whManager = new WebHookManager(_whStore, new TraceLogger()); SubscribeNewUser(); SendWebhookAsync().Wait(); Console.ReadLine(); }
private static IWebHookStore CreateStore() { HttpConfiguration config = new HttpConfiguration(); config.InitializeCustomWebHooksAzureStorage(); IWebHookStore store = CustomServices.GetStore(); Assert.IsType <AzureWebHookStore>(store); return(store); }
static void Main(string[] args) { _whStore = new MemoryWebHookStore(); _whManager = new WebHookManager(_whStore, new TraceLogger()); SubscribeNewUser(); SendWebhookAsync().Wait(); Console.ReadLine(); }
public void GetStore_ReturnsDefaultInstance_IfNoneRegistered() { // Arrange _config.InitializeCustomWebHooks(); // Act IWebHookStore actual = _resolverMock.Object.GetStore(); // Assert Assert.IsType <MemoryWebHookStore>(actual); }
public void CreateStore_Succeeds() { // Arrange ILogger logger = new Mock <ILogger>().Object; // Act IWebHookStore actual = AzureWebHookStore.CreateStore(logger); // Assert Assert.IsType <AzureWebHookStore>(actual); }
public void CreateStore_WithCustomSettings_Succeeds() { // Arrange ILogger logger = new Mock <ILogger>().Object; // Act IWebHookStore actual = SqlWebHookStore.CreateStore(logger, true, WebHookStoreContext.ConnectionStringName, "WebHooks", "WebHooks"); // Assert Assert.IsType <SqlWebHookStore>(actual); }
public WebHookRegistrationsControllerTests() { _resolverMock = new Mock<IDependencyResolver>(); _managerMock = new Mock<IWebHookManager>(); _resolverMock.Setup(r => r.GetService(typeof(IWebHookManager))) .Returns(_managerMock.Object) .Verifiable(); _store = new MemoryWebHookStore(); _resolverMock.Setup(r => r.GetService(typeof(IWebHookStore))) .Returns(_store) .Verifiable(); _user = new WebHookUser(); _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser))) .Returns(_user) .Verifiable(); _filterProviderMock = new Mock<IWebHookFilterProvider>(); _filterManager = new WebHookFilterManager(new[] { new WildcardWebHookFilterProvider(), _filterProviderMock.Object }); _resolverMock.Setup(r => r.GetService(typeof(IWebHookFilterManager))) .Returns(_filterManager) .Verifiable(); _config = new HttpConfiguration(); _config.DependencyResolver = _resolverMock.Object; ClaimsIdentity identity = new ClaimsIdentity(); Claim claim = new Claim(ClaimTypes.Name, TestUser); identity.AddClaim(claim); IPrincipal principal = new ClaimsPrincipal(identity); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, Address); request.SetConfiguration(_config); HttpRequestContext requestContext = new HttpRequestContext() { Configuration = _config, Principal = principal, Url = new UrlHelper(request), }; _controllerContext = new HttpControllerContext() { Configuration = _config, Request = new HttpRequestMessage(), RequestContext = requestContext, }; _controller = new WebHookRegistrationsControllerMock(); _controller.Initialize(_controllerContext); }
/// <summary> /// Initializes a new instance of the <see cref="WebHookCaller{TSubscription, TActions}"/> /// class with the specified services. /// </summary> /// <param name="webHookStore">Used to access subscriptions.</param> /// <param name="backgroundTaskQueue">Used to schedule background tasks.</param> /// <param name="httpClient">Used to send requests.</param> /// <param name="options">Options for the caller.</param> public WebHookCaller(IWebHookStore <TSubscription, TActions> webHookStore, IBackgroundTaskQueue backgroundTaskQueue, HttpClient httpClient, IOptionsMonitor <WebHookCallerOptions>?options) { ValidateEnum <TActions>(); _webHookStore = webHookStore; _backgroundTaskQueue = backgroundTaskQueue; _httpClient = httpClient; _options = options; }
/// <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 CreateStore_Succeeds() { // Arrange ILogger logger = new Mock <ILogger>().Object; // Act IWebHookStore actual = SqlWebHookStore.CreateStore(logger, encryptData: false); // Assert Assert.IsType <SqlWebHookStore>(actual); }
public void SetStore_GetStore_Roundtrips() { // Arrange Mock <IWebHookStore> storeMock = new Mock <IWebHookStore>(); // Act CustomServices.SetStore(storeMock.Object); IWebHookStore actual = CustomServices.GetStore(); // Assert Assert.Same(storeMock.Object, actual); }
public void GetStore_ReturnsSameInstance_IfNoneRegistered() { // Arrange _config.InitializeCustomWebHooks(); // Act IWebHookStore actual1 = _resolverMock.Object.GetStore(); IWebHookStore actual2 = _resolverMock.Object.GetStore(); // Assert Assert.Same(actual1, actual2); }
public void InitializeStore_SetsStore() { // Arrange HttpConfiguration config = new HttpConfiguration(); // Act config.InitializeCustomWebHooksAzureStorage(); IWebHookStore actual = CustomServices.GetStore(); // Assert Assert.IsType <AzureWebHookStore>(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> /// Initialize a new instance of the <see cref="WebHookManager"/> with the given retry policy, <paramref name="options"/>, /// and <paramref name="httpClient"/>. This constructor is intended for unit testing purposes. /// </summary> internal WebHookManager( IWebHookStore webHookStore, ILogger logger, IEnumerable<TimeSpan> retryDelays, ExecutionDataflowBlockOptions options, HttpClient httpClient, Action<WebHookWorkItem> onWebHookSuccess, Action<WebHookWorkItem> onWebHookFailure) { if (webHookStore == null) { throw new ArgumentNullException("webHookStore"); } if (logger == null) { throw new ArgumentNullException("logger"); } _webHookStore = webHookStore; _logger = logger; retryDelays = retryDelays ?? DefaultRetries; options = options ?? new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = DefaultMaxConcurrencyLevel }; _httpClient = httpClient ?? new HttpClient(); // Create the launch processors with the given retry delays _launchers = new ActionBlock<WebHookWorkItem>[1 + retryDelays.Count()]; int offset = 0; _launchers[offset++] = new ActionBlock<WebHookWorkItem>(async item => await LaunchWebHook(item), options); foreach (TimeSpan delay in retryDelays) { _launchers[offset++] = new ActionBlock<WebHookWorkItem>(async item => await DelayedLaunchWebHook(item, delay)); } string msg = string.Format(CultureInfo.CurrentCulture, CustomResources.Manager_Started, typeof(WebHookManager).Name, _launchers.Length); _logger.Info(msg); // Set handlers for testing purposes _onWebHookSuccess = onWebHookSuccess; _onWebHookFailure = onWebHookFailure; }
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(); }
/// <summary> /// Initialize a new instance of the <see cref="WebHookManager"/> with the given <paramref name="httpClient"/>. This /// constructor is intended for unit testing purposes. /// </summary> internal WebHookManager(IWebHookStore webHookStore, IWebHookSender webHookSender, ILogger logger, HttpClient httpClient) { if (webHookStore == null) { throw new ArgumentNullException("webHookStore"); } if (webHookSender == null) { throw new ArgumentNullException("webHookSender"); } if (logger == null) { throw new ArgumentNullException("logger"); } _webHookStore = webHookStore; _webHookSender = webHookSender; _logger = logger; _httpClient = httpClient ?? new HttpClient(); }
/// <summary> /// Initialize a new instance of the <see cref="WebHookManager"/> with a default retry policy. /// </summary> public WebHookManager(IWebHookStore webHookStore, ILogger logger) : this(webHookStore, logger, retryDelays: null, options: null, httpClient: null, onWebHookSuccess: null, onWebHookFailure: null) { }
/// <inheritdoc /> protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); _manager = Configuration.DependencyResolver.GetManager(); _store = Configuration.DependencyResolver.GetStore(); _user = Configuration.DependencyResolver.GetUser(); }
/// <summary> /// Initialize a new instance of the <see cref="WebHookManager"/> with a default retry policy. /// </summary> /// <param name="webHookStore">The current <see cref="IWebHookStore"/>.</param> /// <param name="webHookSender">The current <see cref="IWebHookSender"/>.</param> /// <param name="logger">The current <see cref="ILogger"/>.</param> public WebHookManager(IWebHookStore webHookStore, IWebHookSender webHookSender, ILogger logger) : this(webHookStore, webHookSender, logger, httpClient: null) { }
public static IWebHookManager GetManager(IWebHookStore store, IWebHookSender sender, ILogger logger) { if (_manager != null) { return _manager; } if (store == null) { throw new ArgumentNullException("store"); } if (sender == null) { throw new ArgumentNullException("sender"); } if (logger == null) { throw new ArgumentNullException("logger"); } IWebHookManager instance = new WebHookManager(store, sender, logger); Interlocked.CompareExchange(ref _manager, instance, null); return _manager; }
/// <summary> /// For testing purposes /// </summary> internal static void Reset() { _filterManager = null; _filterProviders = null; _store = null; _sender = null; _manager = null; _user = null; }
/// <summary> /// Sets a default <see cref="IWebHookStore"/> implementation which is used if none are registered with the /// Dependency Injection engine. /// </summary> /// <param name="instance">The <see cref="IWebHookStore"/> to use. If <c>null</c> then a default implementation is used.</param> public static void SetStore(IWebHookStore instance) { _store = instance; }