/// <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));
 }
        private void NotifyRegisteredWebHooks <T>(T entityDto, string webhookEvent, List <int> storeIds)
        {
            if (storeIds.Count > 0)
            {
                // Notify all webhooks that the entity is mapped to their store.
                _webHookManager.NotifyAllAsync(webhookEvent, new { Item = entityDto }, (hook, hookUser) => IsEntityMatchingTheWebHookStoreId(hookUser, storeIds));

                if (typeof(T) == typeof(ProductDto) || typeof(T) == typeof(CategoryDto))
                {
                    NotifyUnmappedEntityWebhooks(entityDto, storeIds);
                }
            }
            else
            {
                _webHookManager.NotifyAllAsync(webhookEvent, new { Item = entityDto });
            }
        }
        /// <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));
        }
Exemple #4
0
        public void HandleEvent(EntityInserted <Customer> eventMessage)
        {
            // There is no need to send webhooks for guest customers.
            if (eventMessage.Entity.IsGuest())
            {
                return;
            }

            CustomerDto customer = _customerApiService.GetCustomerById(eventMessage.Entity.Id);

            _webHookManager.NotifyAllAsync(WebHookNames.CustomerCreated, new { Item = customer });
        }
        public async Task ProcessAsync(
            [ServiceBusTrigger(ApplicationSettings.ConfirmationTopic, ApplicationSettings.WebHookSubscription)] BrokeredMessage message,
            TextWriter log)
        {
            var subscription = message.GetBody <Subscription>();

            await log.WriteLineAsync($"Sending web hook for {subscription.EmailAddress}");

            await _webHookManager.NotifyAllAsync(
                ApplicationSettings.WebHookSubscription,
                $"Welcome, {subscription.FirstName} {subscription.LastName}"
                );

            await log.WriteLineAsync("Sent WebHook");
        }
        /// <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));
        }
Exemple #7
0
        /// <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 <IWebHookNotification> notifications, Func <WebHook, string, bool> predicate)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }
            if (notifications == null)
            {
                throw new ArgumentNullException("notifications");
            }
            if (!notifications.Any())
            {
                return(0);
            }

            // Send a notification to registered WebHooks across all users with matching filters
            IWebHookManager manager = (IWebHookManager)controller.HttpContext.RequestServices.GetService(typeof(IWebHookManager));

            return(await manager.NotifyAllAsync(notifications, predicate));
        }