예제 #1
0
        public IEnumerable <DicomCMoveResponse> OnCMoveRequest(DicomCMoveRequest request)
        {
            List <DicomCMoveResponse> response = new List <DicomCMoveResponse>();
            List <Pathmodel>          pathList = qrm.CMove(request.Dataset, request.Level);
            DicomClient cstoreClient           = new DicomClient();

            try
            {
                foreach (Pathmodel p in pathList)
                {
                    DicomCStoreRequest cstorerq = new DicomCStoreRequest(p.Path);
                    cstorerq.OnResponseReceived = (rq, rs) =>
                    {
                        if (rs.Status == DicomStatus.Success)
                        {
                            DicomCMoveResponse rsp = new DicomCMoveResponse(request, DicomStatus.Pending);
                            SendResponse(rsp);
                        }
                    };
                    cstoreClient.AddRequest(cstorerq);
                    cstoreClient.Send("127.0.0.1", 2222, false, this.Association.CalledAE, request.DestinationAE);
                }
                return(response);
            }
            catch
            {
                DicomCMoveResponse rs = new DicomCMoveResponse(request, DicomStatus.StorageStorageOutOfResources);
                response.Add(rs);
                return(response);
            }
        }
예제 #2
0
        public async Task SendingMoveRequestToServerThatSendsPendingResponsesWithinTimeoutShouldNotTimeout()
        {
            var port = Ports.GetNext();

            using (CreateServer <FastPendingResponsesDicomServer>(port))
            {
                var client = CreateClient(port);

                client.ServiceOptions.RequestTimeout = TimeSpan.FromSeconds(2);

                DicomCMoveResponse lastResponse = null;
                var request = new DicomCMoveRequest("another-AE", "study123")
                {
                    OnResponseReceived = (req, res) => lastResponse = res
                };

                DicomRequest.OnTimeoutEventArgs onTimeoutEventArgs = null;
                request.OnTimeout += (sender, args) => onTimeoutEventArgs = args;

                await client.AddRequestAsync(request).ConfigureAwait(false);

                var sendTask = client.SendAsync();
                var sendTimeoutCancellationTokenSource = new CancellationTokenSource();
                var sendTimeout = Task.Delay(TimeSpan.FromSeconds(10), sendTimeoutCancellationTokenSource.Token);

                var winner = await Task.WhenAny(sendTask, sendTimeout).ConfigureAwait(false);

                sendTimeoutCancellationTokenSource.Cancel();
                sendTimeoutCancellationTokenSource.Dispose();

                Assert.Equal(winner, sendTask);
                Assert.NotNull(lastResponse);
                Assert.Equal(lastResponse.Status, DicomStatus.Success);
                Assert.Null(onTimeoutEventArgs);
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: xydoublez/CSDN
        public virtual IEnumerable <DicomCMoveResponse> OnCMoveRequest(DicomCMoveRequest request)
        {
            DicomStatus status             = DicomStatus.Success;
            IList <DicomCMoveResponse> rsp = new List <DicomCMoveResponse>();
            /*----to do------*/
            //添加查询数据库的代码,即根据request的条件提取指定的图像
            //然后将图像信息添加到rsp响应中

            //创建C-STORE-SCU,发起C-STORE-RQ
            IList <DicomDataset> queries;
            DicomClient          clt = new DicomClient();

            if (OnZSCMoveRequest != null)
            {
                queries = OnZSCMoveRequest(request);
                if (queries != null)
                {
                    Logger.Info("需要发送{0}个数据", queries.Count);
                    int len = queries.Count;
                    int cnt = 0;
                    foreach (var item in queries)
                    {
                        //zssure:
                        //取巧的方法直接利用request来构造response中相同的部分
                        //这部分与mDCM方式很不同
                        var studyUid = item.Get <string>(DicomTag.StudyInstanceUID);
                        var instUid  = item.Get <string>(DicomTag.SOPInstanceUID);
                        //需要在c:\cmovetest目录下手动添加C-MOVE SCU请求的图像
                        //本地构造的目录结构为,
                        //      c:\cmovetest\12\0.dcm
                        //      c:\cmovetest\12\1.dcm
                        //      c:\cmovetest\12\2.dcm
                        var path = Path.GetFullPath(@"c:\cmovetest");

                        try
                        {
                            path = Path.Combine(path, studyUid);
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }
                            path = Path.Combine(path, instUid) + ".dcm";
                            DicomCStoreRequest cstorerq = new DicomCStoreRequest(path);
                            cstorerq.OnResponseReceived = (rq, rs) =>
                            {
                                if (rs.Status != DicomStatus.Pending)
                                {
                                }
                                if (rs.Status == DicomStatus.Success)
                                {
                                    DicomCMoveResponse rsponse = new DicomCMoveResponse(request, DicomStatus.Pending);
                                    rsponse.Remaining = --len;
                                    rsponse.Completed = ++cnt;
                                    rsponse.Warnings  = 0;
                                    rsponse.Failures  = 0;
                                    //zssure:2014-12-24
                                    //修复发送C-MOVE-RSP的逻辑错误
                                    SendResponse(rsponse);
                                    //rsp.Add(rsponse);
                                    //zssure:end
                                }
                            };
                            clt.AddRequest(cstorerq);
                            //注意:这里给出的IP地址与C-MOVE请求的IP地址相同,意思就是说C-MOVE SCP需要向C-MOVE SCU发送C-STORE-RQ请求
                            //将查询到的图像返回给C-MOVE SCU
                            //所以四尺C-STORE-RQ中的IP地址与C-MOVE SCU相同,但是端口不同,因为同一个端口不能被绑定多次。
                            clt.Send("127.0.0.1", 22345, false, this.Association.CalledAE, request.DestinationAE);
                        }
                        catch (System.Exception ex)
                        {
                            DicomCMoveResponse rs = new DicomCMoveResponse(request, DicomStatus.StorageStorageOutOfResources);
                            rsp.Add(rs);
                            return(rsp);
                        }
                    }
                    //zssure:
                    //发送完成后统一返回C-MOVE RESPONSE
                    //貌似响应流程有问题,有待进一步核实
                    //注意,如果最后为发送DicomStatus.Success消息,TCP连接不会释放,浪费资源
                    rsp.Add(new DicomCMoveResponse(request, DicomStatus.Success));
                    return(rsp);
                }
                else
                {
                    rsp.Add(new DicomCMoveResponse(request, DicomStatus.NoSuchObjectInstance));
                    return(rsp);
                }
            }
            rsp.Add(new DicomCMoveResponse(request, DicomStatus.NoSuchObjectInstance));
            return(rsp);
        }