Beispiel #1
0
    	/// <summary>
        /// Insert a request to restore the specified <seealso cref="StudyStorage"/>
        /// </summary>
        /// <param name="storage"></param>
        /// <returns>Reference to the <see cref="RestoreQueue"/> that was inserted.</returns>
        static public RestoreQueue InsertRestoreRequest(StudyStorage storage)
        {
            // TODO:
            // Check the stored procedure to see if it will insert another request if one already exists

            Platform.CheckForNullReference(storage, "storage");

            using (IUpdateContext updateContext = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                IInsertRestoreQueue broker = updateContext.GetBroker<IInsertRestoreQueue>();

                InsertRestoreQueueParameters parms = new InsertRestoreQueueParameters {StudyStorageKey = storage.Key};

            	RestoreQueue queue = broker.FindOne(parms);

                if (queue == null)
                {
                    Platform.Log(LogLevel.Error, "Unable to request restore for study {0}", storage.StudyInstanceUid);
                    return null;
                }

                updateContext.Commit();
                Platform.Log(LogLevel.Info, "Restore requested for study {0}", storage.StudyInstanceUid);
                return queue;
            }
        }
Beispiel #2
0
 /// <summary>
 /// Loads the related <see cref="StudyStorage"/> entity.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 private StudyStorage LoadStudyStorage(IPersistenceContext context)
 {
     if (_studyStorage == null)
     {
         lock (_syncLock)
         {
             _studyStorage = StudyStorage.Load(context, StudyStorageKey);
         }
     }
     return _studyStorage;
 }
		public PurgeStudyCommand(StudyStorage studyStorage) : base()
		{
			var storageLocations = StudyStorageLocation.FindStorageLocations(studyStorage);
			AddSubCommand(new VerifyStudyHasBeenArchivedCommand(studyStorage));
			foreach (var location in storageLocations)
			{
				string path = location.GetStudyPath();
				AddSubCommand(new Dicom.Utilities.Command.DeleteDirectoryCommand(path, false));
			}

			AddSubCommand(new SetStudyStatusNearlineCommand(studyStorage));
		}
Beispiel #4
0
        private void LoadRelatedEntities()
        {
            if (_study==null || _studyStorage==null)
            {
                using (var context = new ServerExecutionContext())
                {
                    lock (SyncRoot)
                    {
                        if (_study == null)
                            _study = LoadStudy(context.ReadContext);

                        if (_studyStorage == null)
                            _studyStorage = LoadStudyStorage(context.ReadContext);
                    }
                }    
            }
        }
        /// <summary>
        /// Returns all authority groups (data-access or not) 
        /// that have access to the study not through direct data access assignment but through other means, such as administrative tokens
        /// </summary>
        /// <param name="studyStorage"></param>
        /// <returns></returns>
        public IList<AuthorityGroupStudyAccessInfo> ListAuthorityGroupsForStudyViaToken(StudyStorage studyStorage)
        {
            // list all Authority Groups (data or non data-access) with permission to access all studies on the same partition
            var adapter = new ServerPartitionDataAdapter();
            IList<AuthorityGroupDetail> groupWithAccessToAllStudies;
            adapter.GetAuthorityGroupsForPartition(studyStorage.ServerPartitionKey, false, out groupWithAccessToAllStudies);

            // Convert into AuthorityGroupStudyAccessInfo objects for rendering
            var result = new List<AuthorityGroupStudyAccessInfo>();
            foreach (var groupDetail in groupWithAccessToAllStudies)
            {
                result.Add(new AuthorityGroupStudyAccessInfo(groupDetail));
            }


            return result;
        }
Beispiel #6
0
        private void LoadRelatedEntities()
        {
            if (_study==null || _studyStorage==null)
            {
                using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                {
                    lock (SyncRoot)
                    {
                        if (_study == null)
                            _study = LoadStudy(context);

                        if (_studyStorage == null)
                            _studyStorage = LoadStudyStorage(context);
                    }

                }    
            }
            
        }
        /// <summary>
        /// Finds a list of <see cref="StudyHistory"/> records of the specified <see cref="StudyHistoryTypeEnum"/> 
        /// for the specified <see cref="StudyStorage"/>.
        /// </summary>
        /// <param name="studyStorage"></param>
        /// <returns></returns>
        /// <param name="types"></param>
        static public IList<StudyHistory> FindStudyHistories(StudyStorage studyStorage, IEnumerable<StudyHistoryTypeEnum> types)
        {
            // Use of ExecutionContext to re-use db connection if possible
            using (ServerExecutionContext scope = new ServerExecutionContext())
            {
                IStudyHistoryEntityBroker broker = scope.PersistenceContext.GetBroker<IStudyHistoryEntityBroker>();
                StudyHistorySelectCriteria criteria = new StudyHistorySelectCriteria();
                criteria.StudyStorageKey.EqualTo(studyStorage.Key);
                criteria.StudyHistoryTypeEnum.EqualTo(StudyHistoryTypeEnum.StudyReconciled);

                if (types != null)
                {
                    criteria.StudyHistoryTypeEnum.In(types);
                }

                criteria.InsertTime.SortAsc(0);
                IList<StudyHistory> historyList = broker.Find(criteria);
                return historyList;
            }
        }
Beispiel #8
0
 static public StudyStorage Insert(StudyStorage entity)
 {
     using (var update = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
     {
         StudyStorage newEntity = Insert(update, entity);
         update.Commit();
         return newEntity;
     }
 }
		public StudyItem(Study study)
		{
			_study = study;
			StudyStorage = StudyStorage.Load(_study.StudyStorageKey);
			StudyStorageLocation = StudyStorageLocation.FindStorageLocations(StudyStorage).FirstOrDefault();
			_status = StudyStorage.StudyStatusEnum.Description;
		}
		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;
			}
		}
Beispiel #11
0
 static public StudyStorage Insert(IUpdateContext update, StudyStorage entity)
 {
     var broker = update.GetBroker<IStudyStorageEntityBroker>();
     var updateColumns = new StudyStorageUpdateColumns();
     updateColumns.ServerPartitionKey = entity.ServerPartitionKey;
     updateColumns.StudyInstanceUid = entity.StudyInstanceUid;
     updateColumns.InsertTime = entity.InsertTime;
     updateColumns.LastAccessedTime = entity.LastAccessedTime;
     updateColumns.WriteLock = entity.WriteLock;
     updateColumns.ReadLock = entity.ReadLock;
     updateColumns.StudyStatusEnum = entity.StudyStatusEnum;
     updateColumns.QueueStudyStateEnum = entity.QueueStudyStateEnum;
     StudyStorage newEntity = broker.Insert(updateColumns);
     return newEntity;
 }
		/// <summary>
		/// Do the restore.
		/// </summary>
		/// <param name="queueItem">The queue item to restore.</param>
		public void Run(RestoreQueue queueItem)
		{
            using (RestoreProcessorContext context = new RestoreProcessorContext(queueItem))
            {
                try
                {
                    // Load up related classes.
                    using (IReadContext readContext = _nasArchive.PersistentStore.OpenReadContext())
                    {
                        _archiveStudyStorage = ArchiveStudyStorage.Load(readContext, queueItem.ArchiveStudyStorageKey);
                        _serverSyntax = ServerTransferSyntax.Load(readContext, _archiveStudyStorage.ServerTransferSyntaxKey);
                        _syntax = TransferSyntax.GetTransferSyntax(_serverSyntax.Uid);

                        StudyStorageLocationQueryParameters parms = new StudyStorageLocationQueryParameters
                                                                    	{StudyStorageKey = queueItem.StudyStorageKey};
                    	IQueryStudyStorageLocation broker = readContext.GetBroker<IQueryStudyStorageLocation>();
                        _location = broker.FindOne(parms);
                        if (_location == null)
                        {
                            _studyStorage = StudyStorage.Load(readContext, queueItem.StudyStorageKey);
							if (_studyStorage==null)
							{
								DateTime scheduleTime = Platform.Time.AddMinutes(5);
								Platform.Log(LogLevel.Error, "Unable to find storage location, rescheduling restore request to {0}",
											 scheduleTime);
								queueItem.FailureDescription = "Unable to find storage location, rescheduling request.";
								_nasArchive.UpdateRestoreQueue(queueItem, RestoreQueueStatusEnum.Pending, scheduleTime);
								return;
							}
                        }
                    }

					if (_location == null)
						Platform.Log(LogLevel.Info, "Starting restore of nearline study: {0}", _studyStorage.StudyInstanceUid);
					else
                        Platform.Log(LogLevel.Info, "Starting restore of online study: {0}", _location.StudyInstanceUid);

                    // If restoring a Nearline study, select a filesystem
                    string destinationFolder;
                    if (_location == null)
                    {
                        ServerFilesystemInfo fs = _nasArchive.Selector.SelectFilesystem();
                        if (fs == null)
                        {
                            DateTime scheduleTime = Platform.Time.AddMinutes(5);
                            Platform.Log(LogLevel.Error, "No writeable filesystem for restore, rescheduling restore request to {0}",
                                         scheduleTime);
                            queueItem.FailureDescription = "No writeable filesystem for restore, rescheduling request.";
                            _nasArchive.UpdateRestoreQueue(queueItem, RestoreQueueStatusEnum.Pending, scheduleTime);
                            return;
                        }
                        destinationFolder = Path.Combine(fs.Filesystem.FilesystemPath, _nasArchive.ServerPartition.PartitionFolder);
                    }
                    else
                        destinationFolder = _location.GetStudyPath();


                    // Get the zip file path from the xml data in the ArchiveStudyStorage entry
                    // Also store the "StudyFolder" for use below
                    string studyFolder = String.Empty;
                    string filename = String.Empty;
                    string studyInstanceUid = String.Empty;
                    XmlElement element = _archiveStudyStorage.ArchiveXml.DocumentElement;
					if (element!=null)
						foreach (XmlElement node in element.ChildNodes)
							if (node.Name.Equals("StudyFolder"))
								studyFolder = node.InnerText;
							else if (node.Name.Equals("Filename"))
								filename = node.InnerText;
							else if (node.Name.Equals("Uid"))
								studyInstanceUid = node.InnerText;

                    string zipFile = Path.Combine(_nasArchive.NasPath, studyFolder);
                    zipFile = Path.Combine(zipFile, studyInstanceUid);
                    zipFile = Path.Combine(zipFile, filename);


                    // Do a test read of the zip file.  If it succeeds, the file is available, if it 
                    // fails, we just set back to pending and recheck.
                    try
                    {
                        FileStream stream = File.OpenRead(zipFile);
                        // Read a byte, just in case that makes a difference.
                        stream.ReadByte();
                        stream.Close();
                        stream.Dispose();
                    }
                    catch (Exception ex)
                    {
                        DateTime scheduledTime = Platform.Time.AddSeconds(NasSettings.Default.ReadFailRescheduleDelaySeconds);
                        Platform.Log(LogLevel.Error, ex, "Archive {0} for Study  {1} is unreadable, rescheduling restore to {2}",
                                     zipFile, _studyStorage == null ? (_location == null ? string.Empty : _location.StudyInstanceUid) : _studyStorage.StudyInstanceUid,
                                     scheduledTime);
                        // Just reschedule in "Restoring" state, the file is unreadable.
                        _nasArchive.UpdateRestoreQueue(queueItem, RestoreQueueStatusEnum.Restoring,
                                                       scheduledTime);
                        return;
                    }

                    if (_location == null)
                        RestoreNearlineStudy(queueItem, zipFile, destinationFolder, studyFolder);
                    else
                        RestoreOnlineStudy(queueItem, zipFile, destinationFolder);
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Error, e, "Unexpected exception processing restore request for {0} on archive {1}",
                        _studyStorage == null ? (_location == null ? string.Empty : _location.StudyInstanceUid) : _studyStorage.StudyInstanceUid,
                        _nasArchive.PartitionArchive.Description);
                    queueItem.FailureDescription = e.Message;
                    _nasArchive.UpdateRestoreQueue(queueItem, RestoreQueueStatusEnum.Failed, Platform.Time);
                }
            }
			
		}
Beispiel #13
0
 public StudyStorage LoadStudyStorage(IPersistenceContext context)
 {
     return(StudyStorage.Load(StudyStorageKey));
 }
		private void LoadEntities()
		{
			_storage = StudyStorage.Load(_oldStudyLocation.Key);
			_study = _storage.LoadStudy(UpdateContext);
		}
 static public IList <StudyStorageLocation> FindStorageLocations(
     IPersistenceContext context, StudyStorage storage)
 {
     return(FindStorageLocations(context, storage, null));
 }
Beispiel #16
0
 /// <summary>
 /// Finds all <see cref="StudyHistory"/> records for the specified <see cref="StudyStorage"/>.
 /// </summary>
 /// <param name="studyStorage"></param>
 /// <returns></returns>
 static public IList<StudyHistory> FindStudyHistories(StudyStorage studyStorage)
 {
     return FindStudyHistories(studyStorage, null);
 }
		public SetStudyStatusNearlineCommand(StudyStorage studyStorage)
			: base("Set Study to Nearline")
		{
			_storage = studyStorage;
		}
Beispiel #18
0
        public IList <StudyStorageLocation> LoadStudyLocations(IPersistenceContext context)
        {
            StudyStorage storage = LoadStudyStorage(context);

            return(StudyStorageLocation.FindStorageLocations(context, storage));
        }
		public DeleteAllArchiveQueueItemCommand(StudyStorage studyStorage, PartitionArchive archive)
			:base("Delete Archive Queue items")
		{
			_archive = archive;
			_studyStorage = studyStorage;
		}
        public string GetFolderPath()
        {
            if (_location == null)
            {
                if (_studyStorage == null)
                {
                    using (IReadContext context = PersistentStoreRegistry.GetDefaultStore().OpenReadContext())
                    {
                        _studyStorage = StudyStorage.Load(context, _item.StudyStorageKey);
                    }
                }

                _location = StudyStorageLocation.FindStorageLocations(_studyStorage)[0];

            }

            String path = Path.Combine(_location.FilesystemPath, _location.PartitionFolder);
			path = Path.Combine(path, ServerPlatform.ReconcileStorageFolder);
            if(!string.IsNullOrEmpty(_item.GroupID)) path = Path.Combine(path, _item.GroupID);
            path = Path.Combine(path, _location.StudyInstanceUid);

            return path;
        }
		/// <summary>
		/// Do the restore.
		/// </summary>
		/// <param name="queueItem">The queue item to restore.</param>
		public void Run(RestoreQueue queueItem)
		{
            using (var context = new RestoreProcessorContext(queueItem))
            {
                try
                {
                    // Load up related classes.
                    using (IReadContext readContext = _hsmArchive.PersistentStore.OpenReadContext())
                    {
                        _archiveStudyStorage = ArchiveStudyStorage.Load(readContext, queueItem.ArchiveStudyStorageKey);
                        _serverSyntax = ServerTransferSyntax.Load(readContext, _archiveStudyStorage.ServerTransferSyntaxKey);
                        _syntax = TransferSyntax.GetTransferSyntax(_serverSyntax.Uid);

                        var parms = new StudyStorageLocationQueryParameters
                                                                    	{StudyStorageKey = queueItem.StudyStorageKey};
                    	var broker = readContext.GetBroker<IQueryStudyStorageLocation>();
                        _location = broker.FindOne(parms);
                        if (_location == null)
                        {
                            _studyStorage = StudyStorage.Load(readContext, queueItem.StudyStorageKey);
							if (_studyStorage==null)
							{
								DateTime scheduleTime = Platform.Time.AddMinutes(5);
								Platform.Log(LogLevel.Error, "Unable to find storage location, rescheduling restore request to {0}",
											 scheduleTime);
								queueItem.FailureDescription = "Unable to find storage location, rescheduling request.";
								_hsmArchive.UpdateRestoreQueue(queueItem, RestoreQueueStatusEnum.Pending, scheduleTime);
								return;
							}
                        }
                    }

                    if (_location == null)
                    {
                        Platform.Log(LogLevel.Info, "Starting restore of nearline study: {0}",
                                     _studyStorage.StudyInstanceUid);

                        // Get the zip file path from the xml data in the ArchiveStudyStorage entry
                        // Also store the "StudyFolder" for use below
                        string studyFolder;
                        string zipFile = GetZipFileName(out studyFolder);

                        // Do a test read of the zip file.  If it succeeds, the file is available, if it 
                        // fails, we just set back to pending and recheck.
                        if (!CanReadZip(zipFile, queueItem))
                            return;

                        RestoreNearlineStudy(queueItem, zipFile, studyFolder);
                    }
                    else
                    {
                        Platform.Log(LogLevel.Info, "Starting restore of online study: {0}", _location.StudyInstanceUid);

                         // Get the zip file path from the xml data in the ArchiveStudyStorage entry
                         // Also store the "StudyFolder" for use below
                         string studyFolder;
                         string zipFile = GetZipFileName(out studyFolder);

                         // Do a test read of the zip file.  If it succeeds, the file is available, if it 
                         // fails, we just set back to pending and recheck.
                         if (!CanReadZip(zipFile, queueItem))
                             return;

                        RestoreOnlineStudy(queueItem, zipFile, _location.GetStudyPath());
                    }       
                }
                catch (Exception e)
                {
                    Platform.Log(LogLevel.Error, e, "Unexpected exception processing restore request for {0} on archive {1}",
                        _studyStorage == null ? (_location == null ? string.Empty : _location.StudyInstanceUid) : _studyStorage.StudyInstanceUid,
                        _hsmArchive.PartitionArchive.Description);
                    queueItem.FailureDescription = e.Message;
                    _hsmArchive.UpdateRestoreQueue(queueItem, RestoreQueueStatusEnum.Failed, Platform.Time);
                }
            }
			
		}
		public VerifyStudyHasBeenArchivedCommand(StudyStorage storage)
			: base("Verify Study has been archived", true)
		{
			_storage = storage;
		}