118 lines
2.3 KiB
C#
118 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Xml;
|
|
|
|
namespace DMX2
|
|
{
|
|
public class SequenceurMaitre
|
|
{
|
|
public class Ligne {
|
|
public Ligne(){}
|
|
string nom;
|
|
TimeSpan duree = TimeSpan.Zero;
|
|
Dictionary<Sequenceur,string> data = new Dictionary<Sequenceur, string>();
|
|
|
|
public string Nom {
|
|
get {
|
|
return nom;
|
|
}
|
|
set {
|
|
nom = value;
|
|
}
|
|
}
|
|
|
|
public TimeSpan Duree {
|
|
get {
|
|
return duree;
|
|
}
|
|
set {
|
|
duree = value;
|
|
}
|
|
}
|
|
|
|
public string this [Sequenceur index] {
|
|
get {
|
|
string value;
|
|
if(!data.TryGetValue(index, out value)) return string.Empty;
|
|
return value;
|
|
}
|
|
set {
|
|
if(value.Length==0) {
|
|
if(data.ContainsKey(index))
|
|
data.Remove(index);
|
|
}
|
|
else
|
|
data[index] = value;
|
|
}
|
|
}
|
|
public void Save (XmlElement parent)
|
|
{
|
|
XmlElement el = parent.OwnerDocument.CreateElement ("Ligne");
|
|
parent.AppendChild (el);
|
|
|
|
el.SetAttribute ("nom", nom);
|
|
el.SetAttribute ("duree", duree.ToString ());
|
|
|
|
XmlElement xmlSeq;
|
|
foreach (var val in data) {
|
|
el.AppendChild(xmlSeq=parent.OwnerDocument.CreateElement ("data"));
|
|
xmlSeq.SetAttribute("seq",val.Key.ID.ToString());
|
|
xmlSeq.SetAttribute("val",val.Value);
|
|
}
|
|
}
|
|
|
|
public static Ligne Load (Conduite c, XmlElement el)
|
|
{
|
|
Ligne l = new Ligne();
|
|
l.nom = el.GetAttribute ("nom");
|
|
l.duree = TimeSpan.Parse(el.GetAttribute("duree"));
|
|
|
|
foreach (var xv in el.GetElementsByTagName("data")) {
|
|
XmlElement xmlSeq = xv as XmlElement;
|
|
Sequenceur seq = c.GetSeqByID(int.Parse(xmlSeq.GetAttribute("seq")));
|
|
l[seq]= xmlSeq.GetAttribute ("val");
|
|
}
|
|
return l;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
List<Ligne> lignes = new List<Ligne>();
|
|
|
|
|
|
|
|
public List<Ligne> Lignes {
|
|
get {
|
|
return lignes;
|
|
}
|
|
}
|
|
|
|
public SequenceurMaitre ()
|
|
{
|
|
lignes.Add(new Ligne());
|
|
}
|
|
|
|
public void Save (XmlElement parent)
|
|
{
|
|
XmlElement el = parent.OwnerDocument.CreateElement("SequenceurMaitre");
|
|
parent.AppendChild(el);
|
|
|
|
foreach(Ligne l in lignes)
|
|
l.Save(el);
|
|
|
|
}
|
|
|
|
|
|
public static SequenceurMaitre Load (Conduite c, XmlElement el)
|
|
{
|
|
SequenceurMaitre seq = new SequenceurMaitre ();
|
|
|
|
foreach (var xl in el.GetElementsByTagName("Ligne")) {
|
|
seq.Lignes.Add(Ligne.Load(c,xl as XmlElement));
|
|
}
|
|
|
|
return seq;
|
|
}
|
|
}
|
|
}
|