private void echoButton_Click(object sender, RoutedEventArgs e)
        {
            // Store the details of the daemon (Ae Title , IP , port )
            var daemon = new Entity(DaemonTitleTextBox.Text, DaemonIpTextBox.Text, int.Parse(DaemonPortTextBox.Text));
            // Store the details of the client (Ae Title , port ) -> IP address is determined by CreateLocal() method
            var local = Entity.CreateLocal(AEtitleTextBox.Text, int.Parse(AEportTextBox.Text));
            // Set up a client ( DICOM SCU = Service Class User )
            var client = new DICOMSCU(local);
            var storer = client.GetCStorer(daemon);
            //ushort msgId = 1;

            var canPing = client.Ping(daemon);

            if (canPing)
            {
                echoButton.Background = System.Windows.Media.Brushes.LawnGreen;
                ShowLogMsg("\nImport is possible. Echo to Daemon succeeded.");
                ProgressTextBlock.Text = "Echo succeeded. Press Start to begin Import.";
            }
            else
            {
                echoButton.Background = System.Windows.Media.Brushes.PaleVioletRed;
                ShowLogMsg("\nNo import is possible. Echo to Daemon failed.");
                ProgressTextBlock.Text = "Echo failed. Import will also fail.";
            }
        }
        /// <summary>
        /// This tutorial is outlined in chapter 4 of Scripting in RT for Physicists (C-Store)
        /// </summary>
        public static void Run()
        {
            //Store the details of the daemon (Ae Title, IP, port)
            var daemon = new Entity("PHYSX_DICOM", "10.22.86.64", 51402);
            //Store the details of the client (Ae Title, port) -> IP address is determined by CreateLocal() method
            var local = Entity.CreateLocal("DICOMEC1", 9999);
            //Set up a client (DICOM SCU = Service Class User)
            var client = new DICOMSCU(local);
            var storer = client.GetCStorer(daemon);

            var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var storagePath = Path.Combine(desktopPath, "DICOM Storage");

            ushort msgId    = 1;
            var    dcmFiles = Directory.GetFiles(storagePath);

            foreach (var path in dcmFiles)
            {
                //Reads DICOM object into memory
                var dcm      = DICOMObject.Read(path);
                var response = storer.SendCStore(dcm, ref msgId);
                //Write results to console
                Console.WriteLine($"DICOM C-Store from {local.AeTitle} => " +
                                  $"{daemon.AeTitle} @{daemon.IpAddress}:{daemon.Port}:" +
                                  $"{(Status)response.Status}");
            }
            Console.Read(); //Stop here
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            var scp = new DICOMSCP(Entity.CreateLocal("SCP", 9999));
            ////new ConsoleLogger(scp.Logger);
            //scp.SupportedAbstractSyntaxes = AbstractSyntax.ALL_RADIOTHERAPY_STORAGE;
            //int i = 1;
            //scp.DIMSEService.CStoreService.CStorePayloadAction = (dcm, asc) =>
            //{
            //    Thread.Sleep(6000);
            //    Assert.AreEqual(dcm.SOPClass, SOPClass.CTImageStorage);
            //    Assert.AreEqual(dcm.PixelStream.Length, 10000);
            //    Assert.AreEqual(dcm.GetSelector().PatientID.Data, "123456");
            //    Console.WriteLine($"Received {i++} files");
            //    return true;
            //};
            //scp.ListenForIncomingAssociations(true);


            var scu = new DICOMSCU(Entity.CreateLocal("SCU", 9998));

            scu.IdleTimeout = 10000;
            ushort msg = 1;

            foreach (var dcm in GenerateDICOMFiles())
            {
                var resp = scu.GetCStorer(scp.ApplicationEntity).SendCStore(dcm, ref msg);
                if (resp == null)
                {
                    Console.WriteLine("SCU Timeout!");
                    break;
                }
                else if (resp.Status == (ushort)Status.FAILURE)
                {
                    Console.WriteLine("No connection");
                    break;
                }
            }
            Console.Read();
        }
        private void runButton_Click(object sender, RoutedEventArgs e)
        {
            // Store the details of the daemon (Ae Title , IP , port )
            var daemon = new Entity(DaemonTitleTextBox.Text, DaemonIpTextBox.Text, int.Parse(DaemonPortTextBox.Text));
            // Store the details of the client (Ae Title , port ) -> IP address is determined by CreateLocal() method
            var local = Entity.CreateLocal(AEtitleTextBox.Text, int.Parse(AEportTextBox.Text));
            // Set up a client ( DICOM SCU = Service Class User )
            var    client = new DICOMSCU(local);
            var    storer = client.GetCStorer(daemon);
            ushort msgId  = 1;

            var canPing = client.Ping(daemon);

            if (canPing)
            {
                echoButton.Background = System.Windows.Media.Brushes.LawnGreen;
                progressBar.Value     = 0;
                runButton.IsEnabled   = false;

                if (!Directory.Exists(outputFolderPath))
                {
                    Directory.CreateDirectory(outputFolderPath);
                }

                runButton.IsEnabled = false;

                string dir         = inputFolderPath;
                var    toAnonymize = Enumerable.Empty <string>();
                if (subDirCheckBox.IsChecked == false)
                {
                    toAnonymize = Directory.GetFiles(dir).Where(f => DumpSingleDicomTag(f, "0008,0060") != "fail" & !Path.GetFileName(f).Contains("_ignore"));
                }
                else
                {
                    toAnonymize = Directory.GetFiles(dir, "*", SearchOption.AllDirectories).Where(f => DumpSingleDicomTag(f, "0008,0060") != "fail" & !Path.GetFileName(f).Contains("_ignore"));
                }
                int np = toAnonymize.Count();
                ShowLogMsg("\nNew import process has started.");
                ShowLogMsg("Number of DICOM files for importing: " + np.ToString() + "\n");

                int  count         = 1;
                bool importSuccess = true;
                foreach (var file in toAnonymize)
                {
                    // Reads DICOM object into memory
                    var dcm      = EvilDICOM.Core.DICOMObject.Read(file);
                    var response = storer.SendCStore(dcm, ref msgId);
                    // Write results to console
                    //await Task.Run(() => ShowLogMsg($" DICOM C-Store of {Path.GetFileName(file)} from { local.AeTitle } => { daemon.AeTitle } {(EvilDICOM.Network.Enums.Status)response.Status }"));

                    progressBar.Value      = count * 100 / np;
                    ProgressTextBlock.Text = "Import in progress....";

                    count++;
                }

                if (importSuccess == true)
                {
                    ShowLogMsg("\nImport completed successfully.");
                    ShowLogMsg("");
                    ProgressTextBlock.Text = "Import completed successfully";
                    progressBar.Value      = 100;
                }
                else
                {
                    ShowLogMsg("\nImport completed with Erros.");
                    ShowLogMsg("");
                    ProgressTextBlock.Text = "Import completed with Errors";
                    progressBar.Value      = 100;
                }


                runButton.IsEnabled = true;
            }
            else
            {
                echoButton.Background = System.Windows.Media.Brushes.PaleVioletRed;
                ShowLogMsg("\nNo import is possible. Echo to Daemon failed.");
                ProgressTextBlock.Text = "Echo failed. No Import was done.";
            }
        }