static public RequestAttributes Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
Exemplo n.º 2
0
 static public ArchiveStudyStorage Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
Exemplo n.º 3
0
 static public FilesystemQueue Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
 static public ServerPartitionAlternateAeTitle Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
Exemplo n.º 5
0
 static public StudyIntegrityQueueUid Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
        protected override void OnProcess(Model.ServiceLock item)
        {
            _store = PersistentStoreRegistry.GetDefaultStore();
            using (var context = new ServerExecutionContext())
            {
                var broker   = context.ReadContext.GetBroker <IServerPartitionEntityBroker>();
                var criteria = new ServerPartitionSelectCriteria();
                criteria.AeTitle.SortAsc(0);

                _partitions = broker.Find(criteria);
            }

            ServerFilesystemInfo info = FilesystemMonitor.Instance.GetFilesystemInfo(item.FilesystemKey);

            Platform.Log(LogLevel.Info, "Starting reinventory of filesystem: {0}", info.Filesystem.Description);

            ReinventoryFilesystem(info.Filesystem);

            item.ScheduledTime = item.ScheduledTime.AddDays(1);

            if (CancelPending)
            {
                Platform.Log(LogLevel.Info,
                             "Filesystem Reinventory of {0} has been canceled, rescheduling.  Note that the entire Filesystem will be reinventoried again.",
                             info.Filesystem.Description);
                UnlockServiceLock(item, true, Platform.Time.AddMinutes(1));
            }
            else
            {
                Platform.Log(LogLevel.Info, "Filesystem Reinventory of {0} has completed.",
                             info.Filesystem.Description);
                UnlockServiceLock(item, false, Platform.Time.AddDays(1));
            }
        }
Exemplo n.º 7
0
 public static StudyStorage Load(ServerEntityKey partitionKey, string studyInstanceUid)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, partitionKey, studyInstanceUid));
     }
 }
Exemplo n.º 8
0
 static public WorkQueueTypeProperties Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Returns number of Delete Study, Tier Migrate, and Study Purge work queue items
        /// that are still Pending or In Progress for the filesystem associated with the
        /// specified <see cref="ServiceLock"/>.
        /// </summary>
        /// <param name="item">The ServiceLock item.</param>
        /// <returns>The number of WorkQueue entries pending.</returns>
        private int CheckWorkQueueCount(Model.ServiceLock item)
        {
            using (ServerExecutionContext context = new ServerExecutionContext())
            {
                IWorkQueueEntityBroker select = context.ReadContext.GetBroker <IWorkQueueEntityBroker>();

                WorkQueueSelectCriteria criteria = new WorkQueueSelectCriteria();

                criteria.WorkQueueTypeEnum.In(new[]
                {
                    WorkQueueTypeEnum.DeleteStudy, WorkQueueTypeEnum.MigrateStudy,
                    WorkQueueTypeEnum.PurgeStudy
                });

                // Do Pending status, in case there's a Failure status entry, we don't want to
                // block on that.
                criteria.WorkQueueStatusEnum.In(new[] { WorkQueueStatusEnum.Pending, WorkQueueStatusEnum.InProgress });

                FilesystemStudyStorageSelectCriteria filesystemCriteria = new FilesystemStudyStorageSelectCriteria();

                filesystemCriteria.FilesystemKey.EqualTo(item.FilesystemKey);

                criteria.FilesystemStudyStorageRelatedEntityCondition.Exists(filesystemCriteria);
                int count = select.Count(criteria);

                return(count);
            }
        }
Exemplo n.º 10
0
 public static WorkQueue Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return Load(context.ReadContext, key);
     }
 }
        /// <summary>
        /// Load the <see cref="ServerRulesEngine"/> for each partition.
        /// </summary>
        private void LoadRulesEngine()
        {
            using (var context = new ServerExecutionContext())
            {
                var broker   = context.ReadContext.GetBroker <IServerPartitionEntityBroker>();
                var criteria = new ServerPartitionSelectCriteria();
                IList <ServerPartition> partitions = broker.Find(criteria);

                foreach (ServerPartition partition in partitions)
                {
                    //TODO CR (Jan 2014) - Cached engine not being used now, due to #11673
                    var engine = new ServerRulesEngine(ServerRuleApplyTimeEnum.StudyProcessed, partition.Key);
                    engine.Load();
                    _engines.Add(partition, engine);

                    engine = new ServerRulesEngine(ServerRuleApplyTimeEnum.StudyArchived, partition.Key);
                    engine.Load();
                    _postArchivalEngines.Add(partition, engine);

                    engine = new ServerRulesEngine(ServerRuleApplyTimeEnum.StudyProcessed, partition.Key);
                    engine.AddIncludeType(ServerRuleTypeEnum.DataAccess);
                    engine.Load();
                    _dataAccessEngine.Add(partition, engine);
                }
            }
        }
Exemplo n.º 12
0
 static public Order Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Process the <see cref="ServiceLock"/> item.
        /// </summary>
        /// <param name="item"></param>
        protected override void OnProcess(Model.ServiceLock item)
        {
            PersistentStoreRegistry.GetDefaultStore();

            using (ServerExecutionContext context = new ServerExecutionContext())
            {
                IServerPartitionEntityBroker  broker   = context.ReadContext.GetBroker <IServerPartitionEntityBroker>();
                ServerPartitionSelectCriteria criteria = new ServerPartitionSelectCriteria();
                criteria.AeTitle.SortAsc(0);

                _partitions = broker.Find(criteria);
            }

            ServerFilesystemInfo info = FilesystemMonitor.Instance.GetFilesystemInfo(item.FilesystemKey);

            Platform.Log(LogLevel.Info, "Starting rebuilding of Study XML files for filesystem: {0}", info.Filesystem.Description);

            TraverseFilesystemStudies(info.Filesystem);

            item.ScheduledTime = item.ScheduledTime.AddDays(1);

            if (CancelPending)
            {
                Platform.Log(LogLevel.Info,
                             "FilesystemRebuildXml of {0} has been canceled, rescheduling.  Note that the entire Filesystem will be rebuilt again.",
                             info.Filesystem.Description);
                UnlockServiceLock(item, true, Platform.Time.AddMinutes(1));
            }
            else
            {
                UnlockServiceLock(item, false, Platform.Time.AddDays(1));
            }

            Platform.Log(LogLevel.Info, "Completed rebuilding of the Study XML files for filesystem: {0}", info.Filesystem.Description);
        }
Exemplo n.º 14
0
 static public DevicePreferredTransferSyntax Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// Retrieves the storage location from the database for the specified study storage key.  Checks if the filesystem is online.
        /// </summary>
        /// <param name="studyStorageKey"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        public bool GetWritableStudyStorageLocation(ServerEntityKey studyStorageKey, out StudyStorageLocation location)
        {
            // NOTE: THIS METHOD SHOULD NOT LOAD THE RECORD FROM THE CACHE

            using (ServerExecutionContext context = new ServerExecutionContext())
            {
                IQueryStudyStorageLocation          procedure = context.ReadContext.GetBroker <IQueryStudyStorageLocation>();
                StudyStorageLocationQueryParameters parms     = new StudyStorageLocationQueryParameters
                {
                    StudyStorageKey = studyStorageKey
                };
                IList <StudyStorageLocation> locationList = procedure.Find(parms);

                foreach (StudyStorageLocation studyLocation in locationList)
                {
                    string reason;
                    if (CheckFilesystemOnline(studyLocation.FilesystemKey, out reason))
                    {
                        location = studyLocation;
                        return(true);
                    }
                }

                // TODO: throw new FilesystemIsNotWritableException();
                location = null;
                return(false);
            }
        }
Exemplo n.º 16
0
 static public StudyDeleteRecord Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// Find all <see cref="StudyStorageLocation"/> associcated with the specified <see cref="StudyStorage"/>
 /// </summary>
 /// <param name="storage"></param>
 /// <returns></returns>
 static public IList <StudyStorageLocation> FindStorageLocations(StudyStorage storage)
 {
     using (var context = new ServerExecutionContext())
     {
         return(FindStorageLocations(context.ReadContext, storage, null));
     }
 }
 static public ServerPartitionDataAccess Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
Exemplo n.º 19
0
        /// <summary>
        /// Validates the state of the study.
        /// </summary>
        /// <param name="context">Name of the application</param>
        /// <param name="studyStorage">The study to validate</param>
        /// <param name="modes">Specifying what validation to execute</param>
        public void ValidateStudyState(String context, StudyStorageLocation studyStorage, StudyIntegrityValidationModes modes)
        {
            Platform.CheckForNullReference(studyStorage, "studyStorage");
            if (modes == StudyIntegrityValidationModes.None)
            {
                return;
            }

            using (ServerExecutionContext scope = new ServerExecutionContext())
            {
                Study study = studyStorage.LoadStudy(scope.PersistenceContext);
                if (study != null)
                {
                    StudyXml studyXml = studyStorage.LoadStudyXml();

                    if (modes == StudyIntegrityValidationModes.Default ||
                        (modes & StudyIntegrityValidationModes.InstanceCount) == StudyIntegrityValidationModes.InstanceCount)
                    {
                        if (studyXml != null && studyXml.NumberOfStudyRelatedInstances != study.NumberOfStudyRelatedInstances)
                        {
                            ValidationStudyInfo validationStudyInfo = new ValidationStudyInfo(study, studyStorage.ServerPartition);

                            throw new StudyIntegrityValidationFailure(
                                      ValidationErrors.InconsistentObjectCount, validationStudyInfo,
                                      String.Format("Number of instances in database and xml do not match: {0} vs {1}.",
                                                    study.NumberOfStudyRelatedInstances,
                                                    studyXml.NumberOfStudyRelatedInstances
                                                    ));
                        }
                    }
                }
            }
        }
Exemplo n.º 20
0
 static public ServerSopClass Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return Load(context.ReadContext, key);
     }
 }
 static public ExternalRequestQueue Load(ServerEntityKey key)
 {
     using (var context = new ServerExecutionContext())
     {
         return(Load(context.ReadContext, key));
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// Retrieves the storage location from the database for the specified study.  Checks if the filesystem is writable.
        /// </summary>
        /// <param name="location">The output storage location</param>
        /// <param name="partitionKey">The primark key of the ServerPartition table.</param>
        /// <param name="studyInstanceUid">The Study Instance UID of the study</param>
        /// <param name="cache">Should the study location be cached?</param>
        /// <param name="restore">If nearline, should the study be restored?</param>
        /// <returns></returns>
        public void GetWritableStudyStorageLocation(ServerEntityKey partitionKey, string studyInstanceUid, StudyRestore restore, StudyCache cache, out StudyStorageLocation location)
        {
            using (var context = new ServerExecutionContext())
            {
                string reason;

                if (cache == StudyCache.True)
                {
                    location = _storageLocationCache.GetCachedStudy(partitionKey, studyInstanceUid);
                    if (location != null)
                    {
                        if (CheckFilesystemWriteable(location.FilesystemKey, out reason))
                        {
                            return;
                        }
                    }
                }
                else
                {
                    location = null;
                }

                IQueryStudyStorageLocation          procedure = context.ReadContext.GetBroker <IQueryStudyStorageLocation>();
                StudyStorageLocationQueryParameters parms     = new StudyStorageLocationQueryParameters
                {
                    ServerPartitionKey = partitionKey,
                    StudyInstanceUid   = studyInstanceUid
                };
                IList <StudyStorageLocation> locationList = procedure.Find(parms);

                bool found = false;
                FilesystemNotWritableException x = new FilesystemNotWritableException();

                foreach (StudyStorageLocation studyLocation in locationList)
                {
                    if (CheckFilesystemWriteable(studyLocation.FilesystemKey, out reason))
                    {
                        location = studyLocation;
                        if (cache == StudyCache.True)
                        {
                            _storageLocationCache.AddCachedStudy(location);
                        }
                        return;
                    }
                    found    = true;
                    x.Reason = reason;
                    x.Path   = studyLocation.StudyFolder;
                }

                if (found)
                {
                    throw x;
                }

                CheckForStudyRestore(context.ReadContext, partitionKey, studyInstanceUid, restore);
            }
        }
Exemplo n.º 23
0
        private static void CheckSystemMode()
        {
            var now = Platform.Time;

            if (!_systemModeLastCheckTimestamp.HasValue || now - _systemModeLastCheckTimestamp > TimeSpan.FromSeconds(15))
            {
                lock (_syncLock)
                {
                    if (!_systemModeLastCheckTimestamp.HasValue || now - _systemModeLastCheckTimestamp > TimeSpan.FromSeconds(15))
                    {
                        try
                        {
                            using (var context = new ServerExecutionContext())
                            {
                                var deleteRuleBroker         = context.ReadContext.GetBroker <IServerRuleEntityBroker>();
                                var deleteRuleSearchCriteria = new ServerRuleSelectCriteria();
                                deleteRuleSearchCriteria.ServerRuleTypeEnum.EqualTo(ServerRuleTypeEnum.StudyDelete);
                                deleteRuleSearchCriteria.Enabled.EqualTo(true);
                                var deleteRules = deleteRuleBroker.Find(deleteRuleSearchCriteria);

                                if (deleteRules == null || deleteRules.Count == 0)
                                {
                                    _serverMode = ServerOperatingMode.Archive;
                                }

                                var defaultDeleteRuleExists = deleteRules.Any(r => r.RuleName.Equals("Default Delete"));
                                var customDeleteRuleExists  = deleteRules.Any(r => !r.RuleName.Equals("Default Delete"));

                                if (defaultDeleteRuleExists)
                                {
                                    _serverMode = ServerOperatingMode.TemporaryCache;
                                }
                                else
                                {
                                    if (customDeleteRuleExists)
                                    {
                                        _serverMode = ServerOperatingMode.MixedMode;
                                    }
                                    else
                                    {
                                        _serverMode = ServerOperatingMode.Archive;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Error, ex);
                        }
                        finally
                        {
                            _systemModeLastCheckTimestamp = now;
                        }
                    }
                }
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Retrieves the storage location from the database for the specified study.  Checks if the filesystem is readable.
        /// </summary>
        /// <param name="partitionKey"></param>
        /// <param name="studyInstanceUid"></param>
        /// <param name="restore"></param>
        /// <param name="cache"></param>
        /// <param name="location"></param>
        public void GetReadableStudyStorageLocation(ServerEntityKey partitionKey, string studyInstanceUid, StudyRestore restore, StudyCache cache,
                                                    out StudyStorageLocation location)
        {
            using (ServerExecutionContext context = new ServerExecutionContext())
            {
                // Get the cached value, if it exists, otherwise fall down and recheck
                // and handle any nearline issues below
                location = _storageLocationCache.GetCachedStudy(partitionKey, studyInstanceUid);
                if (location != null)
                {
                    string reason;
                    if (CheckFilesystemReadable(location.FilesystemKey, out reason))
                    {
                        return;
                    }
                }

                IQueryStudyStorageLocation          procedure = context.ReadContext.GetBroker <IQueryStudyStorageLocation>();
                StudyStorageLocationQueryParameters parms     = new StudyStorageLocationQueryParameters
                {
                    StudyInstanceUid   = studyInstanceUid,
                    ServerPartitionKey = partitionKey
                };
                IList <StudyStorageLocation> locationList = procedure.Find(parms);

                bool foundStudy = false;

                FilesystemNotReadableException x = new FilesystemNotReadableException();

                foreach (StudyStorageLocation studyLocation in locationList)
                {
                    string reason;
                    if (CheckFilesystemReadable(studyLocation.FilesystemKey, out reason))
                    {
                        location = studyLocation;

                        if (cache == StudyCache.True)
                        {
                            _storageLocationCache.AddCachedStudy(location);
                        }

                        return;
                    }
                    foundStudy = true;
                    x.Path     = studyLocation.FilesystemPath;
                    x.Reason   = reason;
                }

                if (foundStudy)
                {
                    throw x;
                }

                CheckForStudyRestore(context.ReadContext, partitionKey, studyInstanceUid, restore);
            }
        }
Exemplo n.º 25
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 context = new ServerExecutionContext())
     {
         var broker   = context.ReadContext.GetBroker <IServiceLockEntityBroker>();
         var criteria = new ServiceLockSelectCriteria();
         criteria.ServiceLockTypeEnum.EqualTo(type);
         return(broker.Find(criteria));
     }
 }
Exemplo n.º 26
0
 public IList <Study> LoadRelatedStudies()
 {
     using (var context = new ServerExecutionContext())
     {
         IStudyEntityBroker  broker   = context.ReadContext.GetBroker <IStudyEntityBroker>();
         StudySelectCriteria criteria = new StudySelectCriteria();
         criteria.PatientKey.EqualTo(Key);
         return(broker.Find(criteria));
     }
 }
Exemplo n.º 27
0
 static public IList <StudyStorageLocation> FindStorageLocations(ServerEntityKey studyStorageKey)
 {
     using (var context = new ServerExecutionContext())
     {
         var parms = new StudyStorageLocationQueryParameters {
             StudyStorageKey = studyStorageKey
         };
         var broker = context.ReadContext.GetBroker <IQueryStudyStorageLocation>();
         return(broker.Find(parms));
     }
 }
Exemplo n.º 28
0
        private static bool GetStudyStorage(ServerPartition partition, string studyInstanceUid, out StudyStorage storage)
        {
            using (ServerExecutionContext context = new ServerExecutionContext())
            {
                storage = StudyStorage.Load(context.ReadContext, partition.Key, studyInstanceUid);
                if (storage != null)
                {
                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Query for the all archival records for a study, sorted by archive time descendingly (latest first).
        /// </summary>
        /// <param name="studyStorageKey">The primary key of the StudyStorgae table.</param>
        /// <returns>null if not found, else the value.</returns>
        static public IList <ArchiveStudyStorage> GetArchiveLocations(ServerEntityKey studyStorageKey)
        {
            using (var context = new ServerExecutionContext())
            {
                ArchiveStudyStorageSelectCriteria archiveStudyStorageCriteria = new ArchiveStudyStorageSelectCriteria();
                archiveStudyStorageCriteria.StudyStorageKey.EqualTo(studyStorageKey);
                archiveStudyStorageCriteria.ArchiveTime.SortDesc(0);

                IArchiveStudyStorageEntityBroker broker = context.ReadContext.GetBroker <IArchiveStudyStorageEntityBroker>();

                return(broker.Find(archiveStudyStorageCriteria));
            }
        }
Exemplo n.º 30
0
 static public IList <StudyStorageLocation> FindStorageLocations(ServerEntityKey partitionKey, string studyInstanceUid)
 {
     using (var context = new ServerExecutionContext())
     {
         IQueryStudyStorageLocation          locQuery = context.ReadContext.GetBroker <IQueryStudyStorageLocation>();
         StudyStorageLocationQueryParameters locParms = new StudyStorageLocationQueryParameters
         {
             StudyInstanceUid   = studyInstanceUid,
             ServerPartitionKey = partitionKey
         };
         IList <StudyStorageLocation> list = locQuery.Find(locParms);
         return(list);
     }
 }