private CoapDotNetHttpResponse Proxy(CoapDotNetHttpRequest request, Uri coapUri) { var coapRequest = HttpTranslator.GetCoapRequest(request, Request.Url.SiteBase, true); coapRequest.URI = coapUri; //Setup response handler Response response = null; EventHandler<ResponseEventArgs> responseHandler = null; responseHandler = (_, e) => { response = e.Response; coapRequest.Respond -= responseHandler; }; coapRequest.Respond += responseHandler; //send request coapRequest.Send(); DateTime start = DateTime.Now; // ReSharper disable once LoopVariableIsNeverChangedInsideLoop while (response == null && (DateTime.Now - start).TotalSeconds < 30) Thread.Sleep(1); if (response == null) return null; //Turn COAP response into HTTP response var httpResponse = new CoapDotNetHttpResponse { MaxAge = response.MaxAge }; HttpTranslator.GetHttpResponse(request, response, httpResponse); return httpResponse; }
private CoapDotNetHttpResponse Proxy(CoapDotNetHttpRequest request, Uri coapUri) { var coapRequest = HttpTranslator.GetCoapRequest(request, Request.Url.SiteBase, true); coapRequest.URI = coapUri; //Setup response handler Response response = null; EventHandler <ResponseEventArgs> responseHandler = null; responseHandler = (_, e) => { response = e.Response; coapRequest.Respond -= responseHandler; }; coapRequest.Respond += responseHandler; //send request coapRequest.Send(); DateTime start = DateTime.Now; // ReSharper disable once LoopVariableIsNeverChangedInsideLoop while (response == null && (DateTime.Now - start).TotalSeconds < 30) { Thread.Sleep(1); } if (response == null) { return(null); } //Turn COAP response into HTTP response var httpResponse = new CoapDotNetHttpResponse { MaxAge = response.MaxAge }; HttpTranslator.GetHttpResponse(request, response, httpResponse); return(httpResponse); }