Ejemplo n.º 1
0
        public async static Task <string> GetData(string urlRequested)
        {
            try
            {
                HttpClient http       = new HttpClient();
                Uri        requestUri = new Uri(urlRequested);

                var response = await http.GetAsync(requestUri);

                var result = await response.Content.ReadAsStringAsync();

                Debug.WriteLine("---> Connection:");
                Debug.WriteLine(urlRequested);
                Debug.WriteLine(result);

                return(result);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error en GetData. " + e.Message);
                CustomNotifications.displayInfoDialog("Error de conexión", "Compruebe su conexión a Internet.");
                // TODO: throw exception
                throw;
            }
        }
        public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
        {
            // Get data from WebHook
            CustomNotifications data = context.GetDataOrDefault <CustomNotifications>();

            // Get data from each notification in this WebHook
            foreach (IDictionary <string, object> notification in data.Notifications)
            {
                // Process data
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 3
0
        public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
        {
            CustomNotifications data = context.GetDataOrDefault <CustomNotifications>();

            // Get data from each notification in this WebHook
            foreach (IDictionary <string, object> notification in data.Notifications)
            {
                // Process data
                Console.WriteLine(notification.Values.ToString());
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 接收 webhook 進來的資料,
        /// 當同一個 webapi 註冊接收一堆的 webhook,
        /// 可以透過 context?.Id ,或是 context.Actions.FirstOrDefault()
        /// 例如 context?.Id 是否為 lol, 或是 context.Actions.FirstOrDefault() 開頭是否為 lol_
        /// </summary>
        public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
        {
            //if (context?.Id != "lol")
            //    return Task.FromResult(1);
            var id = context?.Id;

            Debug.WriteLine($"id:{id}");
            string action            = context.Actions.FirstOrDefault();
            CustomNotifications data = context.GetDataOrDefault <CustomNotifications>();

            foreach (IDictionary <string, object> notification in data.Notifications)
            {
                var     dataAction = notification["Action"];
                JObject message    = (JObject)notification["message"];
                Debug.WriteLine(message);
            }
            return(Task.FromResult(1));
        }
        public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
        {
            // Get data from Webhook.
            CustomNotifications data = context.GetDataOrDefault <CustomNotifications>();

            // Get the JObject from the Dictionary that corresponds to the "ProductViewModel" entrance.
            var productAsJObject = data.Notifications
                                   .First()
                                   .Where(item => item.Key == "ProductViewModel")
                                   .Select(item => item.Value)
                                   .FirstOrDefault();

            if (productAsJObject != null)
            {
                var newProduct = ((JObject)productAsJObject).ToObject <ProductViewModel>();
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 6
0
        public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
        {
            string webhooksFilePath = null;

            // Get data from WebHook
            CustomNotifications data = context.GetDataOrDefault <CustomNotifications>();

            // Get data from each notification in this WebHook
            foreach (IDictionary <string, object> notification in data.Notifications)
            {
                string action = notification["Action"] as string;
                switch (action)
                {
                case WebHookFilters.Reports:
                    webhooksFilePath = this.ReportNotificationDataFileName;
                    break;

                case WebHookFilters.Categories:
                    webhooksFilePath = this.CategoryNotificationDataFileName;
                    break;

                case WebHookFilters.DataAlerts:
                    webhooksFilePath = this.DataAlertNotificationDataFileName;
                    break;

                case WebHookFilters.DataConnections:
                    webhooksFilePath = this.DataConnectionNotificationDataFileName;
                    break;

                case WebHookFilters.ScheduledTasks:
                    webhooksFilePath = this.ScheduledTaskNotificationDataFileName;
                    break;

                default:
                    throw (new System.Exception(NoSuchActionError));
                }

                this.RecreateJsonDataFile(webhooksFilePath, notification);
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 7
0
        public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)
        {
            //如果有 Id 則離開,只處理沒有 Id 的...
            if (context?.Id != "")
            {
                return(Task.FromResult(true));
            }

            CustomNotifications data = context.GetDataOrDefault <CustomNotifications>();

            // 如果這裡會處理太久的話,建議將資料放到 Queue 之中慢慢處理,先回傳 true
            //https://docs.asp.net/projects/webhooks/en/latest/receiving/handlers.html
            // Get data from each notification in this WebHook
            foreach (IDictionary <string, object> notification in data.Notifications)
            {
                var     action  = notification["Action"];
                JObject product = (JObject)notification["Product"];
            }
            return(Task.FromResult(true));
        }
Ejemplo n.º 8
0
        public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
        {
            // Get data from WebHook
            CustomNotifications data = context.GetDataOrDefault <CustomNotifications>();

            // Get data from each notification in this WebHook
            foreach (IDictionary <string, object> notification in data.Notifications)
            {
                if (notification == null)
                {
                    continue;
                }

                // Process data
                switch (notification["Action"].ToString())
                {
                case "AddedProduct":
                    Product product = new Product()
                    {
                        Id          = (long)notification["Id"],
                        Name        = (string)notification["Name"],
                        Description = (string)notification["Description"]
                    };

                    var hubContext = GlobalHost.ConnectionManager.GetHubContext <WebHookHub>();
                    hubContext.Clients.All.addedProduct(product);
                    break;

                default:
                    break;
                }
                ;
            }

            context.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Gone);
            return(Task.FromResult(true));
        }
    public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
    {
        CustomNotifications notifications = context.GetDataOrDefault <CustomNotifications>();

        foreach (var notification in notifications.Notifications)
        {