do not require method classes to actually be defined, and simplify GetInstanceTextHack

This commit is contained in:
Michael Becker 2024-08-14 22:40:21 -04:00
parent dd91aac0db
commit b417342093

View File

@ -59,13 +59,7 @@ public abstract class Oms
MethodImplementation[] methodImplementations = MBS.Core.Reflection.TypeLoader.GetAvailableTypes<MethodImplementation>(new System.Reflection.Assembly[] { Assembly.GetExecutingAssembly() });
foreach (MethodImplementation impl in methodImplementations)
{
if (TryGetInstance(impl.MethodClassGuid, out InstanceHandle methodClassInstance))
{
RegisterMethodImplementation(methodClassInstance, impl);
}
else{
Console.WriteLine("failed to load method type '{0}' from instance {1} (inst not found)", impl.GetType().FullName, impl.MethodClassGuid);
}
RegisterMethodImplementation(impl.MethodClassGuid, impl);
}
}
@ -669,10 +663,10 @@ public abstract class Oms
return value;
}
private Dictionary<InstanceHandle, MethodImplementation> methodImplementations = new Dictionary<InstanceHandle, MethodImplementation>();
private void RegisterMethodImplementation(InstanceHandle methodClass, MethodImplementation implementation)
private Dictionary<Guid, MethodImplementation> methodImplementations = new Dictionary<Guid, MethodImplementation>();
private void RegisterMethodImplementation(Guid methodClassId, MethodImplementation implementation)
{
methodImplementations[methodClass] = implementation;
methodImplementations[methodClassId] = implementation;
implementation.Initialize(this);
}
@ -705,6 +699,8 @@ public abstract class Oms
public InstanceHandle Execute(OmsContext context, InstanceHandle methodOrMethodBinding, InstanceHandle? targetInstance = null)
{
InstanceHandle parentClass = GetParentClass(methodOrMethodBinding);
Guid parentClassId = GetGlobalIdentifier(parentClass);
if (IsInstanceOf(methodOrMethodBinding, GetInstance(KnownInstanceGuids.Classes.MethodBinding)))
/*
if (IsInstanceOf(methodOrMethodBinding, GetInstance(KnownInstanceGuids.Classes.ReturnAttributeMethodBinding))
@ -728,7 +724,7 @@ public abstract class Oms
}
else
{
if (methodImplementations.ContainsKey(parentClass))
if (methodImplementations.ContainsKey(parentClassId))
{
if (targetInstance != null)
{
@ -736,7 +732,7 @@ public abstract class Oms
InstanceHandle pclassInstance = GetParentClass(hh);
context.SetWorkData(pclassInstance, hh);
}
return methodImplementations[parentClass].Execute(this, context, methodOrMethodBinding);
return methodImplementations[parentClassId].Execute(this, context, methodOrMethodBinding);
}
}
throw new NotImplementedException(String.Format("method implementation not found for method class {0}", GetGlobalIdentifier(parentClass)));
@ -837,17 +833,7 @@ public abstract class Oms
private string _GetInstanceTextHack(InstanceHandle inst)
{
StringBuilder sb = new StringBuilder();
if (IsInstanceOf(inst, GetInstance(KnownInstanceGuids.Classes.Class)))
{
string name = GetAttributeValue<string>(inst, GetInstance(KnownAttributeGuids.Text.Name));
sb.Append(name);
}
else if (IsInstanceOf(inst, GetInstance(KnownInstanceGuids.Classes.Attribute)))
{
string name = GetAttributeValue<string>(inst, GetInstance(KnownAttributeGuids.Text.Name));
sb.Append(name);
}
else if (IsInstanceOf(inst, GetInstance(KnownInstanceGuids.Classes.Relationship)))
if (IsInstanceOf(inst, GetInstance(KnownInstanceGuids.Classes.Relationship)))
{
InstanceHandle sourceClass = GetRelatedInstance(inst, GetInstance(KnownRelationshipGuids.Relationship__has_source__Class));
string relationshipType = GetAttributeValue<string>(inst, GetInstance(KnownAttributeGuids.Text.RelationshipType));
@ -892,6 +878,14 @@ public abstract class Oms
sb.Append(GetInstanceText(executesMethod));
sb.Append("[rsmb]");
}
else
{
string name = GetAttributeValue<string>(inst, GetInstance(KnownAttributeGuids.Text.Name));
if (name != null)
{
sb.Append(name);
}
}
return sb.ToString();
}