示例#1
0
        static void Debug2()
        {
            //ADCM.DownloadOneSeries("1.2.840.114202.4.2604463977.4026103162.3502102038.3123374876", "1.3.51.0.7.225049604.36789.12869.46787.35328.59718.43415");

            var cstore = new DicomSCP("CAPITZZRADPAE", 104);
            ////var cstore = new DicomSCP("CAPITZZKPACS", 105);
            cstore.Start();
            ////while (!cstore.IsRunning)
            ////    System.Threading.Thread.Sleep(1000);

            MoveScuBase moveScu = new StudyRootMoveScu("CAPITZZRADPAE", "CAPITCYMOD1", "192.168.115.240", 5000, "CAPITZZRADPAE");


            moveScu.ReadTimeout = 600000;
            moveScu.WriteTimeout = 600000;
            moveScu.AddStudyInstanceUid("1.2.840.114202.4.2604463977.4026103162.3502102038.3123374876");
            moveScu.AddSeriesInstanceUid("1.3.51.0.7.225049604.36789.12869.46787.35328.59718.43415");
            moveScu.Move();

            Console.WriteLine("Done");
        }
示例#2
0
    public static bool DownloadOneSeries(string studyuid, string seriesuid, int retryCount = 0)
    {
        var node = GetSelectedNode();
        var cstore = new DicomSCP(node.LocalAe, 104);
        try
        {
            LOG.Write("Retry Count: " + retryCount);

            StudyRootFindScu findScu = new StudyRootFindScu();
            SeriesQueryIod queryMessage = new SeriesQueryIod();
            queryMessage.SetCommonTags();
            queryMessage.StudyInstanceUid = studyuid;
            queryMessage.SeriesInstanceUid = seriesuid;
            IList<SeriesQueryIod> results = findScu.Find(node.LocalAe, node.AET, node.IP, node.Port, queryMessage);
            if (results.Count != 1)
                throw new Exception(string.Format("Unable to query study on PACS: [{0}]", studyuid));

            int expectedFiles = (int)results[0].NumberOfSeriesRelatedInstances;

            if (!System.IO.Directory.Exists(node.LocalStorage))
                System.IO.Directory.CreateDirectory(node.LocalStorage);
            cstore.Start();
            while (!cstore.IsRunning)
                System.Threading.Thread.Sleep(1000);

            MoveScuBase moveScu = new StudyRootMoveScu(node.LocalAe, node.AET, node.IP, node.Port, node.LocalAe);
            moveScu.ReadTimeout = 600000;
            moveScu.WriteTimeout = 600000;
            moveScu.AddStudyInstanceUid(studyuid);
            moveScu.AddSeriesInstanceUid(seriesuid);

            DateTime started = DateTime.Now;

            moveScu.Move();
            System.Threading.Thread.Sleep(2000);
            if (moveScu.Status == ScuOperationStatus.AssociationRejected || moveScu.Status == ScuOperationStatus.Canceled ||
                moveScu.Status == ScuOperationStatus.ConnectFailed || moveScu.Status == ScuOperationStatus.Failed ||
                moveScu.Status == ScuOperationStatus.NetworkError || moveScu.Status == ScuOperationStatus.TimeoutExpired ||
                moveScu.Status == ScuOperationStatus.UnexpectedMessage || moveScu.FailureSubOperations != 0)
            {
                if (retryCount > 4)
                    throw new Exception(string.Format("Failed moving study [{0}] | Status : {1} | Failed Operations: {2}", studyuid, moveScu.Status, moveScu.FailureSubOperations));
                retryCount += 1;
                if (cstore.IsRunning)
                    cstore.Stop();
                DownloadOneSeries(studyuid, seriesuid, retryCount);
            }

            string downloadFolder = GetStoreString();
            downloadFolder = Path.Combine(downloadFolder, studyuid, seriesuid);
            bool direxist = Directory.Exists(downloadFolder);
            while (!direxist)
            {
                if ((DateTime.Now - started).TotalMinutes > 3)
                {
                    if (cstore.IsRunning)
                        cstore.Stop();
                    throw new Exception("Waited too long for images to come in");
                }
                //LOG.Write("Waiting for images to come in...");
                System.Threading.Thread.Sleep(1 * 1000);
                direxist = Directory.Exists(downloadFolder);
            }

            var dcmfiles = Directory.GetFiles(downloadFolder, "*.dcm");
            var dcmCount = dcmfiles.Length;
            while (dcmCount < expectedFiles)
            {
                if ((DateTime.Now - started).TotalMinutes > 3)
                {
                    if (cstore.IsRunning)
                        cstore.Stop();
                    throw new Exception("Waited too long for images to come in");
                }
                //LOG.Write("Waiting for images to come in...");
                System.Threading.Thread.Sleep(1 * 1000);
                dcmfiles = Directory.GetFiles(downloadFolder, "*.dcm");
                if (dcmfiles.Length != dcmCount)
                {
                    if (dcmfiles.Length >= expectedFiles) { break; }
                    dcmCount = dcmfiles.Length;
                    started = DateTime.Now;
                }
            }

            if (cstore.IsRunning)
                cstore.Stop();
            LOG.Write("Series successfully downloaded from PACS");
            return true;
        }
        catch (Exception ex)
        {
            if (cstore.IsRunning)
                cstore.Stop();
            string errorString = "Error at :" + System.Reflection.MethodBase.GetCurrentMethod().Name;
            LOG.Write(errorString);
            LOG.Write(ex.Message);
            return false;
        }
    }