public List <long> Evaluate(CDRelationshipPool RelationshipSpace, EXEScope Scope) { List <long> Result = null; EXEReferenceHandle StartVariable = Scope.FindReferenceHandleByName(this.StartingVariable); if (StartVariable != null && this.RelationshipSpecification.Any()) { List <long> CurrentIds = StartVariable.GetReferencedIds(); if (CurrentIds == null) { return(null); } String CurrentClass = StartVariable.ClassName; foreach (EXERelationshipLink RelationshipLink in this.RelationshipSpecification) { if (CurrentIds == null || !CurrentIds.Any()) { break; } CurrentIds = RelationshipLink.RetrieveIds(CurrentIds, CurrentClass, RelationshipSpace); CurrentClass = RelationshipLink.ClassName; } Result = CurrentIds; } return(Result); }
public String Evaluate(EXEScope Scope, CDClassPool ExecutionSpace) { String Result = null; String ValueType = EXETypes.DetermineVariableType("", this.Value); if (ValueType == null) { return(Result); } // If we have simple value, e.g. 5, 3.14, "hi Madelyn", we are good if (!EXETypes.ReferenceTypeName.Equals(ValueType)) { Result = this.Value; } // We got here because we have a variable name, the variable is of primitive value else if (EXETypes.ReferenceTypeName.Equals(ValueType)) { EXEPrimitiveVariable ThisVariable = Scope.FindPrimitiveVariableByName(this.Value); if (ThisVariable != null) { Result = ThisVariable.Value; } } /*Console.WriteLine("Operand: " + this.Value); * Console.WriteLine("Result: " + Result);*/ return(Result); }
// SetUloh1 - this method is done. Do the same with two similar methods below it public EXEPrimitiveVariable FindPrimitiveVariableByName(String Name) { EXEPrimitiveVariable Result = null; EXEScope CurrentScope = this; while (CurrentScope != null) { foreach (EXEPrimitiveVariable CurrentVariable in CurrentScope.PrimitiveVariables) { if (CurrentVariable.Name == Name) { Result = CurrentVariable; break; } } if (Result != null) { break; } CurrentScope = CurrentScope.SuperScope; } return(Result); }
public Dictionary <String, String> GetRefStateAttrsDictRecursive(CDClassPool ExecutionSpace) { Dictionary <String, String> Result = new Dictionary <String, String>(); EXEScope CurrentScope = this; while (CurrentScope != null) { foreach (EXEReferencingVariable Var in CurrentScope.ReferencingVariables) { CDClassInstance Inst = Var.RetrieveReferencedClassInstance(ExecutionSpace); if (Inst == null) { continue; } foreach (var Attribute in Inst.GetStateWithoutID()) { Result[Var.Name + "." + Attribute.Key] = Attribute.Value; } } CurrentScope = CurrentScope.SuperScope; } return(Result); }
public EXEReferencingVariable FindReferencingVariableByName(String Name) { EXEReferencingVariable Result = null; EXEScope CurrentScope = this; while (CurrentScope != null) { foreach (EXEReferencingVariable CurrentVariable in CurrentScope.ReferencingVariables) { if (String.Equals(CurrentVariable.Name, Name)) { Result = CurrentVariable; break; } } if (Result != null) { break; } CurrentScope = CurrentScope.SuperScope; } return(Result); }
public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { //OALProgram.RequestNextStep(); OALProgram.ThreadSyncer.RequestStep(this, Scope, null); return(true); }
public EXEScope() { this.PrimitiveVariables = new List <EXEPrimitiveVariable>(); this.ReferencingVariables = new List <EXEReferencingVariable>(); this.SetReferencingVariables = new List <EXEReferencingSetVariable>(); this.SuperScope = null; this.Commands = new List <EXECommand>(); this.OALProgram = null; }
public virtual Boolean SynchronizedExecute(OALProgram OALProgram, EXEScope Scope) { OALProgram.AccessInstanceDatabase(); Console.WriteLine(this.ToCode()); Boolean Success = this.Execute(OALProgram, Scope); Console.WriteLine("Done"); OALProgram.LeaveInstanceDatabase(); return(Success); }
public void AnimateDistributors() { CDClassPool cp = new CDClassPool(); CDRelationshipPool rp = new CDRelationshipPool(); cp.SpawnClass("Outer Control Class"); cp.SpawnClass("Order"); cp.SpawnClass("Careful Distributor"); cp.SpawnClass("Regular Distributor"); cp.SpawnClass("Messenger"); cp.SpawnClass("Line Item"); CDRelationship R1 = rp.SpawnRelationship("Outer Control Class", "Order"); CDRelationship R2 = rp.SpawnRelationship("Careful Distributor", "Order"); CDRelationship R3 = rp.SpawnRelationship("Regular Distributor", "Order"); CDRelationship R4 = rp.SpawnRelationship("Messenger", "Order"); EXEScope OALProgramSuperscope = new EXEScope(); EXECommandQueryCreate CreateQuery1 = new EXECommandQueryCreate("Outer Control Class", "ooc"); EXECommandQueryCreate CreateQuery2 = new EXECommandQueryCreate("Order", "order"); EXECommandQueryCreate CreateQuery3 = new EXECommandQueryCreate("Careful Distributor", "car_distrib"); EXECommandQueryCreate CreateQuery4 = new EXECommandQueryCreate("Regular Distributor", "reg_distrib"); EXECommandQueryCreate CreateQuery5 = new EXECommandQueryCreate("Messenger", "messenger"); OALProgramSuperscope.AddCommand(CreateQuery1); OALProgramSuperscope.AddCommand(CreateQuery2); OALProgramSuperscope.AddCommand(CreateQuery3); OALProgramSuperscope.AddCommand(CreateQuery4); OALProgramSuperscope.AddCommand(CreateQuery5); for (int i = 0; i < 3; i++) { OALProgramSuperscope.AddCommand(new EXECommandQueryCreate("Line Item", "li" + i)); } EXECommandQueryRelate RelQuery1 = new EXECommandQueryRelate("ooc", "order", R1.RelationshipName); EXECommandQueryRelate RelQuery2 = new EXECommandQueryRelate("car_distrib", "order", R2.RelationshipName); EXECommandQueryRelate RelQuery3 = new EXECommandQueryRelate("reg_distrib", "order", R3.RelationshipName); EXECommandQueryRelate RelQuery4 = new EXECommandQueryRelate("messenger", "order", R4.RelationshipName); OALProgramSuperscope.AddCommand(RelQuery1); OALProgramSuperscope.AddCommand(RelQuery2); OALProgramSuperscope.AddCommand(RelQuery3); OALProgramSuperscope.AddCommand(RelQuery4); EXECommandCall Call1 = new EXECommandCall("ooc", "InitiateDispatch", R1.RelationshipName, "order", "dispatch"); EXECommandQuerySelect SelectSetQuery = new EXECommandQuerySelect(EXECommandQuerySelect.CardinalityMany, "Line Item", "line_items"); OALProgramSuperscope.AddCommand(Call1); OALProgramSuperscope.AddCommand(SelectSetQuery); EXEScopeForEach ForEachCommand = new EXEScopeForEach("current_li", "line_items"); // EXEScopeCondition IfCommand = new EXEScopeCondition(new EXEASTNodeLeaf(EXETypes.BooleanTrue)); }
public override bool Execute(OALProgram OALProgram, EXEScope Scope) { bool Result = DecoratedCommand.Execute(OALProgram, Scope); if (!Result) { return(Result); } CallTextBuffer.Append(DecoratedCommand.ToCode()); return(Result); }
public void RequestStep(EXECommand Command, EXEScope SuperScope, AnimationCommandStorage ACS) { lock (this.Syncer) { Debug.Log("Got into Thread Syncer"); //If the room has been entered previously and has not been emptied yet, we must wait until it's emptied while (this.Blocked) { Monitor.Wait(this.Syncer); } //If someone changed number of threads, let's do it PerformThreadCountChange(); //Let us let know everyone of our presence this.InLockCount++; this.UntilLockResetCount--; if (this.InLockCount == 1) { //AnimationCommandStorage.GetInstance();//.NewAnimationSequence(); ACS.NewAnimationSequence(); } /*Animation.Instance.AddAnimationStep(new AnimationCommand(SuperScope, Command));*/ ACS.AddAnimationStep(new AnimationCommand(SuperScope, Command)); //If we have to wait for more threads, let's sleep until they come while (this.UntilLockResetCount > 0) { //If someone changed number of threads, let's do it PerformThreadCountChange(); Monitor.Wait(this.Syncer); } //If we are the last thread to come, let's block the room until everyone leaves and wake everyone up if (this.UntilLockResetCount == 0) { this.Blocked = true; OALProgram.RequestNextStep(); Monitor.PulseAll(this.Syncer); } //Let know that we are leaving this.InLockCount--; //If we are the last one leaving, unblock the room and reset counters. And wake up possible sleepers if (this.InLockCount == 0) { this.Blocked = false; this.UntilLockResetCount = this.ThreadCount; //Animation.Instance.NewAnimationSequence(); ACS.NewAnimationSequence(); Monitor.PulseAll(this.Syncer); } } }
public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { //Console.WriteLine("Assignment is being executed"); Boolean Result = false; String AssignedValue = this.AssignedExpression.Evaluate(Scope, OALProgram.ExecutionSpace); if (AssignedValue == null) { return(Result); } // If we are assigning to a variable if (this.AttributeName == null) { //Console.WriteLine("Assigning value: " + AssignedValue + " to variable " + this.VariableName); EXEPrimitiveVariable Variable = Scope.FindPrimitiveVariableByName(this.VariableName); // If the variable doesnt exist, we simply create it if (Variable == null) { //Console.WriteLine("Creating new var " + this.VariableName); Result = Scope.AddVariable(new EXEPrimitiveVariable(this.VariableName, AssignedValue)); } //If variable exists and its type is UNDEFINED else if (EXETypes.UnitializedName.Equals(Variable.Type)) { //Console.WriteLine("Assigning to unitialized var" + this.VariableName); Result = Variable.AssignValue(Variable.Name, AssignedValue); } // If the variable exists and is primitive else if (!EXETypes.ReferenceTypeName.Equals(Variable.Type)) { //Console.WriteLine("Assigning to initialized var" + this.VariableName); // If the types don't match, this fails and returns false AssignedValue = EXETypes.AdjustAssignedValue(Variable.Type, AssignedValue); Result = Variable.AssignValue("", AssignedValue); } // Variable exists and is not primitive. What to do, what to do? // We do nothing, we CANNOT ASSIGN TO HANDLES!!! } // We are assigning to an attribute of a variable else { EXEReferenceEvaluator RefEvaluator = new EXEReferenceEvaluator(); Result = RefEvaluator.SetAttributeValue(this.VariableName, this.AttributeName, Scope, OALProgram.ExecutionSpace, AssignedValue); //Console.WriteLine("Tried to assign " + AssignedValue + " to " + this.VariableName + "." + this.AttributeName); } //Console.WriteLine("Assignment Result: " + Result); return(Result); }
public bool VerifyReferences(EXEScope Scope, CDClassPool ExecutionSpace) { bool Result = false; if (!EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Value))) { Result = true; } else { Result = Scope.VariableNameExists(this.Value); } return(Result); }
public override bool Execute(OALProgram OALProgram, EXEScope Scope) { bool Result = false; EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.VariableName); if (Variable != null) { bool DestructionSuccess = OALProgram.ExecutionSpace.DestroyInstance(Variable.ClassName, Variable.ReferencedInstanceId); if (DestructionSuccess) { Result = Scope.UnsetReferencingVariables(Variable.ClassName, Variable.ReferencedInstanceId); } } return(Result); }
public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { //OALProgram.RequestNextStep(); OALProgram.ThreadSyncer.RequestStep(this, Scope, null); //Filip, ak mas null v executablecode tak vrat true inak toto dole EXEScopeMethod ExecutableCode = OALProgram.ExecutionSpace.getClassByName(this.CalledClass).getMethodByName(this.CalledMethod).ExecutableCode; if (ExecutableCode != null) { return(ExecutableCode.SynchronizedExecute(OALProgram, Scope)); } return(true); }
public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { this.OALProgram = OALProgram; this.OALProgram.ThreadSyncer.RegisterThread((uint)this.Threads.Count); EXEScopeParallel ParallelScope = this; Boolean Success = true; lock (this.MyThreadEndSyncer) { this.ActiveThreadCount = this.Threads.Count; } OALProgram.ThreadSyncer.UnregisterThread(); foreach (EXEScope ThreadScope in this.Threads) { new Thread(() => { Thread.CurrentThread.IsBackground = false; Boolean MySuccess = ThreadScope.SynchronizedExecute(OALProgram, ParallelScope); OALProgram.ThreadSyncer.UnregisterThread(); lock (ParallelScope.MyThreadEndSyncer) { Success &= MySuccess; ParallelScope.ActiveThreadCount--; if (ParallelScope.ActiveThreadCount == 0) { Monitor.PulseAll(this.MyThreadEndSyncer); } } }).Start(); } lock (this.MyThreadEndSyncer) { while (this.ActiveThreadCount > 0) { Monitor.Wait(this.MyThreadEndSyncer); } } OALProgram.ThreadSyncer.RegisterThread(1); return(Success); }
public EXEScope(EXEScope SuperScope, EXECommand[] Commands) { this.PrimitiveVariables = new List <EXEPrimitiveVariable>(); this.ReferencingVariables = new List <EXEReferencingVariable>(); this.SetReferencingVariables = new List <EXEReferencingSetVariable>(); this.SetSuperScope(SuperScope); this.Commands = new List <EXECommand>(); foreach (EXECommand Command in Commands) { this.AddCommand(Command); } this.OALProgram = null; }
public String EvaluateNotEmpty(String Operand, EXEScope Scope) { String Result = null; String TempResult = EvaluateEmpty(Operand, Scope); if (EXETypes.BooleanTrue.Equals(TempResult)) { Result = EXETypes.BooleanFalse; } else if (EXETypes.BooleanFalse.Equals(TempResult)) { Result = EXETypes.BooleanTrue; } return(Result); }
//"Scope" param is ignored here, because this class is a scope public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { this.OALProgram = OALProgram; Boolean Success = true; foreach (EXECommand Command in this.Commands) { Success = Command.SynchronizedExecute(OALProgram, this); if (!Success) { break; } } return(Success); }
public override void SetSuperScope(EXEScope SuperScope) { base.SetSuperScope(SuperScope); if (this.ElifScopes != null) { foreach (EXEScope ElifScope in this.ElifScopes) { ElifScope.SetSuperScope(this.GetSuperScope()); } } if (this.ElseScope != null) { this.ElseScope.SetSuperScope(this.GetSuperScope()); } }
public EXEReferencingSetVariable FindSetReferencingVariableByName(String Name) { EXEScope CurrentScope = this; while (CurrentScope != null) { foreach (EXEReferencingSetVariable ReferencingSetVariable in CurrentScope.SetReferencingVariables) { if (String.Equals(ReferencingSetVariable.Name, Name)) { return(ReferencingSetVariable); } } CurrentScope = CurrentScope.SuperScope; } return(null); }
public Dictionary <String, String> GetStateDictRecursive() { Dictionary <String, String> Result = new Dictionary <String, String>(); EXEScope CurrentScope = this; while (CurrentScope != null) { foreach (EXEPrimitiveVariable CurrentVariable in CurrentScope.PrimitiveVariables) { Result[CurrentVariable.Name] = CurrentVariable.Value; } CurrentScope = CurrentScope.SuperScope; } return(Result); }
public String EvaluateCardinality(String Operand, EXEScope Scope) { String Result = null; if (EXETypes.UnitializedName.Equals(Operand)) { Result = "0"; return(Result); } EXEReferencingVariable SingleInstanceVariable = Scope.FindReferencingVariableByName(Operand); if (SingleInstanceVariable != null) { if (SingleInstanceVariable.IsInitialized()) { Result = "1"; } else { Result = "0"; } return(Result); } EXEReferencingSetVariable MultiInstanceVariable = Scope.FindSetReferencingVariableByName(Operand); if (MultiInstanceVariable != null) { if (MultiInstanceVariable.GetReferencingVariables().Any()) { Result = MultiInstanceVariable.GetReferencingVariables().Count.ToString(); } else { Result = "0"; } return(Result); } return(Result); }
public String EvaluateEmpty(String Operand, EXEScope Scope) { String Result = null; if (EXETypes.UnitializedName.Equals(Operand)) { Result = EXETypes.BooleanTrue; return(Result); } EXEReferencingVariable SingleInstanceVariable = Scope.FindReferencingVariableByName(Operand); if (SingleInstanceVariable != null) { if (SingleInstanceVariable.IsInitialized()) { Result = EXETypes.BooleanFalse; } else { Result = EXETypes.BooleanTrue; } return(Result); } EXEReferencingSetVariable MultiInstanceVariable = Scope.FindSetReferencingVariableByName(Operand); if (MultiInstanceVariable != null) { if (MultiInstanceVariable.GetReferencingVariables().Any()) { Result = EXETypes.BooleanFalse; } else { Result = EXETypes.BooleanTrue; } return(Result); } return(Result); }
// SetUloh2 public override bool Execute(OALProgram OALProgram, EXEScope Scope) { //Create an instance of given class -> will affect ExecutionSpace. //If ReferencingVariableName is provided (is not ""), create a referencing variable pointing to this instance -> will affect scope CDClass Class = OALProgram.ExecutionSpace.getClassByName(this.ClassName); if (Class == null) { return(false); } EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.ReferencingVariableName); if (Variable != null) { if (!String.Equals(this.ClassName, Variable.ClassName)) { return(false); } } CDClassInstance Instance = Class.CreateClassInstance(); if (Instance == null) { return(false); } if (!"".Equals(this.ReferencingVariableName)) { if (Variable != null) { Variable.ReferencedInstanceId = Instance.UniqueID; } else { Variable = new EXEReferencingVariable(this.ReferencingVariableName, Class.Name, Instance.UniqueID); return(Scope.AddVariable(Variable)); } } return(true); }
public Dictionary <String, String> GetRefStateDictRecursive() { Dictionary <String, String> Result = new Dictionary <String, String>(); EXEScope CurrentScope = this; while (CurrentScope != null) { foreach (EXEReferencingVariable CurrentVariable in CurrentScope.ReferencingVariables) { Result[CurrentVariable.Name] = CurrentVariable.ClassName; } foreach (EXEReferencingSetVariable CurrentVariable in CurrentScope.SetReferencingVariables) { Result[CurrentVariable.Name + "[" + CurrentVariable.ValidVariableCount() + "]"] = CurrentVariable.ClassName; } CurrentScope = CurrentScope.SuperScope; } return(Result); }
public String Evaluate(String Operator, List <String> Operands, EXEScope Scope) { Console.WriteLine("EXEEvaluatorHandleOperators.Evaluate"); String Result = null; if (Operator == null || Operands == null) { return(Result); } Console.WriteLine("EXEEvaluatorHandleOperators.Evaluate - OPERATOR and OPERANDS not null"); if (!IsHandleOperator(Operator)) { return(Result); } if (Operands.Count == 1) { switch (Operator) { case "empty": Console.WriteLine("Time to evaluate 'empty' operator"); Result = EvaluateEmpty(Operands.First(), Scope); break; case "not_empty": Result = EvaluateNotEmpty(Operands.First(), Scope); break; case "cardinality": Result = EvaluateCardinality(Operands.First(), Scope); break; } } return(Result); }
// Create a relationship instance (between two variables pointing to class instances) // Based on class names get the CDRelationship from RelationshipSpace // Based on variable names get the instance ids from Scope.ReferencingVariables // Create relationship between the given instance ids (CDRelationship.CreateRelationship) and return result of it public override bool Execute(OALProgram OALProgram, EXEScope Scope) { EXEReferencingVariable Variable1 = Scope.FindReferencingVariableByName(this.Variable1Name); if (Variable1 == null) { return(false); } EXEReferencingVariable Variable2 = Scope.FindReferencingVariableByName(this.Variable2Name); if (Variable2 == null) { return(false); } CDRelationship Relationship = OALProgram.RelationshipSpace.GetRelationship(this.RelationshipName, Variable1.ClassName, Variable2.ClassName); if (Relationship == null) { return(false); } bool Success = Relationship.DestroyRelationship(Variable1.ReferencedInstanceId, Variable2.ReferencedInstanceId); return(Success); }
public override Boolean Execute(OALProgram OALProgram, EXEScope Scope) { this.OALProgram = OALProgram; OALProgram.AccessInstanceDatabase(); EXEReferencingVariable IteratorVariable = this.FindReferencingVariableByName(this.IteratorName); EXEReferencingSetVariable IterableVariable = this.FindSetReferencingVariableByName(this.IterableName); OALProgram.LeaveInstanceDatabase(); Boolean Success = true; // We cannot iterate over not existing reference set if (Success && IterableVariable == null) { Success = false; } // If iterator already exists and its class does not match the iterable class, we cannot do this if (Success && IteratorVariable != null && !IteratorVariable.ClassName.Equals(IterableVariable.ClassName)) { Success = false; } // If iterator name is already taken for another variable, we quit again. Otherwise we create the iterator variable if (Success && IteratorVariable == null) { IteratorVariable = new EXEReferencingVariable(this.IteratorName, IterableVariable.ClassName, -1); Success = this.GetSuperScope().AddVariable(IteratorVariable); } if (Success) { foreach (EXEReferencingVariable CurrentItem in IterableVariable.GetReferencingVariables()) { //!!NON-RECURSIVE!! this.ClearVariables(); IteratorVariable.ReferencedInstanceId = CurrentItem.ReferencedInstanceId; Console.WriteLine("ForEach: " + CurrentItem.ReferencedInstanceId); foreach (EXECommand Command in this.Commands) { if (this.CurrentLoopControlCommand != LoopControlStructure.None) { break; } Success = Command.SynchronizedExecute(OALProgram, this); if (!Success) { break; } } if (!Success) { break; } if (this.CurrentLoopControlCommand == LoopControlStructure.Break) { this.CurrentLoopControlCommand = LoopControlStructure.None; break; } else if (this.CurrentLoopControlCommand == LoopControlStructure.Continue) { this.CurrentLoopControlCommand = LoopControlStructure.None; continue; } } } return(Success); }
public override Boolean SynchronizedExecute(OALProgram OALProgram, EXEScope Scope) { Boolean Success = this.Execute(OALProgram, this); return(Success); }