Пример #1
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);
            }
        }
Пример #2
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);
            }
        }