private void ReadQueueData(Model.WorkQueue item)
        {
            if (item.Data != null)
            {
                _queueData = XmlUtils.Deserialize <ReprocessStudyQueueData>(item.Data);
            }

            if (_queueData == null)
            {
                _queueData = new ReprocessStudyQueueData
                {
                    State = new ReprocessStudyState
                    {
                        ExecuteAtLeastOnce = false
                    }
                };
            }

            // Convert the paths stored in _queueData.AdditionalFiles to the actual paths
            if (_queueData.AdditionalFiles != null)
            {
                _additionalFilesToProcess = new List <string>();
                var list = _queueData.AdditionalFiles.ToArray();
                foreach (var entry in list)
                {
                    var path     = FilesystemDynamicPath.Parse(entry);
                    var realPath = path.ConvertToAbsolutePath(this.StorageLocation);
                    _additionalFilesToProcess.Add(realPath);
                }
            }
        }
        /// <summary>
        /// Reprocess the file requested by the process which initiates the reprocess.
        /// If the file is located outside the study folder, it will be moved to the incoming folder for import.
        /// </summary>
        private void ProcessAdditionalFiles()
        {
            if (_additionalFilesToProcess != null && _additionalFilesToProcess.Count > 0)
            {
                if (string.IsNullOrEmpty(base.GetServerPartitionIncomingFolder()))
                {
                    var error = "Some files need to be moved to the Incoming folder in order to be reprocess. However, there is no active incoming folder. Make sure the Import Files Service is enabled";
                    throw new Exception(error);
                }
                else
                {
                    try
                    {
                        foreach (var entry in _additionalFilesToProcess)
                        {
                            var path     = FilesystemDynamicPath.Parse(entry);
                            var realPath = path.ConvertToAbsolutePath(this.StorageLocation);

                            try
                            {
                                // On one hand, if the file is in the study folder then we should have processed it in prev stage.
                                // But on the other hand, the original WQI may have failed because the file was missing. If this is the case, we should fail
                                var fileInfo = new FileInfo(realPath);
                                if (fileInfo.FullName.IndexOf(StorageLocation.GetStudyPath()) == 0)
                                {
                                    // only check if file exists if it's a DCM file. Other type of files (eg xml, gz) may have been deleted during reprocessing
                                    if (fileInfo.Extension.Equals(ServerPlatform.DicomFileExtension, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        if (!fileInfo.Exists)
                                        {
                                            throw new FileNotFoundException(string.Format("{0} is expected but it could not be found", fileInfo.FullName));
                                        }

                                        Platform.Log(LogLevel.Debug, "Skip reprocessing {0} since it is in the study folder", realPath);
                                    }
                                }
                                else
                                {
                                    MoveFileToIncomingFolder(fileInfo.FullName);

                                    // delete empty directories if necessary
                                    if (path.Type == FilesystemDynamicPath.PathType.RelativeToReconcileFolder)
                                    {
                                        var folderToDelete = fileInfo.Directory.FullName;

                                        DirectoryUtility.DeleteIfEmpty(folderToDelete, StorageLocation.GetReconcileRootPath());
                                    }
                                }

                                _queueData.AdditionalFiles.Remove(entry);
                            }
                            catch (FileNotFoundException ex)
                            {
                                throw; // File is missing. Better leave decision making to the user.
                            }
                            catch (DirectoryNotFoundException ex)
                            {
                                // ignore?
                            }
                        }
                    }
                    finally
                    {
                        // update the list so we don't have to reprocess again when the WQI resumes (that will cause problem because we may have moved the files somewhere else)
                        SaveState(WorkQueueItem, _queueData);
                    }
                }
            }
        }