private void SendSetImageBoxRequest(DicomClient client, ClientAssociationParameters association, DicomMessage responseMessage)
 {
     if (this._currentImageBoxIndex >= this._imageBoxPixelModuleIods.Count)
     {
         this._nextRequestType = RequestType.PrintAction;
         this.SendActionPrintRequest(client, association, responseMessage);
     }
     else
     {
         if (this._currentImageBoxIndex == 0)
         {
             this._firstFilmBoxResponseMessage = responseMessage.DataSet;
             this._imageBoxUid = responseMessage.AffectedSopInstanceUid;
         }
         BasicFilmBoxModuleIod iod = new BasicFilmBoxModuleIod(this._firstFilmBoxResponseMessage);
         if (this._currentImageBoxIndex > iod.ReferencedImageBoxSequenceList.Count)
         {
             throw new DicomException("Current Image Box Index is greater than number of Referenced ImageBox Sequences - set image box data");
         }
         ImageBoxPixelModuleIod iod2    = this._imageBoxPixelModuleIods[this._currentImageBoxIndex];
         DicomMessage           message = new DicomMessage(null, iod2.DicomAttributeCollection)
         {
             RequestedSopClassUid    = SopClass.BasicGrayscaleImageBoxSopClassUid,
             RequestedSopInstanceUid = iod.ReferencedImageBoxSequenceList[this._currentImageBoxIndex].ReferencedSopInstanceUid
         };
         byte presentationID = association.FindAbstractSyntax(SopClass.BasicGrayscalePrintManagementMetaSopClass);
         this._currentImageBoxIndex++;
         client.SendNSetRequest(presentationID, client.NextMessageID(), message);
     }
 }
        private void SendSetImageBoxRequest(DicomClient client, ClientAssociationParameters association)
        {
            if (_currentImageBoxIndex >= _imageBoxPixelModuleIods.Count)
            {
                // done sending images box - send print request
                _nextRequestType = RequestType.PrintAction;
                SendActionPrintRequest(client, association);
            }
            else
            {
                // want to get first film box response - although not sure if CC is using .net 3.5.. prolly not so do it old way
                IEnumerator <DicomAttributeCollection> filmBoxResponseEnumerator = _filmBoxResponseMessages.Values.GetEnumerator();
                filmBoxResponseEnumerator.Reset();
                filmBoxResponseEnumerator.MoveNext();

                BasicFilmBoxModuleIod basicFilmBoxModuleIod = new BasicFilmBoxModuleIod(filmBoxResponseEnumerator.Current);

                if (_currentImageBoxIndex > basicFilmBoxModuleIod.ReferencedImageBoxSequenceList.Count)
                {
                    throw new DicomException("Current Image Box Index is greater than number of Referenced ImageBox Sequences - set image box data");
                }

                ImageBoxPixelModuleIod imageBoxPixelModuleIod = _imageBoxPixelModuleIods[_currentImageBoxIndex];

                DicomMessage newRequestMessage = new DicomMessage(null, (DicomAttributeCollection)imageBoxPixelModuleIod.DicomAttributeProvider);
                newRequestMessage.RequestedSopClassUid    = SopClass.BasicGrayscaleImageBoxSopClassUid;
                newRequestMessage.RequestedSopInstanceUid = basicFilmBoxModuleIod.ReferencedImageBoxSequenceList[_currentImageBoxIndex].ReferencedSopInstanceUid;

                byte pcid = association.FindAbstractSyntax(SopClass.BasicGrayscalePrintManagementMetaSopClass);

                _currentImageBoxIndex++;
                client.SendNSetRequest(pcid, client.NextMessageID(), newRequestMessage);
            }
        }
 public DicomState Print(string clientAETitle, string remoteAE, string remoteHost, int remotePort, BasicFilmSessionModuleIod basicFilmSessionModuleIod, BasicFilmBoxModuleIod basicFilmBoxModuleIod, IList <ImageBoxPixelModuleIod> imageBoxPixelModuleIods)
 {
     this._results    = null;
     this._filmBoxUid = null;
     this._basicFilmSessionModuleIod   = basicFilmSessionModuleIod;
     this._basicFilmBoxModuleIod       = basicFilmBoxModuleIod;
     this._imageBoxPixelModuleIods     = imageBoxPixelModuleIods;
     this._firstFilmBoxResponseMessage = null;
     this._currentImageBoxIndex        = 0;
     base.Connect(clientAETitle, remoteAE, remoteHost, remotePort);
     return(base.ResultStatus);
 }
 /// <summary>
 /// Prints with the specified parameters.
 /// </summary>
 /// <param name="clientAETitle">The client AE title.</param>
 /// <param name="remoteAE">The remote AE.</param>
 /// <param name="remoteHost">The remote host.</param>
 /// <param name="remotePort">The remote port.</param>
 /// <param name="basicFilmSessionModuleIod">The basic film session module iod.</param>
 /// <param name="basicFilmBoxModuleIod">The basic film box module iod.</param>
 /// <param name="imageBoxPixelModuleIods">The image box pixel module iods.</param>
 public DicomState Print(string clientAETitle, string remoteAE, string remoteHost, int remotePort, BasicFilmSessionModuleIod basicFilmSessionModuleIod, BasicFilmBoxModuleIod basicFilmBoxModuleIod, IList <ImageBoxPixelModuleIod> imageBoxPixelModuleIods)
 {
     _results                   = null;
     _filmSessionUid            = null;
     _basicFilmSessionModuleIod = basicFilmSessionModuleIod;
     _basicFilmBoxModuleIod     = basicFilmBoxModuleIod;
     _imageBoxPixelModuleIods   = imageBoxPixelModuleIods;
     _filmBoxResponseMessages.Clear();
     _currentImageBoxIndex = 0;
     _filmBoxUids.Clear();
     Connect(clientAETitle, remoteAE, remoteHost, remotePort);
     if (Status == ScuOperationStatus.AssociationRejected || Status == ScuOperationStatus.Failed || Status == ScuOperationStatus.ConnectFailed ||
         Status == ScuOperationStatus.NetworkError || Status == ScuOperationStatus.TimeoutExpired)
     {
         return(DicomState.Failure);
     }
     return(ResultStatus);
 }
Esempio n. 5
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)
        {
            try
            {
                this.ResultStatus = message.Status.Status;
                switch (this.ResultStatus)
                {
                case DicomState.Cancel:
                case DicomState.Pending:
                case DicomState.Failure:
                    Platform.Log(LogLevel.Error, string.Format("{0} status received in Print Scu response message", message.Status.Status));

                    this.FailureDescription = SR.MessagePrinterError;
                    this.ReleaseConnection(client);
                    return;

                case DicomState.Warning:
                    Platform.Log(LogLevel.Warn, string.Format("{0} status received in Print Scu response message", message.Status.Status));
                    break;

                case DicomState.Success:
                    break;
                }

                EventsHelper.Fire(this.ProgressUpdated, this, new ProgressUpdateEventArgs(_numberOfImageBoxesSent));

                if (Canceled)
                {
                    Platform.Log(LogLevel.Info, "Cancel requested by user.  Closing association.");
                    client.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified);
                    return;
                }

                Platform.Log(LogLevel.Info, "Success status received in Print Scu");

                var affectedUid = new DicomUid(message.AffectedSopInstanceUid, "Instance UID", UidType.SOPInstance);

                switch (message.CommandField)
                {
                case DicomCommandField.NCreateResponse:
                    switch (_eventObject)
                    {
                    case EventObject.FilmSession:
                        _filmSession.OnCreated(affectedUid);
                        break;

                    case EventObject.FilmBox:
                    {
                        var responseFilmBoxModule = new BasicFilmBoxModuleIod(message.DataSet);
                        _filmSession.OnFilmBoxCreated(affectedUid,
                                                      CollectionUtils.Map <ReferencedInstanceSequenceIod, DicomUid>(
                                                          responseFilmBoxModule.ReferencedImageBoxSequenceList,
                                                          imageBoxModule => new DicomUid(imageBoxModule.ReferencedSopInstanceUid, "Instance UID", UidType.SOPInstance)
                                                          ));
                    }
                    break;
                    }

                    break;

                case DicomCommandField.NDeleteResponse:
                    switch (_eventObject)
                    {
                    case EventObject.FilmSession:
                        _filmSession.OnDeleted();
                        this.ReleaseConnection(client);
                        break;

                    case EventObject.FilmBox:
                        _filmSession.OnFilmBoxDeleted();
                        break;
                    }

                    break;

                case DicomCommandField.NSetResponse:
                    _numberOfImageBoxesSent++;
                    _filmSession.OnImageBoxSet(affectedUid);
                    break;

                case DicomCommandField.NActionResponse:
                    _filmSession.OnFilmBoxPrinted(affectedUid);

                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                this.FailureDescription = ex.Message;
                Platform.Log(LogLevel.Error, ex.ToString());
                ReleaseConnection(client);
                throw;
            }
        }
Esempio n. 6
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)
		{
			try
			{
				this.ResultStatus = message.Status.Status;
				switch (this.ResultStatus)
				{
					case DicomState.Cancel:
					case DicomState.Pending:
					case DicomState.Failure:
						Platform.Log(LogLevel.Error, string.Format("{0} status received in Print Scu response message", message.Status.Status));

						this.FailureDescription = SR.MessagePrinterError;
						this.ReleaseConnection(client);
						return;

					case DicomState.Warning:
						Platform.Log(LogLevel.Warn, string.Format("{0} status received in Print Scu response message", message.Status.Status));
						break;

					case DicomState.Success:
						break;
				}

				EventsHelper.Fire(this.ProgressUpdated, this, new ProgressUpdateEventArgs(_numberOfImageBoxesSent));

				if (Canceled)
				{
					Platform.Log(LogLevel.Info, "Cancel requested by user.  Closing association.");
					client.SendAssociateAbort(DicomAbortSource.ServiceUser, DicomAbortReason.NotSpecified);
					return;
				}

				Platform.Log(LogLevel.Info, "Success status received in Print Scu");

				var affectedUid = new DicomUid(message.AffectedSopInstanceUid, "Instance UID", UidType.SOPInstance);

				switch (message.CommandField)
				{
					case DicomCommandField.NCreateResponse:
						switch (_eventObject)
						{
							case EventObject.FilmSession:
								_filmSession.OnCreated(affectedUid);
								break;
                            case EventObject.FilmBox:
                                {
                                    var responseFilmBoxModule = new BasicFilmBoxModuleIod(message.DataSet);
                                    _filmSession.OnFilmBoxCreated(affectedUid,
                                                                  responseFilmBoxModule.ReferencedImageBoxSequenceList.Select(
                                                                  imageBoxModule => new DicomUid(imageBoxModule.ReferencedSopInstanceUid, 
                                                                      "Instance UID", UidType.SOPInstance)).ToList());
								}
								break;
						}

						break;

					case DicomCommandField.NDeleteResponse:
						switch (_eventObject)
						{
							case EventObject.FilmSession:
								_filmSession.OnDeleted();
								this.ReleaseConnection(client);
								break;
							case EventObject.FilmBox:
								_filmSession.OnFilmBoxDeleted();
								break;
						}

						break;

					case DicomCommandField.NSetResponse:
						_numberOfImageBoxesSent++;
						_filmSession.OnImageBoxSet(affectedUid);
						break;

					case DicomCommandField.NActionResponse:
						_filmSession.OnFilmBoxPrinted(affectedUid);

						break;
					default:
						break;
				}
			}
			catch (Exception ex)
			{
				this.FailureDescription = ex.Message;
				Platform.Log(LogLevel.Error, ex.ToString());
				ReleaseConnection(client);
				throw;
			}
		}
        // Methods
        public IAsyncResult BeginPrint(string clientAETitle, string remoteAE, string remoteHost, int remotePort, BasicFilmSessionModuleIod basicFilmSessionModuleIod, BasicFilmBoxModuleIod basicFilmBoxModuleIod, IList <ImageBoxPixelModuleIod> imageBoxPixelModuleIods, AsyncCallback callback, object asyncState)
        {
            PrintDelegate delegate2 = new PrintDelegate(this.Print);

            return(delegate2.BeginInvoke(clientAETitle, remoteAE, remoteHost, remotePort, basicFilmSessionModuleIod, basicFilmBoxModuleIod, imageBoxPixelModuleIods, callback, asyncState));
        }
        private void InternalPrint(PrintJob job)
        {
            BasicFilmSessionModuleIod basicFilmSessionModuleIod = new BasicFilmSessionModuleIod
            {
                NumberOfCopies  = job.Copies,
                MediumType      = job.MediumType,
                FilmDestination = job.FilmDestination
            };
            BasicFilmBoxModuleIod basicFilmBoxModuleIod = new BasicFilmBoxModuleIod
            {
                //ImageDisplayFormat = @"STANDARD\1,1",
                ImageDisplayFormat    = ImageDisplayFormat.Standard_1x1,
                FilmSizeId            = job.FilmSize,
                Illumination          = job.Illumination,
                FilmOrientation       = job.FilmOrientation,
                ReflectedAmbientLight = job.ReflectedAmbientLight,
                MagnificationType     = job.MagnificationType
            };
            IList <ImageBoxPixelModuleIod> imageBoxPixelModuleIods = new List <ImageBoxPixelModuleIod>();
            bool           userCancelled = false;
            BackgroundTask task          = new BackgroundTask(delegate(IBackgroundTaskContext context)
            {
                try
                {
                    BackgroundTaskProgress progress;
                    ushort num  = 1;
                    int percent = 0;
                    new List <string>();
                    ImageBoxPixelModuleIod item = new ImageBoxPixelModuleIod
                    {
                        ImageBoxPosition = 1
                    };
                    BasicGrayscaleImageSequenceIod iod2 = new BasicGrayscaleImageSequenceIod
                    {
                        PhotometricInterpretation = job.MonochormeType
                    };
                    Size size    = this.CalcMaxSize(job.Format, job.Images);
                    Bitmap image = new Bitmap(size.Width, size.Height);
                    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
                    foreach (PreviewTile tile in job.Images)
                    {
                        percent  = (int)((((float)(num - 1)) / ((float)job.Images.Count)) * 80f);
                        num      = (ushort)(num + 1);
                        progress = new BackgroundTaskProgress(percent, string.Format(SR.CreatingImageBuffer, num, job.Images.Count));
                        context.ReportProgress(progress);
                        if (tile.ImageData != null)
                        {
                            Platform.Log(LogLevel.Error, "TITLE IMAGEDATA");
                            Bitmap printImagePixel = tile.GetPrintImagePixel(false);
                            float x      = tile.NormalizedRectangle.X * size.Width;
                            float y      = tile.NormalizedRectangle.Y * size.Height;
                            float width  = tile.NormalizedRectangle.Width * size.Width;
                            float height = tile.NormalizedRectangle.Height * size.Height;
                            g.DrawImage(printImagePixel, x, y, width, height);
                            g.DrawRectangle(Pens.White, x, y, width, height);
                            Rectangle destination = new Rectangle(((int)x) + 2, ((int)y) + 2, ((int)width) - 4, ((int)height) - 4);
                            try
                            {
                                IconCreator.DrawTextOverlay(g, destination, tile.ImageData);
                            }
                            catch (Exception ex)
                            {
                                Platform.Log(LogLevel.Error, " exception: " + ex.ToString());
                            }
                            printImagePixel.Dispose();
                            if (context.CancelRequested)
                            {
                                userCancelled = true;
                                break;
                            }
                        }
                    }

                    //clear
                    foreach (PreviewTile tile in job.Images)
                    {
                        ImageSop sop  = ((IImageSopProvider)tile.ImageData).ImageSop;
                        string strUID = sop.SopInstanceUid;
                        //获取UID 的 accession
                        try
                        {
                            if (Conn.isOracle())
                            {
                                string sqlstr = string.Format(" update examrecord set filmprint='{0}' where  id=(select AccessionNumber from images where SopInstanceUID='{1}') and modulename='RIS' ",
                                                              "1", strUID);
                                OracleCommand sqlCmd = new OracleCommand();
                                sqlCmd.Connection    = GlobalData.MainConn.ChangeTypeOracle();
                                sqlCmd.CommandText   = sqlstr;
                                sqlCmd.ExecuteNonQuery();
                                sqlCmd.Dispose();
                            }
                            else
                            {
                                string sqlstr = string.Format(" update examrecord set filmprint='{0}' where  id=(select AccessionNumber from images where SopInstanceUID='{1}') and modulename='RIS' ",
                                                              "1", strUID);
                                SqlCommand sqlCmd  = new SqlCommand();
                                sqlCmd.Connection  = GlobalData.MainConn.ChangeType();
                                sqlCmd.CommandText = sqlstr;
                                sqlCmd.ExecuteNonQuery();
                                sqlCmd.Dispose();
                                Platform.Log(LogLevel.Error, " sql is  " + sqlstr);
                            }
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Error, "exception is " + ex.ToString());
                        }
                        //tile.Dispose();
                        tile.RemoveImage();
                    }

                    job.Images.Clear();


                    g.Dispose();
                    //iod2.AddBitmap(image);
                    Unlock();
                    RasterImage lRasterImage   = null;
                    RasterCodecs lRasterCodecs = new RasterCodecs();

                    lRasterImage = RasterImageConverter.ConvertFromImage(image, ConvertFromImageOptions.None);
                    lRasterCodecs.Save(lRasterImage, System.Windows.Forms.Application.StartupPath + @"\print.jpg", RasterImageFormat.Tif, 8);
                    string lDicomFile = "1" + DateTime.Now.ToString("HHmmss", DateTimeFormatInfo.InvariantInfo);
                    lRasterCodecs.Save(lRasterImage, System.Windows.Forms.Application.StartupPath + @"\PrintFiles\" + lDicomFile, RasterImageFormat.DicomGray, 16);
                    //image.Save("d:\\test.jpg");
                    image.Dispose();
                    lRasterImage.Dispose();
                    lRasterCodecs.Dispose();
                    //item.BasicGrayscaleImageSequenceList.Add(iod2);
                    //imageBoxPixelModuleIods.Add(item);
                    if (userCancelled)
                    {
                        Platform.Log(LogLevel.Info, SR.UserCancel);
                    }
                    else
                    {
                        progress = new BackgroundTaskProgress(80, SR.BeginSendImage);
                        context.ReportProgress(progress);
                        PrintDicomFiles(lDicomFile, 1, 1, lDicomFile, job);

                        //BasicGrayscalePrintScu scu = new BasicGrayscalePrintScu();
                        //scu.Print(job.Printer.AET, job.Printer.CalledAET, job.Printer.Host, job.Printer.Port, basicFilmSessionModuleIod, basicFilmBoxModuleIod, imageBoxPixelModuleIods);
                        //if (scu.ResultStatus == DicomState.Success)
                        //{
                        //    this.UpdateStudyPrintStatus(this.GetStudyInstanceUIDs(job.Images));
                        //    PrintToolComponent.TilesComponent.ResetTiles();
                        //}
                        //else
                        //{
                        //    this._component.ShowMessageBox(SR.FilmError);
                        //}
                    }
                }
                catch (OutOfMemoryException)
                {
                    Platform.Log(LogLevel.Error, "内存不够");
                    BackgroundTaskProgress progress2 = new BackgroundTaskProgress(100, SR.OutOfMemory);
                    context.ReportProgress(progress2);
                    this._component.ShowMessageBox(SR.OutOfMemory);
                }
                catch (Exception exception)
                {
                    Platform.Log(LogLevel.Error, exception.Message);
                    BackgroundTaskProgress progress3 = new BackgroundTaskProgress(100, exception.Message);
                    context.ReportProgress(progress3);
                    this._component.ShowMessageBox(SR.PrinterError);
                }
                finally
                {
                    context.Complete(null);
                }
            }, true);

            ProgressDialog.Show(task, this._window, true, ProgressBarStyle.Blocks);
        }
 private bool GoPrint(PrintJob printJob, out int successSend)
 {
     successSend = 0;
     try
     {
         BasicFilmSessionModuleIod basicFilmSessionModuleIod = new BasicFilmSessionModuleIod
         {
             NumberOfCopies  = printJob.Copies,
             MediumType      = printJob.MediumType,
             FilmDestination = printJob.FilmDestination
         };
         BasicFilmBoxModuleIod basicFilmBoxModuleIod = new BasicFilmBoxModuleIod
         {
             //ImageDisplayFormat = printJob.Format,
             FilmSizeId            = printJob.FilmSize,
             Illumination          = printJob.Illumination,
             FilmOrientation       = printJob.FilmOrientation,
             ReflectedAmbientLight = printJob.ReflectedAmbientLight,
             MagnificationType     = printJob.MagnificationType
         };
         IList <ImageBoxPixelModuleIod> imageBoxPixelModuleIods = new List <ImageBoxPixelModuleIod>();
         ushort num = 1;
         foreach (PreviewTile tile in printJob.Images)
         {
             this.ChangeSendStatus(printJob.ID, string.Format(SR.CreatingImageBuffer, num, printJob.Images.Count));
             ImageBoxPixelModuleIod item = new ImageBoxPixelModuleIod
             {
                 ImageBoxPosition = tile.Position
             };
             BasicGrayscaleImageSequenceIod iod4 = new BasicGrayscaleImageSequenceIod
             {
                 PhotometricInterpretation = printJob.MonochormeType
             };
             Bitmap printImagePixel = tile.GetPrintImagePixel(true);
             iod4.AddBitmap(printImagePixel);
             printImagePixel.Dispose();
             item.BasicGrayscaleImageSequenceList.Add(iod4);
             imageBoxPixelModuleIods.Add(item);
         }
         if (this.StopKey)
         {
             return(false);
         }
         this.ChangeSendStatus(printJob.ID, SR.BeginSendImage);
         try
         {
             for (int i = 0; i < printJob.Copies; i++)
             {
                 BasicGrayscalePrintScu scu = new BasicGrayscalePrintScu();
                 this.ChangeSendStatus(printJob.ID, string.Format(SR.Sending, i.ToString(), printJob.Copies.ToString()));
                 if (scu.Print(printJob.Printer.AET, printJob.Printer.CalledAET, printJob.Printer.Host, printJob.Printer.Port, basicFilmSessionModuleIod, basicFilmBoxModuleIod, imageBoxPixelModuleIods) == DicomState.Success)
                 {
                     successSend++;
                 }
             }
         }
         catch (Exception exception)
         {
             Platform.Log(LogLevel.Error, exception);
         }
     }
     catch (Exception exception2)
     {
         Platform.Log(LogLevel.Error, exception2);
     }
     if (successSend == 0)
     {
         return(false);
     }
     return(true);
 }