improved console/extension reliability

This commit is contained in:
Bitl 2023-01-06 12:03:47 -07:00
parent 1e7bffcd8a
commit 79ecfafeb5
5 changed files with 43 additions and 34 deletions

View File

@ -22,10 +22,9 @@ namespace Novetus.Core
public virtual bool IsValidURL(string absolutePath, string host) { return false; }
public virtual Task OnBeforeTunnelConnectRequest(object sender, TunnelConnectSessionEventArgs e) { return Task.CompletedTask; }
public virtual Task OnRequest(object sender, SessionEventArgs e)
public virtual async Task OnRequest(object sender, SessionEventArgs e)
{
e.Ok("Test successful. \nRunning Novetus " + GlobalVars.ProgramInformation.Version + " on " + GlobalVars.ProgramInformation.NetVersion);
return Task.CompletedTask;
}
}
@ -227,7 +226,7 @@ namespace Novetus.Core
}
else
{
e.DecryptSsl = false;
continue;
}
}
}
@ -255,9 +254,13 @@ namespace Novetus.Core
catch (Exception)
{
e.GenericResponse("", HttpStatusCode.InternalServerError);
return;
continue;
}
}
else
{
continue;
}
}
e.GenericResponse("", HttpStatusCode.NotFound);

View File

@ -15,6 +15,7 @@ namespace Novetus.Core
public static readonly string RootPath = Directory.GetParent(RootPathLauncher).ToString();
public static readonly string BasePath = RootPath.Replace(@"\", @"\\");
public static readonly string DataPath = BasePath + @"\\shareddata";
public static readonly string AssetsPath = BasePath + @"\\assets";
public static readonly string BinDir = BasePath + @"\\bin";
public static readonly string ConfigDir = BasePath + @"\\config";
public static readonly string LogDir = BasePath + @"\\logs";

View File

@ -2,6 +2,7 @@
#region Usings
using Mono.Nat;
using System;
using System.Web;
#endregion
namespace Novetus.Core
@ -50,6 +51,16 @@ namespace Novetus.Core
}
}
}
public static string FindQueryString(Uri uri, string searchQuery)
{
return FindQueryString(uri.Query, searchQuery);
}
public static string FindQueryString(string query, string searchQuery)
{
return HttpUtility.ParseQueryString(query)[searchQuery];
}
}
#endregion
}

View File

@ -44,7 +44,7 @@ namespace Novetus.Core
box.SelectionColor = color;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
//box.SelectionColor = box.ForeColor;
}
#endregion
@ -592,7 +592,7 @@ namespace Novetus.Core
{
string message = (ex.Message != null ? ex.Message.ToString() : "N/A");
ConsolePrint(ex.Source + " Exception: " + message, 2, false, true);
ConsolePrint(ex.Source + " Exception: " + message, 2, true);
LogPrint("EXCEPTION|MESSAGE: " + message, 2);
LogPrint("EXCEPTION|STACK TRACE: " + (!string.IsNullOrWhiteSpace(ex.StackTrace) ? ex.StackTrace : "N/A"), 2);
@ -680,13 +680,8 @@ namespace Novetus.Core
return (p <= 0);
}
public static void ConsolePrint(string text, int type = 1, bool notime = false, bool noLog = false)
public static void ConsolePrint(string text, int type = 1, bool noLog = false)
{
if (!notime)
{
ConsoleText("[" + DateTime.Now.ToShortTimeString() + "] - ", ConsoleColor.White);
}
switch (type)
{
case 0:
@ -721,20 +716,20 @@ namespace Novetus.Core
}
#if LAUNCHER
if (GlobalVars.consoleForm != null)
{
FormPrint(text, type, GlobalVars.consoleForm.ConsoleBox, notime);
}
if (GlobalVars.consoleForm != null)
{
FormPrint(text, type, GlobalVars.consoleForm.ConsoleBox);
}
#endif
}
public static void ConsolePrintMultiLine(string text, int type = 1, bool notime = false, bool noLog = false)
public static void ConsolePrintMultiLine(string text, int type = 1, bool noLog = false)
{
try
{
string[] NewlineChars = { Environment.NewLine, "\n" };
string[] lines = text.Split(NewlineChars, StringSplitOptions.None);
ConsolePrintMultiLine(lines, type, notime, noLog);
ConsolePrintMultiLine(lines, type, noLog);
}
catch (Exception e)
{
@ -744,33 +739,35 @@ namespace Novetus.Core
}
}
public static void ConsolePrintMultiLine(ICollection<string> textColection, int type = 1, bool notime = false, bool noLog = false)
public static void ConsolePrintMultiLine(ICollection<string> textColection, int type = 1, bool noLog = false)
{
if (!textColection.Any())
return;
if (textColection.Count == 1)
{
ConsolePrint(textColection.First(), type, notime, noLog);
ConsolePrint(textColection.First(), type, noLog);
return;
}
foreach (string text in textColection)
{
ConsolePrint(text, type, notime, noLog);
ConsolePrint(text, type, noLog);
}
}
private static void FormPrint(string text, int type, RichTextBox box, bool noTime = false)
private static void FormPrint(string text, int type, RichTextBox box)
{
if (box == null)
return;
if (!noTime)
foreach (string line in box.Lines)
{
box.AppendText("[" + DateTime.Now.ToShortTimeString() + "] - ", Color.White);
Regex.Replace(line, @"^\s+$[\r\n]*", "", RegexOptions.Multiline);
}
box.AppendText("\r\n", Color.White);
switch (type)
{
case 1:
@ -793,8 +790,6 @@ namespace Novetus.Core
box.AppendText(text, Color.Black);
break;
}
box.AppendText(Environment.NewLine, Color.White);
}
private static void ConsoleText(string text, ConsoleColor color, bool newLine = false)
@ -818,11 +813,11 @@ namespace Novetus.Core
try
{
string[] vals = line.Split('|');
ConsolePrint(vals[0], Convert.ToInt32(vals[1]), true, true);
ConsolePrint(vals[0], Convert.ToInt32(vals[1]), true);
}
catch (Exception)
{
ConsolePrint(line, 1, true, true);
ConsolePrint(line, 1, true);
}
}
}

View File

@ -441,16 +441,16 @@ namespace NovetusLauncher
public void ConsoleHelp()
{
ClearConsole();
Util.ConsolePrint("Help:", 3, true, true);
Util.ConsolePrint("Help:", 3, true);
Util.ReadTextFileWithColor(GlobalPaths.BasePath + "\\" + GlobalPaths.ConsoleHelpFileName);
Util.ConsolePrint(GlobalVars.Important2, 0, true, true);
Util.ConsolePrint(GlobalVars.Important2, 0, true);
ScrollToTop();
}
public void ClientScriptDoc()
{
ClearConsole();
Util.ConsolePrint("ClientScript Documentation:", 3, true, true);
Util.ConsolePrint("ClientScript Documentation:", 3, true);
Util.ReadTextFileWithColor(GlobalPaths.BasePath + "\\" + GlobalPaths.ClientScriptDocumentationFileName);
ScrollToTop();
}
@ -476,7 +476,6 @@ namespace NovetusLauncher
if (e.KeyCode == Keys.Enter)
{
ConsoleBox.AppendText(Environment.NewLine, Color.White);
ConsoleProcessCommands(lastLine);
e.Handled = true;
}
@ -499,8 +498,8 @@ namespace NovetusLauncher
private void ClearConsole()
{
ConsoleBox.Text = "";
ConsoleBox.SelectionStart = 0;
ConsoleBox.ScrollToCaret();
ScrollToTop();
Console.Clear();
}
private void ScrollToTop()