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; }
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++; } } }