Testing Cotija comms

This commit is contained in:
Neil Dorin
2017-05-25 14:26:30 -07:00
parent 86c54ca9e6
commit a2fb565524
7 changed files with 72 additions and 17 deletions

View File

@@ -48,8 +48,8 @@ namespace PepperDash.Essentials
/// </summary>
public void GoWithLoad()
{
var thread = new Thread(o =>
{
// var thread = new Thread(o =>
// {
try
{
CrestronConsole.AddNewConsoleCommand(EnablePortalSync, "portalsync", "Loads Portal Sync",
@@ -58,9 +58,9 @@ namespace PepperDash.Essentials
//PortalSync = new PepperDashPortalSyncClient();
//Temp Cotija testing
//CotijaInterfaceController CotijaInterface = new CotijaInterfaceController("WebClient1");
CotijaInterfaceController CotijaInterface = new CotijaInterfaceController("WebClient1");
//CotijaInterface.InitializeClient("http://192.168.1.105");
//CotijaInterface.InitializeClientAndEventStream("http://localhost:3000/api/system/stream/abcdefgh");
Debug.Console(0, "Starting Essentials load from configuration");
ConfigReader.LoadConfig2();
@@ -77,8 +77,8 @@ namespace PepperDash.Essentials
{
Debug.Console(0, "FATAL INITIALIZE ERROR. System is in an inconsistent state:\r{0}", e);
}
return null;
}, null);
// return null;
// }, null);
}
public void EnablePortalSync(string s)

View File

@@ -78,6 +78,7 @@ namespace PepperDash.Essentials.Fusion
public EssentialsHuddleSpaceFusionSystemController(EssentialsHuddleSpaceRoom room, uint ipId)
: base(room.Key + "-fusion")
{
Room = room;
IpId = ipId;

View File

@@ -14,23 +14,77 @@ namespace PepperDash.Essentials
{
public class CotijaInterfaceController : Device
{
StreamReader Reader;
Crestron.SimplSharp.Net.Connection Connection;
public CotijaInterfaceController(string key) : base(key)
{
CrestronConsole.AddNewConsoleCommand(InitializeClient, "InitializeHttpClient", "Initializes a new HTTP client connection to a specified URL", ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(InitializeClientAndEventStream, "InitializeHttpClient", "Initializes a new HTTP client connection to a specified URL", ConsoleAccessLevelEnum.AccessOperator);
}
public void InitializeClient(string url)
public void InitializeClientAndEventStream(string url)
{
HttpClient webClient = new HttpClient();
webClient.Verbose = true;
HttpClientRequest request = new HttpClientRequest();
request.Url.Parse(url);
request.Header.AddHeader(new HttpHeader("accept", "text/event-stream"));
request.Header.SetHeaderValue("Expect", "");
webClient.DispatchAsync(request, (resp, err) =>
try
{
CrestronConsole.PrintLine(resp.ContentString);
});
HttpClient webClient = new HttpClient();
webClient.Verbose = true;
HttpClientRequest request = new HttpClientRequest();
request.Url = new UrlParser(url);
request.Header.AddHeader(new HttpHeader("Accept", "text/event-stream"));
request.KeepAlive = true;
/// Experimenting with grabbing connection before the request
Connection = webClient.ConnectNew("192.168.1.120", 3000);
Debug.Console(1, this, "Connection Port: {0}", Connection.LocalEndPointPort);
Reader = new StreamReader(Connection);
Connection.OnBytesReceived += new EventHandler(DataConnection_OnBytesReceived);
/// Not sure if this is starting a new connection
webClient.DispatchAsync(request, StreamConnectionCallback);
}
catch (Exception e)
{
Debug.Console(1, this, "Error Initializing Cotija client:\n{0}", e);
}
}
// This callback happens but none of the events would fire (when not commented out)
void StreamConnectionCallback(HttpClientResponse resp, HTTP_CALLBACK_ERROR err)
{
Debug.Console(1, this, "Connection Port: {0}", resp.DataConnection.LocalEndPointPort);
Debug.Console(1, this, "Connections are equal {0}", resp.DataConnection == Connection);
Debug.Console(1, this, "Callback Fired");
//resp.DataConnection.OnBytesReceived += new EventHandler(DataConnection_OnBytesReceived);
//Debug.Console(1, this, "Received: '{0}'", resp.ContentString);
//resp.OnTransferEnd += new Crestron.SimplSharp.Net.TransferEndEventHandler(resp_OnTransferEnd);
//resp.OnTransferProgress += new Crestron.SimplSharp.Net.TransferProgressEventHandler(resp_OnTransferProgress);
//resp.OnTransferStart += new Crestron.SimplSharp.Net.TransferStartEventHandler(resp_OnTransferStart);
}
// We could never get this event handler to fire
void DataConnection_OnBytesReceived(object sender, EventArgs e)
{
Debug.Console(1, this, "OnBytesReceived Event Fired.");
Debug.Console(1, this, "Event: Received: '{0}'", Reader.ReadToEnd());
}
//void resp_OnTransferStart(object sender, Crestron.SimplSharp.Net.TransferStartEventArgs e)
//{
// Debug.Console(1, this, "OnTransferStart");
//}
//void resp_OnTransferProgress(object sender, Crestron.SimplSharp.Net.TransferProgressEventArgs e)
//{
// Debug.Console(1, this, "OnTransferProgress");
//}
//void resp_OnTransferEnd(object sender, Crestron.SimplSharp.Net.TransferEndEventArgs e)
//{
// Debug.Console(1, this, "OnTransferEnd");
//}
}
}