mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-12 19:25:00 +00:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -239,6 +239,12 @@ namespace ICD.Common.Utils
|
||||
}
|
||||
return ramfree;
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public static string GetMilliseconds()
|
||||
{
|
||||
return IcdEnvironment.GetLocalTime().ToString("fff");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
38
ICD.Common.Utils/Extensions/ByteExtensions.cs
Normal file
38
ICD.Common.Utils/Extensions/ByteExtensions.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
|
||||
namespace ICD.Common.Utils.Extensions
|
||||
{
|
||||
public static class ByteExtensions
|
||||
{
|
||||
public static bool GetBit(this byte b, int n)
|
||||
{
|
||||
if (n > 7 || n < 0)
|
||||
throw new ArgumentException();
|
||||
|
||||
return (b & (1 << n)) == (1 << n);
|
||||
}
|
||||
|
||||
public static byte SetBit(this byte b, int n, bool v)
|
||||
{
|
||||
if (v)
|
||||
return SetBitOn(b, n);
|
||||
return SetBitOff(b, n);
|
||||
}
|
||||
|
||||
public static byte SetBitOn(this byte b, int n)
|
||||
{
|
||||
if (n > 7 || n < 0)
|
||||
throw new ArgumentException();
|
||||
|
||||
return (byte)(b | (1 << n));
|
||||
}
|
||||
|
||||
public static byte SetBitOff(this byte b, int n)
|
||||
{
|
||||
if (n > 7 || n < 0)
|
||||
throw new ArgumentException();
|
||||
|
||||
return (byte)(b & ~(1 << n));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,8 +122,8 @@ namespace ICD.Common.Utils.Extensions
|
||||
if (chunkSize <= 0)
|
||||
throw new InvalidOperationException("chunkSize must be greater than 0");
|
||||
|
||||
return Enumerable.Range(0, extends.Length / chunkSize)
|
||||
.Select(i => extends.Substring(i * chunkSize, chunkSize));
|
||||
return Enumerable.Range(0, (int)Math.Ceiling(extends.Length / (double)chunkSize))
|
||||
.Select(i => extends.Substring(i * chunkSize, Math.Min(chunkSize, extends.Length - (i * chunkSize))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
<Compile Include="EventArguments\UShortEventArgs.cs" />
|
||||
<Compile Include="EventArguments\XmlRecursionEventArgs.cs" />
|
||||
<None Include="ObfuscationSettings.cs" />
|
||||
<Compile Include="Extensions\ByteExtensions.cs" />
|
||||
<Compile Include="Properties\Annotations.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\Logging\ILoggerService.cs" />
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
#if SIMPLSHARP
|
||||
using Crestron.SimplSharp.CrestronIO;
|
||||
using GC = Crestron.SimplSharp.CrestronEnvironment.GC;
|
||||
#else
|
||||
using System.IO;
|
||||
using GC = System.GC;
|
||||
#endif
|
||||
|
||||
namespace ICD.Common.Utils.IO
|
||||
@@ -13,6 +15,8 @@ namespace ICD.Common.Utils.IO
|
||||
|
||||
public TextWriter WrappedTextWriter { get { return m_TextWriter; } }
|
||||
|
||||
private bool disposed = false;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
@@ -27,12 +31,25 @@ namespace ICD.Common.Utils.IO
|
||||
|
||||
~IcdTextWriter()
|
||||
{
|
||||
Dispose();
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
m_TextWriter.Dispose();
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected void Dispose(bool disposing)
|
||||
{
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
m_TextWriter.Dispose();
|
||||
}
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace ICD.Common.Utils
|
||||
throw new ArgumentNullException("bytes");
|
||||
|
||||
byte[] cast = bytes as byte[] ?? bytes.ToArray();
|
||||
return Encoding.UTF8.GetString(cast, 0, cast.Length);
|
||||
return Encoding.GetEncoding(28591).GetString(cast, 0, cast.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -153,7 +153,7 @@ namespace ICD.Common.Utils
|
||||
throw new ArgumentNullException("bytes");
|
||||
|
||||
byte[] cast = bytes as byte[] ?? bytes.ToArray();
|
||||
return Encoding.UTF8.GetString(cast, 0, length);
|
||||
return Encoding.GetEncoding(28591).GetString(cast, 0, length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -164,7 +164,7 @@ namespace ICD.Common.Utils
|
||||
[PublicAPI]
|
||||
public static byte[] ToBytes(string input)
|
||||
{
|
||||
return Encoding.UTF8.GetBytes(input);
|
||||
return Encoding.GetEncoding(28591).GetBytes(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user