Files
ICD.Common.Utils/ICD.Common/Utils/IcdConsole.cs
2017-06-21 22:41:54 -04:00

109 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#if SIMPLSHARP
using Crestron.SimplSharp;
#endif
using ICD.Common.Properties;
namespace ICD.Common.Utils
{
public sealed class IcdConsole
{
public enum eAccessLevel
{
Operator = 0,
Programmer = 1,
Administrator = 2
}
/// <summary>
/// Wraps CrestronConsole.ConsoleCommandResponse for S+ compatibility.
/// </summary>
/// <param name="message"></param>
/// <param name="args"></param>
[PublicAPI]
public static void ConsoleCommandResponseLine(string message, params object[] args)
{
ConsoleCommandResponse(message + IcdEnvironment.NewLine, args);
}
/// <summary>
/// Wraps CrestronConsole.ConsoleCommandResponse for S+ compatibility.
/// </summary>
/// <param name="message"></param>
/// <param name="args"></param>
[PublicAPI]
public static void ConsoleCommandResponse(string message, params object[] args)
{
message = string.Format(message, args);
#if SIMPLSHARP
try
{
CrestronConsole.ConsoleCommandResponse(message);
}
catch (NotSupportedException)
{
CrestronConsole.Print(message);
}
#else
System.Console.Write(message, args);
#endif
}
public static void PrintLine(string message)
{
#if SIMPLSHARP
CrestronConsole.PrintLine(message);
#else
System.Console.WriteLine(message);
#endif
}
public static void PrintLine(string message, params object[] args)
{
#if SIMPLSHARP
CrestronConsole.PrintLine(message, args);
#else
System.Console.WriteLine(message, args);
#endif
}
public static void Print(string message)
{
#if SIMPLSHARP
CrestronConsole.Print(message);
#else
System.Console.Write(message);
#endif
}
public static void Print(string message, params object[] args)
{
#if SIMPLSHARP
CrestronConsole.Print(message, args);
#else
System.Console.Write(message, args);
#endif
}
public static bool SendControlSystemCommand(string command, ref string result)
{
#if SIMPLSHARP
return CrestronConsole.SendControlSystemCommand(command, ref result);
#else
result = string.Empty;
return false;
#endif
}
public static void AddNewConsoleCommand(Action<string> callback, string command, string help, eAccessLevel accessLevel)
{
#if SIMPLSHARP
CrestronConsole.AddNewConsoleCommand(str => callback(str), command, help, (ConsoleAccessLevelEnum)(int)accessLevel);
#endif
}
}
}