Skip to content

Commit

Permalink
Update to allow "root" Http configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed May 30, 2023
1 parent cb7a425 commit 02dbbc4
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public abstract class MTConnectAgentApplication : IMTConnectAgentApplication

protected Type ConfigurationType { get; set; }


public IMTConnectAgentBroker Agent => _mtconnectAgent;

public EventHandler<AgentConfiguration> OnRestart { get; set; }
Expand Down
27 changes: 22 additions & 5 deletions src/MTConnect.NET-HTTP/Configurations/HttpAgentConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// TrakHound Inc. licenses this file to you under the MIT license.

using MTConnect.Http;
using MTConnect.Tls;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using YamlDotNet.Serialization;
Expand All @@ -17,10 +18,6 @@ public class HttpAgentConfiguration : AgentConfiguration, IHttpAgentConfiguratio
public IEnumerable<HttpServerConfiguration> Http { get; set; }






/// <summary>
/// The port number the agent binds to for requests.
/// </summary>
Expand All @@ -33,6 +30,9 @@ public class HttpAgentConfiguration : AgentConfiguration, IHttpAgentConfiguratio
[JsonPropertyName("server")]
public string Server { get; set; }

[JsonPropertyName("tls")]
public TlsConfiguration Tls { get; set; }

/// <summary>
/// Gets or Sets the List of Encodings (ex. gzip, br, deflate) to pass to the Accept-Encoding HTTP Header
/// </summary>
Expand All @@ -56,6 +56,22 @@ public IEnumerable<HttpResponseCompression> ResponseCompression
}
return null;
}
set
{
if (!value.IsNullOrEmpty())
{
var strValues = new List<string>();
foreach (var val in value)
{
strValues.Add(val.ToString());
}
ResponseCompressionString = strValues;
}
else
{
ResponseCompressionString = null;
}
}
}

[JsonPropertyName("responseCompression")]
Expand Down Expand Up @@ -110,7 +126,8 @@ public IEnumerable<HttpResponseCompression> ResponseCompression

public HttpAgentConfiguration()
{
Server = "127.0.0.1";
Server = null;
//Server = "127.0.0.1";
Port = 5000;
AllowPut = false;
AllowPutFrom = null;
Expand Down
33 changes: 17 additions & 16 deletions src/MTConnect.NET-HTTP/Configurations/HttpServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace MTConnect.Configurations
{
public class HttpServerConfiguration
public class HttpServerConfiguration : IHttpServerConfiguration
{
/// <summary>
/// The port number the agent binds to for requests.
Expand All @@ -23,21 +23,6 @@ public class HttpServerConfiguration
[JsonPropertyName("tls")]
public TlsConfiguration Tls { get; set; }

//[JsonPropertyName("useTls")]
//public bool UseTls { get; set; }

//[JsonPropertyName("tlsCertificateChain")]
//public string TlsCertificateChain { get; set; }

//[JsonPropertyName("tlsPrivateKey")]
//public string TlsPrivateKey { get; set; }

//[JsonPropertyName("tlsCertificatePassword")]
//public string TlsCertificatePassword { get; set; }

//[JsonPropertyName("tlsVerifyClientCertificate")]
//public string TlsVerifyClientCertificate { get; set; }

/// <summary>
/// Gets or Sets the List of Encodings (ex. gzip, br, deflate) to pass to the Accept-Encoding HTTP Header
/// </summary>
Expand All @@ -61,6 +46,22 @@ public IEnumerable<HttpResponseCompression> ResponseCompression
}
return null;
}
set
{
if (!value.IsNullOrEmpty())
{
var strValues = new List<string>();
foreach (var val in value)
{
strValues.Add(val.ToString());
}
ResponseCompressionString = strValues;
}
else
{
ResponseCompressionString = null;
}
}
}

[JsonPropertyName("responseCompression")]
Expand Down
58 changes: 1 addition & 57 deletions src/MTConnect.NET-HTTP/Configurations/IHttpAgentConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,15 @@
// Copyright (c) 2023 TrakHound Inc., All Rights Reserved.
// TrakHound Inc. licenses this file to you under the MIT license.

using MTConnect.Http;
using System.Collections.Generic;

namespace MTConnect.Configurations
{
/// <summary>
/// Configuration for an MTConnect Http Agent
/// </summary>
public interface IHttpAgentConfiguration : IAgentConfiguration
public interface IHttpAgentConfiguration : IAgentConfiguration, IHttpServerConfiguration
{
IEnumerable<HttpServerConfiguration> Http { get; }


/// <summary>
/// The port number the agent binds to for requests.
/// </summary>
int Port { get; }

/// <summary>
/// The server Hostname to bind to. Change this to the server's IP Address or hostname
/// </summary>
string Server { get; }


/// <summary>
/// Gets or Sets the List of Encodings (ex. gzip, br, deflate) to pass to the Accept-Encoding HTTP Header
/// </summary>
IEnumerable<HttpResponseCompression> ResponseCompression { get; }

/// <summary>
/// Allow HTTP PUT or POST of data item values or assets.
/// </summary>
bool AllowPut { get; }

/// <summary>
/// Allow HTTP PUT or POST from a specific host or list of hosts.
/// Lists are comma (,) separated and the host names will be validated by translating them into IP addresses.
/// </summary>
IEnumerable<string> AllowPutFrom { get; }

/// <summary>
/// The maximum number of Threads to use for the Http Stream Requests
/// </summary>
int MaxStreamingThreads { get; }


/// <summary>
/// Gets or Sets the default response document indendation
/// </summary>
bool IndentOutput { get; }

/// <summary>
/// Gets or Sets the default response document comments output. Comments contain descriptions from the MTConnect standard
/// </summary>
bool OutputComments { get; }

/// <summary>
/// Gets or Sets the default response document validation level. 0 = Ignore, 1 = Warning, 2 = Strict
/// </summary>
OutputValidationLevel OutputValidationLevel { get; }


/// <summary>
/// Gets or Sets the configuration for Static Files that can be served from the Http Server
/// </summary>
IEnumerable<FileConfiguration> Files { get; }
}
}
64 changes: 64 additions & 0 deletions src/MTConnect.NET-HTTP/Configurations/IHttpServerConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using MTConnect.Http;
using MTConnect.Tls;
using System.Collections.Generic;

namespace MTConnect.Configurations
{
public interface IHttpServerConfiguration
{
/// <summary>
/// The port number the agent binds to for requests.
/// </summary>
int Port { get; set; }

/// <summary>
/// The server Hostname to bind to. Change this to the server's IP Address or hostname
/// </summary>
string Server { get; set; }

TlsConfiguration Tls { get; set; }

/// <summary>
/// Gets or Sets the List of Encodings (ex. gzip, br, deflate) to pass to the Accept-Encoding HTTP Header
/// </summary>
IEnumerable<HttpResponseCompression> ResponseCompression { get; set; }

/// <summary>
/// Allow HTTP PUT or POST of data item values or assets.
/// </summary>
bool AllowPut { get; set; }

/// <summary>
/// Allow HTTP PUT or POST from a specific host or list of hosts.
/// </summary>
IEnumerable<string> AllowPutFrom { get; set; }

/// <summary>
/// The maximum number of Threads to use for the Http Stream Requests
/// </summary>
int MaxStreamingThreads { get; set; }


/// <summary>
/// Gets or Sets the default response document indendation
/// </summary>
bool IndentOutput { get; set; }

/// <summary>
/// Gets or Sets the default response document comments output. Comments contain descriptions from the MTConnect standard
/// </summary>
bool OutputComments { get; set; }


/// <summary>
/// Gets or Sets the default response document validation level. 0 = Ignore, 1 = Warning, 2 = Strict
/// </summary>
OutputValidationLevel OutputValidationLevel { get; set; }


/// <summary>
/// Gets or Sets the configuration for Static Files that can be served from the Http Server
/// </summary>
IEnumerable<FileConfiguration> Files { get; set; }
}
}
22 changes: 18 additions & 4 deletions src/MTConnect.NET-HTTP/Servers/MTConnectHttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,25 @@ public void Start()
{
_stop = new CancellationTokenSource();

if (_configuration != null && !_configuration.Http.IsNullOrEmpty())
if (_configuration != null)
{
foreach (var httpServer in _configuration.Http)
var httpServerConfigurations = new List<IHttpServerConfiguration>();

if (!_configuration.Http.IsNullOrEmpty())
{
httpServerConfigurations.AddRange(_configuration.Http);
}
else
{
httpServerConfigurations.Add(_configuration);
}

if (!httpServerConfigurations.IsNullOrEmpty())
{
_ = Task.Run(() => StartServer(httpServer, _stop.Token));
foreach (var httpServer in httpServerConfigurations)
{
_ = Task.Run(() => StartServer(httpServer, _stop.Token));
}
}
}
}
Expand All @@ -125,7 +139,7 @@ public void Stop()
public void Dispose() { Stop(); }


private async Task StartServer(HttpServerConfiguration serverConfiguration, CancellationToken cancellationToken)
private async Task StartServer(IHttpServerConfiguration serverConfiguration, CancellationToken cancellationToken)
{
if (serverConfiguration != null)
{
Expand Down
11 changes: 10 additions & 1 deletion src/MTConnect.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MTConnect-Agent-MQTT-Broker
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MTConnect-Agent-MQTT-Relay-Gateway", "..\applications\Agents\MTConnect-Agent-MQTT-Relay-Gateway\MTConnect-Agent-MQTT-Relay-Gateway.csproj", "{61CB960E-761A-4F89-A365-E9394AD3FA30}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MTConnect.NET-TLS", "MTConnect.NET-TLS\MTConnect.NET-TLS.csproj", "{82B8CF89-A378-47FF-B0DE-EE5F020D9586}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MTConnect.NET-TLS", "MTConnect.NET-TLS\MTConnect.NET-TLS.csproj", "{82B8CF89-A378-47FF-B0DE-EE5F020D9586}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MTConnect-Agent", "..\applications\Agents\MTConnect-Agent\MTConnect-Agent.csproj", "{45DD20AA-AB6E-4F48-95F1-56424ABAB69F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -313,6 +315,12 @@ Global
{82B8CF89-A378-47FF-B0DE-EE5F020D9586}.Package|Any CPU.Build.0 = Debug|Any CPU
{82B8CF89-A378-47FF-B0DE-EE5F020D9586}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82B8CF89-A378-47FF-B0DE-EE5F020D9586}.Release|Any CPU.Build.0 = Release|Any CPU
{45DD20AA-AB6E-4F48-95F1-56424ABAB69F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45DD20AA-AB6E-4F48-95F1-56424ABAB69F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45DD20AA-AB6E-4F48-95F1-56424ABAB69F}.Package|Any CPU.ActiveCfg = Debug|Any CPU
{45DD20AA-AB6E-4F48-95F1-56424ABAB69F}.Package|Any CPU.Build.0 = Debug|Any CPU
{45DD20AA-AB6E-4F48-95F1-56424ABAB69F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45DD20AA-AB6E-4F48-95F1-56424ABAB69F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -351,6 +359,7 @@ Global
{44BAF649-0F9F-446A-B1A4-6F2DCF91C968} = {6C3F47E0-BC95-48CB-93A4-C34A0D5CA43B}
{61CB960E-761A-4F89-A365-E9394AD3FA30} = {6C3F47E0-BC95-48CB-93A4-C34A0D5CA43B}
{82B8CF89-A378-47FF-B0DE-EE5F020D9586} = {E0233BEB-F66C-43C4-9DC8-20182894CF5F}
{45DD20AA-AB6E-4F48-95F1-56424ABAB69F} = {6C3F47E0-BC95-48CB-93A4-C34A0D5CA43B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CC13D3AD-18BF-4695-AB2A-087EF0885B20}
Expand Down

0 comments on commit 02dbbc4

Please sign in to comment.