mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-18 22:24:48 +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,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.Net.Http;
|
||||
using Crestron.SimplSharp.Net.Https;
|
||||
@@ -10,6 +7,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic RESTful communication class
|
||||
/// "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"
|
||||
/// </summary>
|
||||
public class GenericRESTfulClient
|
||||
{
|
||||
@@ -74,7 +72,6 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
{
|
||||
HttpClient client = new HttpClient();
|
||||
HttpClientRequest request = new HttpClientRequest();
|
||||
HttpClientResponse response;
|
||||
|
||||
client.KeepAlive = false;
|
||||
|
||||
@@ -96,8 +93,8 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
request.Url.Parse(url);
|
||||
request.RequestType = (Crestron.SimplSharp.Net.Http.RequestType)requestType;
|
||||
|
||||
response = client.Dispatch(request);
|
||||
|
||||
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()))
|
||||
@@ -105,6 +102,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
|
||||
if (response.Code > 0)
|
||||
OnUshrtChange((ushort)response.Code, 0, GenericRESTfulConstants.ResponseCodeChange);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -215,12 +213,12 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
{
|
||||
var args = new BoolChangeEventArgs(state, type);
|
||||
args.Index = index;
|
||||
BoolChange(this, args);
|
||||
handler(this, args);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Protected mehtod to handle ushort change events
|
||||
/// Protected method to handle ushort change events
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="index"></param>
|
||||
@@ -232,7 +230,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
{
|
||||
var args = new UshrtChangeEventArgs(value, type);
|
||||
args.Index = index;
|
||||
UshrtChange(this, args);
|
||||
handler(this, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +247,7 @@ namespace PepperDash.Core.GenericRESTfulCommunications
|
||||
{
|
||||
var args = new StringChangeEventArgs(value, type);
|
||||
args.Index = index;
|
||||
StringChange(this, args);
|
||||
handler(this, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,10 @@
|
||||
<PackageReference Include="WebSocketSharp" Version="1.0.3-rc11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
|
||||
<PackageReference Include="Microsoft.Net.Http" Version="2.2.29" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user