public void ExecuteSequence() { var currentVersion = new Version("1.0"); var updateTo2 = new Mock <IScript>(MockBehavior.Strict); updateTo2.SetupGet(s => s.DisplayName).Returns("2.0"); var updateTo3 = new Mock <IScript>(MockBehavior.Strict); updateTo3.SetupGet(s => s.DisplayName).Returns("3.0"); var stepTo2 = new ScriptStep(currentVersion, new Version("2.0"), updateTo2.Object); var stepTo3 = new ScriptStep(new Version("2.0"), new Version("3.0"), updateTo3.Object); _database.Setup(d => d.GetCurrentVersion()).Returns(currentVersion); _database .Setup(d => d.Execute(updateTo2.Object, stepTo2.From, stepTo2.To)) .Callback(() => _database.Setup(d => d.Execute(updateTo3.Object, stepTo3.From, stepTo3.To))); _scriptSequence.Setup(s => s.BuildSequence(currentVersion)).Returns(new[] { stepTo2, stepTo3 }); _sut.Execute(); _database.VerifyAll(); _scriptSequence.VerifyAll(); }
public void StopExecutionOnError() { var currentVersion = new Version("1.0"); var updateTo2 = new Mock <IScript>(MockBehavior.Strict); updateTo2.SetupGet(s => s.DisplayName).Returns("2.0"); var updateTo3 = new Mock <IScript>(MockBehavior.Strict); updateTo3.SetupGet(s => s.DisplayName).Returns("3.0"); var stepTo2 = new ScriptStep(currentVersion, new Version("2.0"), updateTo2.Object); var stepTo3 = new ScriptStep(new Version("2.0"), new Version("3.0"), updateTo3.Object); _database.Setup(d => d.GetCurrentVersion()).Returns(currentVersion); _database.Setup(d => d.Execute(updateTo2.Object, stepTo2.From, stepTo2.To)).Throws <InvalidOperationException>(); _scriptSequence.Setup(s => s.BuildSequence(currentVersion)).Returns(new[] { stepTo2, stepTo3 }); Assert.Throws <InvalidOperationException>(_sut.Execute); _database.VerifyAll(); _scriptSequence.VerifyAll(); }
private void DiagnosticButton_Click(object sender, RoutedEventArgs e) { var CompleteSyntax = ScriptStep.GenerateUsingSyntax() + editor.Text; AssemblyGenerator.CompileCode(CompleteSyntax, out string diagnosticMessage); DiagnosticTextBox.Text = diagnosticMessage; }
public MainWindow() { InitializeComponent(); var programText = ScriptStep.GetInitialScript(); editor.Text = programText; }
void Repeat() { switch (currentStep) { case ScriptStep.Step1A: case ScriptStep.Step1B: case ScriptStep.Step1C: currentStep = ScriptStep.Step1A; break; case ScriptStep.Step2A: case ScriptStep.Step2B: case ScriptStep.Step2C: case ScriptStep.Step2D: currentStep = ScriptStep.Step2A; break; case ScriptStep.Step3A: case ScriptStep.Step3B: case ScriptStep.Step3C: currentStep = ScriptStep.Step3A; break; case ScriptStep.Step4A: case ScriptStep.Step4B: case ScriptStep.Step4C: currentStep = ScriptStep.Step4A; break; case ScriptStep.Step5A: case ScriptStep.Step5B: case ScriptStep.Step5C: case ScriptStep.Step5D: currentStep = ScriptStep.Step5A; break; case ScriptStep.Step6A: case ScriptStep.Step6B: case ScriptStep.Step6C: case ScriptStep.Step6D: currentStep = ScriptStep.Step6A; break; case ScriptStep.Step7A: case ScriptStep.Step7B: case ScriptStep.Step7C: currentStep = ScriptStep.Step7A; break; case ScriptStep.Step8A: case ScriptStep.Step8B: case ScriptStep.Step8C: currentStep = ScriptStep.Step8A; break; default: break; } }
private List <ScriptStep> SampleScripStep() { var CompleteSyntax = ScriptStep.GenerateUsingSyntax() + editor.Text; List <ScriptStep> scriptSteps = new List <ScriptStep>(); scriptSteps.Add(new ScriptStep(CompleteSyntax) { LowerLimit = 110, UpperLimit = 200, Value = 150, Number = 1, Description = "1 voltage", stepTypes = StepTypes.ScriptStep }); scriptSteps.Add(new ScriptStep(CompleteSyntax) { LowerLimit = 120, UpperLimit = 200, Value = 210, Number = 2, Description = "2 voltage", stepTypes = StepTypes.JumpStep, NumberofExecution = 3, JumpToNumber = 1 }); scriptSteps.Add(new ScriptStep(CompleteSyntax) { LowerLimit = 130, UpperLimit = 200, Value = 150, Number = 3, Description = "3 voltage", stepTypes = StepTypes.ScriptStep }); scriptSteps.Add(new ScriptStep(CompleteSyntax) { LowerLimit = 140, UpperLimit = 200, Value = 100, Number = 4, Description = "4 voltage", stepTypes = StepTypes.JumpStep,//jumpstep NumberofExecution = 3, JumpToNumber = 3 }); scriptSteps.Add(new ScriptStep(CompleteSyntax) { LowerLimit = 100, UpperLimit = 200, Value = 50, Number = 5, Description = "5 voltage", stepTypes = StepTypes.ScriptStep }); return(scriptSteps); }
void Proceed(object sender, ElapsedEventArgs e) { waitTimer.Enabled = false; waitTimer.Interval = WAIT_TIME; humanMoveComplete = false; moveLogged = false; leftAtTarget = false; rightAtTarget = false; wilsonState = 0; if (goBack) { // try again if (currentStep < ScriptStep.Step2A) { currentStep = ScriptStep.Step1A; } else if (currentStep < ScriptStep.Step3A) { currentStep = ScriptStep.Step2A; } else if (currentStep < ScriptStep.Step4A) { currentStep = ScriptStep.Step3A; } else if (currentStep < ScriptStep.Step5A) { currentStep = ScriptStep.Step4A; } else if (currentStep < ScriptStep.Step6A) { currentStep = ScriptStep.Step5A; } else if (currentStep < ScriptStep.Step7A) { currentStep = ScriptStep.Step6A; } else if (currentStep < ScriptStep.Step8A) { currentStep = ScriptStep.Step7A; } else if (currentStep < ScriptStep.Step9A) { currentStep = ScriptStep.Step8A; } else if (currentStep < ScriptStep.Step10) { currentStep = ScriptStep.Step9A; } } else { currentStep = (ScriptStep)((int)currentStep + 1); } }
void OnEnable() { // set default state foreach (string obj in defaultState.Keys) { GameObject.Find(obj).transform.position = defaultState[obj]; GameObject.Find(obj).GetComponent <Voxeme>().targetPosition = defaultState[obj]; } currentStep = ScriptStep.Step0; }
// Use this for initialization void Start() { base.Start(); Wilson = GameObject.Find("Wilson"); Diana = GameObject.Find("Diana"); animator = Wilson.GetComponent <Animator>(); relationTracker = GameObject.Find("BehaviorController").GetComponent <RelationTracker>(); eventManager = GameObject.Find("BehaviorController").GetComponent <EventManager>(); inputController = GameObject.Find("IOController").GetComponent <InputController>(); leftGrasper = animator.GetBoneTransform(HumanBodyBones.LeftHand).transform.gameObject; rightGrasper = animator.GetBoneTransform(HumanBodyBones.RightHand).transform.gameObject; graspController = Wilson.GetComponent <GraspScript>(); ikControl = Wilson.GetComponent <IKControl>(); leftTarget = ikControl.leftHandObj.GetComponent <IKTarget>(); rightTarget = ikControl.rightHandObj.GetComponent <IKTarget>(); headTarget = ikControl.lookObj.GetComponent <IKTarget>(); outputModality = GameObject.Find("OutputModality").GetComponent <OutputModality>(); goBack = false; currentStep = ScriptStep.Step0; waitTimer = new Timer(WAIT_TIME); waitTimer.Enabled = false; waitTimer.Elapsed += Proceed; humanMoveComplete = false; leftAtTarget = false; rightAtTarget = false; inputController.InputReceived += HumanInputReceived; eventManager.QueueEmpty += HumanMoveComplete; eventManager.ForceClear += EventsForceCleared; leftTarget.AtTarget += LeftAtTarget; rightTarget.AtTarget += RightAtTarget; OpenLog(demoName, outputModality.modality); }
void Repeat() { switch (currentStep) { case ScriptStep.Step1A: case ScriptStep.Step1B: case ScriptStep.Step1C: case ScriptStep.Step1D: currentStep = ScriptStep.Step1A; break; case ScriptStep.Step2A: case ScriptStep.Step2B: case ScriptStep.Step2C: case ScriptStep.Step2D: currentStep = ScriptStep.Step2A; break; case ScriptStep.Step3A: case ScriptStep.Step3B: case ScriptStep.Step3C: currentStep = ScriptStep.Step3A; break; case ScriptStep.Step4A: case ScriptStep.Step4B: case ScriptStep.Step4C: currentStep = ScriptStep.Step4A; break; case ScriptStep.Step5A: case ScriptStep.Step5B: case ScriptStep.Step5C: currentStep = ScriptStep.Step5A; break; default: break; } }
// Update is called once per frame void Update() { base.Update(); if (currentStep == ScriptStep.Step0) { if ((int)(wilsonState & WilsonState.Rest) == 0) { waitTimer.Interval = WAIT_TIME + initialLeaderTime; waitTimer.Enabled = true; wilsonState |= (WilsonState.Rest | WilsonState.LookForward); Rest(); LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("Please help me build something!"); } } } if (currentStep == ScriptStep.Step1A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; string objName = "block8"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("Take that block"); } } } if (currentStep == ScriptStep.Step1B) { string objName = "block2"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("And put it behind that block"); } } } if (currentStep == ScriptStep.Step1C) { string obj1Name = "block8"; string obj2Name = "block2"; if ((int)(wilsonState & WilsonState.Claw) == 0) { wilsonState |= (WilsonState.Claw | WilsonState.LookForward); Claw(GameObject.Find(obj1Name).transform.position, GameObject.Find(obj2Name).transform.position - (Vector3.forward * 0.5f)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, string.Format("behind({0}, Persp = Wilson)", obj2Name)))); LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find(obj1Name), GameObject.Find(obj2Name) }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("in_front") && relations.Contains("touching")) { satisfied = true; break; } } } if (humanMoveComplete) { CheckAgreement(satisfied); } } } if (currentStep == ScriptStep.Step2A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; string objName = "block3"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("Take that block"); } } } if (currentStep == ScriptStep.Step2B) { string objName = "block2"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("And put it in front of that block"); } } } if (currentStep == ScriptStep.Step2C) { string obj1Name = "block3"; string obj2Name = "block2"; if ((int)(wilsonState & WilsonState.Claw) == 0) { wilsonState |= (WilsonState.Claw | WilsonState.LookForward); Claw(GameObject.Find(obj1Name).transform.position, GameObject.Find(obj2Name).transform.position + (Vector3.forward * 0.5f)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, string.Format("in_front({0}, Persp = Wilson)", obj2Name)))); LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find(obj1Name), GameObject.Find(obj2Name) }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("behind") && relations.Contains("touching")) { satisfied = true; break; } } } if (humanMoveComplete) { CheckAgreement(satisfied); } } } if (currentStep == ScriptStep.Step3A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; string objName = "block5"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("Take that block"); } } } if (currentStep == ScriptStep.Step3B) { string objName = "block3"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("And that block"); } } } if (currentStep == ScriptStep.Step3C) { if ((int)(wilsonState & WilsonState.LookForward) == 0) { wilsonState |= WilsonState.LookForward; LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } leftTarget.targetPosition = new Vector3(1.0f, 2.5f, 0.0f); rightTarget.targetPosition = new Vector3(-1.0f, 2.5f, 0.0f); if (leftAtTarget && rightAtTarget) { currentStep = (ScriptStep)((int)currentStep + 1); } } if (currentStep == ScriptStep.Step3D) { string obj1Name = "block5"; string obj2Name = "block3"; if ((int)(wilsonState & WilsonState.PushTogether) == 0) { wilsonState |= WilsonState.PushTogether; PushTogether(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("And put them together"); } } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find(obj1Name), GameObject.Find(obj2Name) }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("left") && relations.Contains("touching")) { satisfied = true; break; } } } if (humanMoveComplete) { CheckAgreement(satisfied); } } } if (currentStep == ScriptStep.Step4A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; string objName = "block1"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("Take that block"); } } } if (currentStep == ScriptStep.Step4B) { string objName = "block3"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("And that block"); } } } if (currentStep == ScriptStep.Step4C) { if ((int)(wilsonState & WilsonState.LookForward) == 0) { wilsonState |= WilsonState.LookForward; LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } leftTarget.targetPosition = new Vector3(1.0f, 2.5f, 0.0f); rightTarget.targetPosition = new Vector3(-1.0f, 2.5f, 0.0f); if (leftAtTarget && rightAtTarget) { currentStep = (ScriptStep)((int)currentStep + 1); } } if (currentStep == ScriptStep.Step4D) { string obj1Name = "block1"; string obj2Name = "block3"; if ((int)(wilsonState & WilsonState.PushTogether) == 0) { wilsonState |= WilsonState.PushTogether; PushTogether(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("And put them together"); } } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find(obj1Name), GameObject.Find(obj2Name) }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("right") && relations.Contains("touching")) { satisfied = true; break; } } } if (humanMoveComplete) { CheckAgreement(satisfied); } } } if (currentStep == ScriptStep.Step5A) { string objName = "block7"; currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("Take that block"); } } } if (currentStep == ScriptStep.Step5B) { string objName = "block3"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("And put it on that block"); } } } if (currentStep == ScriptStep.Step5C) { string obj1Name = "block7"; string obj2Name = "block3"; if ((int)(wilsonState & WilsonState.Claw) == 0) { wilsonState |= (WilsonState.Claw | WilsonState.LookForward); Claw(GameObject.Find(obj1Name).transform.position, GameObject.Find(obj2Name).transform.position); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, obj2Name))); LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find(obj2Name), GameObject.Find(obj1Name) }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("support")) { satisfied = true; break; } } } if (humanMoveComplete) { CheckAgreement(satisfied); } } } if (currentStep == ScriptStep.Step6A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; string objName = "block6"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("Take that block"); } } } if (currentStep == ScriptStep.Step6B) { string objName = "block3"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("And put it in front of that block"); } } } if (currentStep == ScriptStep.Step6C) { string obj1Name = "block6"; string obj2Name = "block3"; if ((int)(wilsonState & WilsonState.Claw) == 0) { wilsonState |= (WilsonState.Claw | WilsonState.LookForward); Claw(GameObject.Find(obj1Name).transform.position, GameObject.Find(obj2Name).transform.position + (Vector3.forward * 0.5f)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, string.Format("in_front({0}, Persp = Wilson)", obj2Name)))); LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find(obj1Name), GameObject.Find(obj2Name) }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("behind") && relations.Contains("touching")) { satisfied = true; break; } } } if (humanMoveComplete) { CheckAgreement(satisfied); } } } if (currentStep == ScriptStep.Step7A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; string objName = "block4"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("Take that block"); } } } if (currentStep == ScriptStep.Step7B) { string objName = "block6"; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find(objName)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, objName))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("And put it in front of that block"); } } } if (currentStep == ScriptStep.Step7C) { string obj1Name = "block4"; string obj2Name = "block6"; if ((int)(wilsonState & WilsonState.Claw) == 0) { wilsonState |= (WilsonState.Claw | WilsonState.LookForward); Claw(GameObject.Find(obj1Name).transform.position, GameObject.Find(obj2Name).transform.position + (Vector3.forward * 0.5f)); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, string.Format("in_front({0}, Persp = Wilson)", obj2Name)))); LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find(obj1Name), GameObject.Find(obj2Name) }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("behind") && relations.Contains("touching")) { satisfied = true; break; } } } if (humanMoveComplete) { CheckAgreement(satisfied); } } } if (currentStep == ScriptStep.Step8) { if ((int)(wilsonState & WilsonState.Rest) == 0) { wilsonState |= WilsonState.Rest; Rest(); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { PrintAndLogLinguisticOutput("OK, we're done!"); } CloseLog(); } } }
// Update is called once per frame void Update() { base.Update(); if (currentStep == ScriptStep.Step0) { if ((int)(wilsonState & WilsonState.Rest) == 0) { waitTimer.Interval = WAIT_TIME + initialLeaderTime; waitTimer.Enabled = true; wilsonState |= (WilsonState.Rest | WilsonState.LookForward); Rest(); LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Let's build a pyramid!"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Let's build a pyramid!\"")); } } } if (currentStep == ScriptStep.Step1A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find("block1")); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block1"))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Take that block"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Take that block\"")); } } } if (currentStep == ScriptStep.Step1B) { if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find("block3")); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block3"))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "And that block"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"And that block\"")); } } } if (currentStep == ScriptStep.Step1C) { if ((int)(wilsonState & WilsonState.LookForward) == 0) { wilsonState |= WilsonState.LookForward; LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } leftTarget.targetPosition = new Vector3(1.0f, 2.5f, 0.0f); rightTarget.targetPosition = new Vector3(-1.0f, 2.5f, 0.0f); if (leftAtTarget && rightAtTarget) { currentStep = (ScriptStep)((int)currentStep + 1); } } if (currentStep == ScriptStep.Step1D) { if ((int)(wilsonState & WilsonState.PushTogether) == 0) { wilsonState |= WilsonState.PushTogether; PushTogether(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "And put them together"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"And put them together\"")); } } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find("block1"), GameObject.Find("block3") }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("right") && relations.Contains("touching")) { satisfied = true; break; } } } if (humanMoveComplete) { List <object> diff = GlobalHelper.DiffLists(currentState, relationTracker.relStrings.Cast <object>().ToList()); OnLogEvent(this, new LogEventArgs("Result: " + string.Join(";", diff.Cast <string>().ToArray()))); if (satisfied) { OnLogEvent(this, new LogEventArgs("Wilson: Resp = Agreement")); if ((int)(wilsonState & (WilsonState.ThumbsUp | WilsonState.HeadNod)) == 0) { waitTimer.Enabled = true; wilsonState |= (WilsonState.ThumbsUp | WilsonState.HeadNod); ThumbsUp(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); HeadNod(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Great!"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Great!\"")); } } } else { OnLogEvent(this, new LogEventArgs("Wilson: Resp = Disgreement")); if ((int)(wilsonState & WilsonState.HeadShake) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.HeadShake; HeadShake(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "That's not quite what I had in mind."); OnLogEvent(this, new LogEventArgs("Wilson: S = \"That's not quite what I had in mind.\"")); goBack = true; } } } moveLogged = true; } } } if (currentStep == ScriptStep.Step2A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find("block2")); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block2"))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Take that block"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Take that block\"")); } } } if (currentStep == ScriptStep.Step2B) { if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find("block3")); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block3"))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "And that block"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"And that block\"")); } } } if (currentStep == ScriptStep.Step2C) { if ((int)(wilsonState & WilsonState.LookForward) == 0) { wilsonState |= WilsonState.LookForward; LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } leftTarget.targetPosition = new Vector3(1.0f, 2.5f, 0.0f); rightTarget.targetPosition = new Vector3(-1.0f, 2.5f, 0.0f); if (leftAtTarget && rightAtTarget) { currentStep = (ScriptStep)((int)currentStep + 1); } } if (currentStep == ScriptStep.Step2D) { if ((int)(wilsonState & WilsonState.PushTogether) == 0) { wilsonState |= WilsonState.PushTogether; PushTogether(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "And put them together"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"And put them together\"")); } } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find("block2"), GameObject.Find("block3") }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("left") && relations.Contains("touching")) { satisfied = true; break; } } } if (humanMoveComplete) { List <object> diff = GlobalHelper.DiffLists(currentState, relationTracker.relStrings.Cast <object>().ToList()); OnLogEvent(this, new LogEventArgs("Result: " + string.Join(";", diff.Cast <string>().ToArray()))); if (satisfied) { OnLogEvent(this, new LogEventArgs("Wilson: Resp = Agreement")); if ((int)(wilsonState & (WilsonState.ThumbsUp | WilsonState.HeadNod)) == 0) { waitTimer.Enabled = true; wilsonState |= (WilsonState.ThumbsUp | WilsonState.HeadNod); ThumbsUp(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); HeadNod(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Great!"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Great!\"")); } } } else { OnLogEvent(this, new LogEventArgs("Wilson: Resp = Disagreement")); if ((int)(wilsonState & WilsonState.HeadShake) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.HeadShake; HeadShake(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "That's not quite what I had in mind."); OnLogEvent(this, new LogEventArgs("Wilson: S = \"That's not quite what I had in mind.\"")); goBack = true; } } } } moveLogged = true; } } if (currentStep == ScriptStep.Step3A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find("block4")); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block4"))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Take that block"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Take that block\"")); } } } if (currentStep == ScriptStep.Step3B) { if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find("block3")); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block3"))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "And put it behind that block"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"And put it behind that block\"")); } } } if (currentStep == ScriptStep.Step3C) { if ((int)(wilsonState & WilsonState.Claw) == 0) { wilsonState |= (WilsonState.Claw | WilsonState.LookForward); Claw(GameObject.Find("block4").transform.position, GameObject.Find("block3").transform.position - (Vector3.forward * 0.5f)); OnLogEvent(this, new LogEventArgs( "Wilson: G = " + string.Format(mostRecentGesture, "behind(block3, Persp = Wilson)"))); LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find("block4"), GameObject.Find("block3") }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("in_front")) { satisfied = true; break; } } } if (humanMoveComplete) { List <object> diff = GlobalHelper.DiffLists(currentState, relationTracker.relStrings.Cast <object>().ToList()); OnLogEvent(this, new LogEventArgs("Result: " + string.Join(";", diff.Cast <string>().ToArray()))); if (satisfied) { OnLogEvent(this, new LogEventArgs("Wilson: Resp = Agreement")); if ((int)(wilsonState & (WilsonState.ThumbsUp | WilsonState.HeadNod)) == 0) { waitTimer.Enabled = true; wilsonState |= (WilsonState.ThumbsUp | WilsonState.HeadNod); ThumbsUp(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); HeadNod(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Great!"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Great!\"")); } } } else { OnLogEvent(this, new LogEventArgs("Wilson: Resp = Disagreement")); if ((int)(wilsonState & WilsonState.HeadShake) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.HeadShake; HeadShake(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "That's not quite what I had in mind."); OnLogEvent(this, new LogEventArgs("Wilson: S = \"That's not quite what I had in mind.\"")); goBack = true; } } } moveLogged = true; } } } if (currentStep == ScriptStep.Step4A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find("block5")); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block5"))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Take that block"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Take that block\"")); } } } if (currentStep == ScriptStep.Step4B) { if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find("block3")); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block3"))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "And put it in front of that block"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"And put it in front of that block\"")); } } } if (currentStep == ScriptStep.Step4C) { if ((int)(wilsonState & WilsonState.Claw) == 0) { wilsonState |= (WilsonState.Claw | WilsonState.LookForward); Claw(GameObject.Find("block5").transform.position, GameObject.Find("block3").transform.position + Vector3.forward); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "in_front(block3, Persp = Wilson)"))); LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find("block5"), GameObject.Find("block3") }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("behind")) { satisfied = true; break; } } } if (humanMoveComplete) { List <object> diff = GlobalHelper.DiffLists(currentState, relationTracker.relStrings.Cast <object>().ToList()); OnLogEvent(this, new LogEventArgs("Result: " + string.Join(";", diff.Cast <string>().ToArray()))); if (satisfied) { OnLogEvent(this, new LogEventArgs("Response: Agreement")); if ((int)(wilsonState & (WilsonState.ThumbsUp | WilsonState.HeadNod)) == 0) { waitTimer.Enabled = true; wilsonState |= (WilsonState.ThumbsUp | WilsonState.HeadNod); ThumbsUp(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); HeadNod(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Great!"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Great!\"")); } } } else { OnLogEvent(this, new LogEventArgs("Response: Disagreement")); if ((int)(wilsonState & WilsonState.HeadShake) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.HeadShake; HeadShake(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "That's not quite what I had in mind."); OnLogEvent(this, new LogEventArgs("Wilson: S = \"That's not quite what I had in mind.\"")); goBack = true; } } } moveLogged = true; } } } if (currentStep == ScriptStep.Step5A) { currentState = relationTracker.relStrings.Cast <object>().ToList(); goBack = false; if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find("block6")); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block6"))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Take that block"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Take that block\"")); } } } if (currentStep == ScriptStep.Step5B) { if ((int)(wilsonState & WilsonState.Point) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.Point; PointAt(GameObject.Find("block3")); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block3"))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "And put it on that block"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"And put it on that block\"")); } } } if (currentStep == ScriptStep.Step5C) { if ((int)(wilsonState & WilsonState.Claw) == 0) { wilsonState |= (WilsonState.Claw | WilsonState.LookForward); Claw(GameObject.Find("block6").transform.position, GameObject.Find("block3").transform.position); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture, "block3"))); LookForward(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); } else { bool satisfied = false; foreach (List <GameObject> key in relationTracker.relations.Keys) { if (key.SequenceEqual(new List <GameObject>(new GameObject[] { GameObject.Find("block3"), GameObject.Find("block6") }))) { string[] relations = relationTracker.relations[key].ToString().Split(','); if (relations.Contains("support")) { satisfied = true; break; } } } if (humanMoveComplete) { List <object> diff = GlobalHelper.DiffLists(currentState, relationTracker.relStrings.Cast <object>().ToList()); OnLogEvent(this, new LogEventArgs("Result: " + string.Join(";", diff.Cast <string>().ToArray()))); if (satisfied) { OnLogEvent(this, new LogEventArgs("Response: Agreement")); if ((int)(wilsonState & (WilsonState.ThumbsUp | WilsonState.HeadNod)) == 0) { waitTimer.Enabled = true; wilsonState |= (WilsonState.ThumbsUp | WilsonState.HeadNod); ThumbsUp(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); HeadNod(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "Great!"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"Great!\"")); } } } else { OnLogEvent(this, new LogEventArgs("Response: Disagreement")); if ((int)(wilsonState & WilsonState.HeadShake) == 0) { waitTimer.Enabled = true; wilsonState |= WilsonState.HeadShake; HeadShake(); OnLogEvent(this, new LogEventArgs("Wilson: G = " + string.Format(mostRecentGesture))); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "That's not quite what I had in mind."); OnLogEvent(this, new LogEventArgs("Wilson: S = \"That's not quite what I had in mind.\"")); goBack = true; } } } moveLogged = true; } } } if (currentStep == ScriptStep.Step6) { if ((int)(wilsonState & WilsonState.Rest) == 0) { wilsonState |= WilsonState.Rest; Rest(); if ((int)(outputModality.modality & OutputModality.Modality.Linguistic) == 1) { OutputHelper.PrintOutput(Role.Planner, "OK, we're done!"); OnLogEvent(this, new LogEventArgs("Wilson: S = \"OK, we're done!\"")); } CloseLog(); } } /*if (Input.GetKeyDown (KeyCode.Space)) { * wilsonState = 0; * currentStep = (DemoStep)((int)currentStep + 1); * }*/ }
//Script解析:核心 public bool ExcuteScript(ScriptStep _Step) { Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); Workbook workBook = null; object oMissiong = Missing.Value; object[,] data = null; try { for (int i = 0; i < _Script_Step.StepCounts; ++i) { if (_Script_Step.m_Step[i].ScriptType == 1) { workBook = app.Workbooks.Open(m_Edit_File_Excel.Text, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong, oMissiong); if (workBook == null) { return(false); } } else if (_Script_Step.m_Step[i].ScriptType == 2) { Worksheet workSheet = (Worksheet)workBook.Worksheets.Item[_Script_Step.m_Step[i].Position_X]; data = workSheet.Range[_Script_Step.m_Step[i].StringBuffer].Value2; m_Edit_Process.AppendText("---->Info: Open worksheet " + workSheet.Name + "\r\n"); } else if (_Script_Step.m_Step[i].ScriptType == 5) { if (_Script_Step.m_Step[i].StringBuffer != "#NULL") { m_Edit_Process.AppendText(_Script_Step.m_Step[i].StringBuffer + "\r\n"); } else { m_Edit_Process.AppendText("\r\n"); } } else if (_Script_Step.m_Step[i].ScriptType == 6) { string m_Check = (_Script_Step.m_Step[i].StringCheck != "#NULL") ? _Script_Step.m_Step[i].StringCheck : string.Empty; string m_Buffer = (_Script_Step.m_Step[i].StringBuffer != "#NULL") ? _Script_Step.m_Step[i].StringBuffer : string.Empty; if (_Script_Step.m_Step[i].CaculatorSymbol == "==") { if (Convert.ToString(data[_Script_Step.m_Step[i].Position_Y, _Script_Step.m_Step[i].Position_X]) != m_Check) { m_Edit_Process.AppendText(m_Buffer + "\r\n"); } } else if (_Script_Step.m_Step[i].CaculatorSymbol == "!=") { if (Convert.ToString(data[_Script_Step.m_Step[i].Position_Y, _Script_Step.m_Step[i].Position_X]) == m_Check) { m_Edit_Process.AppendText(m_Buffer + "\r\n"); } } else { m_Edit_Process.AppendText(string.Format("ScriptStep:{0:D} Error:Invalid CaculatorSymbol!\r\n", i)); return(false); } } else if (_Script_Step.m_Step[i].ScriptType == 7) { string m_Check = (_Script_Step.m_Step[i].StringCheck != "#NULL") ? _Script_Step.m_Step[i].StringCheck : string.Empty; string m_Buffer = (_Script_Step.m_Step[i].StringBuffer != "#NULL") ? _Script_Step.m_Step[i].StringBuffer : string.Empty; string m_NRCDes = (_Script_Step.m_Step[i].M_NRC_Des != "#NULL") ? _Script_Step.m_Step[i].StringBuffer : string.Empty; string u_NRCDes = (_Script_Step.m_Step[i].U_NRC_Des != "#NULL") ? _Script_Step.m_Step[i].StringBuffer : string.Empty; bool _Flag = false; string _BufferText = _Script_Step.m_Step[i].M_NRC_Des; string _NRC = Convert.ToString(data[_Script_Step.m_Step[i].Position_Y, _Script_Step.m_Step[i].Position_X]); //首先分割必须支持的NRC if (m_Buffer != string.Empty) { string[] M_NRC = m_Buffer.Split('-'); for (int j = 0; j < M_NRC.Length; ++j) { if (_NRC.Contains(M_NRC[j]) == false) { _BufferText = _BufferText + " " + M_NRC[j]; _Flag = true; } } if (_Flag) { m_Edit_Process.AppendText(_BufferText + "\r\n"); } } //分割不需要支持的NRC if (m_Check != string.Empty) { string[] U_NRC = m_Check.Split('-'); string _BufferTextU = _Script_Step.m_Step[i].U_NRC_Des; _Flag = false; for (int j = 0; j < U_NRC.Length; ++j) { if (_NRC.Contains(U_NRC[j]) == true) { _BufferTextU = _BufferTextU + " " + U_NRC[j]; _Flag = true; } } if (_Flag) { m_Edit_Process.AppendText(_BufferTextU + "\r\n"); } } } else if (_Script_Step.m_Step[i].ScriptType == 8) { List <DTCInfo> _DTC = new List <DTCInfo>(); DTCInfo _DTC_Buffer = new DTCInfo(); for (int j = 1; j <= _Script_Step.m_Step[i].DTC_Count; ++j) //提取内容 { _DTC_Buffer.DTCCode = Convert.ToString(data[j, _Script_Step.m_Step[i].Position_X]).Trim(); _DTC_Buffer.DTCHex = Convert.ToString(data[j, _Script_Step.m_Step[i].Position_Y]).Trim(); _DTC_Buffer._NO = j; _DTC.Add(_DTC_Buffer); } //第一步:检测DTCCode重复 List <string> lisDupValues2 = _DTC.GroupBy(x => x.DTCCode).Where(x => x.Count() > 1).Select(x => x.Key).ToList(); for (int j = 0; j < lisDupValues2.Count; ++j) { m_Edit_Process.AppendText("---->Error: DTCCode: " + lisDupValues2[j] + " Duplicate\r\n"); } //剔除重复的,然后再执行下列步骤 for (int j = 0; j < _DTC.Count; ++j) //循环次数 { for (int k = _DTC.Count - 1; k > j; --k) //比较次数 { if (_DTC[j].DTCCode == _DTC[k].DTCCode) { _DTC.RemoveAt(k); } } } //执行后续检测 for (int j = 0; j < _DTC.Count; ++j) { bool _Flag_Code = true; bool _Flag_HEX = true; //检测长度 if (_DTC[j].DTCCode.Length != 7) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid Length\r\n", _DTC[j]._NO)); _Flag_Code = false; } else { if (!CheckDTCInvalid(0, _DTC[j])) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid Value\r\n", _DTC[j]._NO)); _Flag_Code = false; } } if (_DTC[j].DTCHex.Length != 6) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCHex: " + _DTC[j].DTCHex + " Invalid Length\r\n", _DTC[j]._NO)); _Flag_HEX = false; } else { if (!CheckDTCInvalid(1, _DTC[j])) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCHex: " + _DTC[j].DTCHex + " Invalid Value\r\n", _DTC[j]._NO)); _Flag_HEX = false; } } //检测失效类型(目前仅检测ISO预留范围) if (_Flag_Code) { //检测最后一个字节的失效类型 string _FailureType = _DTC[j].DTCCode.Substring(5, 2); //取失效类型 if (_FailureType[0] == '0') { if (_FailureType[1] >= 'A') { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } } if (_FailureType[0] == '1') { if (_FailureType[1] == '0') { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } } if (_FailureType[0] == '2') { if ((_FailureType[1] == '0') || ((_FailureType[1] >= 'A') && (_FailureType[1] <= 'E'))) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } } if (_FailureType[0] == '3') { if ((_FailureType[1] == '0') || ((_FailureType[1] >= 'B') && (_FailureType[1] <= 'F'))) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } } if (_FailureType[0] == '4') { if ((_FailureType[1] == '0') || ((_FailureType[1] >= 'C') && (_FailureType[1] <= 'F'))) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } } if (_FailureType[0] == '5') { if ((_FailureType[1] == '0') || ((_FailureType[1] >= '6') && (_FailureType[1] <= 'F'))) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } } if (_FailureType[0] == '6') { if ((_FailureType[1] == '0') || ((_FailureType[1] >= '9') && (_FailureType[1] <= 'F'))) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } } if (_FailureType[0] == '7') { if ((_FailureType[1] == '0') || ((_FailureType[1] >= 'C') && (_FailureType[1] <= 'F'))) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } } if (_FailureType[0] == '8') { if ((_FailureType[1] == '0') || ((_FailureType[1] >= '9') && (_FailureType[1] <= 'E'))) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } } if (_FailureType[0] == '9') { if ((_FailureType[1] == '0') || ((_FailureType[1] >= '9') && (_FailureType[1] <= 'F'))) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } } if (_FailureType[0] >= 'A' && _FailureType[0] <= 'E') { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " Invalid FailureType(ISO/SAE Reserved)\r\n", _DTC[j]._NO)); continue; } if (_FailureType[0] == 'F') { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Warning: DTCCode: " + _DTC[j].DTCCode + " Use OEM defined FailureType\r\n", _DTC[j]._NO)); continue; } } //检测HEX及Code一致性 if (_Flag_Code && _Flag_HEX) //只有都是有效值,才会核对该内容 { //B if (_DTC[j].DTCCode.Substring(0, 2) == "B0") { if (_DTC[j].DTCCode.Replace("B0", "8") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "B1") { if (_DTC[j].DTCCode.Replace("B1", "9") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "B2") { if (_DTC[j].DTCCode.Replace("B2", "A") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "B3") { if (_DTC[j].DTCCode.Replace("B3", "B") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } //C if (_DTC[j].DTCCode.Substring(0, 2) == "C0") { if (_DTC[j].DTCCode.Replace("C0", "4") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "C1") { if (_DTC[j].DTCCode.Replace("C1", "5") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "C2") { if (_DTC[j].DTCCode.Replace("C2", "6") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "C3") { if (_DTC[j].DTCCode.Replace("C3", "7") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } //P if (_DTC[j].DTCCode.Substring(0, 2) == "P0") { if (_DTC[j].DTCCode.Replace("P0", "0") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "P1") { if (_DTC[j].DTCCode.Replace("P1", "1") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "P2") { if (_DTC[j].DTCCode.Replace("P2", "2") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "P3") { if (_DTC[j].DTCCode.Replace("P3", "3") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } //U if (_DTC[j].DTCCode.Substring(0, 2) == "U0") { if (_DTC[j].DTCCode.Replace("U0", "C") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "U1") { if (_DTC[j].DTCCode.Replace("U1", "D") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "U2") { if (_DTC[j].DTCCode.Replace("U2", "E") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } if (_DTC[j].DTCCode.Substring(0, 2) == "U3") { if (_DTC[j].DTCCode.Replace("U3", "F") != _DTC[j].DTCHex) { m_Edit_Process.AppendText(string.Format("---->[NO.{0:D}]Error: DTCCode: " + _DTC[j].DTCCode + " && DTCHex: " + _DTC[j].DTCHex + " is inconsistent\r\n", _DTC[j]._NO)); continue; } } } } } } return(true); } catch (Exception err) { m_Edit_Process.AppendText("---->Error:" + err.Message + "\r\n"); return(false); } finally { //COM组件方式调用完记得释放资源 if (workBook != null) { workBook.Close(false, oMissiong, oMissiong); Marshal.ReleaseComObject(workBook); app.Workbooks.Close(); app.Quit(); PublicMethod.Kill(app); } } }
public void ReadScript(string ScriptPath, ref ScriptStep _Step) { _Step.Define_Text = string.Empty; _Step.StepCounts = 0; _Step.m_Step = new List <ScriptMode>(); string[] ScriptLine = File.ReadAllLines(ScriptPath); //读取每行 Match match; Regex ScriptDefine = new Regex("^Define\\(\"(.+)\"\\);"); //描述字符 Regex ScriptShow = new Regex("^Show\\(\"(.+)\"\\);"); //显示字符 Regex ScriptOpenExcel = new Regex("^OpenExcel\\(\\);"); //打开Excel Regex ScriptOpenWorkSheet = new Regex("^OpenWorkSheet\\((.+),\"(.+)\"\\);"); //打开工作页 Regex ScriptCloseExcel = new Regex("^CloseExcel\\(\\);"); //关闭Excel Regex ScriptCloseWorkSheet = new Regex("^CloseWorkSheet\\(\\);"); //关闭工作页 Regex ScriptCheckItem = new Regex("^CheckItem\\((.+),(.+),(.+),\"(.+)\",\"(.+)\"\\);"); //打开工作页 Regex ScriptCheckNRC = new Regex("^CheckNRC\\((.+),(.+),\"(.+)\",\"(.+)\",\"(.+)\",\"(.+)\"\\);"); //打开工作页 Regex ScriptCheckDTC = new Regex("^CheckDTCCodeHex\\((.+),(.+),(.+)\\);"); //检查DTC for (int i = 0; i < ScriptLine.Length; ++i) //获取有效的行数,确定步骤数目 { if (ScriptLine[i] != string.Empty) { if (ScriptLine[i].Substring(0, 2) == "//") { //跳过注释行 continue; } else if (ScriptDefine.IsMatch(ScriptLine[i])) { match = ScriptDefine.Match(ScriptLine[i]); if (match.Groups[1].Value != "#NULL") { _Step.Define_Text = _Step.Define_Text + match.Groups[1].Value + "\r\n"; } else { _Step.Define_Text = _Step.Define_Text + "\r\n"; } continue; } else if (ScriptCheckItem.IsMatch(ScriptLine[i])) { ScriptMode _Buffer = new ScriptMode(); match = ScriptCheckItem.Match(ScriptLine[i]); _Buffer.ScriptType = 6; _Buffer.Position_Y = Convert.ToInt32(match.Groups[1].Value); _Buffer.Position_X = Convert.ToInt32(match.Groups[2].Value); _Buffer.CaculatorSymbol = match.Groups[3].Value; _Buffer.StringCheck = match.Groups[4].Value; _Buffer.StringBuffer = match.Groups[5].Value; _Step.m_Step.Add(_Buffer); _Step.StepCounts++; continue; } else if (ScriptShow.IsMatch(ScriptLine[i])) { ScriptMode _Buffer = new ScriptMode(); match = ScriptShow.Match(ScriptLine[i]); _Buffer.ScriptType = 5; _Buffer.StringBuffer = match.Groups[1].Value; _Step.m_Step.Add(_Buffer); _Step.StepCounts++; continue; } else if (ScriptOpenExcel.IsMatch(ScriptLine[i])) { ScriptMode _Buffer = new ScriptMode(); match = ScriptOpenExcel.Match(ScriptLine[i]); _Buffer.ScriptType = 1; _Step.m_Step.Add(_Buffer); _Step.StepCounts++; continue; } else if (ScriptOpenWorkSheet.IsMatch(ScriptLine[i])) { ScriptMode _Buffer = new ScriptMode(); match = ScriptOpenWorkSheet.Match(ScriptLine[i]); _Buffer.ScriptType = 2; _Buffer.Position_X = Convert.ToInt32(match.Groups[1].Value); _Buffer.StringBuffer = match.Groups[2].Value; _Step.m_Step.Add(_Buffer); _Step.StepCounts++; continue; } else if (ScriptCheckNRC.IsMatch(ScriptLine[i])) { ScriptMode _Buffer = new ScriptMode(); match = ScriptCheckNRC.Match(ScriptLine[i]); _Buffer.ScriptType = 7; _Buffer.Position_Y = Convert.ToInt32(match.Groups[1].Value); _Buffer.Position_X = Convert.ToInt32(match.Groups[2].Value); _Buffer.StringBuffer = match.Groups[3].Value; //支持NRC _Buffer.StringCheck = match.Groups[4].Value; //不支持NRC _Buffer.M_NRC_Des = match.Groups[5].Value; _Buffer.U_NRC_Des = match.Groups[6].Value; _Step.m_Step.Add(_Buffer); _Step.StepCounts++; continue; } else if (ScriptCheckDTC.IsMatch(ScriptLine[i])) { ScriptMode _Buffer = new ScriptMode(); match = ScriptCheckDTC.Match(ScriptLine[i]); _Buffer.ScriptType = 8; _Buffer.Position_Y = Convert.ToInt32(match.Groups[2].Value); _Buffer.Position_X = Convert.ToInt32(match.Groups[1].Value); _Buffer.DTC_Count = Convert.ToInt32(match.Groups[3].Value); _Step.m_Step.Add(_Buffer); _Step.StepCounts++; continue; } else { continue; } } } m_Edit_Process.AppendText(_Step.Define_Text); }
static string GetDefaultScript(BuildType type, ScriptStep step, NDKType ndk) { return File.ReadAllText (Path.Combine (Drosh.ScriptsTopdir, String.Format ("__default_script_{0}_{1}_{2}.txt", type, step, ndk))); }