Exemplo n.º 1
0
        public BitmapImage downloadImage(SeriesResponseQuery series)
        {
            clearFolder(Constants.imageThumbsFolder);

            ImageLevelQuery query = new ImageLevelQuery(series);

            GetQueryResponsesList g = new GetQueryResponsesList();
            // IMAGE LEVEL QUERY
            List <QueryObject> listImages = g.getResponsesList(query, "Image");

            if (listImages.Count > 0)
            {
                int numImageToDownload   = (int)(listImages.Count / 2.0f);
                ImageResponseQuery image = (ImageResponseQuery)listImages[numImageToDownload];

                watch(Constants.imageThumbsFolder);

                QueryRetrieve q    = new QueryRetrieve();
                String        path = Path.Combine(Constants.imageThumbsFolder, "singleImage.txt");
                File.WriteAllText(path, "gotImage");

                //MOVE IMAGE
                q.move(GUILogic.readFromFile("thisMachineAE"), image, "Image", guiLogic);
                bool a = manualResetEvent.WaitOne(500);
                // now wait

                watcher.Dispose();

                if (isImage)
                {
                    return(loadImageSource());
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(new BitmapImage());
            }
        }
Exemplo n.º 2
0
        public void move(string callingAE, QueryObject query, string level, GUILogic guiLogic)
        {
            var cmove = new DicomCMoveRequest("", "");

            if (query.GetType().ToString() == "QueryRetrieveService.StudyResponseQuery")
            {
                string studyId = ((StudyResponseQuery)query).StudyInstanceUID;
                cmove = new DicomCMoveRequest(callingAE, studyId);
            }

            if (query.GetType().ToString() == "QueryRetrieveService.SeriesResponseQuery")
            {
                string studyId  = ((SeriesResponseQuery)query).StudyInstanceUID;
                string seriesId = ((SeriesResponseQuery)query).SeriesInstanceUID;
                cmove = new DicomCMoveRequest(callingAE, studyId, seriesId);
            }

            if (query.GetType().ToString() == "QueryRetrieveService.ImageResponseQuery")
            {
                string studyId  = ((ImageResponseQuery)query).StudyInstanceUID;
                string seriesId = ((ImageResponseQuery)query).SeriesInstanceUID;
                string imageId  = ((ImageResponseQuery)query).SOPInstanceUID;
                cmove = new DicomCMoveRequest(callingAE, studyId, seriesId, imageId);
                Console.WriteLine(studyId + " " + seriesId + " " + imageId);
            }

            var client = new DicomClient();

            bool?moveSuccessfully = null;

            cmove.OnResponseReceived += (DicomCMoveRequest requ, DicomCMoveResponse response) =>
            {
                if (response.Status.State == DicomState.Pending)
                {
                    Console.WriteLine("Sending is in progress. please wait: " + response.Remaining.ToString());
                }
                else if (response.Status.State == DicomState.Success)
                {
                    Console.WriteLine("Sending successfully finished");
                    moveSuccessfully = true;
                }
                else if (response.Status.State == DicomState.Failure)
                {
                    Console.WriteLine("Error sending datasets: " + response.Status.Description);
                    moveSuccessfully = false;
                }
                Console.WriteLine(response.Status);
            };
            var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids(
                DicomStorageCategory.Image,
                DicomTransferSyntax.ExplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRLittleEndian,
                DicomTransferSyntax.ImplicitVRBigEndian);

            client.AdditionalPresentationContexts.AddRange(pcs);

            client.AddRequest(cmove);
            // cicle to kill listener and restart it (thus ending associatio) if move takes too much time
            bool sendSuccess = false;

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                Thread.Sleep(5000);
                if (!sendSuccess)
                {
                    guiLogic.listenerProcess.Kill();
                    guiLogic.newProcess();
                }
            }).Start();
            client.Send(GUILogic.readFromFile("server"), Int32.Parse(GUILogic.readFromFile("serverPort")), false, GUILogic.readFromFile("thisMachineAE"), GUILogic.readFromFile("serverAE"), 1000);
            sendSuccess = true;
        }
Exemplo n.º 3
0
        public void find(QueryObject query, string level)
        {
            if (level != "Study" && level != "Series" && level != "Image")
            {
                MessageBox.Show("incorrect level"); return;
            }

            DicomQueryRetrieveLevel queryLevel = (DicomQueryRetrieveLevel)Enum.Parse(typeof(DicomQueryRetrieveLevel), level);
            DicomCFindRequest       cfind      = new DicomCFindRequest(queryLevel);
            Type tipo = query.GetType();

            PropertyInfo[] properties1 = tipo.GetProperties();

            foreach (PropertyInfo property in properties1)
            {
                var      tag    = typeof(DicomTag).GetField(property.Name).GetValue(null);
                DicomTag theTag = (DicomTag.Parse(tag.ToString()));

                var variabile = property.GetValue(query);
                if (variabile.GetType().ToString() == "System.String")
                {
                    String a = (String)variabile;
                    cfind.Dataset.Add(theTag, a);
                }
                if (variabile.GetType().ToString() == "Dicom.DicomDateRange")
                {
                    DicomDateRange a = (DicomDateRange)variabile;
                    cfind.Dataset.Add(theTag, a);
                }
            }

            cfind.OnResponseReceived = (DicomCFindRequest rq, DicomCFindResponse rp) => {
                if (rp.HasDataset)
                {
                    var type     = Type.GetType("QueryRetrieveService." + level + "ResponseQuery");
                    var response = (QueryObject)Activator.CreateInstance(type);
                    queryResponses.Add(response);

                    PropertyInfo[] properties = response.GetType().GetProperties();
                    foreach (PropertyInfo property in properties)
                    {
                        var      tag   = typeof(DicomTag).GetField(property.Name).GetValue(null);
                        DicomTag myTag = DicomTag.Parse(tag.ToString());
                        try {
                            property.SetValue(response, rp.Dataset.GetValues <string>(myTag)[0]);
                        } catch (Exception e)
                        {
                            //                 MessageBox.Show("tag " + myTag.ToString() + " not found in this dataset");
                        }
                    }
                    RaiseEvent(response);
                }
            };


            var client = new DicomClient();

            client.AddRequest(cfind);
            client.AssociationReleased += (sender, e) => {
                // non può inviare la lista 'queryResponses' prima
                // che 'cfind.OnResponseReceived' abbia finito di riempirla!!
                Thread.Sleep(5);
                RaiseConnectionClosed(queryResponses);
            };
            try
            {
                client.Send(GUILogic.readFromFile("server"), Int32.Parse(GUILogic.readFromFile("serverPort")), false, GUILogic.readFromFile("thisMachineAE"), GUILogic.readFromFile("serverAE"), 1000);
            } catch (Exception e) { MessageBox.Show("impossible connect to server"); }
        }