/// <summary>
        /// This is where your processing happens
        /// </summary>
        /// <param name="manager"></param>
        private void controller_ExecuteStart(QueueMessageManager manager)
        {
            // get active queue item
            var item = manager.Item;

            // Typically perform tasks based on some Action/request
            if (item.Action == "PRINTIMAGE")
            {
                // recommend you offload processing
                //PrintImage(manager);
            }
            else if (item.Action == "RESIZETHUMBNAIL")
            {
                //ResizeThumbnail(manager);
            }

            // just for kicks
            Interlocked.Increment(ref RequestCount);

            // every other request should throw exception, trigger ExecuteFailed
            if (RequestCount % 2 == 0)
            {
                // Execption:
                object obj = null;
                obj.ToString();
            }

            // Complete request
            manager.CompleteRequest(messageText: "Completed request " + DateTime.Now,
                                    autoSave: true);
        }
        protected override void OnExecuteStart(QueueMessageManager manager)
        {
            base.OnExecuteStart(manager);

            var queueItem = manager.Item;

            try
            {
                string action = queueItem.Action;

                if (!string.IsNullOrEmpty(action))
                {
                    //Initialize Anything
                    action = action.Trim();
                }

                switch (action)
                {
                default:
                    // TODO: Remove for production
                    Thread.Sleep((int)(DateTime.Now.Ticks % 500));

                    // use this instead to ensure that messages get updated properly and consistently
                    // that is: All flags are set, date is always UTC date, etc.
                    //if (!manager.CancelRequest(messageText: "Unknown Action", autoSave: true))
                    if (!manager.CompleteRequest(messageText: "Processing complete.", autoSave: true))
                    {
                        // this is pointless - if this save fails
                        // it's likely the save you are doing in
                        // onError will also fail
                        OnError(manager);
                        return;
                    }
                    //manager.CompleteCancelRequest(messageText: "Invalid message action provided.");
                    break;
                }
            }
            catch (Exception ex)
            {
                OnError(manager, ex.GetBaseException().Message);
                return;
            }
        }
Esempio n. 3
0
        protected override void OnExecuteStart(QueueMessageManager manager)
        {
            // write a 'request starting' message to QueueMonitor
            manager.Item.TextInput = DateTime.UtcNow.ToString("u");
            QueueMonitorServiceHub.WriteMessage(manager.Item);

            // always call base to allow any explicit events to also process
            base.OnExecuteStart(manager);

            var queueItem = manager.Item;

            try
            {
                // Action can be used as a routing mechanism
                // to determine which operation to perfom
                string action = queueItem.Action;

                switch (action)
                {
                case "HELLOWORLD":
                {
                    // call whatever long running operations you need to run
                    Thread.Sleep(2000);

                    // always either complete or cancel the request
                    manager.CompleteRequest(messageText: queueItem.Message +
                                            " - HELLOWORLD completed at " + DateTime.Now,
                                            autoSave: true);
                    break;
                }

                case "NEWXMLORDER":
                {
                    // call whatever long running operations you need to run
                    Thread.Sleep(2000);

                    // always either complete or cancel the request
                    manager.CompleteRequest(messageText: queueItem.Message +
                                            " - NEWXMLORDER completed at " + DateTime.Now,
                                            autoSave: true);
                    break;
                }

                case "GOBIG":
                {
                    // call whatever long running operations you need to run
                    Thread.Sleep(4000);

                    // always either complete or cancel the request
                    manager.CompleteRequest(messageText: queueItem.Message +
                                            " - GO BIG OR GO HOME completed at " + DateTime.Now,
                                            autoSave: true);
                    break;
                }

                default:
                    // All requests that get picked up by the queue get their started properties set,
                    // so we MUST mark them complete, even if we did not have any local action code here,
                    // because we cannot leave them in the half-way complete state.
                    manager.CancelRequest(messageText: "Processing failed - action not supported: " + action,
                                          autoSave: true);
                    break;
                }
            }
            catch (Exception ex)
            {
                var ex2 = ex.GetBaseException();

                // route to OnError (base) which logs error
                // and cancels the request
                OnError(manager, ex2.Message, ex2);
            }
        }
        protected override void OnExecuteStart(QueueMessageManager manager)
        {
            // write a 'request starting' message to QueueMonitor
            manager.Item.TextInput = DateTime.UtcNow.ToString("u");
            QueueMonitorServiceHub.WriteMessage(manager.Item);

            // always call base to allow any explicit events to also process
            base.OnExecuteStart(manager);

            var queueItem = manager.Item;

            try
            {
                // Action can be used as a routing mechanism 
                // to determine which operation to perfom
                string action = queueItem.Action;

                switch (action)
                {
                    case "HELLOWORLD":
                    {
                        // call whatever long running operations you need to run
                        Thread.Sleep(2000);

                        // always either complete or cancel the request
                        manager.CompleteRequest(messageText: queueItem.Message +
                                                             " - HELLOWORLD completed at " + DateTime.Now,
                            autoSave: true);
                        break;                    
                    }
                    case "NEWXMLORDER":
                    {
                        // call whatever long running operations you need to run
                        Thread.Sleep(2000);

                        // always either complete or cancel the request
                        manager.CompleteRequest(messageText: queueItem.Message +
                                                             " - NEWXMLORDER completed at " + DateTime.Now,
                            autoSave: true);
                        break;
                    }
                    case "GOBIG":
                    {
                        // call whatever long running operations you need to run
                        Thread.Sleep(4000);

                        // always either complete or cancel the request
                        manager.CompleteRequest(messageText: queueItem.Message +
                                                             " - GO BIG OR GO HOME completed at " + DateTime.Now,
                            autoSave: true);
                        break;
                    }

                    default:
                        // All requests that get picked up by the queue get their started properties set,
                        // so we MUST mark them complete, even if we did not have any local action code here,
                        // because we cannot leave them in the half-way complete state.
                        manager.CancelRequest(messageText: "Processing failed - action not supported: " + action,
                            autoSave: true);
                        break;
                }
            }
            catch (Exception ex)
            {
                var ex2 = ex.GetBaseException();

                // route to OnError (base) which logs error
                // and cancels the request
                OnError(manager, ex2.Message, ex2);                
            }
        }