Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Chris Cameron
2017-07-18 12:46:48 -04:00
6 changed files with 69 additions and 7 deletions

View File

@@ -239,6 +239,12 @@ namespace ICD.Common.Utils
} }
return ramfree; return ramfree;
} }
[PublicAPI]
public static string GetMilliseconds()
{
return IcdEnvironment.GetLocalTime().ToString("fff");
}
} }
} }

View 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));
}
}
}

View File

@@ -122,8 +122,8 @@ namespace ICD.Common.Utils.Extensions
if (chunkSize <= 0) if (chunkSize <= 0)
throw new InvalidOperationException("chunkSize must be greater than 0"); throw new InvalidOperationException("chunkSize must be greater than 0");
return Enumerable.Range(0, extends.Length / chunkSize) return Enumerable.Range(0, (int)Math.Ceiling(extends.Length / (double)chunkSize))
.Select(i => extends.Substring(i * chunkSize, chunkSize)); .Select(i => extends.Substring(i * chunkSize, Math.Min(chunkSize, extends.Length - (i * chunkSize))));
} }
/// <summary> /// <summary>

View File

@@ -84,6 +84,7 @@
<Compile Include="EventArguments\UShortEventArgs.cs" /> <Compile Include="EventArguments\UShortEventArgs.cs" />
<Compile Include="EventArguments\XmlRecursionEventArgs.cs" /> <Compile Include="EventArguments\XmlRecursionEventArgs.cs" />
<None Include="ObfuscationSettings.cs" /> <None Include="ObfuscationSettings.cs" />
<Compile Include="Extensions\ByteExtensions.cs" />
<Compile Include="Properties\Annotations.cs" /> <Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\Logging\ILoggerService.cs" /> <Compile Include="Services\Logging\ILoggerService.cs" />

View File

@@ -1,8 +1,10 @@
using System; using System;
#if SIMPLSHARP #if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
using GC = Crestron.SimplSharp.CrestronEnvironment.GC;
#else #else
using System.IO; using System.IO;
using GC = System.GC;
#endif #endif
namespace ICD.Common.Utils.IO namespace ICD.Common.Utils.IO
@@ -13,6 +15,8 @@ namespace ICD.Common.Utils.IO
public TextWriter WrappedTextWriter { get { return m_TextWriter; } } public TextWriter WrappedTextWriter { get { return m_TextWriter; } }
private bool disposed = false;
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
@@ -27,12 +31,25 @@ namespace ICD.Common.Utils.IO
~IcdTextWriter() ~IcdTextWriter()
{ {
Dispose(); Dispose(false);
} }
public void Dispose() 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;
} }
} }
} }

View File

@@ -137,7 +137,7 @@ namespace ICD.Common.Utils
throw new ArgumentNullException("bytes"); throw new ArgumentNullException("bytes");
byte[] cast = bytes as byte[] ?? bytes.ToArray(); 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> /// <summary>
@@ -153,7 +153,7 @@ namespace ICD.Common.Utils
throw new ArgumentNullException("bytes"); throw new ArgumentNullException("bytes");
byte[] cast = bytes as byte[] ?? bytes.ToArray(); byte[] cast = bytes as byte[] ?? bytes.ToArray();
return Encoding.UTF8.GetString(cast, 0, length); return Encoding.GetEncoding(28591).GetString(cast, 0, length);
} }
/// <summary> /// <summary>
@@ -164,7 +164,7 @@ namespace ICD.Common.Utils
[PublicAPI] [PublicAPI]
public static byte[] ToBytes(string input) public static byte[] ToBytes(string input)
{ {
return Encoding.UTF8.GetBytes(input); return Encoding.GetEncoding(28591).GetBytes(input);
} }
/// <summary> /// <summary>