Compare commits
2 Commits
4938eaaa44
...
3023d6e513
| Author | SHA1 | Date | |
|---|---|---|---|
| 3023d6e513 | |||
| ae6a7c3059 |
@ -119,19 +119,46 @@ public class Program : WebApplication
|
||||
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
Console.Error.WriteLine("path not found: " + path);
|
||||
Log.WriteLine("path not found: " + path);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryLoadLibrary(Oms, path, "net.alcetech.Mocha.System.mcl"))
|
||||
string[] requiredLibraries = new string[]
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!TryLoadLibrary(Oms, path, "net.alcetech.Mocha.Web.mcl"))
|
||||
"net.alcetech.Mocha.System.mcl",
|
||||
"net.alcetech.Mocha.Web.mcl"
|
||||
};
|
||||
|
||||
for (int i = 0; i < requiredLibraries.Length; i++)
|
||||
{
|
||||
return;
|
||||
Log.WriteLine("loading prerequisite library '{0}'... ", requiredLibraries[i]);
|
||||
if (!TryLoadLibrary(Oms, path, "net.alcetech.Mocha.System.mcl"))
|
||||
{
|
||||
Log.WriteLine("[^b^1FAILED^0] loading prerequisite library '{0}'", requiredLibraries[i]);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.WriteLine("[^b^2SUCCESS^0] loading prerequisite library '{0}'", requiredLibraries[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Log.WriteLine("registering system routines");
|
||||
RegisterSystemRoutines();
|
||||
Oms.SystemRoutineExecuted += oms_SystemRoutineExecuted;
|
||||
|
||||
Log.WriteLine("updating Mochafile");
|
||||
UpdateMochafile();
|
||||
|
||||
Log.WriteLine("reloading storages");
|
||||
Oms.ReloadStorages();
|
||||
|
||||
Log.WriteLine("initial startup routine finished!");
|
||||
// now we can start the Web server
|
||||
base.OnStartup(e);
|
||||
}
|
||||
|
||||
protected virtual void RegisterSystemRoutines()
|
||||
{
|
||||
// implement functions to get user IP address
|
||||
Oms.RegisterSystemAttributeRoutine<string>(KnownInstanceGuids.SystemAttributeRoutines.GetIPAddress, delegate (Oms oms2, OmsContext ctx2)
|
||||
{
|
||||
@ -145,14 +172,6 @@ public class Program : WebApplication
|
||||
bool b = UpdateMochafile();
|
||||
return b;
|
||||
});
|
||||
Oms.SystemRoutineExecuted += oms_SystemRoutineExecuted;
|
||||
|
||||
UpdateMochafile();
|
||||
|
||||
Oms.ReloadStorages();
|
||||
|
||||
// now we can start the Web server
|
||||
base.OnStartup(e);
|
||||
}
|
||||
|
||||
private bool UpdateMochafile()
|
||||
|
||||
@ -64,13 +64,14 @@ public class ElementCommand : InstanceCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
// not an element,
|
||||
// update related work sets
|
||||
foreach (KeyValuePair<string, string> kvp in e.Context.Request.Form)
|
||||
{
|
||||
if (kvp.Key == "relatedInstance")
|
||||
{
|
||||
object? v = oms.ParseValue(kvp.Value);
|
||||
|
||||
|
||||
InstanceHandle relatedWorkSet = oms.GetRelatedInstance(ProcessingInstance, oms.GetInstance(KnownRelationshipGuids.Task__has_related__Work_Set));
|
||||
if (relatedWorkSet != InstanceHandle.Empty)
|
||||
{
|
||||
@ -127,7 +128,7 @@ public class ElementCommand : InstanceCommand
|
||||
// render the default task for the given instance
|
||||
InstanceHandle parentClass = oms.GetParentClass(ProcessingInstance);
|
||||
// if (!oms.TryParseInstanceRef())//blahh
|
||||
InstanceHandle defaultTask = oms.GetRelatedInstance(parentClass, oms.GetInstance(KnownRelationshipGuids.Class__has_default__Task));
|
||||
InstanceHandle defaultTask = oms.GetRelatedInstance(parentClass, oms.GetInstance(KnownRelationshipGuids.Class__has_default__Task));
|
||||
if (defaultTask != InstanceHandle.Empty)
|
||||
{
|
||||
ctx.InitiatingInstance = ProcessingInstance;
|
||||
@ -165,6 +166,11 @@ public class ElementCommand : InstanceCommand
|
||||
}
|
||||
else
|
||||
{
|
||||
InstanceHandle processedByCT = oms.GetRelatedInstance(elem, oms.GetInstance(KnownRelationshipGuids.Element__processed_by__Control_Transaction_Method));
|
||||
InstanceHandle buildsResponseWithBRMB = oms.GetRelatedInstance(processedByCT, oms.GetInstance(KnownRelationshipGuids.Control_Transaction_Method__uses__Build_Response_Method_Binding));
|
||||
InstanceHandle respondsWithElement = oms.GetRelatedInstance(buildsResponseWithBRMB, oms.GetInstance(KnownRelationshipGuids.Build_UI_Response_Method__uses__Executable_returning_Element));
|
||||
|
||||
|
||||
Response r = oms.ProcessElement(omsContext, elem, null);
|
||||
JsonObject obj = r.GetResponse(oms, omsContext);
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using MBS.Web;
|
||||
using Mocha.Core;
|
||||
using Mocha.Core.Logging;
|
||||
using Mocha.Core.UI;
|
||||
|
||||
namespace Mocha.Core.UI.Server.Commands;
|
||||
@ -54,7 +55,7 @@ public class RelationshipsCommand : InstanceCommand
|
||||
string key = String.Format("item{0}", i);
|
||||
if (e.Context.Request.Form.ContainsKey(key))
|
||||
{
|
||||
Console.Error.WriteLine("debug: trying to add inst " + e.Context.Request.Form[key]);
|
||||
Log.WriteLine("debug: trying to add inst " + e.Context.Request.Form[key]);
|
||||
if (oms.TryParseInstanceRef(e.Context.Request.Form[key], out InstanceHandle inst))
|
||||
{
|
||||
ary1.Add(JsonRenderer.InstanceToJson(oms, inst));
|
||||
@ -63,7 +64,7 @@ public class RelationshipsCommand : InstanceCommand
|
||||
}
|
||||
}
|
||||
|
||||
Console.Error.WriteLine("ok assigning relationship");
|
||||
Log.WriteLine("ok assigning relationship");
|
||||
oms.AssignRelationship(ProcessingInstance, rel, list.ToArray());
|
||||
|
||||
e.Context.Response.ResponseCode = 200;
|
||||
|
||||
@ -21,6 +21,21 @@ public static class Log
|
||||
{
|
||||
public static List<Logger> Loggers { get; } = new List<Logger>();
|
||||
|
||||
public static void Write(string text)
|
||||
{
|
||||
foreach (Logger logger in Loggers)
|
||||
{
|
||||
logger.Write(text);
|
||||
}
|
||||
}
|
||||
public static void Write(string text, params object[] format)
|
||||
{
|
||||
foreach (Logger logger in Loggers)
|
||||
{
|
||||
logger.Write(text, format);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteLine(string text)
|
||||
{
|
||||
foreach (Logger logger in Loggers)
|
||||
|
||||
@ -48,12 +48,22 @@ public class Logger
|
||||
Stream = st;
|
||||
}
|
||||
|
||||
public virtual void Write(string text)
|
||||
{
|
||||
StreamWriter?.Write(text);
|
||||
}
|
||||
public void Write(string text, params object?[] format)
|
||||
{
|
||||
Write(String.Format(text, format));
|
||||
}
|
||||
|
||||
public void WriteLine(string text)
|
||||
{
|
||||
StreamWriter?.WriteLine(text);
|
||||
Write(text);
|
||||
Write(System.Environment.NewLine);
|
||||
}
|
||||
public void WriteLine(string text, params object?[] format)
|
||||
{
|
||||
StreamWriter?.WriteLine(text, format);
|
||||
WriteLine(String.Format(text, format));
|
||||
}
|
||||
}
|
||||
@ -19,8 +19,167 @@ namespace Mocha.Core.Logging.Loggers;
|
||||
|
||||
public class ConsoleLogger : Logger
|
||||
{
|
||||
public bool EnableColorization { get; set; } = true;
|
||||
|
||||
public ConsoleLogger()
|
||||
{
|
||||
Stream = Console.OpenStandardOutput();
|
||||
}
|
||||
|
||||
public override void Write(string text)
|
||||
{
|
||||
if (text.Contains('^') && EnableColorization)
|
||||
{
|
||||
// Q3 console colors - see https://quake3world.com/forum/viewtopic.php?t=7760
|
||||
// with some modifications by yours truly
|
||||
string[] ps = text.Split(new char[] { '^' });
|
||||
Console.Write(ps[0]);
|
||||
if (ps.Length > 1)
|
||||
{
|
||||
int state = 0; // bold = 1, underline = 2
|
||||
for (int i = 1; i < ps.Length; i++)
|
||||
{
|
||||
if (ps[i][0] == '0')
|
||||
{
|
||||
Console.Write("\x1b[0m");
|
||||
}
|
||||
else if (ps[i][0] == '1')
|
||||
{
|
||||
Console.Write("\x1b[");
|
||||
if (state == 1)
|
||||
{
|
||||
Console.Write('1');
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
Console.Write('4');
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write('0');
|
||||
}
|
||||
Console.Write(";31m");
|
||||
}
|
||||
else if (ps[i][0] == '2')
|
||||
{
|
||||
Console.Write("\x1b[");
|
||||
if (state == 1)
|
||||
{
|
||||
Console.Write('1');
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
Console.Write('4');
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write('0');
|
||||
}
|
||||
Console.Write(";32m");
|
||||
}
|
||||
else if (ps[i][0] == '3')
|
||||
{
|
||||
Console.Write("\x1b[");
|
||||
if (state == 1)
|
||||
{
|
||||
Console.Write('1');
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
Console.Write('4');
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write('0');
|
||||
}
|
||||
Console.Write(";33m");
|
||||
}
|
||||
else if (ps[i][0] == '4')
|
||||
{
|
||||
Console.Write("\x1b[");
|
||||
if (state == 1)
|
||||
{
|
||||
Console.Write('1');
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
Console.Write('4');
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write('0');
|
||||
}
|
||||
Console.Write(";34m");
|
||||
}
|
||||
else if (ps[i][0] == '5')
|
||||
{
|
||||
// looks like it's exactly ASCII except for these two... why???
|
||||
Console.Write("\x1b[");
|
||||
if (state == 1)
|
||||
{
|
||||
Console.Write('1');
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
Console.Write('4');
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write('0');
|
||||
}
|
||||
Console.Write(";36m");
|
||||
}
|
||||
else if (ps[i][0] == '6')
|
||||
{
|
||||
// looks like it's exactly ASCII except for these two... why???
|
||||
Console.Write("\x1b[");
|
||||
if (state == 1)
|
||||
{
|
||||
Console.Write('1');
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
Console.Write('4');
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write('0');
|
||||
}
|
||||
Console.Write(";35m");
|
||||
}
|
||||
else if (ps[i][0] == '7')
|
||||
{
|
||||
Console.Write("\x1b[");
|
||||
if (state == 1)
|
||||
{
|
||||
Console.Write('1');
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
Console.Write('4');
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write('0');
|
||||
}
|
||||
Console.Write(";37m");
|
||||
}
|
||||
else if (ps[i][0] == 'b')
|
||||
{
|
||||
state = 1;
|
||||
}
|
||||
else if (ps[i][0] == '_')
|
||||
{
|
||||
state = 2;
|
||||
}
|
||||
Console.Write(ps[i].Substring(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write(text);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -25,6 +25,7 @@ using System.Text.Json.Nodes;
|
||||
using MBS.Core;
|
||||
using MBS.Core.Collections;
|
||||
using MBS.Core.Extensibility;
|
||||
using Mocha.Core.Logging;
|
||||
using Mocha.Core.Oop;
|
||||
using Mocha.Core.Responses;
|
||||
using Mocha.Core.UI;
|
||||
@ -1783,8 +1784,18 @@ public abstract class Oms
|
||||
{
|
||||
if (_libraries.ContainsKey(name))
|
||||
{
|
||||
Log.WriteLine("[^b^2SUCCESS^0] LoadLibrary - using handle '{0}' for '{1}'", _libraries[name], name);
|
||||
return _libraries[name];
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.WriteLine("[^b^1FAILURE^0] LoadLibrary - not found library '{0}'", name);
|
||||
Log.WriteLine("Available libraries are: ");
|
||||
foreach (KeyValuePair<string, LibraryHandle> kvp in _libraries)
|
||||
{
|
||||
Log.WriteLine("---- {0}", kvp.Key);
|
||||
}
|
||||
}
|
||||
return LibraryHandle.Empty;
|
||||
}
|
||||
private Dictionary<Guid, LibraryHandle> _librariesGuids = new Dictionary<Guid, LibraryHandle>();
|
||||
@ -1816,6 +1827,7 @@ public abstract class Oms
|
||||
// /path/to/directory containing a bunch of XML / JSON / YAML files
|
||||
// .mcz ZIP archive of XML / JSON / YAML files (slowest?)
|
||||
LibraryHandle lh = LibraryHandle.Create();
|
||||
Log.WriteLine("LoadLibrary - registered handle '{0}'", lh);
|
||||
|
||||
Library lib = new Library();
|
||||
// _libraries[name] = lh;
|
||||
@ -1869,7 +1881,6 @@ public abstract class Oms
|
||||
/// <returns></returns>
|
||||
public LibraryHandle LoadLibrary(string filename)
|
||||
{
|
||||
Console.WriteLine("oms: LoadLibrary '{0}'", filename);
|
||||
// some examples:
|
||||
// .mcl compiled binary library file (fastest?)
|
||||
// /path/to/directory containing a bunch of XML / JSON / YAML files
|
||||
@ -1877,7 +1888,8 @@ public abstract class Oms
|
||||
LibraryHandle lh = LibraryHandle.Create();
|
||||
|
||||
Library lib = new Library();
|
||||
// _libraries[name] = lh;
|
||||
string name = System.IO.Path.GetFileNameWithoutExtension(filename);
|
||||
_libraries[name] = lh;
|
||||
|
||||
if (!System.IO.File.Exists(filename) && !Directory.Exists(filename))
|
||||
{
|
||||
@ -2268,42 +2280,47 @@ public abstract class Oms
|
||||
}
|
||||
else
|
||||
{
|
||||
Renderer renderer = new Renderer(this);
|
||||
string title = GetLabelForUIElement(element);
|
||||
Widget widget = renderer.Parse(ctx, element, InstanceHandle.Empty, InstanceHandle.Empty);
|
||||
if (widget == null)
|
||||
{
|
||||
return FailureResponse.UnexpectedFailure;
|
||||
}
|
||||
|
||||
return new PageResponse(delegate (Oms oms, OmsContext ctx)
|
||||
{
|
||||
JsonObject obj3 = widget.ToJSONObject(ctx);
|
||||
|
||||
JsonObject obj2 = new JsonObject();
|
||||
obj2.Add("widget", JsonValue.Create("root"));
|
||||
obj2.Add("body", widget.ToJSONObject(ctx));
|
||||
|
||||
JsonObject objTitle = new JsonObject();
|
||||
// hack
|
||||
if (String.IsNullOrEmpty(title) && ctx.InitiatingTask != InstanceHandle.Empty)
|
||||
{
|
||||
title = oms.GetInstanceText(ctx.InitiatingTask);
|
||||
}
|
||||
objTitle.Add("label", title);
|
||||
// objTitle.Add("src", "Oms");
|
||||
obj2.Add("title", objTitle);
|
||||
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.Add("result", "success");
|
||||
obj.Add("value", obj2);
|
||||
return obj;
|
||||
});
|
||||
return PresentElement(ctx, element);
|
||||
}
|
||||
return null; // FailureResponse.UnexpectedFailure;
|
||||
}
|
||||
|
||||
private Response? ProcessElementContent(OmsContext context, InstanceHandle elementContent, IDictionary<string, string> form, string fqecidPrefix)
|
||||
private Response PresentElement(OmsContext ctx, InstanceHandle element)
|
||||
{
|
||||
Renderer renderer = new Renderer(this);
|
||||
string title = GetLabelForUIElement(element);
|
||||
Widget widget = renderer.Parse(ctx, element, InstanceHandle.Empty, InstanceHandle.Empty);
|
||||
if (widget == null)
|
||||
{
|
||||
return FailureResponse.UnexpectedFailure;
|
||||
}
|
||||
|
||||
return new PageResponse(delegate (Oms oms, OmsContext ctx)
|
||||
{
|
||||
JsonObject obj3 = widget.ToJSONObject(ctx);
|
||||
|
||||
JsonObject obj2 = new JsonObject();
|
||||
obj2.Add("widget", JsonValue.Create("root"));
|
||||
obj2.Add("body", widget.ToJSONObject(ctx));
|
||||
|
||||
JsonObject objTitle = new JsonObject();
|
||||
// hack
|
||||
if (String.IsNullOrEmpty(title) && ctx.InitiatingTask != InstanceHandle.Empty)
|
||||
{
|
||||
title = oms.GetInstanceText(ctx.InitiatingTask);
|
||||
}
|
||||
objTitle.Add("label", title);
|
||||
// objTitle.Add("src", "Oms");
|
||||
obj2.Add("title", objTitle);
|
||||
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.Add("result", "success");
|
||||
obj.Add("value", obj2);
|
||||
return obj;
|
||||
});
|
||||
}
|
||||
|
||||
private Response? ProcessElementContent(OmsContext context, InstanceHandle elementContent, IDictionary<string, string> form, string fqecidPrefix)
|
||||
{
|
||||
InstanceHandle elementContentInstance = GetRelatedInstance(elementContent, GetInstance(KnownRelationshipGuids.Element_Content__has__Instance));
|
||||
if (IsInstanceOf(elementContentInstance, GetInstance(KnownInstanceGuids.Classes.Element)))
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Mocha.NET. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
using Mocha.Core.Logging;
|
||||
|
||||
namespace Mocha.Core.OmsImplementations;
|
||||
|
||||
public class MemoryOms : Oms
|
||||
@ -297,7 +299,7 @@ public class MemoryOms : Oms
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Error.WriteLine("oms: error: trying to add reference to library which hasn't been loaded yet");
|
||||
Log.WriteLine("oms: error: trying to add reference to library which hasn't been loaded yet");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ using System.Reflection.Metadata.Ecma335;
|
||||
using System.Runtime.InteropServices;
|
||||
using MBS.Core;
|
||||
using Mocha.Core;
|
||||
using Mocha.Core.Logging;
|
||||
using Mocha.Plugins.Libraries.McxMini.EditorMini;
|
||||
|
||||
public class McxMiniLibraryPlugin : LibraryPlugin
|
||||
@ -108,7 +109,7 @@ public class McxMiniLibraryPlugin : LibraryPlugin
|
||||
|
||||
if (guidsSection.Count != instancesSection.Count)
|
||||
{
|
||||
Console.Error.WriteLine("guid count not equal to instance count?");
|
||||
Log.WriteLine("[^b^3WARNING^0] guid count not equal to instance count?");
|
||||
}
|
||||
|
||||
r.BaseStream.Seek(guidsSection.Offset, SeekOrigin.Begin);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user