示例#1
0
        public IEnumerable <T> GetResponses <T, U>(U request, Entity e, ref ushort msgId) where U : AbstractDIMSERequest where T : AbstractDIMSEResponse
        {
            System.DateTime lastContact = System.DateTime.Now;
            int             msWait      = 4000;

            var mr = new ManualResetEvent(false);

            List <T> responses = new List <T>();
            var      cr        = new Services.DIMSEService.DIMSEResponseHandler <T>((res, asc) =>
            {
                lastContact = System.DateTime.Now;
                responses.Add(res);
                if (res.Status != (ushort)Status.PENDING)
                {
                    mr.Set();
                }
                else
                {
                    mr.Reset();
                }
            });

            DIMSEService.Subscribe(cr);
            SendMessage(request, e);
            mr.WaitOne(msWait); //Max wait for timeout
            DIMSEService.Unsubscribe(cr);
            msgId += 2;
            return(responses);
        }
示例#2
0
        public T GetResponse <T, U>(U request, Entity e, ref ushort msgId) where U : AbstractDIMSERequest where T : AbstractDIMSEResponse
        {
            System.DateTime lastContact = System.DateTime.Now;
            int             msWait      = 2000;

            var mr   = new ManualResetEvent(false);
            T   resp = null;
            var cr   = new Services.DIMSEService.DIMSEResponseHandler <T>((res, asc) =>
            {
                lastContact = System.DateTime.Now;
                resp        = res;
                if (res.Status != (ushort)Status.PENDING)
                {
                    mr.Set();
                }
                else
                {
                    mr.Reset();
                }
            });

            DIMSEService.Subscribe(cr);
            SendMessage(request, e);
            mr.WaitOne(msWait);
            DIMSEService.Unsubscribe(cr);
            msgId += 2;
            return(resp);
        }
示例#3
0
        public IEnumerable <CMoveResponse> GetResponse(CMoveRequest cMove, Entity ae)
        {
            var client = new TcpClient();

            client.ConnectAsync(IPAddress.Parse(ae.IpAddress), ae.Port).Wait();
            var assoc = new Association(this, client)
            {
                AeTitle = ae.AeTitle
            };

            PDataMessenger.Send(cMove, assoc);
            var responses = new List <CMoveResponse>();

            Services.DIMSEService.DIMSEResponseHandler <CMoveResponse> action = null;
            action = (resp, asc) =>
            {
                responses.Add(resp);
                if (resp.Status != (ushort)Status.PENDING)
                {
                    DIMSEService.CMoveResponseReceived -= action;
                }
            };
            DIMSEService.CMoveResponseReceived += action;
            assoc.Listen();
            return(responses);
        }
示例#4
0
        /// <summary>
        /// Emits a CMove operation to an entity which moves an image from the entity to the specified AETitle
        /// </summary>
        /// <param name="scp">the provider which will perform the move</param>
        /// <param name="sopUid">the uid of the image to be moved</param>
        /// <param name="patientId">the patient id of the image</param>
        /// <param name="toAETite">the entity title which will receive the image</param>
        /// <param name="msgId">the message id</param>
        /// <returns>the move response</returns>
        public CMoveResponse SendCMoveImage(Entity daemon, CFindImageIOD iod, string toAETite, ref ushort msgId)
        {
            var           mr   = new ManualResetEvent(false);
            CMoveResponse resp = null;
            var           cr   = new Services.DIMSEService.DIMSEResponseHandler <CMoveResponse>((res, asc) =>
            {
                if (!(res.Status == (ushort)Status.PENDING))
                {
                    mr.Set();
                }
                resp = res;
            });
            var result = new CMoveIOD
            {
                QueryLevel        = QueryLevel.IMAGE,
                SOPInstanceUID    = iod.SOPInstanceUID,
                PatientId         = iod.PatientId,
                StudyInstanceUID  = iod.StudyInstanceUID,
                SeriesInstanceUID = iod.SeriesInstanceUID
            };
            var request = new CMoveRequest(result, toAETite, Root.STUDY, Core.Enums.Priority.MEDIUM, msgId);

            DIMSEService.CMoveResponseReceived += cr;
            SendMessage(request, daemon);
            mr.WaitOne();
            DIMSEService.CMoveResponseReceived -= cr;
            msgId += 2;
            return(resp);
        }
示例#5
0
        public IEnumerable <T> GetResponses <T, U>(U request, Entity e, ref ushort msgId) where U : AbstractDIMSERequest where T : AbstractDIMSEResponse
        {
            System.DateTime lastContact = System.DateTime.Now;
            int             msWait      = IdleTimeout;

            var      mr        = new ManualResetEvent(false);
            List <T> responses = new List <T>();
            var      cr        = new Services.DIMSEService.DIMSEResponseHandler <T>((res, asc) =>
            {
                asc.IdleClock.Restart();
                lastContact = System.DateTime.Now;
                responses.Add(res);
                if (res.Status != (ushort)Status.PENDING)
                {
                    mr.Set();
                }
                else
                {
                    mr.Reset();
                }
            });

            DIMSEService.Subscribe(cr);

            bool clientConnected;
            //Only wait if message is successful
            var sendStatus = SendMessage(request, e);

            if (clientConnected = sendStatus.WasAccepted)
            {
                //Wait for final response
                mr.WaitOne(msWait);
            }
            DIMSEService.Unsubscribe(cr);
            msgId += 2;

            if (!sendStatus.DidConnect)
            {
                throw new Exception($"Could not connect to remote endpoint {e}");
            }
            if (sendStatus.WasRejected)
            {
                throw new Exception($"Connected, but association refused by {e} : {sendStatus.Reason}");
            }
            return(responses);
        }
示例#6
0
        /// <summary>
        /// Emits a CMove operation to an entity which moves an image from the entity to the specified AETitle
        /// </summary>
        /// <param name="scp">the provider which will perform the move</param>
        /// <param name="sopUid">the uid of the image to be moved</param>
        /// <param name="patientId">the patient id of the image</param>
        /// <param name="toAETite">the entity title which will receive the image</param>
        /// <param name="msgId">the message id</param>
        /// <returns>the move response</returns>
        public CGetResponse SendGetImage(Entity daemon, CFindImageIOD iod, ref ushort msgId)
        {
            var          mr   = new ManualResetEvent(false);
            CGetResponse resp = null;
            var          cr   = new Services.DIMSEService.DIMSEResponseHandler <CGetResponse>((res, asc) =>
            {
                if (!(res.Status == (ushort)Status.PENDING))
                {
                    mr.Set();
                }
                resp = res;
            });

            iod.QueryLevel = QueryLevel.IMAGE;

            var request = new CGetRequest(iod, Root.STUDY, Core.Enums.Priority.MEDIUM, msgId);

            DIMSEService.CGetResponseReceived += cr;
            SendMessage(request, daemon);
            mr.WaitOne();
            DIMSEService.CGetResponseReceived -= cr;
            msgId += 2;
            return(resp);
        }