/// <summary>
        /// Inserts work queue entry to process the duplicates.
        /// </summary>
        /// <param name="entryKey"><see cref="ServerEntityKey"/> of the <see cref="StudyIntegrityQueue"/> entry  that has <see cref="StudyIntegrityReasonEnum"/> equal to <see cref="StudyIntegrityReasonEnum.Duplicate"/> </param>
        /// <param name="action"></param>
        public void Process(ServerEntityKey entryKey, ProcessDuplicateAction action)
        {
            
            DuplicateSopReceivedQueue entry = DuplicateSopReceivedQueue.Load(HttpContextData.Current.ReadContext, entryKey);
            Platform.CheckTrue(entry.StudyIntegrityReasonEnum == StudyIntegrityReasonEnum.Duplicate, "Invalid type of entry");

            IList<StudyIntegrityQueueUid> uids = LoadDuplicateSopUid(entry);

            using(IUpdateContext context = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                ProcessDuplicateQueueEntryQueueData data = new ProcessDuplicateQueueEntryQueueData
                {
                    Action = action,
                    DuplicateSopFolder = entry.GetFolderPath(context),
                    UserName = ServerHelper.CurrentUserName,                                                              		
                }; 
                
                LockStudyParameters lockParms = new LockStudyParameters
                {
                    QueueStudyStateEnum = QueueStudyStateEnum.ReconcileScheduled,
                    StudyStorageKey = entry.StudyStorageKey
                };

                ILockStudy lockBbroker = context.GetBroker<ILockStudy>();
                lockBbroker.Execute(lockParms);
                if (!lockParms.Successful)
                {
                    throw new ApplicationException(lockParms.FailureReason);
                }

            	IWorkQueueProcessDuplicateSopBroker broker = context.GetBroker<IWorkQueueProcessDuplicateSopBroker>();
                WorkQueueProcessDuplicateSopUpdateColumns columns = new WorkQueueProcessDuplicateSopUpdateColumns
                                                                    	{
                                                                    		Data = XmlUtils.SerializeAsXmlDoc(data),
                                                                    		GroupID = entry.GroupID,
                                                                    		ScheduledTime = Platform.Time,
                                                                    		ExpirationTime =
                                                                    			Platform.Time.Add(TimeSpan.FromMinutes(15)),
                                                                    		ServerPartitionKey = entry.ServerPartitionKey,
                                                                    		WorkQueuePriorityEnum =
                                                                    			WorkQueuePriorityEnum.Medium,
                                                                    		StudyStorageKey = entry.StudyStorageKey,
                                                                    		WorkQueueStatusEnum = WorkQueueStatusEnum.Pending
                                                                    	};

            	WorkQueueProcessDuplicateSop processDuplicateWorkQueueEntry = broker.Insert(columns);

                IWorkQueueUidEntityBroker workQueueUidBroker = context.GetBroker<IWorkQueueUidEntityBroker>();
                IStudyIntegrityQueueUidEntityBroker duplicateUidBroke = context.GetBroker<IStudyIntegrityQueueUidEntityBroker>();
                foreach (StudyIntegrityQueueUid uid in uids)
                {
                    WorkQueueUidUpdateColumns uidColumns = new WorkQueueUidUpdateColumns
                                                           	{
                                                           		Duplicate = true,
                                                           		Extension = ServerPlatform.DuplicateFileExtension,
                                                           		SeriesInstanceUid = uid.SeriesInstanceUid,
                                                           		SopInstanceUid = uid.SopInstanceUid,
                                                           		RelativePath = uid.RelativePath,
                                                           		WorkQueueKey = processDuplicateWorkQueueEntry.GetKey()
                                                           	};

                	workQueueUidBroker.Insert(uidColumns);

                    duplicateUidBroke.Delete(uid.GetKey());
                }

                IDuplicateSopEntryEntityBroker duplicateEntryBroker =
                    context.GetBroker<IDuplicateSopEntryEntityBroker>();
                duplicateEntryBroker.Delete(entry.GetKey());


                context.Commit();
            }
        }
		public static void FailUid(WorkQueueUid sop, bool retry)
		{
			using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
			{
				IWorkQueueUidEntityBroker uidUpdateBroker = updateContext.GetBroker<IWorkQueueUidEntityBroker>();
				WorkQueueUidUpdateColumns columns = new WorkQueueUidUpdateColumns();
				if (!retry)
					columns.Failed = true;
				else
				{
					if (sop.FailureCount >= ImageServerCommonConfiguration.WorkQueueMaxFailureCount)
					{
						columns.Failed = true;
					}
					else
					{
						columns.FailureCount = ++sop.FailureCount;
					}
				}

				uidUpdateBroker.Update(sop.GetKey(), columns);
				updateContext.Commit();
			}
		}
Exemplo n.º 3
0
        /// <summary>
        /// Routine for failing a work queue uid record.
        /// </summary>
        /// <param name="uid">The WorkQueueUid record to fail.</param>
        /// <param name="retry">A boolean value indicating whether a retry will be attempted later.</param>
        protected void FailWorkQueueUid(WorkQueueUid uid, bool retry)
        {
            using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                IWorkQueueUidEntityBroker uidUpdateBroker = updateContext.GetBroker<IWorkQueueUidEntityBroker>();
                WorkQueueUidUpdateColumns columns = new WorkQueueUidUpdateColumns();
                if (!retry)
                    columns.Failed = true;
                else
                {
                    if (uid.FailureCount >= ImageServerCommonConfiguration.WorkQueueMaxFailureCount)
                    {
                        columns.Failed = true;
                    }
                    else
                    {
                        columns.FailureCount = ++uid.FailureCount;
                    }
                }

                if (uidUpdateBroker.Update(uid.GetKey(), columns))
                    updateContext.Commit();
                else
                    throw new ApplicationException(String.Format("FailUid(): Unable to update work queue uid {0}", uid.Key));
            }
            
        }
Exemplo n.º 4
0
        /// <summary>
        /// Update an entry in the <see cref="WorkQueueUid"/> table.
        /// </summary>
        /// <remarks>
        /// Note that just the Duplicate, Failed, FailureCount, and Extension columns are updated from the
        /// input parameter <paramref name="sop"/>.
        /// </remarks>
        /// <param name="sop">The <see cref="WorkQueueUid"/> entry to update.</param>
        protected virtual void UpdateWorkQueueUid(WorkQueueUid sop)
        {
            DBUpdateTime.Add(
                TimeSpanStatisticsHelper.Measure(
                delegate
                {
                     using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
                     {
                         IWorkQueueUidEntityBroker update = updateContext.GetBroker<IWorkQueueUidEntityBroker>();

                         WorkQueueUidUpdateColumns columns = new WorkQueueUidUpdateColumns
                                                                 {
                                                                     Duplicate = sop.Duplicate,
                                                                     Failed = sop.Failed,
                                                                     FailureCount = sop.FailureCount
                                                                 };

                         if (sop.Extension != null)
                             columns.Extension = sop.Extension;

                         update.Update(sop.GetKey(), columns);

                         updateContext.Commit();
                     }
                }));

            
        }
Exemplo n.º 5
0
 static public WorkQueueUid Insert(IUpdateContext update, WorkQueueUid entity)
 {
     var broker = update.GetBroker<IWorkQueueUidEntityBroker>();
     var updateColumns = new WorkQueueUidUpdateColumns();
     updateColumns.WorkQueueKey = entity.WorkQueueKey;
     updateColumns.Failed = entity.Failed;
     updateColumns.Duplicate = entity.Duplicate;
     updateColumns.FailureCount = entity.FailureCount;
     updateColumns.GroupID = entity.GroupID;
     updateColumns.RelativePath = entity.RelativePath;
     updateColumns.Extension = entity.Extension;
     updateColumns.SeriesInstanceUid = entity.SeriesInstanceUid;
     updateColumns.SopInstanceUid = entity.SopInstanceUid;
     WorkQueueUid newEntity = broker.Insert(updateColumns);
     return newEntity;
 }
    	/// <summary>
		/// Load all of the instances in a given <see cref="StudyXml"/> file into the component for sending.
		/// </summary>
		/// <param name="studyXml">The <see cref="StudyXml"/> file to load from</param>
		/// <param name="context"></param>
		/// <param name="workQueueKey"></param>
		protected static void InsertWorkQueueUidFromStudyXml(StudyXml studyXml, IUpdateContext context, ServerEntityKey workQueueKey)
		{
			foreach (SeriesXml seriesXml in studyXml)
			{
				foreach (InstanceXml instanceXml in seriesXml)
				{
					WorkQueueUidUpdateColumns updateColumns = new WorkQueueUidUpdateColumns();
					updateColumns.Duplicate = false;
					updateColumns.Failed = false;
					updateColumns.SeriesInstanceUid = seriesXml.SeriesInstanceUid;
					updateColumns.SopInstanceUid = instanceXml.SopInstanceUid;
					updateColumns.WorkQueueKey = workQueueKey;

					IWorkQueueUidEntityBroker broker = context.GetBroker<IWorkQueueUidEntityBroker>();

					broker.Insert(updateColumns);
				}
			}
		}
Exemplo n.º 7
0
        private static void ReconcileStudy(string command,StudyIntegrityQueue item )
        {
            //Ignore the reconcile command if the item is null.
            if (item == null) return;

			// Preload the change description so its not done during the DB transaction
			XmlDocument changeDescription = new XmlDocument();
			changeDescription.LoadXml(command);

			// The Xml in the SIQ item was generated when the images were received and put into the SIQ.
			// We now add the user info to it so that it will be logged in the history
            ReconcileStudyWorkQueueData queueData = XmlUtils.Deserialize<ReconcileStudyWorkQueueData>(item.Details);
            queueData.TimeStamp = Platform.Time;
            queueData.UserId = ServerHelper.CurrentUserName;

			using (IUpdateContext context = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
			{
                
                LockStudyParameters lockParms = new LockStudyParameters
                                                	{
                                                		QueueStudyStateEnum = QueueStudyStateEnum.ReconcileScheduled,
                                                		StudyStorageKey = item.StudyStorageKey
                                                	};
				ILockStudy broker = context.GetBroker<ILockStudy>();
                broker.Execute(lockParms);
                if (!lockParms.Successful)
                {
                    throw new ApplicationException(lockParms.FailureReason);
                }

                
				//Add to Study History
				StudyHistoryeAdaptor historyAdaptor = new StudyHistoryeAdaptor();
				StudyHistoryUpdateColumns parameters = new StudyHistoryUpdateColumns
				                                       	{
				                                       		StudyData = item.StudyData,
				                                       		ChangeDescription = changeDescription,
				                                       		StudyStorageKey = item.StudyStorageKey,
				                                       		StudyHistoryTypeEnum = StudyHistoryTypeEnum.StudyReconciled
				                                       	};

				StudyHistory history = historyAdaptor.Add(context, parameters);

				//Create WorkQueue Entry
				WorkQueueAdaptor workQueueAdaptor = new WorkQueueAdaptor();
				WorkQueueUpdateColumns row = new WorkQueueUpdateColumns
				                             	{
				                             		Data = XmlUtils.SerializeAsXmlDoc(queueData),
				                             		ServerPartitionKey = item.ServerPartitionKey,
				                             		StudyStorageKey = item.StudyStorageKey,
				                             		StudyHistoryKey = history.GetKey(),
				                             		WorkQueueTypeEnum = WorkQueueTypeEnum.ReconcileStudy,
				                             		WorkQueueStatusEnum = WorkQueueStatusEnum.Pending,
				                             		ScheduledTime = Platform.Time,
				                             		ExpirationTime = Platform.Time.AddHours(1),
                                                    GroupID = item.GroupID
				                             	};
				WorkQueue newWorkQueueItem = workQueueAdaptor.Add(context, row);

				StudyIntegrityQueueUidAdaptor studyIntegrityQueueUidAdaptor = new StudyIntegrityQueueUidAdaptor();
				StudyIntegrityQueueUidSelectCriteria crit = new StudyIntegrityQueueUidSelectCriteria();
				crit.StudyIntegrityQueueKey.EqualTo(item.GetKey());
				IList<StudyIntegrityQueueUid> uidList = studyIntegrityQueueUidAdaptor.Get(context, crit);

				WorkQueueUidAdaptor workQueueUidAdaptor = new WorkQueueUidAdaptor();
				WorkQueueUidUpdateColumns update = new WorkQueueUidUpdateColumns();
				foreach (StudyIntegrityQueueUid uid in uidList)
				{
					update.WorkQueueKey = newWorkQueueItem.GetKey();
					update.SeriesInstanceUid = uid.SeriesInstanceUid;
					update.SopInstanceUid = uid.SopInstanceUid;
				    update.RelativePath = uid.RelativePath;
					workQueueUidAdaptor.Add(context, update);
				}

				//DeleteStudyIntegrityQueue Item
				StudyIntegrityQueueUidSelectCriteria criteria = new StudyIntegrityQueueUidSelectCriteria();
				criteria.StudyIntegrityQueueKey.EqualTo(item.GetKey());
				studyIntegrityQueueUidAdaptor.Delete(context, criteria);

				StudyIntegrityQueueAdaptor studyIntegrityQueueAdaptor = new StudyIntegrityQueueAdaptor();
				studyIntegrityQueueAdaptor.Delete(context, item.GetKey());

				context.Commit();
			}

		}