public async void RunTrial() { TrialStart?.Invoke(this, _TrialLoop.CurrentIteration); _Status = StatusType.TrialDelay; try { await TrialDelay.RunAsync(CancelToken); if (!CancelToken.IsCancellationRequested) { CurrentState = StartState; ScriptMachineEventArgs e = new ScriptMachineEventArgs(StartState); ScriptStart?.Invoke(this, e); _MazeDataPoint = new MazeDataPoint(CurrentState.Name); _MazeDataPoint.Session = _SessionLoop.CurrentIteration; _MazeDataPoint.Trial = _TrialLoop.CurrentIteration; DataPointReady?.Invoke(this, _MazeDataPoint); CurrentState.Activate(); _Status = StatusType.Running; _StartTime = DateTime.Now; } else { TrialAborted?.Invoke(this, new EventArgs()); } } catch (Exception ex) { TrialAborted?.Invoke(this, new EventArgs()); } }
private void State_StateCompleted(object sender, ScriptStateEventArgs e) { CurrentState = null; States.TryGetValue(e.NextState, out _CurrentState); if (CurrentState.Type == ScriptState.StateType.Complete) { Status = StatusType.Completed; _EndTime = DateTime.Now; //_MazeDataPoint.Stop(); //DataPointReady?.Invoke(this, _MazeDataPoint); //ScriptEnd?.Invoke(this, new ScriptEndEventArgs(true, RunTime)); //CurrentState = StartState; } StateChanged?.Invoke(this, new ScriptMachineEventArgs(CurrentState)); _MazeDataPoint.Stop(); _MazeDataPoint.ExitAction = e.Condition.Label; //DataPointReady?.Invoke(this, _MazeDataPoint); _MazeDataPoint = new MazeDataPoint(CurrentState.Name); _MazeDataPoint.Session = _SessionLoop.CurrentIteration; _MazeDataPoint.Trial = _TrialLoop.CurrentIteration; DataPointReady?.Invoke(this, _MazeDataPoint); if (CurrentState.Type == ScriptState.StateType.Complete) { ScriptEnd?.Invoke(this, new ScriptEndEventArgs(true, RunTime)); //CurrentState = StartState; if (_TrialLoop.Next() > 0) { RunTrial(); } else { _TrialLoop.Reset(); if (_SessionLoop.Next() > 0) { RunSession(); } else { SessionSetComplete?.Invoke(this, new EventArgs()); } } } }
private void SaveResults() { string Folder = Path.Combine(ResultsFolder, controlPanel1.CurrentScript); Directory.CreateDirectory(Folder); string Filename = $@"{Folder}\{controlPanel1.ResultsName}.csv"; using (StreamWriter fs = new StreamWriter(Filename)) { //var Str = JsonConvert.SerializeObject(mazeRunner1.MazeDataPoints, Formatting.Indented); //fs.Write(Str); fs.WriteLine(String.Join(",", MazeDataPoint.GetFields())); foreach (MazeDataPoint dp in mazeRunner1.MazeDataPoints) { fs.WriteLine(dp.ToString()); } } }
public MazeDataPoint AddDataPoint(MazeDataPoint dp) { MazeDataPoints.Add(dp); _CurrentDataPoint = dp; return(dp); }
private void ScriptFSM_DataPointReady(object sender, MazeDataPoint e) { e.Trial = CurrentTrial; DataPointReady?.Invoke(this, e); }
private void ScriptFSM_DataPointReady(object sender, MazeDataPoint e) { e.Session = CurrentSession; DataPointReady?.Invoke(this, e); }
private void AddMazeDataPoint(MazeDataPoint dp) { mazeRunner1.AddDataPoint(dp); }
private void ScriptFSM_DataPointReady(object sender, MazeDataPoint e) { mazeRunner1.BeginInvoke(new InvokeAddDataPoint(AddMazeDataPoint), new object[] { e }); }