Example #1
0
        /// <summary>
        /// Called when [network error].
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="association">The association.</param>
        /// <param name="e">The e.  Note, e can be null in some instances.</param>
        public void OnNetworkError(DicomClient client, ClientAssociationParameters association, Exception e)
        {
            //TODO: right now this method gets called in timeout and abort situations.  Should add
            // the appropriate methods to the IDicomClientHandler to address this.

            //We don't want to blow away other failure descriptions (e.g. the OnDimseTimeout one).
            if (Status == ScuOperationStatus.Running)
            {
                FailureDescription = String.Format("Unexpected network error: {0}", e == null ? "Unknown" : e.Message);
            }

            if (client.State == DicomAssociationState.Sta13_AwaitingTransportConnectionClose)
            {
                //When this state is set and an error occurs, an appropriate message has already been logged in the client.
            }
            else
            {
                LogAdapter.Logger.Warning(FailureDescription);
            }

            //We don't want to blow away the OnDimseTimeout 'TimeoutExpired' status.
            ScuOperationStatus stopStatus = Status;

            if (stopStatus == ScuOperationStatus.Running)
            {
                stopStatus = ScuOperationStatus.NetworkError;
            }

            ResultStatus = DicomState.Failure;

            StopRunningOperation(stopStatus);
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DicomStatus"/> class.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="status">The status.</param>
        /// <param name="desc">The desc.</param>
        public DicomStatus(string code, DicomState status, string desc)
        {
            Code = ushort.Parse(
                code.Replace('x', '0'),
                System.Globalization.NumberStyles.HexNumber,
                CultureInfo.InvariantCulture);

            StringBuilder msb = new StringBuilder();

            msb.Append(code.ToLower());
            msb.Replace('0', 'F')
            .Replace('1', 'F')
            .Replace('2', 'F')
            .Replace('3', 'F')
            .Replace('4', 'F')
            .Replace('5', 'F')
            .Replace('6', 'F')
            .Replace('7', 'F')
            .Replace('8', 'F')
            .Replace('9', 'F')
            .Replace('a', 'F')
            .Replace('b', 'F')
            .Replace('c', 'F')
            .Replace('d', 'F')
            .Replace('e', 'F')
            .Replace('x', '0');
            Mask = ushort.Parse(
                msb.ToString(),
                System.Globalization.NumberStyles.HexNumber,
                CultureInfo.InvariantCulture);

            State       = status;
            Description = desc;
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DicomStatus"/> class.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="status">The status.</param>
        /// <param name="desc">The desc.</param>
        public DicomStatus(string code, DicomState status, string desc)
        {
            Code = ushort.Parse(
                code.Replace('x', '0'),
                System.Globalization.NumberStyles.HexNumber,
                CultureInfo.InvariantCulture);

            StringBuilder msb = new StringBuilder();
            msb.Append(code.ToLower());
            msb.Replace('0', 'F')
                .Replace('1', 'F')
                .Replace('2', 'F')
                .Replace('3', 'F')
                .Replace('4', 'F')
                .Replace('5', 'F')
                .Replace('6', 'F')
                .Replace('7', 'F')
                .Replace('8', 'F')
                .Replace('9', 'F')
                .Replace('a', 'F')
                .Replace('b', 'F')
                .Replace('c', 'F')
                .Replace('d', 'F')
                .Replace('e', 'F')
                .Replace('x', '0');
            Mask = ushort.Parse(
                msb.ToString(),
                System.Globalization.NumberStyles.HexNumber,
                CultureInfo.InvariantCulture);

            State = status;
            Description = desc;
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DicomStatus"/> class.
 /// </summary>
 internal DicomStatus(ushort code, DicomStatus baseStatus)
 {
     // set the code given by param code...
     Code = code;
     // ... and copy all other values from baseStatus
     Description  = baseStatus.Description;
     ErrorComment = baseStatus.ErrorComment;
     Mask         = baseStatus.Mask;
     State        = baseStatus.State;
 }
Example #5
0
        private void DoPrint(IBackgroundTaskContext context)
        {
            try
            {
                if (_selectPresentationsInformations == null || _selectPresentationsInformations.Count == 0)
                {
                    return;
                }
                Thread.Sleep(20);
                BackgroundTaskReportStatus(context, "Dicom打印开始", 0);
                Thread.Sleep(10);
                BackgroundTaskReportStatus(context, "开始处理图像...", 0);
                Thread.Sleep(10);
                //UISynchronizationContext.Send(DoImageProcess, null);
                DoImageProcess(null);
                if (_selectPresentationsInformations.Count == 0)
                {
                    BackgroundTaskReportStatus(context, "处理图像处理结果为0", 0);
                    return;
                }
                BackgroundTaskReportStatus(context, "开始向打印机发送图像", 0);
                Thread.Sleep(10);
                PrintScu scu = new PrintScu();
                DicomPrintProgressUpdate progressUpdate = new DicomPrintProgressUpdate();
                progressUpdate.dicomPrintManager = this;
                progressUpdate.printScu          = scu;
                progressUpdate.Task  = context;
                scu.ProgressUpdated += progressUpdate.Update;
                _dicomPrintSession   = new DicomPrintSession(DicomPrinter, new SelectPresentationsInformationsCollection(_selectPresentationsInformations));
                PrintScu.FilmSession filmSession = DicomPrintSession.GetFilmSession(_dicomPrintSession.SelectPresentationsCollection, _dicomPrintSession.DicomPrinter.Config);
                DicomState           dicomState  = scu.Print("MacroAETile", _dicomPrintSession.DicomPrinter.AETitle, _dicomPrintSession.DicomPrinter.Host, _dicomPrintSession.DicomPrinter.Port, filmSession);
                scu.Join();
                if (dicomState == DicomState.Success)
                {
                    //UpDicomPrintStatus(context);
                    if (_dicomPrintComponent != null)
                    {
                        UISynchronizationContext.Send(_dicomPrintComponent.PrintedDeleteImage, this);
                    }
                }
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Debug, e);
                BackgroundTaskReportStatus(context, e.Message, 100);
            }

            if (_studyInstanceUid != null)
            {
                _studyInstanceUid.Clear();
                _studyInstanceUid = null;
            }
            GC.Collect();
        }
Example #6
0
        /// <summary>
        /// Called when [dimse timeout].
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="association">The association.</param>
        public virtual void OnDimseTimeout(DicomClient client, ClientAssociationParameters association)
        {
            Status             = ScuOperationStatus.TimeoutExpired;
            ResultStatus       = DicomState.Failure;
            FailureDescription = String.Format("Timeout Expired for remote host {0}, aborting connection", RemoteAE);
            if (LogInformation)
            {
                LogAdapter.Logger.Info(FailureDescription);
            }

            try
            {
                client.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified);
            }
            catch (Exception ex)
            {
                LogAdapter.Logger.TraceException(ex);
            }

            LogAdapter.Logger.WarnWithFormat("Completed aborting connection (after DIMSE timeout) from {0} to {1}", association.CallingAE, association.CalledAE);
            ProgressEvent.Set();
        }
Example #7
0
        /// <summary>
        /// Called when [dimse timeout].
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="association">The association.</param>
        public virtual void OnDimseTimeout(DicomClient client, ClientAssociationParameters association)
        {
            Status       = ScuOperationStatus.TimeoutExpired;
            ResultStatus = DicomState.Failure;

            FailureDescription = String.Format("Timeout Expired ({0} seconds) for remote AE {1}, aborting connection", association.ReadTimeout / 1000,
                                               RemoteAE);
            if (LogInformation)
            {
                Platform.Log(LogLevel.Info, FailureDescription);
            }

            try
            {
                client.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified);
            }
            catch (Exception ex)
            {
                Platform.Log(LogLevel.Error, ex, "Error aborting association");
            }

            Platform.Log(LogLevel.Warn, "Completed aborting connection (after DIMSE timeout) from {0} to {1}", association.CallingAE, association.CalledAE);
            ProgressEvent.Set();
        }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DicomStatus"/> class.
 /// </summary>
 /// <param name="code">The code.</param>
 /// <param name="status">The status.</param>
 /// <param name="desc">The desc.</param>
 /// <param name="comment">The comment.</param>
 public DicomStatus(string code, DicomState status, string desc, string comment)
     : this(code, status, desc)
 {
     ErrorComment = comment;
 }
Example #9
0
 /// <summary>
 /// Called when received response message.  Sets the <see cref="Results"/> property as appropriate.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="association">The association.</param>
 /// <param name="presentationID">The presentation ID.</param>
 /// <param name="message">The message.</param>
 public override void OnReceiveResponseMessage(DicomClient client, ClientAssociationParameters association, byte presentationID, DicomMessage message)
 {
     if (message.Status.Status == DicomState.Pending)
     {
         // one result sent back, add to result list
         _results.Add(message.DataSet);
         if (_maxResults != -1 && !_cancelSent && _results.Count > _maxResults)
         {
             client.SendCFindCancelRequest(presentationID, message.MessageIdBeingRespondedTo);
             _cancelSent = true;
         }
     }
     else
     {
         _cancelSent = false;
         DicomState status = message.Status.Status;
         if (message.Status.Status != DicomState.Success)
         {
             if (status == DicomState.Cancel)
             {
                 if (LogInformation)
                 {
                     Platform.Log(LogLevel.Info, "Cancel status received in Find Scu: {0}", message.Status);
                 }
                 Status = ScuOperationStatus.Canceled;
             }
             else if (status == DicomState.Failure)
             {
                 string msg = String.Format("Failure status received in Find Scu: {0}", message.Status);
                 Platform.Log(LogLevel.Error, msg);
                 Status             = ScuOperationStatus.Failed;
                 FailureDescription = msg;
             }
             else if (status == DicomState.Warning)
             {
                 Platform.Log(LogLevel.Warn, "Warning status received in Find Scu: {0}", message.Status);
             }
             else if (Status == ScuOperationStatus.Canceled)
             {
                 if (LogInformation)
                 {
                     Platform.Log(LogLevel.Info, "Client cancelled Find Scu operation.");
                 }
             }
         }
         else
         {
             if (LogInformation)
             {
                 Platform.Log(LogLevel.Info, "Success status received in Find Scu!");
             }
         }
         if (!ReuseAssociation)
         {
             client.SendReleaseRequest();
             StopRunningOperation();
         }
         else
         {
             ProgressEvent.Set();
         }
     }
 }
Example #10
0
		/// <summary>
		/// Initializes a new instance of the <see cref="DicomStatus"/> class.
		/// </summary>
		/// <param name="code">The code.</param>
		/// <param name="status">The status.</param>
		/// <param name="desc">The desc.</param>
		/// <param name="comment">The comment.</param>
		public DicomStatus(string code, DicomState status, string desc, string comment)
			: this(code, status, desc) {
			ErrorComment = comment;
		}
Example #11
0
        /// <summary>
        /// Called when received response message.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="association">The association.</param>
        /// <param name="presentationID">The presentation ID.</param>
        /// <param name="message">The message.</param>
        public override void OnReceiveResponseMessage(DicomClient client, ClientAssociationParameters association, byte presentationID, DicomMessage message)
        {
            // Discovered issue with an SCP that was not setting these values on the final Success return, so blocking an update of the values if all of them are 0.
            if (message.NumberOfFailedSubOperations != 0 ||
                message.NumberOfCompletedSubOperations != 0 ||
                message.NumberOfRemainingSubOperations != 0 ||
                message.NumberOfWarningSubOperations != 0)
            {
                _failureSubOperations   = message.NumberOfFailedSubOperations;
                _successSubOperations   = message.NumberOfCompletedSubOperations;
                _remainingSubOperations = message.NumberOfRemainingSubOperations;
                _warningSubOperations   = message.NumberOfWarningSubOperations;
                _totalSubOperations     = _failureSubOperations + _successSubOperations + _remainingSubOperations +
                                          _warningSubOperations;
            }

            if (message.Status.Status == DicomState.Pending)
            {
                OnImageMoveCompleted();
            }
            else
            {
                DicomState status = message.Status.Status;
                if (message.Status.Status != DicomState.Success)
                {
                    if (status == DicomState.Cancel)
                    {
                        if (LogInformation)
                        {
                            Platform.Log(LogLevel.Info, "Cancel status received in Move Scu: {0}", message.Status);
                        }
                        Status = ScuOperationStatus.Canceled;
                    }
                    else if (status == DicomState.Failure)
                    {
                        string msg = String.Format("Failure status received in Move Scu: {0}", message.Status);
                        Platform.Log(LogLevel.Error, msg);
                        Status             = ScuOperationStatus.Failed;
                        FailureDescription = msg;
                    }
                    else if (status == DicomState.Warning)
                    {
                        Platform.Log(LogLevel.Warn, "Warning status received in Move Scu: {0}", message.Status);
                    }
                    else if (Status == ScuOperationStatus.Canceled)
                    {
                        if (LogInformation)
                        {
                            Platform.Log(LogLevel.Info, "Client cancelled Move Scu operation.");
                        }
                    }
                }
                else
                {
                    if (LogInformation)
                    {
                        Platform.Log(LogLevel.Info, "Success status received in Move Scu!");
                    }
                }

                client.SendReleaseRequest();
                StopRunningOperation();
            }
        }