tbf/TestBenchFramework/BenchControl/TestMethods/Endurance/CycleStep.cs
2016-12-07 20:57:32 +01:00

92 lines
2.0 KiB
C#

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