public UpdateWorkQueueCommand(DicomMessageBase message, StudyStorageLocation location, bool duplicate, WorkQueueData data=null, WorkQueueUidData uidData=null, ExternalRequestQueue request=null, WorkQueuePriorityEnum priority=null)
            : base("Update/Insert a WorkQueue Entry")
        {
            Platform.CheckForNullReference(message, "Dicom Message object");
            Platform.CheckForNullReference(location, "Study Storage Location");
            
            _message = message;
            _storageLocation = location;
            _duplicate = duplicate;
            _data = data;
            _request = request;
            _uidData = uidData;
	        _priority = priority;
        }
		/// <summary>
		/// Process the duplicate with the supplied <see cref="DuplicateProcessingEnum"/>
		/// </summary>
		/// <param name="context">The processing context</param>
		/// <param name="file">The file</param>
		/// <param name="data">The data</param>
		/// <param name="duplicate">How the processor should handle the duplicate</param>
		public static void ProcessStoredDuplicate(SopInstanceProcessorContext context,
		                                          DicomFile file,
		                                          StudyProcessWorkQueueData data,
		                                          DuplicateProcessingEnum duplicate)
		{
			SaveDuplicate(context, file);
			var uidData = new WorkQueueUidData
				{
					Extension = ServerPlatform.DuplicateFileExtension,
					GroupId = context.Group,
					DuplicateProcessing = duplicate
				};

			if (context.Request != null)
				uidData.OperationToken = context.Request.OperationToken;

			context.CommandProcessor.AddCommand(
				new UpdateWorkQueueCommand(file, context.StudyLocation, true, data, uidData, context.Request));
		}
		private void HandleNonDuplicateFile(string seriesInstanceUid, string sopInstanceUid, StudyStorageLocation studyLocation, ServerCommandProcessor commandProcessor, DicomMessageBase message, string sourcePath, string path, bool dupImage, StudyProcessWorkQueueData data)
		{
			commandProcessor.AddCommand(new CreateDirectoryCommand(path));

			path = Path.Combine(path, studyLocation.PartitionFolder);
			commandProcessor.AddCommand(new CreateDirectoryCommand(path));

			path = Path.Combine(path, studyLocation.StudyFolder);
			commandProcessor.AddCommand(new CreateDirectoryCommand(path));

			path = Path.Combine(path, studyLocation.StudyInstanceUid);
			commandProcessor.AddCommand(new CreateDirectoryCommand(path));

			path = Path.Combine(path, seriesInstanceUid);
			commandProcessor.AddCommand(new CreateDirectoryCommand(path));

			path = Path.Combine(path, sopInstanceUid);
			path += ServerPlatform.DicomFileExtension;

			commandProcessor.AddCommand(new RenameFileCommand(sourcePath, path, true));

			WorkQueueUidData uidData = null;
			if (_context.Request != null && !string.IsNullOrEmpty(_context.Request.OperationToken))
			{
				uidData = new WorkQueueUidData
				{
					OperationToken = _context.Request.OperationToken
				};
			}

			commandProcessor.AddCommand(
				new UpdateWorkQueueCommand(message, studyLocation, dupImage, data, uidData, _context.Request));

			#region SPECIAL CODE FOR TESTING
			if (Diagnostics.Settings.SimulateFileCorruption)
			{
				commandProcessor.AddCommand(new CorruptDicomFileCommand(path));
			}
			#endregion
		}
		/// <summary>
		/// Process the duplicate with the supplied <see cref="DuplicateProcessingEnum"/>
		/// </summary>
		/// <param name="context">The processing context</param>
		/// <param name="message">A subset of the message stored in <paramref name="sourceFilename"/></param>
		/// <param name="sourceFilename">The location of the filename that is a duplicate</param>
		/// <param name="data">The data</param>
		/// <param name="duplicate">How the processor should handle the duplicate</param>
		public static void ProcessStoredDuplicateFile(SopInstanceProcessorContext context,
													  string sourceFilename,
													  DicomMessageBase message,
													  StudyProcessWorkQueueData data,
													  DuplicateProcessingEnum duplicate)
		{
			SaveDuplicateFile(context, message.DataSet[DicomTags.SopInstanceUid].ToString(), sourceFilename);
			var uidData = new WorkQueueUidData
			{
				Extension = ServerPlatform.DuplicateFileExtension,
				GroupId = context.Group,
				DuplicateProcessing = duplicate
			};

			if (context.Request != null)
				uidData.OperationToken = context.Request.OperationToken;

			context.CommandProcessor.AddCommand(
				new UpdateWorkQueueCommand(message, context.StudyLocation, true, data, uidData, context.Request));
		}
		public static XmlDocument SerializeWorkQueueUidDataToXmlDocument(WorkQueueUidData data)
		{
			var s = JsmlSerializer.Serialize(data, "WorkQueueUidData",
			                                 new JsmlSerializer.SerializeOptions
				                                 {
					                                 Hook = WorkItemDataHook,
					                                 DataContractTest = IsWorkQueueDataContract,
					                                 DataMemberTest = IsXmlSerializationDataMember
				                                 });
			var d = new XmlDocument();
			d.LoadXml(s);
			return d;
		}
		public static string SerializeWorkQueueUidData(WorkQueueUidData data)
		{
			return JsmlSerializer.Serialize(data, "WorkQueueUidData",
			                                new JsmlSerializer.SerializeOptions
				                                {
					                                Hook = WorkItemDataHook,
					                                DataContractTest = IsWorkQueueDataContract,
					                                DataMemberTest = IsXmlSerializationDataMember
				                                });
		}