/// <summary> /// Outputs debug info when enabled /// </summary> /// <param name="req"></param> /// <param name="r"></param> /// <param name="e"></param> void CheckHttpDebug(HttpClientResponse r, HTTP_CALLBACK_ERROR e) { if (HttpDebugEnabled) { try { Debug.Console(0, this, "------ Begin HTTP Debug ---------------------------------------"); if (r != null) { Debug.Console(0, this, "HTTP Response URL: {0}", r.ResponseUrl != null ? r.ResponseUrl.ToString() : "NONE"); Debug.Console(0, this, "HTTP Response code: {0}", r.Code); Debug.Console(0, this, "HTTP Response content: \r{0}", r.ContentString); } else { Debug.Console(0, this, "No HTTP response"); } Debug.Console(0, this, "HTTP Response 'error' {0}", e); Debug.Console(0, this, "------ End HTTP Debug -----------------------------------------"); } catch (Exception ex) { Debug.Console(0, this, "HttpDebugError: {0}", ex); } } }
private void AsyncCallback(string response, HTTP_CALLBACK_ERROR err, object userObject) { var callbackObject = userObject as AsyncCallbackObject; if (callbackObject == null) { return; } try { if (Debug == 1) { CrestronConsole.PrintLine("Unity.HttpClient.AsyncCallback({0}) {1}:\r\nRequest: {2}\r\nResponse: {3}", callbackObject.Url, callbackObject.RequestType, callbackObject.Request, response); } if (err != HTTP_CALLBACK_ERROR.COMPLETED) { ErrorMessage.Error("Unity.HttpClient.AsyncCallback({0}) {2} Error1: {1}\r\nRequest: {3}\r\nResponse: {4}", callbackObject.Url, err.ToString(), callbackObject.RequestType, callbackObject.Request, response); } else if (callbackObject.Callback != null) { callbackObject.Callback(response); } } catch (Exception ex) { ErrorMessage.Error("Unity.HttpClient.AsyncCallback({0}) {2} Error2: {1}", callbackObject.Url, ex.Message, callbackObject.RequestType); } finally { try { callbackObject.HttpClient.Abort(); } finally { callbackObject.HttpClient.Dispose(); } } }
private void Callback(HttpClientResponse response, HTTP_CALLBACK_ERROR error) { try { if (error != HTTP_CALLBACK_ERROR.COMPLETED) { CloudLog.Warn("Cannot communicate with AvediaServer to discover receivers"); return; } if (response.Code != 200) { CloudLog.Error("{0} HttpResponse = {1}", GetType().Name, response.Code); return; } var data = JArray.Parse(response.ContentString); #if true Debug.WriteInfo(Debug.AnsiPurple + data.ToString(Formatting.Indented) + Debug.AnsiReset); #endif foreach ( var device in data.Where( d => d["type"].Value <string>() == "Media Player" || d["type"].Value <string>() == "Receiver") ) { if (this.Any(d => d.Id == device["id"].Value <string>())) { this[device["id"].Value <string>()].UpdateInfo(device); } else { Receiver receiver = null; try { receiver = new Receiver(_server, device); } catch (Exception e) { CloudLog.Exception(e, "Error loading receiver object from data"); } if (receiver == null) { continue; } _receivers.Add(receiver); OnReceiverDiscovered(receiver, receiver.Id, receiver.Name); } } } catch (Exception e) { CloudLog.Exception(e); } }
// *** Add a method for source logic that takes info from s+ then uses the rmssource method to get the info to pass along // Callback public void OnHTTPClientResponseCallback(HttpClientResponse userobj, HTTP_CALLBACK_ERROR error) { try { if (error != HTTP_CALLBACK_ERROR.COMPLETED) { ErrorLog.Error("HttpGetRequest OnHTTPClientResponseCallback error: " + error.ToString()); } else if (userobj.ContentString.Length > 0) { DataReceived(userobj.ContentString); } } catch (Exception e) { ErrorLog.Error("Exception HttpGetRequest OnHTTPClientResponseCallback: " + e.Message); } }
private void Response(HttpClientResponse response, HTTP_CALLBACK_ERROR error, object request) { if (error == HTTP_CALLBACK_ERROR.COMPLETED) { var responseReceived = response; if (responseReceived.ContentString.Length > 0) { if (ResponseRecived != null) { ResponseRecived(this, new GenericHttpClientEventArgs(responseReceived.ContentString, (request as HttpClientRequest).Url.ToString(), error)); } Debug.Console(2, this, "GenericHttpClient ResponseReceived"); Debug.Console(2, this, "RX:{0}", responseReceived.ContentString); Debug.Console(2, this, "TX:{0}", (request as HttpClientRequest).Url.ToString()); } } }
private void GetRequestStreamCallback(HttpClientRequest request, HTTP_CALLBACK_ERROR error, object status) { try { // End the the async request operation and return the data stream Stream requestStream = request.ThisClient.EndGetRequestStream(request, null); // If this were something other than a GET we could write to the stream here // Closing makes the request happen requestStream.Close(); // Get a handle on the response stream. request.ThisClient.BeginGetResponseStream(GetResponseStreamCallback, request, status); } catch (Exception e) { ErrorLog.Notice("Exception occured in GetSecureRequestStreamCallback(): " + e.ToString()); } }
private void Callback(HttpClientResponse response, HTTP_CALLBACK_ERROR error) { try { if (error != HTTP_CALLBACK_ERROR.COMPLETED) { CloudLog.Warn("Cannot communicate with AvediaServer to discover channels"); return; } if (response.Code != 200) { CloudLog.Error("{0} HttpResponse = {1}", GetType().Name, response.Code); return; } var channels = JToken.Parse(response.ContentString)["channel"].Select(channel => new Channel(_server, channel)) .ToList(); if (channels.Count > 0) { _channels.Clear(); foreach (var channel in channels) { _channels.Add(channel); } OnChannelsUpdated(this); } else { CloudLog.Warn( "AvediaServer returned no channels in API. Existing collection will remain to prevent loss of channel list."); } } catch (Exception e) { CloudLog.Exception(e); } }
private void Callback(HttpClientResponse response, HTTP_CALLBACK_ERROR error) { try { if (error != HTTP_CALLBACK_ERROR.COMPLETED) { CloudLog.Warn("Cannot communicate with AvediaServer to discover receivers"); return; } if (response.Code != 200) { CloudLog.Error("{0} HttpResponse = {1}", GetType().Name, response.Code); return; } var data = JToken.Parse(response.ContentString); foreach (var device in data["estate"] .Where(d => d["type"].Value <string>() == "Receiver")) { if (this.Any(d => d.Id == device["id"].Value <string>())) { this[device["id"].Value <string>()].UpdateInfo(device); } else { var receiver = new Receiver(_server, device); _receivers.Add(receiver); OnReceiverDiscovered(receiver, receiver.Id, receiver.Name); } } } catch (Exception e) { CloudLog.Exception(e); } }
/// <summary> /// /// </summary> /// <param name="asynchronousResult"></param> /// <param name="error"></param> /// <param name="status"></param> private void GetResponseStreamCallback(HttpClientRequest request, HTTP_CALLBACK_ERROR error, object status) { try { // This closes up the GetResponseStream async var response = request.ThisClient.EndGetResponseStream(request); response.DataConnection.OnBytesReceived += new EventHandler(DataConnection_OnBytesReceived); IsConnected = true; Debug.Console(1, this, "Client Disconnected"); Stream streamResponse = response.ContentStream; // Object containing various states to be passed back to async callback below RequestState asyncState = new RequestState(); asyncState.Request = request; asyncState.Response = response; asyncState.StreamResponse = streamResponse; asyncState.HttpClient = request.ThisClient; // This processes the ongoing data stream Crestron.SimplSharp.CrestronIO.IAsyncResult asyncResult = null; do { asyncResult = streamResponse.BeginRead(asyncState.BufferRead, 0, RequestState.BUFFER_SIZE, new Crestron.SimplSharp.CrestronIO.AsyncCallback(ReadCallBack), asyncState); }while (asyncResult.CompletedSynchronously && !asyncState.Done); //Console.WriteLine("\r\nExit Response Callback\r\n"); } catch (Exception e) { ErrorLog.Notice("Exception occured in GetSecureRequestStreamCallback(): " + e.ToString()); } }
public GenericHttpClientEventArgs(string response, string request, HTTP_CALLBACK_ERROR error) { ResponseText = response; RequestPath = request; Error = error; }
//-------------------------------------// // Function | HTTPClientResponseCallback // Description | ... //-------------------------------------// public static void HTTPClientResponseCallback(HttpClientResponse userobj, HTTP_CALLBACK_ERROR error) { SendStatus(userobj.Code, userobj.ContentString); CrestronConsole.PrintLine("Received {0} from InfluxDB {0}", userobj.Code, userobj.ContentString); }
void Port_LineReceived(string response, HTTP_CALLBACK_ERROR error) { }