2021-12-06 02:49:27 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using BlueWest.Core.ComponentSystem;
|
|
|
|
|
using BlueWest.Tools;
|
|
|
|
|
using PerformanceSolution.Artefacts;
|
2022-08-13 20:15:43 +03:00
|
|
|
|
using PerformanceSolution.Core.System;
|
2021-12-06 02:49:27 +03:00
|
|
|
|
|
|
|
|
|
namespace BlueWest.Core
|
|
|
|
|
{
|
2022-08-13 20:15:43 +03:00
|
|
|
|
public sealed class BlueConsole : DisabledArtefact
|
2021-12-06 02:49:27 +03:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
2022-08-01 00:09:39 +03:00
|
|
|
|
else if (input == "user" || input == "users")
|
2021-12-06 02:49:27 +03:00
|
|
|
|
{
|
|
|
|
|
_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)
|
|
|
|
|
{
|
2022-09-10 00:33:17 +03:00
|
|
|
|
var argument = input?.Split(" ");
|
|
|
|
|
if (argument != null && argument.Length > 1 && argument[0] != "")
|
2021-12-06 02:49:27 +03:00
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
2022-09-10 00:33:17 +03:00
|
|
|
|
var split = input?.Split(" ");
|
2021-12-06 02:49:27 +03:00
|
|
|
|
|
2022-09-10 00:33:17 +03:00
|
|
|
|
if (split != null)
|
|
|
|
|
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;
|
|
|
|
|
}
|
2021-12-06 02:49:27 +03:00
|
|
|
|
|
|
|
|
|
var pathFiles = PathUtils.ListAssemblyPathFiles();
|
|
|
|
|
|
|
|
|
|
InternalLog(pathFiles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|