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);
                }
            }
        }
 private void SaveState(Model.WorkQueue item, ReprocessStudyQueueData queueData)
 {
     // Update the queue state
     using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         queueData.State.ExecuteAtLeastOnce = true;
         var broker = updateContext.GetBroker <IWorkQueueEntityBroker>();
         var parms  = new WorkQueueUpdateColumns {
             Data = XmlUtils.SerializeAsXmlDoc(_queueData)
         };
         broker.Update(item.GetKey(), parms);
         updateContext.Commit();
     }
 }
Beispiel #3
0
        /// <summary>
        /// Inserts a <see cref="WorkQueue"/> request to reprocess the study
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="reason"></param>
        /// <param name="location"></param>
        /// <param name="additionalPaths"></param>
        /// <param name="scheduleTime"></param>
        /// <returns></returns>
        /// <exception cref="InvalidStudyStateOperationException">Study is in a state that reprocessing is not allowed</exception>
        ///
        public WorkQueue ReprocessStudy(IUpdateContext ctx, String reason, StudyStorageLocation location, List <FilesystemDynamicPath> additionalPaths, DateTime scheduleTime)
        {
            Platform.CheckForNullReference(location, "location");

            if (location.StudyStatusEnum.Equals(StudyStatusEnum.OnlineLossy))
            {
                if (location.IsLatestArchiveLossless)
                {
                    string message = String.Format("Study has been archived as lossless and is currently lossy. It must be restored first");
                    throw new InvalidStudyStateOperationException(message);
                }
            }

            Study study = location.LoadStudy(ctx);

            // Unlock first.
            ILockStudy          lockStudy = ctx.GetBroker <ILockStudy>();
            LockStudyParameters lockParms = new LockStudyParameters();

            lockParms.StudyStorageKey     = location.Key;
            lockParms.QueueStudyStateEnum = QueueStudyStateEnum.Idle;
            if (!lockStudy.Execute(lockParms) || !lockParms.Successful)
            {
                // Note: according to the stored proc, setting study state to Idle always succeeds so
                // this will never happen
                return(null);
            }

            // Now relock into ReprocessScheduled state. If another process locks the study before this occurs,
            //
            lockParms.QueueStudyStateEnum = QueueStudyStateEnum.ReprocessScheduled;
            if (!lockStudy.Execute(lockParms) || !lockParms.Successful)
            {
                throw new InvalidStudyStateOperationException(lockParms.FailureReason);
            }

            InsertWorkQueueParameters columns = new InsertWorkQueueParameters();

            columns.ScheduledTime      = scheduleTime;
            columns.ServerPartitionKey = location.ServerPartitionKey;
            columns.StudyStorageKey    = location.Key;
            columns.WorkQueueTypeEnum  = WorkQueueTypeEnum.ReprocessStudy;

            ReprocessStudyQueueData queueData = new ReprocessStudyQueueData();

            queueData.State = new ReprocessStudyState();
            queueData.State.ExecuteAtLeastOnce = false;
            queueData.ChangeLog           = new ReprocessStudyChangeLog();
            queueData.ChangeLog.Reason    = reason;
            queueData.ChangeLog.TimeStamp = Platform.Time;
            queueData.ChangeLog.User      = (Thread.CurrentPrincipal is CustomPrincipal)
                                                        ? (Thread.CurrentPrincipal as CustomPrincipal).Identity.Name
                                                        : String.Empty;

            if (additionalPaths != null)
            {
                queueData.AdditionalFiles = additionalPaths.ConvertAll <string>(path => path.ToString());
            }


            columns.WorkQueueData = XmlUtils.SerializeAsXmlDoc(queueData);
            IInsertWorkQueue insertBroker   = ctx.GetBroker <IInsertWorkQueue>();
            WorkQueue        reprocessEntry = insertBroker.FindOne(columns);

            if (reprocessEntry != null)
            {
                if (study != null)
                {
                    Platform.Log(LogLevel.Info,
                                 "Study Reprocess Scheduled for Study {0}, A#: {1}, Patient: {2}, ID={3}",
                                 study.StudyInstanceUid, study.AccessionNumber, study.PatientsName, study.PatientId);
                }
                else
                {
                    Platform.Log(LogLevel.Info, "Study Reprocess Scheduled for Study {0}.", location.StudyInstanceUid);
                }
            }

            return(reprocessEntry);
        }