/// <summary>
        /// Resets a list of <see cref="WorkQueue"/> items.
        /// </summary>
        /// <param name="items">List of <see cref="WorkQueue"/>  to be reset</param>
        /// <param name="newScheduledTime">The new scheduled start date/time for the entries</param>
        /// <param name="expirationTime">The new expiration start date/time for the entries</param>
        public void ResetWorkQueueItems(IList <WorkQueue> items, DateTime newScheduledTime, DateTime expirationTime)
        {
            if (items == null || items.Count == 0)
            {
                return;
            }

            IPersistentStore store = PersistentStoreRegistry.GetDefaultStore();

            using (IReadContext ctx = store.OpenReadContext())
            {
                IWebResetWorkQueue broker = ctx.GetBroker <IWebResetWorkQueue>();
                foreach (WorkQueue item in items)
                {
                    WebResetWorkQueueParameters parameters = new WebResetWorkQueueParameters
                    {
                        WorkQueueKey      = item.Key,
                        NewScheduledTime  = newScheduledTime,
                        NewExpirationTime = expirationTime
                    };

                    if (!broker.Execute(parameters))
                    {
                        Platform.Log(LogLevel.Error,
                                     "Unexpected error when calling WebResetWorkQueue stored procedure. Could not reset {0} work queue entry {1}",
                                     item.WorkQueueTypeEnum.Description, item.Key);
                    }
                }
            }
        }
Exemplo n.º 2
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
                        {
                            IPersistentStore store = PersistentStoreRegistry.GetDefaultStore();
                            using (IReadContext ctx = store.OpenReadContext())
                            {
                                var deleteRuleBroker         = ctx.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 = Common.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 = Common.ServerOperatingMode.TemporaryCache;
                                }
                                else
                                {
                                    if (customDeleteRuleExists)
                                    {
                                        _serverMode = Common.ServerOperatingMode.MixedMode;
                                    }
                                    else
                                    {
                                        _serverMode = Common.ServerOperatingMode.Archive;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Error, ex);
                        }
                        finally
                        {
                            _systemModeLastCheckTimestamp = now;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Return snapshot of all related items in the Study Integrity Queue.
        /// </summary>
        /// <returns></returns>
        public IList <StudyIntegrityQueue> GetRelatedStudyIntegrityQueueItems()
        {
            lock (SyncRoot) // make this thread-safe
            {
                if (_integrityQueueItems == null)
                {
                    using (IReadContext ctx = _store.OpenReadContext())
                    {
                        IStudyIntegrityQueueEntityBroker integrityQueueBroker =
                            ctx.GetBroker <IStudyIntegrityQueueEntityBroker>();
                        StudyIntegrityQueueSelectCriteria parms = new StudyIntegrityQueueSelectCriteria();

                        parms.StudyStorageKey.EqualTo(GetKey());

                        _integrityQueueItems = integrityQueueBroker.Find(parms);
                    }
                }
            }
            return(_integrityQueueItems);
        }
        /// <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));
            }
        }
Exemplo n.º 5
0
        private Study GetStudyAndQueues(StudyStorageLocation location, out int integrityQueueCount, out int workQueueCount)
        {
            using (IReadContext context = _store.OpenReadContext())
            {
                IStudyIntegrityQueueEntityBroker  integrityBroker   = context.GetBroker <IStudyIntegrityQueueEntityBroker>();
                StudyIntegrityQueueSelectCriteria integrityCriteria = new StudyIntegrityQueueSelectCriteria();
                integrityCriteria.StudyStorageKey.EqualTo(location.Key);
                integrityQueueCount = integrityBroker.Count(integrityCriteria);

                IWorkQueueEntityBroker  workBroker   = context.GetBroker <IWorkQueueEntityBroker>();
                WorkQueueSelectCriteria workCriteria = new WorkQueueSelectCriteria();
                workCriteria.StudyStorageKey.EqualTo(location.Key);
                workQueueCount = workBroker.Count(workCriteria);

                IStudyEntityBroker  procedure = context.GetBroker <IStudyEntityBroker>();
                StudySelectCriteria criteria  = new StudySelectCriteria();
                criteria.StudyStorageKey.EqualTo(location.Key);
                return(procedure.FindOne(criteria));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get the Status of a study.
        /// </summary>
        /// <param name="studyInstanceUid">The Study to check for.</param>
        /// <param name="studyStorage">The returned study storage object</param>
        /// <returns>true on success, false on no records found.</returns>
        public bool GetStudyStatus(string studyInstanceUid, out StudyStorage studyStorage)
        {
            using (IReadContext read = _store.OpenReadContext())
            {
                IStudyStorageEntityBroker  selectBroker = read.GetBroker <IStudyStorageEntityBroker>();
                StudyStorageSelectCriteria criteria     = new StudyStorageSelectCriteria();

                criteria.ServerPartitionKey.EqualTo(Partition.GetKey());
                criteria.StudyInstanceUid.EqualTo(studyInstanceUid);

                IList <StudyStorage> storageList = selectBroker.Find(criteria);

                foreach (StudyStorage studyLocation in storageList)
                {
                    studyStorage = studyLocation;
                    return(true);
                }
                studyStorage = null;
                return(false);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Internal method for loading partition information fromt he database.
        /// </summary>
        private void LoadPartitions()
        {
            bool changed = false;

            lock (_partitionsLock)
            {
                try
                {
                    Dictionary <string, ServerPartition> templist = new Dictionary <string, ServerPartition>();
                    IPersistentStore store = PersistentStoreRegistry.GetDefaultStore();
                    using (IReadContext ctx = store.OpenReadContext())
                    {
                        IServerPartitionEntityBroker  broker   = ctx.GetBroker <IServerPartitionEntityBroker>();
                        ServerPartitionSelectCriteria criteria = new ServerPartitionSelectCriteria();
                        IList <ServerPartition>       list     = broker.Find(criteria);
                        foreach (ServerPartition partition in list)
                        {
                            if (IsChanged(partition))
                            {
                                changed = true;
                            }

                            templist.Add(partition.AeTitle, partition);
                        }
                    }

                    _partitions = templist;

                    if (changed && _changedListener != null)
                    {
                        EventsHelper.Fire(_changedListener, this, new ServerPartitionChangedEventArgs(this));
                    }
                }
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex,
                                 "Unexpected exception when loading partitions, possible database error.  Operation will be retried later");
                }
            }// lock
        }
Exemplo n.º 8
0
        /// <summary>
        /// Load filesystem information from the database.
        /// </summary>
        private void LoadFilesystems()
        {
            bool changed = false;

            lock (SyncLock)
            {
                try
                {
                    List <FilesystemTierEnum> tiers = FilesystemTierEnum.GetAll();

                    // sorted by enum values
                    tiers.Sort((tier1, tier2) => tier1.Enum.CompareTo(tier2.Enum));

                    _tierInfo = new TierInfo();

                    foreach (FilesystemTierEnum tier in tiers)
                    {
                        _tierInfo.Add(tier, new List <ServerFilesystemInfo>());
                    }

                    using (IReadContext read = _store.OpenReadContext())
                    {
                        IFilesystemEntityBroker  filesystemSelect = read.GetBroker <IFilesystemEntityBroker>();
                        FilesystemSelectCriteria criteria         = new FilesystemSelectCriteria();
                        IList <Filesystem>       filesystemList   = filesystemSelect.Find(criteria);

                        foreach (Filesystem filesystem in filesystemList)
                        {
                            if (_filesystemList.ContainsKey(filesystem.Key))
                            {
                                if ((filesystem.HighWatermark != _filesystemList[filesystem.Key].Filesystem.HighWatermark) ||
                                    (filesystem.LowWatermark != _filesystemList[filesystem.Key].Filesystem.LowWatermark))
                                {
                                    Platform.Log(LogLevel.Info, "Watermarks have changed for filesystem {0}, Low: {1}, High: {2}",
                                                 filesystem.Description, filesystem.LowWatermark, filesystem.HighWatermark);
                                }
                                _filesystemList[filesystem.Key].Filesystem = filesystem;
                                _tierInfo[filesystem.FilesystemTierEnum].Add(_filesystemList[filesystem.Key]);
                            }
                            else
                            {
                                ServerFilesystemInfo info = new ServerFilesystemInfo(filesystem);
                                _filesystemList.Add(filesystem.Key, info);
                                _tierInfo[filesystem.FilesystemTierEnum].Add(info);
                                info.LoadFreeSpace();
                                changed = true;
                            }
                        }
                    }
                    if (changed && _changedListener != null)
                    {
                        EventsHelper.Fire(_changedListener, this, new FilesystemChangedEventArgs(this));
                    }
                }
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex,
                                 "Exception has occurred while updating the filesystem list from the datbase. Retry later");
                }
            }
        }