Removing Utils directory to better match namespaces

This commit is contained in:
Chris Cameron
2017-07-06 10:57:04 -04:00
parent c56d9fce3b
commit ac6ca84a8a
68 changed files with 65 additions and 65 deletions

View File

@@ -0,0 +1,69 @@
using System;
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
namespace ICD.Common.Utils.IO
{
public static class IcdDirectory
{
public static string GetApplicationDirectory()
{
#if SIMPLSHARP
return Directory.GetApplicationDirectory();
#else
return Directory.GetCurrentDirectory();
#endif
}
public static bool Exists(string path)
{
if (path == null)
throw new ArgumentNullException("path");
return Directory.Exists(path);
}
public static string[] GetFiles(string path)
{
if (path == null)
throw new ArgumentNullException("path");
return Directory.GetFiles(path);
}
public static string[] GetDirectories(string path)
{
if (path == null)
throw new ArgumentNullException("path");
return Directory.GetDirectories(path);
}
public static void Delete(string path, bool recursive)
{
if (path == null)
throw new ArgumentNullException("path");
Directory.Delete(path, recursive);
}
public static void CreateDirectory(string path)
{
if (path == null)
throw new ArgumentNullException("path");
Directory.CreateDirectory(path);
}
public static string GetDirectoryRoot(string path)
{
if (path == null)
throw new ArgumentNullException("path");
return Directory.GetDirectoryRoot(path);
}
}
}

View File

@@ -0,0 +1,39 @@
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
using System;
using System.Text;
namespace ICD.Common.Utils.IO
{
public sealed class IcdEncodingStringWriter : IcdStringWriter
{
public IcdEncodingStringWriter(StringBuilder output, Encoding encoding)
: base(new EncodingStringWriter(output, encoding))
{
}
private sealed class EncodingStringWriter : StringWriter
{
private readonly Encoding m_Encoding;
public override Encoding Encoding { get { return m_Encoding; } }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="builder"></param>
/// <param name="encoding"></param>
public EncodingStringWriter(StringBuilder builder, Encoding encoding)
: base(builder)
{
if (encoding == null)
throw new ArgumentNullException("encoding");
m_Encoding = encoding;
}
}
}
}

View File

@@ -0,0 +1,60 @@
using ICD.Common.Properties;
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
using System;
using System.Text;
namespace ICD.Common.Utils.IO
{
public static class IcdFile
{
[PublicAPI]
public static string ReadToEnd(string path, Encoding encoding)
{
if (path == null)
throw new ArgumentNullException("path");
if (encoding == null)
throw new ArgumentNullException("encoding");
#if SIMPLSHARP
return File.ReadToEnd(path, encoding);
#else
return File.ReadAllText(path, encoding);
#endif
}
[PublicAPI]
public static bool Exists(string path)
{
if (path == null)
throw new ArgumentNullException("path");
return File.Exists(path);
}
[PublicAPI]
public static void Copy(string pathFrom, string pathTo)
{
if (pathFrom == null)
throw new ArgumentNullException("pathFrom");
if (pathTo == null)
throw new ArgumentNullException("pathTo");
File.Copy(pathFrom, pathTo);
}
[PublicAPI]
public static void Delete(string path)
{
if (path == null)
throw new ArgumentNullException("path");
File.Delete(path);
}
}
}

View File

@@ -0,0 +1,47 @@
using System;
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
namespace ICD.Common.Utils.IO
{
public sealed class IcdFileStream : IcdStream
{
public int Position { get; set; }
public FileStream WrappedFileStream { get { return WrappedStream as FileStream; } }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="fileStrean"></param>
public IcdFileStream(FileStream fileStrean)
: base(fileStrean)
{
}
public static IcdFileStream OpenWrite(string path)
{
if (path == null)
throw new ArgumentNullException("path");
return new IcdFileStream(File.OpenWrite(path));
}
public void Flush()
{
WrappedFileStream.Flush();
}
public void Close()
{
#if SIMPLSHARP
WrappedFileStream.Close();
#else
WrappedFileStream.Dispose();
#endif
}
}
}

View File

@@ -0,0 +1,47 @@
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
namespace ICD.Common.Utils.IO
{
public sealed class IcdMemoryStream : IcdStream
{
public int Position { get; set; }
public MemoryStream WrappedMemoryStream { get { return WrappedStream as MemoryStream; } }
/// <summary>
/// Constructor.
/// </summary>
public IcdMemoryStream()
: this(new MemoryStream())
{
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="memoryStream"></param>
public IcdMemoryStream(MemoryStream memoryStream)
: base(memoryStream)
{
}
public void Flush()
{
WrappedMemoryStream.Flush();
}
public void Close()
{
#if SIMPLSHARP
WrappedMemoryStream.Close();
#else
WrappedMemoryStream.Dispose();
#endif
}
}
}

View File

@@ -0,0 +1,66 @@
using System;
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
namespace ICD.Common.Utils.IO
{
public static class IcdPath
{
public static string GetFileName(string path)
{
if (path == null)
throw new ArgumentNullException("path");
return Path.GetFileName(path);
}
public static string GetFileNameWithoutExtension(string path)
{
if (path == null)
throw new ArgumentNullException("path");
return Path.GetFileNameWithoutExtension(path);
}
public static string GetDirectoryName(string path)
{
if (path == null)
throw new ArgumentNullException("path");
return Path.GetDirectoryName(path);
}
public static string GetExtension(string path)
{
if (path == null)
throw new ArgumentNullException("path");
return Path.GetExtension(path);
}
public static string Combine(string a, string b)
{
if (a == null)
throw new ArgumentNullException("a");
if (b == null)
throw new ArgumentNullException("b");
return Path.Combine(a, b);
}
public static string ChangeExtension(string path, string ext)
{
if (path == null)
throw new ArgumentNullException("path");
if (ext == null)
throw new ArgumentNullException("ext");
return Path.ChangeExtension(path, ext);
}
}
}

View File

@@ -0,0 +1,33 @@
using System;
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
namespace ICD.Common.Utils.IO
{
public class IcdStream : IDisposable
{
private readonly Stream m_Stream;
public Stream WrappedStream { get { return m_Stream; } }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="stream"></param>
public IcdStream(Stream stream)
{
if (stream == null)
throw new ArgumentNullException("stream");
m_Stream = stream;
}
public void Dispose()
{
m_Stream.Dispose();
}
}
}

View File

@@ -0,0 +1,41 @@
using System;
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#elif STANDARD
using System.IO;
#endif
namespace ICD.Common.Utils.IO
{
public sealed class IcdStreamReader : IDisposable
{
private readonly StreamReader m_StreamReader;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="memoryStream"></param>
public IcdStreamReader(IcdMemoryStream memoryStream)
{
if (memoryStream == null)
throw new ArgumentNullException("memoryStream");
m_StreamReader = new StreamReader(memoryStream.WrappedMemoryStream);
}
~IcdStreamReader()
{
Dispose();
}
public string ReadToEnd()
{
return m_StreamReader.ReadToEnd();
}
public void Dispose()
{
m_StreamReader.Dispose();
}
}
}

View File

@@ -0,0 +1,24 @@
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
namespace ICD.Common.Utils.IO
{
public sealed class IcdStringReader : IcdTextReader
{
public StringReader WrappedStringReader { get { return WrappedTextReader as StringReader; } }
public IcdStringReader(string value)
: this(new StringReader(value))
{
}
private IcdStringReader(StringReader stringReader)
: base(stringReader)
{
}
}
}

View File

@@ -0,0 +1,32 @@
using System.Text;
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
namespace ICD.Common.Utils.IO
{
public class IcdStringWriter : IcdTextWriter
{
public StringWriter WrappedStringWriter { get { return WrappedTextWriter as StringWriter; } }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="stringWriter"></param>
public IcdStringWriter(StringWriter stringWriter)
: base(stringWriter)
{
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="stringBuilder"></param>
public IcdStringWriter(StringBuilder stringBuilder)
: this(new StringWriter(stringBuilder))
{
}
}
}

View File

@@ -0,0 +1,21 @@
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
namespace ICD.Common.Utils.IO
{
public class IcdTextReader
{
private readonly TextReader m_TextReader;
public TextReader WrappedTextReader { get { return m_TextReader; } }
protected IcdTextReader(TextReader textReader)
{
m_TextReader = textReader;
}
}
}

View File

@@ -0,0 +1,38 @@
using System;
#if SIMPLSHARP
using Crestron.SimplSharp.CrestronIO;
#else
using System.IO;
#endif
namespace ICD.Common.Utils.IO
{
public class IcdTextWriter : IDisposable
{
private readonly TextWriter m_TextWriter;
public TextWriter WrappedTextWriter { get { return m_TextWriter; } }
/// <summary>
/// Constructor.
/// </summary>
/// <param name="textWriter"></param>
protected IcdTextWriter(TextWriter textWriter)
{
if (textWriter == null)
throw new ArgumentNullException("textWriter");
m_TextWriter = textWriter;
}
~IcdTextWriter()
{
Dispose();
}
public void Dispose()
{
m_TextWriter.Dispose();
}
}
}