/// <summary> /// This method is called by code that intends to start a graph update. /// This method is called on the main thread where node collection in a /// WorkspaceModel can be safely accessed. /// </summary> /// <param name="controller">Reference to an instance of EngineController /// to assist in generating GraphSyncData object for the given set of nodes. /// </param> /// <param name="workspace">Reference to the WorkspaceModel from which a /// set of updated nodes is computed. The EngineController generates the /// resulting GraphSyncData from this list of updated nodes.</param> /// <returns>Returns true if there is any GraphSyncData, or false otherwise /// (in which case there will be no need to schedule UpdateGraphAsyncTask /// for execution).</returns> /// internal bool Initialize(EngineController controller, WorkspaceModel workspace) { try { engineController = controller; TargetedWorkspace = workspace; ModifiedNodes = ComputeModifiedNodes(workspace); graphSyncData = engineController.ComputeSyncData(workspace.Nodes, ModifiedNodes, verboseLogging); if (graphSyncData == null) return false; // We clear dirty flags before executing the task. If we clear // flags after the execution of task, for example in // AsyncTask.Completed or in HandleTaskCompletionCore(), as both // are executed in the other thread, although some nodes are // modified and we request graph execution, but just before // computing sync data, the task completion handler jumps in // and clear dirty flags. Now graph sync data will be null and // graph is in wrong state. foreach (var nodeGuid in graphSyncData.NodeIDs) { var node = workspace.Nodes.FirstOrDefault(n => n.GUID.Equals(nodeGuid)); if (node != null) node.ClearDirtyFlag(); } return true; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("UpgradeGraphAsyncTask saw: " + e.ToString()); return false; } }
public void SimulateConnectedCBNExecution() { // Simulate 2 CBNs where one is connected to the other // [a = 1]----->[x = a] List<string> codes = new List<string>() { @"a = 10;", // CBN 1 contents @"x = a;" // CBN 2 contents }; // Simulate 2 CBNs Guid cbnGuid1 = System.Guid.NewGuid(); Guid cbnGuid2 = System.Guid.NewGuid(); List<Subtree> added = new List<Subtree>(); added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(cbnGuid1, codes[0])); added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(cbnGuid2, codes[1])); var syncData = new GraphSyncData(null, added, null); // Sending the CBN node data to the VM // Execute the DS code liveRunner.UpdateGraph(syncData); // Verify the values of the variables in the CBNs AssertValue("a", 10); AssertValue("x", 10); }
public void BeginUpdateGraph(GraphSyncData syncData) { lock (taskQueue) { taskQueue.Enqueue(new DynamoUpdateGraphTask(syncData, this)); } }
/// <summary> /// Update graph with graph sync data. /// </summary> /// <param name="graphData"></param> public void UpdateGraph(GraphSyncData graphData) { if (dynamoModel.DebugSettings.VerboseLogging) dynamoModel.Logger.Log("LRS.UpdateGraph: " + graphData); liveRunner.UpdateGraph(graphData); }
public void TestInstructionStreamMemory_SimpleWorkflow01() { List<string> codes = new List<string>() { "a = 1;", "a = 2;" }; Guid guid = System.Guid.NewGuid(); // First run // a = 1 List<Subtree> added = new List<Subtree>(); Subtree st = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[0]); added.Add(st); var syncData = new GraphSyncData(null, added, null); liverunner.UpdateGraph(syncData); ProtoCore.Mirror.RuntimeMirror mirror = liverunner.InspectNodeValue("a"); Assert.IsTrue((Int64)mirror.GetData().Data == 1); // Modify // a = 2 List<Subtree> modified = new List<Subtree>(); st = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[1]); modified.Add(st); syncData = new GraphSyncData(null, null, modified); liverunner.UpdateGraph(syncData); mirror = liverunner.InspectNodeValue("a"); Assert.IsTrue((Int64)mirror.GetData().Data == 2); Assert.AreEqual(instrStreamStart, instrStreamEnd); }
/// <summary> /// Update graph with graph sync data. /// </summary> /// <param name="graphData"></param> /// <param name="verboseLogging"></param> public void UpdateGraph(GraphSyncData graphData, bool verboseLogging) { if (verboseLogging) Log("LRS.UpdateGraph: " + graphData); liveRunner.UpdateGraph(graphData); }
public void TestAddedNodes01() { List<string> codes = new List<string>() { "a = 1;" }; Guid guid = System.Guid.NewGuid(); List<Subtree> added = new List<Subtree>(); added.Add(CreateSubTreeFromCode(guid, codes[0])); var syncData = new GraphSyncData(null, added, null); // Get astlist from ChangeSetComputer ChangeSetComputer changeSetState = new ProtoScript.Runners.ChangeSetComputer(core); List<AssociativeNode> astList = changeSetState.GetDeltaASTList(syncData); // Get expected ASTList // The list must be in the order that it is expected List<string> expectedCode = new List<string>() { "a = 1;" }; List<AssociativeNode> expectedAstList = ProtoCore.Utils.CoreUtils.BuildASTList(core, expectedCode); // Compare ASTs to be equal for (int n = 0; n < astList.Count; ++n) { AssociativeNode node1 = astList[n]; AssociativeNode node2 = expectedAstList[n]; bool isEqual = node1.Equals(node2); Assert.IsTrue(isEqual); } }
public void TestGuidStability() { //Test to ensure that the first time the code is executed the wasTraced attribute is marked as false //and the secodn time it is marked as true string setupCode = @"import(""FFITarget.dll""); x = 0; mtcA = IncrementerTracedClass.IncrementerTracedClass(x); mtcAID = mtcA.ID; mtcAWasTraced = mtcA.WasCreatedWithTrace(); "; // Create 2 CBNs List<Subtree> added = new List<Subtree>(); // Simulate a new new CBN Guid guid1 = System.Guid.NewGuid(); added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid1, setupCode)); var syncData = new GraphSyncData(null, added, null); astLiveRunner.UpdateGraph(syncData); TestFrameWork.AssertValue("mtcAID", 0, astLiveRunner); TestFrameWork.AssertValue("mtcAWasTraced", false, astLiveRunner); var core = astLiveRunner.RuntimeCore; var ctorCallsites = core.RuntimeData.CallsiteCache.Values.Where(c => c.MethodName == "IncrementerTracedClass"); Assert.IsTrue(ctorCallsites.Count() == 1); Guid guid = ctorCallsites.First().CallSiteID; ExecuteMoreCode("x = 1;"); // Verify that a is re-executed TestFrameWork.AssertValue("mtcAID", 0, astLiveRunner); TestFrameWork.AssertValue("mtcAWasTraced", true, astLiveRunner); //Verify that the GUID has been adjusted var ctorCallsites2 = core.RuntimeData.CallsiteCache.Values.Where(c => c.MethodName == "IncrementerTracedClass"); Assert.IsTrue(ctorCallsites2.Count() == 1); Guid guid2 = ctorCallsites2.First().CallSiteID; Assert.AreEqual(guid, guid2); }
public GraphUpdateReadyEventArgs(GraphSyncData syncData, EventStatus resultStatus, String errorString) { this.SyncData = syncData; this.ResultStatus = resultStatus; this.ErrorString = errorString; if (string.IsNullOrEmpty(this.ErrorString)) this.ErrorString = ""; Errors = new List<ErrorObject>(); Warnings = new List<ErrorObject>(); }
private void SynchronizeInternal(GraphSyncData syncData, out string code) { code = string.Empty; if (syncData == null) { ResetForDeltaASTExecution(); return; } if (syncData.AddedSubtrees != null) { foreach (var st in syncData.AddedSubtrees) { Validity.Assert(st.AstNodes != null && st.AstNodes.Count > 0); ProtoCore.CodeGenDS codeGen = new ProtoCore.CodeGenDS(st.AstNodes); code += codeGen.GenerateCode(); } } if (syncData.DeletedSubtrees != null) { foreach (var st in syncData.DeletedSubtrees) { Validity.Assert(st.AstNodes != null && st.AstNodes.Count > 0); List <ProtoCore.AST.AssociativeAST.AssociativeNode> astNodeList = new List <AssociativeNode>(); foreach (var node in st.AstNodes) { if (node is BinaryExpressionNode) { (node as BinaryExpressionNode).RightNode = new NullNode(); astNodeList.Add(node); } } ProtoCore.CodeGenDS codeGen = new ProtoCore.CodeGenDS(astNodeList); code += codeGen.GenerateCode(); } } if (syncData.ModifiedSubtrees != null) { foreach (var st in syncData.ModifiedSubtrees) { Validity.Assert(st.AstNodes != null && st.AstNodes.Count > 0); ProtoCore.CodeGenDS codeGen = new ProtoCore.CodeGenDS(st.AstNodes); code += codeGen.GenerateCode(); } } CompileAndExecuteForDeltaExecution(code); }
public void UpdateGraph(GraphSyncData syncData) { while (true) { lock (taskQueue) { if (taskQueue.Count == 0) { SynchronizeInternal(syncData); return; } } } }
public GraphUpdateReadyEventArgs(GraphSyncData syncData, EventStatus resultStatus, String errorString) { this.SyncData = syncData; this.ResultStatus = resultStatus; this.ErrorString = errorString; if (string.IsNullOrEmpty(this.ErrorString)) { this.ErrorString = ""; } Errors = new List <ErrorObject>(); Warnings = new List <ErrorObject>(); }
/// <summary> /// Call this method to intialize a CompileCustomNodeAsyncTask with an /// EngineController, nodes from the corresponding CustomNodeWorkspaceModel, /// and inputs/outputs of the CustomNodeDefinition. /// </summary> /// <param name="initParams">Input parameters required for compilation of /// the CustomNodeDefinition.</param> /// <returns>Returns true if GraphSyncData is generated successfully and /// that the CompileCustomNodeAsyncTask should be scheduled for execution. /// Returns false otherwise.</returns> /// internal bool Initialize(CompileCustomNodeParams initParams) { engineController = initParams.EngineController; try { graphSyncData = engineController.ComputeSyncData(initParams); return graphSyncData != null; } catch (Exception) { return false; } }
/// <summary> /// This method is called by codes that intent to start a graph update. /// This method is called on the main thread where node collection in a /// WorkspaceModel can be safely accessed. /// </summary> /// <param name="controller">Reference to an instance of EngineController /// to assist in generating GraphSyncData object for the given set of nodes. /// </param> /// <param name="workspace">Reference to the WorkspaceModel from which a /// set of updated nodes is computed. The EngineController generates the /// resulting GraphSyncData from this list of updated nodes.</param> /// <returns>Returns true if there is any GraphSyncData, or false otherwise /// (in which case there will be no need to schedule UpdateGraphAsyncTask /// for execution).</returns> /// internal bool Initialize(EngineController controller, WorkspaceModel workspace) { try { engineController = controller; TargetedWorkspace = workspace; modifiedNodes = ComputeModifiedNodes(workspace); graphSyncData = engineController.ComputeSyncData(modifiedNodes); return graphSyncData != null; } catch (Exception) { return false; } }
/// <summary> /// This API needs to be called for every delta AST execution /// </summary> /// <param name="syncData"></param> public void UpdateGraph(GraphSyncData syncData) { while (true) { lock (taskQueue) { if (taskQueue.Count == 0) { string code = null; runnerCore.Options.IsDeltaCompile = true; SynchronizeInternal(syncData, out code); return; } } } }
/// <summary> /// This API needs to be called for every delta AST execution /// </summary> /// <param name="syncData"></param> /// public void UpdateGraph(GraphSyncData syncData) { //while (true) //{ // lock (taskQueue) // { // if (taskQueue.Count == 0) // { // string code = null; // runnerCore.Options.IsDeltaCompile = true; // SynchronizeInternal(syncData, out code); // return; // } // } //} }
public void TestPreviewModify1Node01() { List<string> codes = new List<string>() { @" a = 1; ", @" x = a; y = x; ", @" a = 10; ", }; Guid guid1 = System.Guid.NewGuid(); Guid guid2 = System.Guid.NewGuid(); // Create and run the graph [a = 1;] and [x = a; y = x;] ProtoScript.Runners.LiveRunner liveRunner = new ProtoScript.Runners.LiveRunner(); List<Subtree> added = new List<Subtree>(); added.Add(CreateSubTreeFromCode(guid1, codes[0])); added.Add(CreateSubTreeFromCode(guid2, codes[1])); var syncData = new GraphSyncData(null, added, null); liveRunner.UpdateGraph(syncData); // Modify [a = 1;] to [a = 10;] List<Subtree> modified = new List<Subtree>(); modified.Add(CreateSubTreeFromCode(guid1, codes[2])); syncData = new GraphSyncData(null, null, modified); // Get astlist from ChangeSetComputer ChangeSetComputer changeSetState = new ProtoScript.Runners.ChangeSetComputer(liveRunner.Core); List<AssociativeNode> astList = changeSetState.GetDeltaASTList(syncData); // Get the the preview guids (affected graphs) List<Guid> reachableGuidList = changeSetState.EstimateNodesAffectedByASTList(astList); // Check if the the affected guids are in the list List<Guid> expectedGuid = new List<Guid>{guid2}; AssertPreview(reachableGuidList, expectedGuid, 1); }
/// <summary> /// This method is called by code that intends to start a graph update. /// This method is called on the main thread where node collection in a /// WorkspaceModel can be safely accessed. /// </summary> /// <param name="controller">Reference to an instance of EngineController /// to assist in generating GraphSyncData object for the given set of nodes. /// </param> /// <param name="workspace">Reference to the WorkspaceModel from which a /// set of updated nodes is computed. The EngineController generates the /// resulting GraphSyncData from this list of updated nodes.</param> /// <returns>Returns true if there is any GraphSyncData, or false otherwise /// (in which case there will be no need to schedule UpdateGraphAsyncTask /// for execution).</returns> /// internal bool Initialize(EngineController controller, WorkspaceModel workspace) { try { engineController = controller; TargetedWorkspace = workspace; ModifiedNodes = ComputeModifiedNodes(workspace); graphSyncData = engineController.ComputeSyncData(workspace.Nodes, ModifiedNodes, verboseLogging); return graphSyncData != null; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("UpgradeGraphAsyncTask saw: " + e.ToString()); return false; } }
public void SimulateCBNExecution() { // DS code in a CBN node string code = @"a = 10;"; // Generate a GUID for the CBN Guid guid = System.Guid.NewGuid(); // Build data structure that contains the DS code in the CBN // This simulates Dynamo generating the CBN node data List<Subtree> added = new List<Subtree>(); added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, code)); var syncData = new GraphSyncData(null, added, null); // Sending the CBN node data to the VM // Execute the DS code liveRunner.UpdateGraph(syncData); // Verify the CBN result AssertValue("a", 10); }
/// <summary> /// Call this method to intialize a CompileCustomNodeAsyncTask with an /// EngineController and an GraphSyncData that is required to compile the /// associated custom node. /// </summary> /// <param name="initParams">Input parameters required for custom node /// graph updates.</param> /// <returns>Returns true if GraphSyncData is not empty and that the /// CompileCustomNodeAsyncTask should be scheduled for execution. Returns /// false otherwise.</returns> /// internal bool Initialize(CompileCustomNodeParams initParams) { if (initParams == null) throw new ArgumentNullException("initParams"); engineController = initParams.EngineController; graphSyncData = initParams.SyncData; if (engineController == null) throw new ArgumentNullException("engineController"); if (graphSyncData == null) throw new ArgumentNullException("graphSyncData"); var added = graphSyncData.AddedSubtrees; var deleted = graphSyncData.DeletedSubtrees; var modified = graphSyncData.ModifiedSubtrees; // Returns true if there is any actual data. return ((added != null && added.Count > 0) || (modified != null && modified.Count > 0) || (deleted != null && deleted.Count > 0)); }
public void GraphILTest_Assign01() { // Build the AST trees ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("a"), new ProtoCore.AST.AssociativeAST.IntNode(10), ProtoCore.DSASM.Operator.assign); List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); astList.Add(assign); // Instantiate GraphSyncData List<Subtree> addedList = new List<Subtree>(); addedList.Add(new Subtree(astList, System.Guid.NewGuid())); GraphSyncData syncData = new GraphSyncData(null, addedList, null); // emit the DS code from the AST tree ProtoScript.Runners.ILiveRunner liveRunner = new ProtoScript.Runners.LiveRunner(); liveRunner.UpdateGraph(syncData); ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("a"); Assert.IsTrue((Int64)mirror.GetData().Data == 10); }
/// <summary> /// Called for delta execution of AST node input /// </summary> /// <param name="astNode"></param> public void UpdateGraph(AssociativeNode astNode) { CodeBlockNode cNode = astNode as CodeBlockNode; if (cNode != null) { List<AssociativeNode> astList = cNode.Body; List<Subtree> addedList = new List<Subtree>(); addedList.Add(new Subtree(astList, System.Guid.NewGuid())); GraphSyncData syncData = new GraphSyncData(null, addedList, null); UpdateGraph(syncData); } else if (astNode is AssociativeNode) { List<AssociativeNode> astList = new List<AssociativeNode>(); astList.Add(astNode); List<Subtree> addedList = new List<Subtree>(); addedList.Add(new Subtree(astList, System.Guid.NewGuid())); GraphSyncData syncData = new GraphSyncData(null, addedList, null); UpdateGraph(syncData); } else { throw new NotImplementedException(); } }
/// <summary> /// This API needs to be called for every delta AST preview /// </summary> /// <param name="syncData"></param> public List<Guid> PreviewGraph(GraphSyncData syncData) { while (true) { lock (taskQueue) { if (taskQueue.Count == 0) { return PreviewInternal(syncData); } } Thread.Sleep(1); } }
/// <summary> /// This API needs to be called for every delta AST execution /// </summary> /// <param name="syncData"></param> public void UpdateGraph(GraphSyncData syncData) { while (true) { lock (taskQueue) { if (taskQueue.Count == 0) { SynchronizeInternal(syncData); return; } } Thread.Sleep(0); } }
/// <summary> /// Preview graph with graph sync data. /// </summary> /// <param name="graphData"></param> public List<Guid> PreviewGraph(GraphSyncData graphData, bool verboseLogging) { if (verboseLogging) Log("LRS.PreviewGraph: " + graphData); return liveRunner.PreviewGraph(graphData); }
/// <summary> /// Compiles all ASTs within the syncData to SSA /// </summary> /// <param name="syncData"></param> private void CompileToSSA(GraphSyncData syncData) { List<AssociativeNode> newASTList = null; if (null != syncData.AddedSubtrees) { foreach (Subtree st in syncData.AddedSubtrees) { if (null != st.AstNodes) { CompileToSSA(st.GUID, st.AstNodes, out newASTList); st.AstNodes.Clear(); st.AstNodes.AddRange(newASTList); } } } if (null != syncData.ModifiedSubtrees) { foreach (Subtree st in syncData.ModifiedSubtrees) { if (null != st.AstNodes) { CompileToSSA(st.GUID, st.AstNodes, out newASTList); st.AstNodes.Clear(); st.AstNodes.AddRange(newASTList); } } } if (null != syncData.DeletedSubtrees) { foreach (Subtree st in syncData.DeletedSubtrees) { if (null != st.AstNodes) { CompileToSSA(st.GUID, st.AstNodes, out newASTList); st.AstNodes.Clear(); st.AstNodes.AddRange(newASTList); } } } }
}
private void SynchronizeInternal(GraphSyncData syncData) { throw new NotImplementedException(); }
public DynamoUpdateGraphTask(GraphSyncData syncData, LiveRunner runner) : base(runner) { this.syncData = syncData; }
public void RegressMAGN747() { List<string> codes = new List<string>() { "a = 1;", }; Guid guid = System.Guid.NewGuid(); // add two nodes IEnumerable<int> index = Enumerable.Range(0, codes.Count); var added = index.Select(idx => ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[idx])).ToList(); var syncData = new GraphSyncData(null, added, null); liveRunner.UpdateGraph(syncData); ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("a"); var value = (Int64)mirror.GetData().Data; Assert.AreEqual(value, 1); // Simulate delete a = 1 and add CBN a = 2 int newval = 2; codes[0] = "a = " + newval.ToString() + ";"; var modified = index.Select(idx => ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[idx])).ToList(); List<Subtree> deletedList = new List<Subtree>(); deletedList.Add(new Subtree(null, guid)); syncData = new GraphSyncData(deletedList, null, modified); liveRunner.UpdateGraph(syncData); Console.WriteLine("a = " + liveRunner.InspectNodeValue("a").GetStringData()); AssertValue("a", newval); }
public List<AssociativeNode> GetDeltaASTList(GraphSyncData syncData) { csData = new ChangeSetData(); List<AssociativeNode> finalDeltaAstList = new List<AssociativeNode>(); finalDeltaAstList.AddRange(GetDeltaAstListDeleted(syncData.DeletedSubtrees)); finalDeltaAstList.AddRange(GetDeltaAstListAdded(syncData.AddedSubtrees)); finalDeltaAstList.AddRange(GetDeltaAstListModified(syncData.ModifiedSubtrees)); csData.ContainsDeltaAST = finalDeltaAstList.Count > 0; return finalDeltaAstList; }
private List<Guid> PreviewInternal(GraphSyncData syncData) { var previewChangeSetComputer = changeSetComputer.Clone(); // Get the list of ASTs that will be affected by syncData var previewAstList = previewChangeSetComputer.GetDeltaASTList(syncData); // Get the list of guid's affected by the astlist List<Guid> cbnGuidList = previewChangeSetComputer.EstimateNodesAffectedByASTList(previewAstList); return cbnGuidList; }
public void TestAdd01() { List<string> codes = new List<string>() { "a = 1;", "x = a; y = a; z = a; p = DummyPoint.ByCoordinates(x, y, z); px = p.X;", }; List<Guid> guids = Enumerable.Range(0, codes.Count).Select(_ => System.Guid.NewGuid()).ToList(); IEnumerable<int> index = Enumerable.Range(0, codes.Count); int shuffleCount = codes.Count; // in which add order, LiveRunner should get the same result. for (int i = 0; i < shuffleCount; ++i) { ILiveRunner liveRunner = new ProtoScript.Runners.LiveRunner(); liveRunner.ResetVMAndResyncGraph(new List<string> { "FFITarget.dll" }); index = index.OrderBy(_ => randomGen.Next()); var added = index.Select(idx => ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guids[idx], codes[idx])).ToList(); var syncData = new GraphSyncData(null, added, null); liveRunner.UpdateGraph(syncData); ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("px"); var value = (double)mirror.GetData().Data; Assert.AreEqual(value, 1); } }
public void GraphILTest_DeletedNode01() { //==================================== // Create a = 10 // Execute and verify a = 10 // Delete a = 10 // Create b = a // Execute and verify b = null //==================================== // Create a = 10 // Execute and verify a = 10 ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("a"), new ProtoCore.AST.AssociativeAST.IntNode(10), ProtoCore.DSASM.Operator.assign); List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); astList.Add(assign); Guid guid = System.Guid.NewGuid(); // Instantiate GraphSyncData List<Subtree> addedList = new List<Subtree>(); addedList.Add(new Subtree(astList, guid)); GraphSyncData syncData = new GraphSyncData(null, addedList, null); // emit the DS code from the AST tree liveRunner = new ProtoScript.Runners.LiveRunner(); liveRunner.UpdateGraph(syncData); ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("a"); Assert.IsTrue((Int64)mirror.GetData().Data == 10); // Delete a = 10 List<Subtree> deletedList = new List<Subtree>(); deletedList.Add(new Subtree(null, guid)); syncData = new GraphSyncData(deletedList, null, null); liveRunner.UpdateGraph(syncData); // Create b = a // Execute and verify b = null ProtoCore.AST.AssociativeAST.BinaryExpressionNode assign2 = new ProtoCore.AST.AssociativeAST.BinaryExpressionNode( new ProtoCore.AST.AssociativeAST.IdentifierNode("b"), new ProtoCore.AST.AssociativeAST.IdentifierNode("a"), ProtoCore.DSASM.Operator.assign); astList = new List<ProtoCore.AST.AssociativeAST.AssociativeNode>(); astList.Add(assign2); guid = System.Guid.NewGuid(); // Instantiate GraphSyncData addedList = new List<Subtree>(); addedList.Add(new Subtree(astList, guid)); syncData = new GraphSyncData(null, addedList, null); // emit the DS code from the AST tree liveRunner.UpdateGraph(syncData); mirror = liveRunner.InspectNodeValue("b"); Assert.IsTrue(mirror.GetData().IsNull); }
public GraphUpdateReadyEventArgs(GraphSyncData syncData) : this(syncData, EventStatus.OK, null) { }
private void SynchronizeInternal(GraphSyncData syncData) { runnerCore.Options.IsDeltaCompile = true; if (syncData == null) { ResetForDeltaExecution(); return; } // Get AST list that need to be executed var finalDeltaAstList = changeSetComputer.GetDeltaASTList(syncData); changeSetComputer.UpdateCachedASTFromSubtrees(syncData.ModifiedSubtrees); // Prior to execution, apply state modifications to the VM given the delta AST's changeSetApplier.Apply(runnerCore, runtimeCore, changeSetComputer.csData); CompileAndExecuteForDeltaExecution(finalDeltaAstList); }
public void TestModify01() { List<string> codes = new List<string>() { "a = 1;", "x = a; y = a; z = a; p = DummyPoint.ByCoordinates(x, y, z); px = p.X;", }; List<Guid> guids = Enumerable.Range(0, codes.Count).Select(_ => System.Guid.NewGuid()).ToList(); // add two nodes IEnumerable<int> index = Enumerable.Range(0, codes.Count); var added = index.Select(idx => ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guids[idx], codes[idx])).ToList(); var syncData = new GraphSyncData(null, added, null); liveRunner.UpdateGraph(syncData); ProtoCore.Mirror.RuntimeMirror mirror = liveRunner.InspectNodeValue("px"); var value = (double)mirror.GetData().Data; Assert.AreEqual(value, 1); for (int i = 0; i < 10; ++i) { codes[0] = "a = " + i.ToString() + ";"; var modified = index.Select(idx => ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guids[idx], codes[idx])).ToList(); syncData = new GraphSyncData(null, null, modified); liveRunner.UpdateGraph(syncData); mirror = liveRunner.InspectNodeValue("px"); value = (double)mirror.GetData().Data; Assert.AreEqual(value, i); } }
public void SimulateConnectedCBNReExecution() { // Simulate 2 CBNs where one is connected to the other // [a = 1]----->[x = a] // // Modify CBN 1 // [a = 10]----->[x = a] List<string> codes = new List<string>() { @"a = 10;", // CBN 1 contents @"x = a;", // CBN 2 contents @"a = 20;" // CBN 1 modified contents }; // Simulate 2 CBNs Guid cbnGuid1 = System.Guid.NewGuid(); Guid cbnGuid2 = System.Guid.NewGuid(); List<Subtree> added = new List<Subtree>(); added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(cbnGuid1, codes[0])); added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(cbnGuid2, codes[1])); var syncData = new GraphSyncData(null, added, null); // Sending the CBN node data to the VM liveRunner.UpdateGraph(syncData); // Verify the values of the variables in the CBNs AssertValue("a", 10); AssertValue("x", 10); // Modify the CBN 1 only List<Subtree> modified = new List<Subtree>(); Subtree subtree = ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(cbnGuid1, codes[2]); modified.Add(subtree); syncData = new GraphSyncData(null, null, modified); // Sending the CBN node data to the VM liveRunner.UpdateGraph(syncData); // Verify that both variables have been modified AssertValue("a", 20); AssertValue("x", 20); }
public void TestModifyReplicationGuide01() { List<string> codes = new List<string>() { @" a = (1..2) + (1..2); i = a[0]; ", @" a = (1..2)<1> + (1..2)<2>; i = a[0][0]; " }; Guid guid = System.Guid.NewGuid(); List<Subtree> added = new List<Subtree>(); added.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[0])); var syncData = new GraphSyncData(null, added, null); liveRunner.UpdateGraph(syncData); AssertValue("i", 2); // Modify function def - removed imperative block List<Subtree> modified = new List<Subtree>(); modified.Add(ProtoTestFx.TD.TestFrameWork.CreateSubTreeFromCode(guid, codes[1])); syncData = new GraphSyncData(null, null, modified); liveRunner.UpdateGraph(syncData); AssertValue("i", 2); }