MarkObserveCancel() 공개 메소드

Sets CoAP's observe option to the value of 1 to proactively cancel.
public MarkObserveCancel ( ) : Request
리턴 Request
예제 #1
0
        public void ProactiveCancel()
        {
            Request cancel = Request.NewGet();

            // copy options, but set Observe to cancel
            cancel.SetOptions(_request.GetOptions());
            cancel.MarkObserveCancel();
            // use same Token
            cancel.Token       = _request.Token;
            cancel.Destination = _request.Destination;

            // dispatch final response to the same message observers
            cancel.CopyEventHandler(_request);

            cancel.Send(_endpoint);
            // cancel old ongoing request
            _request.IsCancelled = true;
            _canceled            = true;
        }
예제 #2
0
        public void CancelObserve(ObjectType objectType, string instanceID, string resourceID, bool useReset)
        {
            if (_ObserveRequests != null)
            {
                string uriPath;
                if (string.IsNullOrEmpty(instanceID))
                    uriPath = objectType.Path;
                else if (string.IsNullOrEmpty(resourceID))
                    uriPath = string.Concat(objectType.Path, "/", instanceID);
                else
                    uriPath = string.Concat(objectType.Path, "/", instanceID, "/", resourceID);
                int index = 0;
                while (index < _ObserveRequests.Count)
                {
                    if (_ObserveRequests[index].Request.UriPath == uriPath)
                    {
                        Request observeRequest = _ObserveRequests[index].Request;
                        _ObserveRequests.RemoveAt(index);
                        if (observeRequest != null)
                        {
                            if (useReset)
                            {
                                observeRequest.IsCancelled = true;
                            }
                            else
                            {
                                Request request = new Request(Method.GET);
                                request.Accept = _DataFormat;
                                request.Destination = observeRequest.Destination;
                                request.EndPoint = observeRequest.EndPoint;
                                request.UriPath = observeRequest.UriPath;
                                request.MarkObserveCancel();
                                SendRequest(request);
                                observeRequest.IsCancelled = true;
                            }
                        }

                    }
                    else
                        index++;
                }
            }
        }