예제 #1
0
 static public Patient Insert(Patient entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         Patient newEntity = Insert(update, entity);
         update.Commit();
         return(newEntity);
     }
 }
예제 #2
0
 static public StudyDeleteRecord Insert(StudyDeleteRecord entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         StudyDeleteRecord newEntity = Insert(update, entity);
         update.Commit();
         return(newEntity);
     }
 }
예제 #3
0
 static public ServerPartition Insert(ServerPartition entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         ServerPartition newEntity = Insert(update, entity);
         update.Commit();
         return(newEntity);
     }
 }
예제 #4
0
 static public NotificationQueue Insert(NotificationQueue entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         NotificationQueue newEntity = Insert(update, entity);
         update.Commit();
         return(newEntity);
     }
 }
예제 #5
0
 static public RequestAttributes Insert(RequestAttributes entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         RequestAttributes newEntity = Insert(update, entity);
         update.Commit();
         return(newEntity);
     }
 }
예제 #6
0
 static public WorkQueueTypeProperties Insert(WorkQueueTypeProperties entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         WorkQueueTypeProperties newEntity = Insert(update, entity);
         update.Commit();
         return(newEntity);
     }
 }
예제 #7
0
 static public DataAccessGroup Insert(DataAccessGroup entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         DataAccessGroup newEntity = Insert(update, entity);
         update.Commit();
         return(newEntity);
     }
 }
 static public DevicePreferredTransferSyntax Insert(DevicePreferredTransferSyntax entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         DevicePreferredTransferSyntax newEntity = Insert(update, entity);
         update.Commit();
         return(newEntity);
     }
 }
 static public FilesystemStudyStorage Insert(FilesystemStudyStorage entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         FilesystemStudyStorage newEntity = Insert(update, entity);
         update.Commit();
         return(newEntity);
     }
 }
        /// <summary>
        /// Reset queue items that were unadvertly left in "in progress" state by previous run.
        /// </summary>
        public static void ResetFailedItems()
        {
            var settings = WorkQueueSettings.Instance;

            WorkQueueStatusEnum pending = WorkQueueStatusEnum.Pending;
            WorkQueueStatusEnum failed  = WorkQueueStatusEnum.Failed;

            using (IUpdateContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                IWorkQueueReset          reset = ctx.GetBroker <IWorkQueueReset>();
                WorkQueueResetParameters parms = new WorkQueueResetParameters();
                parms.ProcessorID = ServerPlatform.ProcessorId;

                // reschedule to start again now
                parms.RescheduleTime = Platform.Time;
                // retry will expire X minutes from now (so other process MAY NOT remove them)
                parms.RetryExpirationTime = Platform.Time.AddMinutes(2);

                // if an entry has been retried more than WorkQueueMaxFailureCount, it should be failed
                parms.MaxFailureCount = 3;
                // failed item expires now (so other process can remove them if desired)
                parms.FailedExpirationTime = Platform.Time;

                IList <Model.WorkQueue> modifiedList = reset.Find(parms);

                if (modifiedList != null)
                {
                    // output the list of items that have been reset
                    foreach (Model.WorkQueue queueItem in modifiedList)
                    {
                        if (queueItem.WorkQueueStatusEnum.Equals(pending))
                        {
                            Platform.Log(LogLevel.Info, "Cleanup: Reset Queue Item : {0} --> Status={1} Scheduled={2} ExpirationTime={3}",
                                         queueItem.GetKey().Key,
                                         queueItem.WorkQueueStatusEnum,
                                         queueItem.ScheduledTime,
                                         queueItem.ExpirationTime);
                        }
                    }

                    // output the list of items that have been failed because it exceeds the max retry count
                    foreach (Model.WorkQueue queueItem in modifiedList)
                    {
                        if (queueItem.WorkQueueStatusEnum.Equals(failed))
                        {
                            Platform.Log(LogLevel.Info, "Cleanup: Fail Queue Item  : {0} : FailureCount={1} ExpirationTime={2}",
                                         queueItem.GetKey().Key,
                                         queueItem.FailureCount,
                                         queueItem.ExpirationTime);
                        }
                    }
                }

                ctx.Commit();
            }
        }
 private IList <WorkQueueUid> LoadAllWorkQueueUids()
 {
     using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
     {
         IWorkQueueUidEntityBroker  broker   = context.GetBroker <IWorkQueueUidEntityBroker>();
         WorkQueueUidSelectCriteria criteria = new WorkQueueUidSelectCriteria();
         criteria.WorkQueueKey.EqualTo(WorkQueueItem.Key);
         return(broker.Find(criteria));
     }
 }
예제 #12
0
 public IList <Study> LoadRelatedStudies()
 {
     using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
     {
         IStudyEntityBroker  broker   = read.GetBroker <IStudyEntityBroker>();
         StudySelectCriteria criteria = new StudySelectCriteria();
         criteria.PatientKey.EqualTo(Key);
         return(broker.Find(criteria));
     }
 }
예제 #13
0
 /// <summary>
 /// Finds all <see cref="WorkQueueUids"/> this item.
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public static IList <WorkQueueUid> LoadAllWorkQueueUid(this WorkQueue item)
 {
     using (var readctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
     {
         IWorkQueueUidEntityBroker broker = readctx.GetBroker <IWorkQueueUidEntityBroker>();
         var criteria = new WorkQueueUidSelectCriteria();
         criteria.WorkQueueKey.EqualTo(item.Key);
         return(broker.Find(criteria));
     }
 }
예제 #14
0
 public bool IsArchivingScheduled()
 {
     using (var ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
     {
         var broker   = ctx.GetBroker <IArchiveQueueEntityBroker>();
         var criteria = new ArchiveQueueSelectCriteria();
         criteria.StudyStorageKey.EqualTo(StudyStorage.GetKey());
         return(broker.Find(criteria).Any());
     }
 }
예제 #15
0
 private PartitionArchive SelectPartitionArchive(StudyItem study)
 {
     using (var ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
     {
         var partitionArchiveBroker   = ctx.GetBroker <IPartitionArchiveEntityBroker>();
         var partitionArchiveCriteria = new PartitionArchiveSelectCriteria();
         partitionArchiveCriteria.ServerPartitionKey.EqualTo(study.StudyStorage.ServerPartitionKey);
         return(partitionArchiveBroker.Find(partitionArchiveCriteria).FirstOrDefault());
     }
 }
예제 #16
0
 /// <summary>
 /// Finds all <see cref="ServiceLock"/> of the specified <see cref="ServiceLockTypeEnum"/>
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static IList <ServiceLock> FindServicesOfType(ServiceLockTypeEnum type)
 {
     using (var readCtx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
     {
         var broker   = readCtx.GetBroker <IServiceLockEntityBroker>();
         var criteria = new ServiceLockSelectCriteria();
         criteria.ServiceLockTypeEnum.EqualTo(type);
         return(broker.Find(criteria));
     }
 }
예제 #17
0
        public WorkQueueProcessor(int numberThreads, ManualResetEvent terminateEvent, string name)
        {
            _terminateEvent = terminateEvent;
            _threadStop     = new ManualResetEvent(false);

            using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IWorkQueueTypePropertiesEntityBroker  broker   = ctx.GetBroker <IWorkQueueTypePropertiesEntityBroker>();
                WorkQueueTypePropertiesSelectCriteria criteria = new WorkQueueTypePropertiesSelectCriteria();

                IList <WorkQueueTypeProperties> propertiesList = broker.Find(criteria);
                foreach (WorkQueueTypeProperties prop in propertiesList)
                {
                    _propertiesDictionary.Add(prop.WorkQueueTypeEnum, prop);
                }
            }


            _threadPool =
                new WorkQueueThreadPool(numberThreads,
                                        WorkQueueSettings.Instance.PriorityWorkQueueThreadCount,
                                        WorkQueueSettings.Instance.MemoryLimitedWorkQueueThreadCount,
                                        _propertiesDictionary)
            {
                ThreadPoolName = name + " Pool"
            };


            WorkQueueFactoryExtensionPoint ep = new WorkQueueFactoryExtensionPoint();

            object[] factories = ep.CreateExtensions();

            if (factories == null || factories.Length == 0)
            {
                // No extension for the workqueue processor.
                Platform.Log(LogLevel.Warn, "No WorkQueueFactory Extension found.");
            }
            else
            {
                foreach (object obj in factories)
                {
                    IWorkQueueProcessorFactory factory = obj as IWorkQueueProcessorFactory;
                    if (factory != null)
                    {
                        WorkQueueTypeEnum type = factory.GetWorkQueueType();
                        _extensions.Add(type, factory);
                    }
                    else
                    {
                        Platform.Log(LogLevel.Error, "Unexpected incorrect type loaded for extension: {0}",
                                     obj.GetType());
                    }
                }
            }
        }
예제 #18
0
        /// <summary>
        /// Delete a Study.
        /// </summary>
        public void DeleteStudy(ServerEntityKey studyKey, string reason)
        {
            StudySummary study = StudySummaryAssembler.CreateStudySummary(HttpContextData.Current.ReadContext, Study.Load(HttpContextData.Current.ReadContext, studyKey));

            if (study.IsReconcileRequired)
            {
                throw new ApplicationException(
                          String.Format("Deleting the study is not allowed at this time : there are items to be reconciled."));

                // NOTE: another check will occur when the delete is actually processed
            }


            using (IUpdateContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                LockStudyParameters lockParms = new LockStudyParameters
                {
                    QueueStudyStateEnum = QueueStudyStateEnum.WebDeleteScheduled,
                    StudyStorageKey     = study.TheStudyStorage.Key
                };
                ILockStudy broker = ctx.GetBroker <ILockStudy>();
                broker.Execute(lockParms);
                if (!lockParms.Successful)
                {
                    throw new ApplicationException(String.Format("Unable to lock the study : {0}", lockParms.FailureReason));
                }


                InsertWorkQueueParameters insertParms = new InsertWorkQueueParameters
                {
                    WorkQueueTypeEnum  = WorkQueueTypeEnum.WebDeleteStudy,
                    ServerPartitionKey = study.ThePartition.Key,
                    StudyStorageKey    = study.TheStudyStorage.Key,
                    ScheduledTime      = Platform.Time
                };

                WebDeleteStudyLevelQueueData extendedData = new WebDeleteStudyLevelQueueData
                {
                    Level    = DeletionLevel.Study,
                    Reason   = reason,
                    UserId   = ServerHelper.CurrentUserId,
                    UserName = ServerHelper.CurrentUserName
                };
                insertParms.WorkQueueData = XmlUtils.SerializeAsXmlDoc(extendedData);
                IInsertWorkQueue insertWorkQueue = ctx.GetBroker <IInsertWorkQueue>();

                if (insertWorkQueue.FindOne(insertParms) == null)
                {
                    throw new ApplicationException("DeleteStudy failed");
                }


                ctx.Commit();
            }
        }
예제 #19
0
        protected override void Stop()
        {
            //TODO CR (Jan 2014): Move this into the base if it applies to all subclasses?
            PersistentStoreRegistry.GetDefaultStore().ShutdownRequested = true;

            if (_theProcessor != null)
            {
                _theProcessor.Stop();
                _theProcessor = null;
            }
        }
예제 #20
0
 private static StudyStorage FindStudyStorage(ScanResultEntry result)
 {
     using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
     {
         IStudyStorageEntityBroker  broker   = ctx.GetBroker <IStudyStorageEntityBroker>();
         StudyStorageSelectCriteria criteria = new StudyStorageSelectCriteria();
         criteria.StudyInstanceUid.EqualTo(result.StudyInstanceUid);
         criteria.ServerPartitionKey.EqualTo(result.ServerPartitionKey);
         return(broker.FindOne(criteria));
     }
 }
        /// <summary>
        /// Finds all storage locations used for the study.
        /// </summary>
        protected void FindAllRelatedDirectories()
        {
            // Check the work queue for other entries
            IList <Model.WorkQueue> list;

            // NOTE: a local read context is used for lookup because we want to
            // release the lock on the rows asap.
            using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IWorkQueueEntityBroker  broker   = ctx.GetBroker <IWorkQueueEntityBroker>();
                WorkQueueSelectCriteria criteria = new WorkQueueSelectCriteria();
                criteria.StudyStorageKey.EqualTo(WorkQueueItem.StudyStorageKey);
                list = broker.Find(criteria);
            }


            List <DirectoryInfo> dirs = new List <DirectoryInfo>();

            foreach (Model.WorkQueue item in list)
            {
                string path = GetWorkQueueSecondaryFolder(item);
                if (!string.IsNullOrEmpty(path))
                {
                    dirs.Add(new DirectoryInfo(path));
                }
            }

            // NOTE: Under normal operation, the SIQ entries should be
            // empty at this point because the Delete Study button is disabled otherwise.
            // This block of code is still needed just in case this DeleteStudy work queue entry
            // is inserted through different means.
            IList <StudyIntegrityQueue> siqList;

            using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IStudyIntegrityQueueEntityBroker  broker   = ctx.GetBroker <IStudyIntegrityQueueEntityBroker>();
                StudyIntegrityQueueSelectCriteria criteria = new StudyIntegrityQueueSelectCriteria();
                criteria.StudyStorageKey.EqualTo(WorkQueueItem.StudyStorageKey);
                siqList = broker.Find(criteria);
            }

            foreach (StudyIntegrityQueue item in siqList)
            {
                string path = GetSIQItemStorageFolder(item);
                if (!string.IsNullOrEmpty(path))
                {
                    dirs.Add(new DirectoryInfo(path));
                }
            }


            _relatedDirectories = dirs;
        }
        /// <summary>
        /// Load the list of currently configured <see cref="ServerPartition"/> instances.
        /// </summary>
        /// <returns>The partition list.</returns>
        private static IList <ServerPartition> LoadPartitions()
        {
            //Get partitions
            IPersistentStore store = PersistentStoreRegistry.GetDefaultStore();

            using (IReadContext read = store.OpenReadContext())
            {
                IServerPartitionEntityBroker  broker   = read.GetBroker <IServerPartitionEntityBroker>();
                ServerPartitionSelectCriteria criteria = new ServerPartitionSelectCriteria();
                return(broker.Find(criteria));
            }
        }
예제 #23
0
        private static bool CheckIfStudyIsInWorkQueue(ScanResultEntry scanResult)
        {
            using (IReadContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IWorkQueueEntityBroker  broker   = ctx.GetBroker <IWorkQueueEntityBroker>();
                WorkQueueSelectCriteria criteria = new WorkQueueSelectCriteria();
                criteria.StudyStorageKey.EqualTo(scanResult.Storage.Key);
                var list = broker.Find(criteria);
                scanResult.IsInWorkQueue = list != null && list.Count > 0;
            }

            return(scanResult.IsInWorkQueue);
        }
예제 #24
0
        public void EditStudy(Study study, List <UpdateItem> updateItems, string reason)
        {
            Platform.Log(LogLevel.Info, String.Format("Editing study {0}", study.StudyInstanceUid));

            using (IUpdateContext ctx = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                IList <WorkQueue> entries = StudyEditorHelper.EditStudy(ctx, study.StudyStorageKey, updateItems, reason, ServerHelper.CurrentUserName, EditType.WebEdit);
                if (entries != null)
                {
                    ctx.Commit();
                }
            }
        }
예제 #25
0
        private StudyStorageLocation ReloadStorageLocation()
        {
            using (IReadContext readContext = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                var parms = new StudyStorageLocationQueryParameters {
                    StudyStorageKey = _location.Key
                };
                var broker = readContext.GetBroker <IQueryStudyStorageLocation>();
                _location = broker.FindOne(parms);
            }

            return(_location);
        }
예제 #26
0
 protected override void Stop()
 {
     //TODO CR (Jan 2014): Move this into the base if it applies to all subclasses?
     PersistentStoreRegistry.GetDefaultStore().ShutdownRequested = true;
     lock (_syncLock)
     {
         foreach (PartitionArchiveService node in _archiveServiceList)
         {
             Platform.Log(LogLevel.Info, "Stopping partition archive: {0}", node.PartitionArchive.Description);
             node.ArchivePlugin.Stop();
         }
     }
 }
예제 #27
0
        private void LoadStudyPartition(string studyInstanceUid)
        {
            using (IReadContext read = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IStudyEntityBroker selectStudy = read.GetBroker <IStudyEntityBroker>();

                StudySelectCriteria criteria = new StudySelectCriteria();
                criteria.StudyInstanceUid.EqualTo(studyInstanceUid);
                Study theStudy = selectStudy.FindOne(criteria);

                Partition = ServerPartition.Load(read, theStudy.ServerPartitionKey);
            }
        }
        /// <summary>
        /// Load the list of <see cref="PartitionArchive"/> entries that are enabled.
        /// </summary>
        /// <returns>The list of <see cref="PartitionArchive"/> instances from the persistant store</returns>
        private static IList <PartitionArchive> LoadEnabledPartitionArchives()
        {
            using (IReadContext readContext = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IPartitionArchiveEntityBroker broker = readContext.GetBroker <IPartitionArchiveEntityBroker>();

                PartitionArchiveSelectCriteria criteria = new PartitionArchiveSelectCriteria();

                criteria.Enabled.EqualTo(true);

                return(broker.Find(criteria));
            }
        }
예제 #29
0
        protected bool GetStudyStorageLocation(ServerEntityKey partitionKey, string studyInstanceUid, out StudyStorageLocation location)
        {
            using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                IQueryStudyStorageLocation          procedure = context.GetBroker <IQueryStudyStorageLocation>();
                StudyStorageLocationQueryParameters parms     = new StudyStorageLocationQueryParameters();
                parms.ServerPartitionKey = partitionKey;
                parms.StudyInstanceUid   = studyInstanceUid;
                location = procedure.FindOne(parms);

                return(location != null);
            }
        }
예제 #30
0
        private IList <PartitionSopClass> LoadPartitionSopClassesFromDatabase(ServerPartition partition)
        {
            using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
            {
                // Set the input parameters for query
                var inputParms = new PartitionSopClassQueryParameters {
                    ServerPartitionKey = partition.GetKey()
                };

                var broker = context.GetBroker <IQueryServerPartitionSopClasses>();
                return(broker.Find(inputParms));
            }
        }