コード例 #1
0
        /// <summary>
        /// Called by the base to initialize the processor.
        /// </summary>
        public virtual bool Initialize(WorkItemStatusProxy proxy)
        {
            Proxy = proxy;
            if (proxy.Progress == null)
            {
                proxy.Progress = new TProgress();
            }
            else if (!(proxy.Progress is TProgress))
            {
                proxy.Progress = new TProgress();
            }

            if (Request == null)
            {
                throw new ApplicationException(SR.InternalError);
            }

            if (!string.IsNullOrEmpty(proxy.Item.StudyInstanceUid))
            {
                Location = new StudyLocation(proxy.Item.StudyInstanceUid);
            }

            return(true);
        }
コード例 #2
0
ファイル: WorkItemProcessor.cs プロジェクト: nhannd/Xian
		/// <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);
			}
		}
コード例 #3
0
ファイル: WorkItemProcessor.cs プロジェクト: nhannd/Xian
        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);
            }
        }