Merge remote-tracking branch 'origin/development' into bugfix/ecs-1260

This commit is contained in:
Neil Dorin
2020-02-18 15:52:11 -07:00
30 changed files with 1202 additions and 1029 deletions

View File

@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Net.Http;
using PepperDash.Core;
using PepperDash.Core.DebugThings;
namespace PepperDash.Essentials.Core
{
public class GenericHttpClient : Device, IBasicCommunication
{
public HttpClient Client;
public event EventHandler<GenericHttpClientEventArgs> ResponseRecived;
public GenericHttpClient(string key, string name, string hostname)
: base(key, name)
{
Client = new HttpClient();
Client.HostName = hostname;
}
/// <summary>
///
/// </summary>
/// <param name="path"></param>
public void SendText(string path)
{
HttpClientRequest request = new HttpClientRequest();
string url = string.Format("http://{0}/{1}", Client.HostName, path);
request.Url = new UrlParser(url);
HttpClient.DISPATCHASYNC_ERROR error = Client.DispatchAsyncEx(request, Response, request);
Debug.Console(2, this, "GenericHttpClient SentRequest TX:'{0}'", url);
}
public void SendText(string format, params object[] items)
{
HttpClientRequest request = new HttpClientRequest();
string url = string.Format("http://{0}/{1}", Client.HostName, string.Format(format, items));
request.Url = new UrlParser(url);
HttpClient.DISPATCHASYNC_ERROR error = Client.DispatchAsyncEx(request, Response, request);
Debug.Console(2, this, "GenericHttpClient SentRequest TX:'{0}'", url);
}
public void SendTextNoResponse(string format, params object[] items)
{
HttpClientRequest request = new HttpClientRequest();
string url = string.Format("http://{0}/{1}", Client.HostName, string.Format(format, items));
request.Url = new UrlParser(url);
Client.Dispatch(request);
Debug.Console(2, this, "GenericHttpClient SentRequest TX:'{0}'", url);
}
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());
}
}
}
#region IBasicCommunication Members
public void SendBytes(byte[] bytes)
{
throw new NotImplementedException();
}
#endregion
#region ICommunicationReceiver Members
public event EventHandler<GenericCommMethodReceiveBytesArgs> BytesReceived;
public void Connect()
{
throw new NotImplementedException();
}
public void Disconnect()
{
throw new NotImplementedException();
}
public bool IsConnected
{
get { return true; }
}
public event EventHandler<GenericCommMethodReceiveTextArgs> TextReceived;
#endregion
}
public class GenericHttpClientEventArgs : EventArgs
{
public string ResponseText { get; private set; }
public string RequestPath { get; private set; }
public HTTP_CALLBACK_ERROR Error { get; set; }
public GenericHttpClientEventArgs(string response, string request, HTTP_CALLBACK_ERROR error)
{
ResponseText = response;
RequestPath = request;
Error = error;
}
}
}

View File

@@ -31,7 +31,9 @@ namespace PepperDash.Essentials.Core
}
}
/// <summary>
/// Base class for join maps
/// </summary>
public abstract class JoinMapBase
{
/// <summary>

View File

@@ -113,6 +113,7 @@
<ItemGroup>
<Compile Include="Config\Comm and IR\CecPortController.cs" />
<Compile Include="Config\Comm and IR\GenericComm.cs" />
<Compile Include="Config\Comm and IR\GenericHttpClient.cs" />
<Compile Include="Config\Essentials\ConfigUpdater.cs" />
<Compile Include="Config\Essentials\ConfigReader.cs" />
<Compile Include="Config\Essentials\ConfigWriter.cs" />

View File

@@ -0,0 +1,11 @@
using PepperDash.Core;
using PepperDash.Essentials.Core.Config;
namespace PepperDash.Essentials.Core.Plugins
{
public interface IPluginDeviceConfig
{
string MinimumEssentialsFrameworkVersion { get; }
IKeyed BuildDevice(DeviceConfig dc);
}
}

View File

@@ -0,0 +1,19 @@
using System;
namespace PepperDash.Essentials.Core.Plugins
{
[AttributeUsage(AttributeTargets.Class)]
public sealed class PluginEntryPointAttribute : Attribute
{
private readonly string _uniqueKey;
public string UniqueKey {
get { return _uniqueKey; }
}
public PluginEntryPointAttribute(string key)
{
_uniqueKey = key;
}
}
}

View File

@@ -3,5 +3,5 @@
[assembly: AssemblyTitle("PepperDashEssentialsBase")]
[assembly: AssemblyCompany("PepperDash Technology Corp")]
[assembly: AssemblyProduct("PepperDashEssentialsBase")]
[assembly: AssemblyCopyright("Copyright © Ppperdash 2019")]
[assembly: AssemblyCopyright("Copyright © Pepperdash 2019")]
[assembly: AssemblyVersion("1.4.0.*")]