Exemple #1
0
        private StudyXml RetrieveStudyXml(StudyLoaderArgs studyLoaderArgs)
        {
            var headerParams = new HeaderStreamingParameters
                                   {
                                       StudyInstanceUID = studyLoaderArgs.StudyInstanceUid,
                                       ServerAETitle = _serverAe.AETitle,
                                       ReferenceID = Guid.NewGuid().ToString()
                                   };

            HeaderStreamingServiceClient client = null;
            try
            {

                string uri = String.Format(StreamingSettings.Default.FormatHeaderServiceUri,
                                            _serverAe.ScpParameters.HostName, _serverAe.StreamingParameters.HeaderServicePort);

                client = new HeaderStreamingServiceClient(new Uri(uri));
                client.Open();
                var studyXml = client.GetStudyXml(ServerDirectory.GetLocalServer().AETitle, headerParams);
                client.Close();
                return studyXml;
            }
            catch (FaultException<StudyIsInUseFault> e)
            {
                throw new InUseLoadStudyException(studyLoaderArgs.StudyInstanceUid, e);
            }
            catch (FaultException<StudyIsNearlineFault> e)
            {
				throw new NearlineLoadStudyException(studyLoaderArgs.StudyInstanceUid, e)
					{ IsStudyBeingRestored = e.Detail.IsStudyBeingRestored };
            }
            catch (FaultException<StudyNotFoundFault> e)
            {
                throw new NotFoundLoadStudyException(studyLoaderArgs.StudyInstanceUid, e);
            }
            catch (FaultException e)
            {
                //TODO: Some versions (pre-Team) of the ImageServer
				//throw a generic fault when a study is nearline, instead of the more specialized one.
                string message = e.Message.ToLower();
                if (message.Contains("nearline"))
					throw new NearlineLoadStudyException(studyLoaderArgs.StudyInstanceUid, e)
						{ IsStudyBeingRestored = true }; //assume true in legacy case.

                throw new LoadStudyException(studyLoaderArgs.StudyInstanceUid, e);
            }
            catch (Exception e)
            {
                if (client != null)
                    client.Abort();

                throw new LoadStudyException(studyLoaderArgs.StudyInstanceUid, e);
            }
        }
        public Stream GetStudyHeader(string callingAETitle, HeaderStreamingParameters parameters)
        {
            ConnectionMonitor.GetMonitor(OperationContext.Current.Host).AddContext(OperationContext.Current);
                
            HeaderStreamingStatistics stats = new HeaderStreamingStatistics();
            stats.ProcessTime.Start();

            HeaderLoader loader = null;

            try
            {
                Platform.CheckForEmptyString(callingAETitle, "callingAETitle");
                Platform.CheckForNullReference(parameters, "parameters");
                Platform.CheckForEmptyString(parameters.ReferenceID, "parameters.ReferenceID");
                Platform.CheckForEmptyString(parameters.ServerAETitle, "parameters.ServerAETitle");
                Platform.CheckForEmptyString(parameters.StudyInstanceUID, "parameters.StudyInstanceUID");

                Platform.Log(LogLevel.Debug, "Received request from {0}. Ref # {1} ", callingAETitle, parameters.ReferenceID);

                HeaderStreamingContext context = new HeaderStreamingContext();
                context.ServiceInstanceID = ID;
                context.CallerAE = callingAETitle;
                context.Parameters = parameters;

                // TODO: perform permission check on callingAETitle

                loader = new HeaderLoader(context);

                if (!parameters.IgnoreInUse)
                {
                    if (!loader.StudyLocation.CanBeUsedForDiagnostics())
                        throw new StudyAccessException(SR.FaultFaultStudyTemporarilyNotAccessible, loader.StudyLocation.QueueStudyStateEnum, null);
                }

                Stream stream = loader.Load();
                if (stream == null)
                    throw new FaultException(loader.FaultDescription);

                Platform.Log(LogLevel.Debug, "Response sent to {0}. Ref # {1} ", callingAETitle, parameters.ReferenceID);

                return stream;
            }
            catch (ArgumentException e)
            {
                throw new FaultException(e.Message);
            }
            catch (StudyNotFoundException)
            {
                throw new FaultException<StudyNotFoundFault>(
                            new StudyNotFoundFault(), String.Format(SR.FaultNotExists, parameters.StudyInstanceUID, parameters.ServerAETitle));
            }
            catch (StudyIsNearlineException e)
            {
				throw new FaultException<StudyIsNearlineFault>(
							new StudyIsNearlineFault() { IsStudyBeingRestored = e.RestoreRequested },
							String.Format(SR.FaultStudyIsNearline, parameters.StudyInstanceUID));
            }
            catch (StudyAccessException e)
            {
                if (e.InnerException != null)
                {
                    if (e.InnerException is FileNotFoundException)
                    {
                        throw new FaultException<StudyIsInUseFault>(
                            new StudyIsInUseFault(e.StudyState.Description),
                            String.Format(SR.FaultFaultStudyTemporarilyNotAccessible, parameters.StudyInstanceUID, e.StudyState));

                    }
                }
                throw new FaultException<StudyIsInUseFault>(
                                new StudyIsInUseFault(e.StudyState.Description),
                                String.Format(SR.FaultFaultStudyTemporarilyNotAccessible, parameters.StudyInstanceUID, e.StudyState));
            }
			catch (FilesystemNotReadableException e)
			{
				//interpret as generic fault
				throw new FaultException(e.Message);
			}
			catch (FileNotFoundException e)
            {
                // OOPS.. the header is missing
                Platform.Log(LogLevel.Error, e, "Unable to process study header request from {0}", callingAETitle);
                throw new FaultException(SR.FaultHeaderIsNotAvailable);
            }
			catch (Exception e)
            {
                if (!(e is FaultException))
                    Platform.Log(LogLevel.Error, e, "Unable to process study header request from {0}", callingAETitle);

                throw new FaultException(e.Message);
            }
            finally
            {
                stats.ProcessTime.End();

                if (loader != null && Settings.Default.LogStatistics)
                {
                    stats.AddField("StudyInstanceUid", parameters.StudyInstanceUID);

                    stats.AddSubStats(loader.Statistics);
                    StatisticsLogger.Log(LogLevel.Info, stats);
                }
            }
        }
 /// <summary>
 /// Gets the study header (xml) as a gzipped stream.
 /// </summary>
 /// <param name="callingAETitle">AE title of the local application.</param>
 /// <param name="parameters">Input parameters.</param>
 /// <returns></returns>
 public System.IO.Stream GetStudyHeader(string callingAETitle, HeaderStreamingParameters parameters)
 {
     return(base.Channel.GetStudyHeader(callingAETitle, parameters));
 }