146 lines
3.8 KiB
C#
146 lines
3.8 KiB
C#
using System;
|
|
using System.IO;
|
|
using BlueWest.Core.ComponentSystem;
|
|
using BlueWest.Tools;
|
|
using PerformanceSolution.Artefacts;
|
|
|
|
namespace BlueWest.Core
|
|
{
|
|
public sealed class BlueConsole : Artefact
|
|
{
|
|
private static string _consolePrompt = ">> ";
|
|
|
|
public BlueConsole()
|
|
{
|
|
Frequency = ArtefactFrequency.T3Hz;
|
|
}
|
|
|
|
public static void Log(object message)
|
|
{
|
|
Console.WriteLine($"Logging: {message}");
|
|
}
|
|
|
|
private static void InternalLog(object message)
|
|
{
|
|
Console.WriteLine(message);
|
|
}
|
|
|
|
protected override void Update(double delta)
|
|
{
|
|
Console.Write(_consolePrompt);
|
|
var input = Console.ReadLine();
|
|
ParseInput(input);
|
|
}
|
|
|
|
void ParseInput(string? input)
|
|
{
|
|
if (input != null)
|
|
{
|
|
input = input.ToLower();
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(input))
|
|
{
|
|
}
|
|
|
|
else if (input == "clear")
|
|
{
|
|
Console.Clear();
|
|
}
|
|
else if (input == "time")
|
|
{
|
|
//Console.WriteLine(Time.time);
|
|
}
|
|
else if (input == "user")
|
|
{
|
|
_eventManager.TriggerEvent(new CommandRequestEvent(CommandRequestEventType.GetUsers));
|
|
//Console.WriteLine(Time.time);
|
|
}
|
|
else if (input.StartsWith("user"))
|
|
{
|
|
var a = input.Split(" ");
|
|
int id;
|
|
if (int.TryParse(a[1], out id))
|
|
{
|
|
_eventManager.TriggerEvent(new CommandRequestEvent(CommandRequestEventType.GetUserById, id));
|
|
}
|
|
//Console.WriteLine(Time.time);
|
|
}
|
|
|
|
else if (input == "assembly")
|
|
{
|
|
AssemblyCommand();
|
|
}
|
|
else if (input.StartsWith("ls"))
|
|
{
|
|
LsCommand(input);
|
|
}
|
|
else if (input == "pwd")
|
|
{
|
|
PwdCommand();
|
|
}
|
|
|
|
else if (input == "memory")
|
|
{
|
|
MemoryCommand();
|
|
}
|
|
else if (input.StartsWith("mkdir"))
|
|
{
|
|
MkdirCommand(input);
|
|
}
|
|
else
|
|
{
|
|
InternalLog("# Command not recognized");
|
|
}
|
|
}
|
|
|
|
private static void AssemblyCommand()
|
|
{
|
|
var assemblyPath = AssemblyUtils.GetAssemblyPath();
|
|
Console.WriteLine(assemblyPath);
|
|
}
|
|
|
|
private static void MkdirCommand(string? input)
|
|
{
|
|
var argument = input.Split(" ");
|
|
if (argument.Length > 1 && argument[0] != "")
|
|
{
|
|
PathUtils.CreateDirectory(argument[1]);
|
|
return;
|
|
}
|
|
|
|
Log("Error creating folder");
|
|
}
|
|
|
|
private static void MemoryCommand()
|
|
{
|
|
var memory = AssemblyUtils.GetProcessMemory();
|
|
InternalLog(memory);
|
|
}
|
|
|
|
private static void PwdCommand()
|
|
{
|
|
var pwd = AssemblyUtils.GetAssemblyPath();
|
|
InternalLog(pwd);
|
|
}
|
|
|
|
private static void LsCommand(string? input)
|
|
{
|
|
var split = input.Split(" ");
|
|
|
|
foreach (var name in split)
|
|
{
|
|
if (name == "ls") continue;
|
|
if (string.IsNullOrWhiteSpace(name)) continue;
|
|
var assPath = AssemblyUtils.GetAssemblyPath();
|
|
var fp = Path.GetFullPath(name);
|
|
InternalLog(PathUtils.ListAll(fp));
|
|
return;
|
|
}
|
|
|
|
var pathFiles = PathUtils.ListAssemblyPathFiles();
|
|
|
|
InternalLog(pathFiles);
|
|
}
|
|
}
|
|
} |