Beispiel #1
0
        /// <summary>
        /// Process each item of queue
        /// </summary>
        private static bool ProcessQueueItem(object queueItem1)
        {
            WebhooksNotificationdto.WebhooksData we = (WebhooksNotificationdto.WebhooksData)queueItem1;

            //Get realm from deserialized WebHooksData
            foreach (WebhooksNotificationdto.EventNotifications eventNotifications in we.EventNotifications)
            {
                //Update last updated time for each realm in DB
                DBUtility.UpdateLastUpdatedDateDB(eventNotifications.RealmId);
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Add webhooks notifications to queue
        /// </summary>
        private static void AddToQueue()
        {
            //Deserealiaze webhooks response payload
            WebhooksNotificationdto.WebhooksData webhooksData = JsonConvert.DeserializeObject <WebhooksNotificationdto.WebhooksData>(payloadLoaded);

            //Create a blocking queue/collection
            BlockingCollection <WebhooksNotificationdto.WebhooksData> dataItems = new BlockingCollection <WebhooksNotificationdto.WebhooksData>(1);


            Task.Run(() =>
            {
                // Add items to blocking collection(queue)
                dataItems.Add(webhooksData);

                // Let consumer know we are done.
                dataItems.CompleteAdding();
            });

            Task.Run(() =>
            {
                while (!dataItems.IsCompleted)
                {
                    //Create WebhooksData reference
                    WebhooksNotificationdto.WebhooksData webhooksData1 = null;

                    try
                    {
                        //Take our Items from blocking collection(dequeue)
                        webhooksData1 = dataItems.Take();
                    }
                    catch (InvalidOperationException) { }

                    if (webhooksData1 != null)
                    {
                        //Start processing queue items
                        ProcessQueueItem(webhooksData1);
                    }
                }
            });
        }