Skip to content

Commit

Permalink
Merge branch 'master' into v6-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed May 20, 2023
2 parents 6a2314e + 4c20509 commit d9353c9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ protected override async void OnStartAgentAfterLoad(IEnumerable<DeviceConfigurat
clientConfiguration.PemPrivateKey = _configuration.PemPrivateKey;
clientConfiguration.UseTls = _configuration.UseTls;
clientConfiguration.AllowUntrustedCertificates = _configuration.AllowUntrustedCertificates;
clientConfiguration.TopicPrefix = _configuration.TopicPrefix;


// Set Observation Intervals
Expand Down
43 changes: 35 additions & 8 deletions src/MTConnect.NET-Common/Extensions/StringFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,38 @@ namespace MTConnect
{
public static class StringFunctions
{
private static readonly Random _random = new Random();
private static readonly Encoding _utf8 = Encoding.UTF8;
private static MD5 _md5 = MD5.Create();

[ThreadStatic]
private static MD5 _md5;

[ThreadStatic]
private static Random _random;

private static MD5 MD5Algorithm
{
get
{
if (_md5 == null)
{
_md5 = MD5.Create();
}
return _md5;
}
}

private static Random Random
{
get
{
if (_random == null)
{
_random = new Random();
}

return _random;
}
}

public static string ToPascalCase(this string s)
{
Expand Down Expand Up @@ -237,7 +265,7 @@ public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[_random.Next(s.Length)]).ToArray());
.Select(s => s[Random.Next(s.Length)]).ToArray());
}

public static DateTime ToDateTime(this string s)
Expand All @@ -254,8 +282,7 @@ public static string ToMD5Hash(this string s)
{
try
{
if (_md5 == null) _md5 = MD5.Create();
var hash = _md5.ComputeHash(_utf8.GetBytes(s));
var hash = MD5Algorithm.ComputeHash(_utf8.GetBytes(s));
return string.Concat(hash.Select(b => b.ToString("x2")));
}
catch { }
Expand All @@ -269,7 +296,7 @@ public static string ToMD5Hash(this byte[] bytes)
{
try
{
var hash = _md5.ComputeHash(bytes);
var hash = MD5Algorithm.ComputeHash(bytes);
return string.Concat(hash.Select(b => b.ToString("x2")));
}
catch { }
Expand All @@ -296,7 +323,7 @@ public static byte[] ToMD5HashBytes(this string s)
{
try
{
return _md5.ComputeHash(_utf8.GetBytes(s));
return MD5Algorithm.ComputeHash(_utf8.GetBytes(s));
}
catch { }

Expand All @@ -309,7 +336,7 @@ public static byte[] ToMD5HashBytes(this byte[] bytes)
{
try
{
return _md5.ComputeHash(bytes);
return MD5Algorithm.ComputeHash(bytes);
}
catch { }
}
Expand Down
2 changes: 1 addition & 1 deletion src/MTConnect.NET-MQTT/MTConnectMqttRelay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class MTConnectMqttRelay : IDisposable

public MTConnectMqttFormat Format { get; set; }

public string TopicPrefix { get; set; }
public string TopicPrefix => _configuration.TopicPrefix;

public bool RetainMessages { get; set; }

Expand Down

0 comments on commit d9353c9

Please sign in to comment.