mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 13:14:49 +00:00
fix: added comments to GenericRESTClient
- recommended that non-s+ users utilize system.net.http directly - added in Microsoft.Net.Http for net472 for full httpClient compatibility
This commit is contained in:
@@ -1,17 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.Net.Http;
|
using Crestron.SimplSharp.Net.Http;
|
||||||
using Crestron.SimplSharp.Net.Https;
|
using Crestron.SimplSharp.Net.Https;
|
||||||
|
|
||||||
namespace PepperDash.Core.GenericRESTfulCommunications
|
namespace PepperDash.Core.GenericRESTfulCommunications
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generic RESTful communication class
|
/// Generic RESTful communication class
|
||||||
/// </summary>
|
/// "This class should only be used in the context of simpl+ programs. In an s# pro program, please use System.Net.Http and refer to the following guidelines:https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient"
|
||||||
public class GenericRESTfulClient
|
/// </summary>
|
||||||
|
public class GenericRESTfulClient
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Boolean event handler
|
/// Boolean event handler
|
||||||
@@ -44,7 +42,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
|||||||
/// <param name="password"></param>
|
/// <param name="password"></param>
|
||||||
/// <param name="contentType"></param>
|
/// <param name="contentType"></param>
|
||||||
public void SubmitRequest(string url, ushort port, ushort requestType, string contentType, string username, string password)
|
public void SubmitRequest(string url, ushort port, ushort requestType, string contentType, string username, string password)
|
||||||
{
|
{
|
||||||
if (url.StartsWith("https:", StringComparison.OrdinalIgnoreCase))
|
if (url.StartsWith("https:", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
SubmitRequestHttps(url, port, requestType, contentType, username, password);
|
SubmitRequestHttps(url, port, requestType, contentType, username, password);
|
||||||
@@ -74,7 +72,6 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
|||||||
{
|
{
|
||||||
HttpClient client = new HttpClient();
|
HttpClient client = new HttpClient();
|
||||||
HttpClientRequest request = new HttpClientRequest();
|
HttpClientRequest request = new HttpClientRequest();
|
||||||
HttpClientResponse response;
|
|
||||||
|
|
||||||
client.KeepAlive = false;
|
client.KeepAlive = false;
|
||||||
|
|
||||||
@@ -95,16 +92,17 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
|||||||
|
|
||||||
request.Url.Parse(url);
|
request.Url.Parse(url);
|
||||||
request.RequestType = (Crestron.SimplSharp.Net.Http.RequestType)requestType;
|
request.RequestType = (Crestron.SimplSharp.Net.Http.RequestType)requestType;
|
||||||
|
|
||||||
response = client.Dispatch(request);
|
|
||||||
|
|
||||||
CrestronConsole.PrintLine(string.Format("SubmitRequestHttp Response[{0}]: {1}", response.Code, response.ContentString.ToString()));
|
using (var response = client.Dispatch(request))
|
||||||
|
{
|
||||||
|
CrestronConsole.PrintLine(string.Format("SubmitRequestHttp Response[{0}]: {1}", response.Code, response.ContentString.ToString()));
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(response.ContentString.ToString()))
|
if (!string.IsNullOrEmpty(response.ContentString.ToString()))
|
||||||
OnStringChange(response.ContentString.ToString(), 0, GenericRESTfulConstants.ResponseStringChange);
|
OnStringChange(response.ContentString.ToString(), 0, GenericRESTfulConstants.ResponseStringChange);
|
||||||
|
|
||||||
if (response.Code > 0)
|
if (response.Code > 0)
|
||||||
OnUshrtChange((ushort)response.Code, 0, GenericRESTfulConstants.ResponseCodeChange);
|
OnUshrtChange((ushort)response.Code, 0, GenericRESTfulConstants.ResponseCodeChange);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -215,12 +213,12 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
|||||||
{
|
{
|
||||||
var args = new BoolChangeEventArgs(state, type);
|
var args = new BoolChangeEventArgs(state, type);
|
||||||
args.Index = index;
|
args.Index = index;
|
||||||
BoolChange(this, args);
|
handler(this, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Protected mehtod to handle ushort change events
|
/// Protected method to handle ushort change events
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value"></param>
|
/// <param name="value"></param>
|
||||||
/// <param name="index"></param>
|
/// <param name="index"></param>
|
||||||
@@ -232,7 +230,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
|||||||
{
|
{
|
||||||
var args = new UshrtChangeEventArgs(value, type);
|
var args = new UshrtChangeEventArgs(value, type);
|
||||||
args.Index = index;
|
args.Index = index;
|
||||||
UshrtChange(this, args);
|
handler(this, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,7 +247,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
|||||||
{
|
{
|
||||||
var args = new StringChangeEventArgs(value, type);
|
var args = new StringChangeEventArgs(value, type);
|
||||||
args.Index = index;
|
args.Index = index;
|
||||||
StringChange(this, args);
|
handler(this, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,10 @@
|
|||||||
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
|
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
|
||||||
|
<PackageReference Include="Microsoft.Net.Http" Version="2.2.29" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
|
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user