Example #1
0
        private async Task <CoapObserveRelation> StartObservationAsync(Request request, Action <Response> notify, Action <FailReason> error)
        {
            IEndPoint           endpoint = GetEffectiveEndpoint(request);
            CoapObserveRelation relation = new CoapObserveRelation(request, endpoint, _config);

            request = CreateObservationRequest(request, notify, error, relation, endpoint);
            await SendAsync(request, CancellationToken.None).ConfigureAwait(false);

            return(relation);
        }
Example #2
0
        private CoapObserveRelation StartObservation(Request request, Action <Response> notify, Action <FailReason> error)
        {
            IEndPoint           endpoint = GetEffectiveEndpoint(request);
            CoapObserveRelation relation = new CoapObserveRelation(request, endpoint, _config);

            request = CreateObservationRequest(request, notify, error, relation, endpoint);
            request.Send();

            return(relation);
        }
Example #3
0
        private CoapObserveRelation Observe(Request request, Action <Response> notify, Action <FailReason> error)
        {
            CoapObserveRelation relation = StartObservation(request, notify, error);
            Response            response = relation.Request.WaitForResponse(_timeout);

            if (response == null || !response.HasOption(OptionType.Observe))
            {
                relation.Canceled = true;
            }
            relation.Current = response;
            return(relation);
        }
Example #4
0
        private Request CreateObservationRequest(Request request, Action <Response> notify, Action <FailReason> error, CoapObserveRelation relation,
                                                 IEndPoint endpoint)
        {
            request.Respond += (o, e) =>
            {
                Response resp = e.Response;
                lock (relation)
                {
                    if (relation.Orderer.IsNew(resp))
                    {
                        relation.Current = resp;
                        Deliver(notify, e);
                    }
                    else
                    {
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("Dropping old notification: " + resp);
                        }
                    }
                }
            };
            Action <FailReason> fail = r =>
            {
                relation.Canceled = true;
                Fail(error, r);
            };

            request.Rejected += (o, e) => fail(FailReason.Rejected);
            request.TimedOut += (o, e) => fail(FailReason.TimedOut);

            //await SendAsync(Prepare(request, endpoint));
            var finalRequest = Prepare(request, endpoint);

            return(finalRequest);
        }