示例#1
1
        protected override void OnReceiveCMoveRequest(byte presentationID, ushort messageID, string destinationAE, DcmPriority priority, DcmDataset query)
        {
            Console.WriteLine(String.Format("{0} Receive C-Move from {1} (marked as anonymous:{2})", DateTime.Now, this.Associate.CallingAE, _flagAnonymousAccess));
            Debug.WriteLine(query.Dump());

            AEInfo recipientInfo = FindAE(destinationAE);

            if (recipientInfo == null)
            {
                SendCMoveResponse(presentationID, messageID, DcmStatus.QueryRetrieveMoveDestinationUnknown, 0, 0, 0, 0);
                Console.Write("Moving to:" + recipientInfo.Name + "> ");

                return;
            }

            Console.Write("Moving to:" + recipientInfo.Name + "> ");

            ushort imagesProcessed = 0;
            ushort errorCount = 0;
            ushort successCount = 0;

            try
            {

                using (var database = new MedicalISDataContext())
                {
                    var storeClient = new CStoreClient();
                    storeClient.CallingAE = "CURAPACS";
                    storeClient.CalledAE = destinationAE;
                    storeClient.PreferredTransferSyntax = recipientInfo.TransferSyntax;
                    storeClient.PreloadCount = 10;
                    storeClient.LogID = "store";

                    if (Settings.Default.DebugMove)
                    Dicom.Debug.InitializeConsoleDebugLogger();

                    if (_flagAnonymousAccess)
                        storeClient.DisableFileStreaming = true;

                    var files = GetFilePaths(database, query);

                    if (Settings.Default.UseFixedFolder)
                    {
                        files = Directory.GetFiles(Settings.Default.FixedFolderPath);
                    }

                    long totalSize = 0;

                    foreach (var f in files)
                    {
                        totalSize += new FileInfo(f).Length;
                        storeClient.AddFile(f);
                    }

                    int totalImageCount = (ushort) files.Count();

                    Console.Write("#{0} files > ", totalImageCount);

                    Stopwatch timer = Stopwatch.StartNew();

                    storeClient.OnCStoreRequestBegin = (c, i) =>
                                                           {
                                                               if (_flagAnonymousAccess)
                                                               {
                                                                   var dataset = i.Dataset;

                                                                   AnonymizeDatasetBasedOnStudyInfo(dataset);
                                                               }
                                                           };

                    storeClient.OnCStoreRequestComplete = (c, i) =>
                                                                {
                                                                  timer.Stop();

                                                                  if (i.HasError)
                                                                  {
                                                                      Console.WriteLine("Error:{0}", i.Error);
                                                                  }
                                                                  else
                                                                  {
                                                                  //    Console.WriteLine("Done");
                                                                  }

                                                                  totalImageCount -= storeClient.PendingCount;
                                                              };

                    storeClient.OnCStoreResponseReceived = (c, i) =>
                                                               {

                                                                   if (i.Status == DcmStatus.Success)
                                                                   {
                                                                       successCount++;
                                                                       Console.Write(".");
                                                                   }
                                                                   else
                                                                   {
                                                                       errorCount++;
                                                                       Console.Write("x");
                                                                   }

                                                               };

                    storeClient.OnCStoreRequestProgress = (c, i, p) =>
                                                              {
                                                                  //Console.WriteLine("{0}@{1}", p.BytesTransfered, c.Socket.LocalStats.ToString());
                                                              };

                    storeClient.OnCStoreRequestFailed = (c, i) =>
                                                            {
                                                                Console.WriteLine("");
                                                                Console.WriteLine("Failed. " + i.Error.ToString());
                                                            };

                    storeClient.Connect(recipientInfo.Ip, recipientInfo.Port, DcmSocketType.TCP);

                    if (storeClient.Wait())
                    {

                    }

                    timer.Stop();

                    double bytesPerSeconds = (double) totalSize/timer.Elapsed.TotalSeconds;
                    double MiBPerSecond = bytesPerSeconds/(1024.0*1024.0);

                    Console.WriteLine("");
                    Console.WriteLine("Done. {0} MiB/s (ImagesProcessed={1})", MiBPerSecond, imagesProcessed);

                    SendCMoveResponse(presentationID, messageID, DcmStatus.Success, 0, imagesProcessed, 0, 0);
                    storeClient.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("");
                Console.WriteLine("Failed. => " + ex.ToString());

                SendCMoveResponse(presentationID, messageID, DcmStatus.ProcessingFailure, 0, imagesProcessed, 0, 0);

            }
        }
示例#2
0
        private void UpdateSendInfo(CStoreClient client, CStoreRequestInfo info)
        {
            ListViewItem lvi = (ListViewItem)info.UserState;

            lvi.ImageIndex       = (info.Status == DcmStatus.Success) ? 1 : 2;
            lvi.SubItems[3].Text = info.Status.Description;
            lvSendImages.EnsureVisible(lvi.Index);
        }
示例#3
0
        private void RunDicomSend(object state)
        {
            CStoreClient scu = (CStoreClient)state;

            scu.Connect(Config.RemoteHost, Config.RemotePort, Config.UseTls ? DcmSocketType.TLS : DcmSocketType.TCP);
            if (!scu.Wait())
            {
                Invoke(new MessageBoxDelegate(ShowMessageBox), scu.ErrorMessage, "DICOM C-Store Error", true);
            }

            Invoke(new BoolDelegate(ToggleSendButtons), true);
        }
示例#4
0
        private void OnSend(object sender, EventArgs e)
        {
            ToggleSendButtons(false);

            SaveConfig();

            CStoreClient scu = new CStoreClient();

            scu.DisableFileStreaming           = true;
            scu.CallingAE                      = Config.LocalAE;
            scu.CalledAE                       = Config.RemoteAE;
            scu.MaxPduSize                     = Config.MaxPdu;
            scu.ConnectTimeout                 = 0;
            scu.SocketTimeout                  = Config.Timeout;
            scu.DimseTimeout                   = Config.Timeout;
            scu.SerializedPresentationContexts = true;
            scu.PreferredTransferSyntax        = TransferSyntaxes[Config.TransferSyntax];

            if (scu.PreferredTransferSyntax == DicomTransferSyntax.JPEGProcess1 ||
                scu.PreferredTransferSyntax == DicomTransferSyntax.JPEGProcess2_4)
            {
                DcmJpegParameters param = new DcmJpegParameters();
                param.Quality = Config.Quality;
                scu.PreferredTransferSyntaxParams = param;
            }
            else if (scu.PreferredTransferSyntax == DicomTransferSyntax.JPEG2000Lossy)
            {
                DcmJpeg2000Parameters param = new DcmJpeg2000Parameters();
                param.Rate = Config.Quality;
                scu.PreferredTransferSyntaxParams = param;
            }

            scu.OnCStoreResponseReceived = delegate(CStoreClient client, CStoreRequestInfo info) {
                Invoke(new CStoreRequestCallback(UpdateSendInfo), client, info);
            };

            foreach (ListViewItem lvi in lvSendImages.Items)
            {
                lvi.ImageIndex       = 0;
                lvi.SubItems[3].Text = "Pending";

                CStoreRequestInfo info = (CStoreRequestInfo)lvi.Tag;
                scu.AddFile(info);
            }

            ThreadPool.QueueUserWorkItem(new WaitCallback(RunDicomSend), scu);
        }
示例#5
0
 private void UpdateSendInfo(CStoreClient client, CStoreRequestInfo info)
 {
     ListViewItem lvi = (ListViewItem)info.UserState;
     lvi.ImageIndex = (info.Status == DcmStatus.Success) ? 1 : 2;
     lvi.SubItems[3].Text = info.Status.Description;
     lvSendImages.EnsureVisible(lvi.Index);
 }
示例#6
0
        private void OnSend(object sender, EventArgs e)
        {
            ToggleSendButtons(false);

            SaveConfig();

            CStoreClient scu = new CStoreClient();
            scu.DisableFileStreaming = true;
            scu.CallingAE = Config.LocalAE;
            scu.CalledAE = Config.RemoteAE;
            scu.MaxPduSize = Config.MaxPdu;
            scu.ConnectTimeout = 0;
            scu.SocketTimeout = Config.Timeout;
            scu.DimseTimeout = Config.Timeout;
            scu.SerializedPresentationContexts = true;
            scu.PreferredTransferSyntax = TransferSyntaxes[Config.TransferSyntax];

            //if (scu.PreferredTransferSyntax == DicomTransferSyntax.JPEGProcess1 ||
            //    scu.PreferredTransferSyntax == DicomTransferSyntax.JPEGProcess2_4) {
            //    DcmJpegParameters param = new DcmJpegParameters();
            //    param.Quality = Config.Quality;
            //    scu.PreferredTransferSyntaxParams = param;
            //}
            //else if (scu.PreferredTransferSyntax == DicomTransferSyntax.JPEG2000Lossy) {
            //    DcmJpeg2000Parameters param = new DcmJpeg2000Parameters();
            //    param.Rate = Config.Quality;
            //    scu.PreferredTransferSyntaxParams = param;
            //}

            scu.OnCStoreResponseReceived = delegate(CStoreClient client, CStoreRequestInfo info) {
                Invoke(new CStoreRequestCallback(UpdateSendInfo), client, info);
            };

            foreach (ListViewItem lvi in lvSendImages.Items) {
                lvi.ImageIndex = 0;
                lvi.SubItems[3].Text = "Pending";

                CStoreRequestInfo info = (CStoreRequestInfo)lvi.Tag;
                scu.AddFile(info);
            }

            ThreadPool.QueueUserWorkItem(new WaitCallback(RunDicomSend), scu);
        }