From a10440a45c40652b13e883aec832a0c8ded685e8 Mon Sep 17 00:00:00 2001 From: John T Date: Sun, 5 Nov 2017 18:47:46 -0500 Subject: Added a half-complete ShiftFS and did some code cleanup --- ShiftOS.Engine/Terminal/Commands/Hello.cs | 26 +++-------- ShiftOS.Engine/Terminal/TerminalBackend.cs | 71 +++++++++++++++--------------- ShiftOS.Engine/Terminal/TerminalCommand.cs | 20 +++------ 3 files changed, 50 insertions(+), 67 deletions(-) (limited to 'ShiftOS.Engine/Terminal') diff --git a/ShiftOS.Engine/Terminal/Commands/Hello.cs b/ShiftOS.Engine/Terminal/Commands/Hello.cs index 531bd1f..7d4b82f 100644 --- a/ShiftOS.Engine/Terminal/Commands/Hello.cs +++ b/ShiftOS.Engine/Terminal/Commands/Hello.cs @@ -1,21 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShiftOS.Engine.Terminal.Commands +namespace ShiftOS.Engine.Terminal.Commands { - public class Hello : TerminalCommand - { - public override string GetName() - { - return "Hello"; - } + public class Hello : TerminalCommand + { + public override string GetName() => "Hello"; - public override string Run(params string[] parameters) - { - return "Oh, HELLO, " + String.Join(" ", parameters); - } - } -} + public override string Run(params string[] parameters) => "Oh, HELLO, " + string.Join(" ", parameters); + } +} \ No newline at end of file diff --git a/ShiftOS.Engine/Terminal/TerminalBackend.cs b/ShiftOS.Engine/Terminal/TerminalBackend.cs index 7103238..793b748 100644 --- a/ShiftOS.Engine/Terminal/TerminalBackend.cs +++ b/ShiftOS.Engine/Terminal/TerminalBackend.cs @@ -2,45 +2,46 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace ShiftOS.Engine.Terminal { - public static class TerminalBackend - { - // The line below gets all the terminal commands in... well... the entire ShiftOS.Engine - public static IEnumerable instances = from t in Assembly.GetExecutingAssembly().GetTypes() - where t.IsSubclassOf(typeof(TerminalCommand)) - && t.GetConstructor(Type.EmptyTypes) != null - select Activator.CreateInstance(t) as TerminalCommand; + public static class TerminalBackend + { + // The line below gets all the terminal commands in... well... the entire ShiftOS.Engine + static readonly IEnumerable Instances = from t in Assembly.GetExecutingAssembly().GetTypes() + where t.IsSubclassOf(typeof(TerminalCommand)) && + t.GetConstructor(Type.EmptyTypes) != null + select (TerminalCommand) Activator.CreateInstance(t); - /// - /// Runs a terminal command. - /// - /// - /// Returns all the output from that command. - public static string RunCommand(string command) - { - string name; - try { name = command.Split(' ')[0]; } catch { name = command; } + /// + /// Runs a terminal command. + /// + /// + /// Returns all the output from that command. + public static string RunCommand(string command) + { + string name; + try + { + name = command.Split(' ')[0]; + } + catch + { + name = command; + } - var theParams = new string[command.Split(' ').Length - 1]; - Array.Copy(command.Split(' '), 1, theParams, 0, command.Split(' ').Length - 1); + var theParams = new string[command.Split(' ').Length - 1]; + Array.Copy(command.Split(' '), 1, theParams, 0, command.Split(' ').Length - 1); - foreach (TerminalCommand instance in instances) - { - if (instance.GetName() == name) - return instance.Run(theParams); - } + foreach (var instance in Instances) + { + if (instance.GetName() == name) + { + return instance.Run(theParams); + } + } - return "The command cannot be found."; - } - - // An extra function ;) - private static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace) - { - return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray(); - } - } -} + return "The command cannot be found."; + } + } +} \ No newline at end of file diff --git a/ShiftOS.Engine/Terminal/TerminalCommand.cs b/ShiftOS.Engine/Terminal/TerminalCommand.cs index a344122..81a34b9 100644 --- a/ShiftOS.Engine/Terminal/TerminalCommand.cs +++ b/ShiftOS.Engine/Terminal/TerminalCommand.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ShiftOS.Engine.Terminal +namespace ShiftOS.Engine.Terminal { - public abstract class TerminalCommand - { - public abstract string GetName(); + public abstract class TerminalCommand + { + public abstract string GetName(); - public abstract string Run(params string[] parameters); - } -} + public abstract string Run(params string[] parameters); + } +} \ No newline at end of file -- cgit v1.2.3