using System; using System.Collections.Generic; using System.Text; namespace TBF.BenchControl.TestMethods.Endurance { public class CycleStep { public uint Duration { get; set; } /// Duration in seconds //public virtual string Message { get; set; } /// Message public uint ValvesOpen { get; set; } /// List of valves to be opened public uint ValvesClose { get; set; } /// List of valves to be closed public CycleStep() { Duration = 500; //Message = string.Empty; ValvesOpen = 0; ValvesClose = 0; } public override string ToString() { return string.Format("{0}~{1}~{2}", Duration, ValvesOpen, ValvesClose); } /// /// Create CycleStep from a string generated previously by ToString() function /// /// String generated by ToString() public CycleStep(string savedStr) { string[] strArr = savedStr.Split(new char[] { '~' }); uint duration; uint vOpen; uint vClose; if (strArr.Length != 3 || !uint.TryParse(strArr[0], out duration) || !uint.TryParse(strArr[1], out vOpen) || !uint.TryParse(strArr[2], out vClose)) { Duration = 500; //Message = string.Empty; ValvesOpen = 0; ValvesClose = 0; } else { Duration = duration; //Message = strArr[1]; ValvesOpen = vOpen; ValvesClose = vClose; } } public static string CycleToString(IList cycle) { if (cycle == null) return string.Empty; StringBuilder sb = new StringBuilder(); foreach (var step in cycle) { if (sb.Length > 0) sb.Append('§'); sb.Append(step.ToString()); } return sb.ToString(); } public static IList StringToCycle(string savedCycle) { IList cycle = new List(); if (!string.IsNullOrEmpty(savedCycle)) { string[] lines = savedCycle.Split(new char[] { '§' }); foreach (var line in lines) { cycle.Add(new CycleStep(line)); } } return cycle; } } }