public Sequence(Sequence baseSequence) : this() { //commands.AddRange(baseSequence.commands); baseSequence.commands.ForEach ((BasicCommand bc) => commands.Add (new BasicCommand (bc))); name = "Copy of " + baseSequence.name; startState = baseSequence.startState; endState = baseSequence.endState; }
public bool TryParseSequence(string s, out Sequence seq) { seq = new Sequence(); if (s == "" || !s.Contains("<") || !s.Contains(">")) { seq = null; Logger.Log("TryParseSequence, invalid format s=" + s, Logger.Level.Debug); return false; } var allServos = new List<IRWrapper.IServo>(); foreach (IRWrapper.IControlGroup g in IRWrapper.IRController.ServoGroups) { allServos.AddRange(g.Servos); } // name {:command1:command2} try { var seqName = s.Substring(0, s.IndexOf('<')); Logger.Log("TryParseSequence, seqName =" + seqName, Logger.Level.Debug); var t = seqName.Split('|'); seq.name = t[0]; if (t.Length > 1) { if (!bool.TryParse(t[1], out seq.isLooped)) { seq.isLooped = false; } } if (t.Length > 2) { seq.keyShortcut = t[2]; } if (t.Length > 3) { if (!bool.TryParse(t[3], out seq.autoStart)) { seq.autoStart = false; } } //now find startState and endState by IDs if (t.Length > 5) { var startStateID = t[4]; var endStateID = t[5]; seq.startState = states.Find(st => st.stateID.ToString() == startStateID); seq.endState = states.Find(st => st.stateID.ToString() == endStateID); } //sequencer must have at least one state, so if nothing found, default states to it if (seq.startState == null) seq.startState = states[0]; if (seq.endState == null) seq.endState = states[0]; var seqCommands = s.Substring(s.IndexOf('<') + 1, s.IndexOf('>') - seqName.Length - 1); Logger.Log("TryParseSequence, seqCommands=" + seqCommands, Logger.Level.Debug); var chunks = seqCommands.Split(':'); Logger.Log("TryParseSequence, chunks.length=" + chunks.Length, Logger.Level.Debug); for (int i = 0; i < chunks.Length; i++) { BasicCommand bc; if (TryParseBasicCommand(chunks[i], allServos, out bc)) { seq.commands.Add(bc); } } } catch (Exception e) { Logger.Log("TryParseSequence, string=" + s + ", Exception: " + e.Message, Logger.Level.Debug); } return true; }