public WorkQueueProcessDuplicateSop(WorkQueue workQueue)
        {
            SetKey(workQueue.GetKey());
            Data                  = workQueue.Data;
            ExpirationTime        = workQueue.ExpirationTime;
            FailureCount          = workQueue.FailureCount;
            FailureDescription    = workQueue.FailureDescription;
            InsertTime            = workQueue.InsertTime;
            ProcessorID           = workQueue.ProcessorID;
            ScheduledTime         = workQueue.ScheduledTime;
            ServerPartitionKey    = workQueue.ServerPartitionKey;
            StudyHistoryKey       = workQueue.StudyHistoryKey;
            StudyStorageKey       = workQueue.StudyStorageKey;
            WorkQueuePriorityEnum = workQueue.WorkQueuePriorityEnum;
            WorkQueueStatusEnum   = workQueue.WorkQueueStatusEnum;
            WorkQueueTypeEnum     = workQueue.WorkQueueTypeEnum;

            _queueData = (ProcessDuplicateQueueEntryQueueData)_serializer.Deserialize(new XmlNodeReader(workQueue.Data.DocumentElement));
        }
        public WorkQueueProcessDuplicateSop(WorkQueue workQueue)
        {
            SetKey(workQueue.GetKey());
            Data = workQueue.Data;
            ExpirationTime = workQueue.ExpirationTime;
            FailureCount = workQueue.FailureCount;
            FailureDescription = workQueue.FailureDescription;
            InsertTime = workQueue.InsertTime;
            ProcessorID = workQueue.ProcessorID;
            ScheduledTime = workQueue.ScheduledTime;
            ServerPartitionKey = workQueue.ServerPartitionKey;
            StudyHistoryKey = workQueue.StudyHistoryKey;
            StudyStorageKey = workQueue.StudyStorageKey;
            WorkQueuePriorityEnum = workQueue.WorkQueuePriorityEnum;
            WorkQueueStatusEnum = workQueue.WorkQueueStatusEnum;
            WorkQueueTypeEnum = workQueue.WorkQueueTypeEnum;

            _queueData = (ProcessDuplicateQueueEntryQueueData)_serializer.Deserialize(new XmlNodeReader(workQueue.Data.DocumentElement));

        }
		public bool ReprocessWorkQueueItem(WorkQueue item)
		{
            // #10620: Get a list of remaining WorkQueueUids which need to be reprocess
            // Note: currently only WorkQueueUIDs in failed StudyProcess will be reprocessed
            var remainingWorkQueueUidPaths = item.GetAllWorkQueueUidPaths();

            IPersistentStore store = PersistentStoreRegistry.GetDefaultStore();
			using (IUpdateContext ctx = store.OpenUpdateContext(UpdateContextSyncMode.Flush))
			{
				// delete current workqueue
				IWorkQueueUidEntityBroker uidBroker = ctx.GetBroker<IWorkQueueUidEntityBroker>();
				WorkQueueUidSelectCriteria criteria = new WorkQueueUidSelectCriteria();
				criteria.WorkQueueKey.EqualTo(item.GetKey());

				if (uidBroker.Delete(criteria) >= 0)
				{
					IWorkQueueEntityBroker workQueueBroker = ctx.GetBroker<IWorkQueueEntityBroker>();
					if (workQueueBroker.Delete(item.GetKey()))
					{
					    IList<StudyStorageLocation> locations = item.LoadStudyLocations(ctx);
                        if (locations!=null && locations.Count>0)
                        {
                            StudyReprocessor reprocessor = new StudyReprocessor();
                            String reason = String.Format("User reprocesses failed {0}", item.WorkQueueTypeEnum);
                            WorkQueue reprocessEntry = reprocessor.ReprocessStudy(ctx, reason, locations[0], remainingWorkQueueUidPaths, Platform.Time);
							if (reprocessEntry!=null)
								ctx.Commit();
                        	return reprocessEntry!=null;
                        }	
					}
				}
			}
			return false;
		}
		/// <summary>
		/// Create Duplicate SIQ Entry
		/// </summary>
		/// <param name="file"></param>
		/// <param name="location"></param>
		/// <param name="sourcePath"></param>
		/// <param name="queue"></param>
		/// <param name="uid"></param>
		/// <param name="data"></param>
		public static void CreateDuplicateSIQEntry(DicomFile file, StudyStorageLocation location, string sourcePath,
		                                           WorkQueue queue, WorkQueueUid uid, StudyProcessWorkQueueData data)
		{
			Platform.Log(LogLevel.Info, "Creating Work Queue Entry for duplicate...");
			String uidGroup = queue.GroupID ?? queue.GetKey().Key.ToString();
			using (var commandProcessor = new ServerCommandProcessor("Insert Work Queue entry for duplicate"))
			{
				commandProcessor.AddCommand(new FileDeleteCommand(sourcePath, true));

				var sopProcessingContext = new SopInstanceProcessorContext(commandProcessor, location, uidGroup);
				DicomProcessingResult result = Process(sopProcessingContext, file, data);
				if (!result.Successful)
				{
					FailUid(uid, true);
					return;
				}

				commandProcessor.AddCommand(new DeleteWorkQueueUidCommand(uid));

				if (!commandProcessor.Execute())
				{
					Platform.Log(LogLevel.Error, "Unexpected error when creating duplicate study integrity queue entry: {0}",
					             commandProcessor.FailureReason);
					FailUid(uid, true);
				}
			}
		}