Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }