Exemple #1
0
 // makes Snapshot from XML document with following structure:
 //
 //<snapshot>
 //  <info ... />
 //  <persons>
 //      <person ... />
 //      ...
 //  </persons>
 //  <operations>
 //      <operation ... />
 //      ...
 //  </operations>
 //
 public static Snapshot FromXml(XDocument doc)
 {
     // retrieving nodes
     var persons = doc.Root.Element("persons").Elements("person");
     var operations = doc.Root.Element("operations").Elements("operation");
     // initializing snapshot
     var info = ParseInfo(doc);
     var snapshot = new Snapshot(info);
     // parsing entities, ignoring relationships for now
     foreach (XElement man in persons)
         snapshot.Persons.Add(ParsePerson(man));
     foreach (XElement op in operations)
         snapshot.Operations.Add(ParseOperation(op));
     // filling Person.Operations
     foreach (Person man in snapshot.Persons)
     {
         XElement raw = persons.Single(el => el.Attribute("id").Value == man.ID.ToString());
         int[] operationIds = FromCsv(raw.Attribute("operations").Value);
         foreach (int id in operationIds)
             man.Operations.Add(snapshot.Operations.Single(op => op.ID == id));
     }
     // filling Operation.Participants
     foreach (Operation op in snapshot.Operations)
     {
         XElement raw = operations.Single(el => el.Attribute("id").Value == op.ID.ToString());
         int[] personIds = FromCsv(raw.Attribute("participants").Value);
         foreach (int id in personIds)
             op.Participants.Add(snapshot.Persons.Single(man => man.ID == id));
     }
     return snapshot;
 }
Exemple #2
0
 public SnapshotInfo(Snapshot snapshot)
 {
     Time = snapshot.Time;
     Mark = snapshot.Mark;
     OperationsCount = snapshot.Operations.Count;
     PersonsCount = snapshot.Persons.Count;
 }
Exemple #3
0
        public static XDocument ToXml(Snapshot set)
        {
            var info = new XElement("info",
                new XAttribute("mark", set.Mark),
                new XAttribute("time", set.Time.ToString(DateTimeFormat)),
                new XAttribute("operationsCount", set.Operations.Count.ToString(NumberFormat)),
                new XAttribute("personsCount", set.Persons.Count.ToString(NumberFormat)));

            var persons = new XElement("persons");
            foreach (Person man in set.Persons)
                persons.Add(SerializePerson(man));

            var operations = new XElement("operations");
            foreach (Operation op in set.Operations)
                operations.Add(SerializeOperation(op));

            return new XDocument(
                new XElement("snapshot", info, persons, operations));
        }
Exemple #4
0
 /// <summary>
 /// Saves current snapshot as an xml document to stream
 /// </summary>
 /// <param name="snapshot">Data to backup</param>
 /// <param name="stream">Stream for saving data</param>
 public void SaveTo(Snapshot snapshot, Stream stream)
 {
     XDocument backup = Serializer.ToXml(snapshot);
     backup.Save(stream);
 }
Exemple #5
0
 /// <summary>
 /// Saves current snapshot as an xml document to file
 /// </summary>
 /// <param name="snapshot">Data to backup</param>
 public void Save(Snapshot snapshot)
 {
     XDocument backup = Serializer.ToXml(snapshot);
     backup.Save(GetPath(snapshot.Time));
 }