示例#1
0
        /// <summary>
        ///     The actual delegate
        /// </summary>
        /// <param name="processor"></param>
        /// <param name="queueItem"></param>
        private void ExecuteProcessor(IWorkItemProcessor processor, WorkItem queueItem)
        {
            var proxy = IoC.Get <WorkItemStatusProxy>();

            proxy.Item = queueItem;

            try
            {
                Platform.Log(proxy.LogLevel, "Starting processing of {0} WorkItem for OID {1}", queueItem.Type,
                             queueItem.Oid);

                if (proxy.Item.Status == WorkItemStatusEnum.Deleted ||
                    proxy.Item.Status == WorkItemStatusEnum.DeleteInProgress)
                {
                    if (!processor.Initialize(proxy))
                    {
                        Platform.Log(LogLevel.Error,
                                     "Unable to intialize WorkItem processor for: {0}.  Directly deleting.",
                                     proxy.Request.WorkItemType);
                        proxy.Delete();
                        return;
                    }

                    // Delete the entry
                    processor.Delete();
                    return;
                }

                if (!processor.Initialize(proxy))
                {
                    proxy.Postpone();
                    return;
                }

                processor.Process();
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e,
                             "Unexpected exception when processing WorkQueue item of type {0}.  Failing Queue item. (Oid: {1})",
                             queueItem.Type,
                             queueItem.Oid);
                var error = e.InnerException != null ? e.InnerException.Message : e.Message;

                proxy.Fail(error, WorkItemFailureType.NonFatal);
            }
            finally
            {
                // Signal the parent thread, so it can query again
                _threadStop.Set();

                // Cleanup the processor
                processor.Dispose();
                Platform.Log(proxy.LogLevel, "Done processing of {0} WorkItem for OID {1} and status {2}",
                             proxy.Item.Type, proxy.Item.Oid, proxy.Item.Status);
            }
        }
示例#2
0
 public WorkItemPool(IWorkItemProcessor <T> processor)
 {
     Processor                       = processor;
     monitoredProcessor              = new MonitorableProcessor <T>(Processor);
     completionMonitor               = new CountBasedCompeletionMonitor(this);
     processor.NewWorkItem          += new EventHandler <NewWorkItemEventArgs <T> >(processor_NewWorkItem);
     processor.Complete             += new EventHandler <WorkItemResultEventArgs <T> >(processor_Complete);
     monitoredProcessor.NewWorkItem += new EventHandler <NewWorkItemEventArgs <T> >(tpWorkItem_NewWorkItem);
 }
示例#3
0
        public MultiThreadFileCommand()
        {
            processor = CreateWorkItemProcessor();

            processorThreadPool = new WorkItemPool <TFileWorkItem>(processor);

            processor.Start          += new EventHandler <CancelWorkItemEventArgs <TFileWorkItem> >(processor_Start);
            processor.Complete       += new EventHandler <WorkItemResultEventArgs <TFileWorkItem> >(processor_Complete);
            processor.ProgressUpdate += new EventHandler <ProgressEventArgs <TFileWorkItem> >(processor_ProgressUpdate);
        }
        private void QueueWorkItems(IEnumerable <WorkItem> list)
        {
            try
            {
                foreach (var item in list)
                {
                    if (!_extensions.ContainsKey(item.Request.WorkItemType))
                    {
                        Platform.Log(LogLevel.Error,
                                     "No extensions loaded for WorkItem item type: {0}.  Failing item.",
                                     item.Type);

                        //Just fail the WorkQueue item, not much else we can do
                        var proxy = new WorkItemStatusProxy(item);
                        proxy.Fail("No plugin to handle WorkItem type: " + item.Type, WorkItemFailureType.Fatal);
                        continue;
                    }

                    try
                    {
                        IWorkItemProcessorFactory factory   = _extensions[item.Request.WorkItemType];
                        IWorkItemProcessor        processor = factory.GetItemProcessor();

                        // Enqueue the actual processing of the item to the thread pool.
                        _threadPool.Enqueue(processor, item, ExecuteProcessor);
                    }
                    catch (Exception e)
                    {
                        Platform.Log(LogLevel.Error, e, "Unexpected exception creating WorkItem processor.");
                        var proxy = new WorkItemStatusProxy(item);
                        proxy.Fail("No plugin to handle WorkItem type: " + item.Type, WorkItemFailureType.Fatal);
                    }
                }
            }
            catch (Exception e)
            {
                // Wait for only 3 seconds
                Platform.Log(LogLevel.Error, e, "Exception occured when processing WorkItem item.");
                _threadStop.WaitOne(3000, false);
            }
        }
        /// <summary>
        /// Enqueue a WorkItem entry for processing.
        /// </summary>
        /// <param name="processor"></param>
        /// <param name="item"></param>
        /// <param name="del"></param>
        public void Enqueue(IWorkItemProcessor processor, WorkItem item, WorkItemThreadDelegate del)
        {
            var parameter = new WorkItemThreadParameter(processor, item, del);

            lock (_syncLock)
            {
                if (item.Priority.Equals(WorkItemPriorityEnum.Stat))
                {
                    _statPriorityCount++;
                }

                _totalThreadCount++;

                _queuedItems.Add(parameter);
            }

            Enqueue(parameter, delegate(WorkItemThreadParameter threadParameter)
            {
                threadParameter.Delegate(threadParameter.Processor, threadParameter.Item);

                ThreadComplete(threadParameter.Item);
            });
        }
 public WorkItemThreadParameter(IWorkItemProcessor processor, WorkItem item, WorkItemThreadDelegate del)
 {
     _item      = item;
     _processor = processor;
     _del       = del;
 }
示例#7
0
		/// <summary>
		/// The actual delegate 
		/// </summary>
		/// <param name="processor"></param>
		/// <param name="queueItem"></param>
        private void ExecuteProcessor(IWorkItemProcessor processor, WorkItem queueItem)
		{
		    var proxy = new WorkItemStatusProxy(queueItem);

            try
            {
                Platform.Log(proxy.LogLevel, "Starting processing of {0} WorkItem for OID {1}", queueItem.Type, queueItem.Oid);

                if (proxy.Item.Status == WorkItemStatusEnum.Deleted || proxy.Item.Status == WorkItemStatusEnum.DeleteInProgress)
                {
                    if (!processor.Initialize(proxy))
                    {
                        Platform.Log(LogLevel.Error, "Unable to intialize WorkItem processor for: {0}.  Directly deleting.", proxy.Request.ActivityTypeString);
                        proxy.Delete();
                        return;
                    }

                    // Delete the entry
                    processor.Delete();
                    return;
                }

                if (!processor.Initialize(proxy))
                {
                    proxy.Postpone();
                    return;
                }

                processor.Process();
            }
            catch (NotEnoughStorageException e)
            {
                // No space. Can fail right way. 
                Platform.Log(LogLevel.Error, "Not enough storage space when processing WorkQueue item of type {0}.  Failing Queue item. (Oid: {1})", queueItem.Type, queueItem.Oid);                
                proxy.Fail(SR.ExceptionNotEnoughStorage, WorkItemFailureType.Fatal);
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e,
                             "Unexpected exception when processing WorkQueue item of type {0}.  Failing Queue item. (Oid: {1})",
                             queueItem.Type,
                             queueItem.Oid);
                String error = e.InnerException != null ? e.InnerException.Message : e.Message;

                proxy.Fail(error, WorkItemFailureType.NonFatal);
            }
			finally
			{
                // Signal the parent thread, so it can query again
                _threadStop.Set();

                // Cleanup the processor
                processor.Dispose();
                Platform.Log(proxy.LogLevel, "Done processing of {0} WorkItem for OID {1} and status {2}", proxy.Item.Type, proxy.Item.Oid, proxy.Item.Status);
			}
		}
示例#8
0
 public MonitorableProcessor(IWorkItemProcessor <T> processor)
 {
     Processor              = processor;
     Processor.NewWorkItem += new EventHandler <NewWorkItemEventArgs <T> >(Processor_OnNewWorkItem);
 }