public static void Read(string filepath, ProjectManager projects, ReferenceTable references, IdTable ids) { var xml = new XPathDocument(filepath).CreateNavigator(); var project = new Project(); var pnode = xml.SelectSingleNode("/Project"); ids[project] = new Guid(pnode.GetAttribute("id", "")); AssignProperties(pnode, project, references); references.Update(ids); // force Project.Property assignment var aci = pnode.Select("Assignments/FlatAssignmentCollection"); while (aci.MoveNext()) { var acnode = aci.Current; var flatid = acnode.SelectSingleNode("Flat").Value; var collection = project.Assignments.First(ac => ids[ac.Flat].ToString() == flatid); ids[collection] = new Guid(acnode.GetAttribute("id", "")); AssignProperties(acnode, collection, references); var ai = acnode.Select("FlatAssignment"); while (ai.MoveNext()) { var anode = ai.Current; var a = new FlatAssignment(project); ids[a] = new Guid(anode.GetAttribute("id", "")); AssignProperties(anode, a, references); collection.Add(a); } } references.Update(ids); // force Assignments for CostOptions generation var ci = pnode.Select("Costs/Cost"); while (ci.MoveNext()) { var cnode = ci.Current; var c = project.CreateCost(); ids[c] = new Guid(cnode.GetAttribute("id", "")); AssignProperties(cnode, c, references); var oi = cnode.Select("Options/CostOptions"); while (oi.MoveNext()) { var onode = oi.Current; var lesseeid = onode.SelectSingleNode("Lessee").Value; var option = c.Options.First(o => ids[o.Lessee].ToString() == lesseeid); ids[option] = new Guid(onode.GetAttribute("id", "")); AssignProperties(onode, option, references); } } projects.Add(project); }
public static void Write(ProjectManager projects, string path, IdTable ids) { foreach (var p in projects) { if (p == Project.Empty) { continue; } var f = new XmlWriter(path + p.Name + ".xml"); f.Begin(p, ids); f.Begin("Assignments"); var faclist = new FlatAssignmentCollection[p.Assignments.Count]; lock (p.Assignments) p.Assignments.CopyTo(faclist, 0); foreach (var fac in faclist) { f.Begin(fac, ids); var falist = new FlatAssignment[fac.Count]; lock (fac) fac.CopyTo(falist, 0); foreach (var fa in falist) { f.Write(fa, ids); } f.End(fac); } f.End("Assignments"); f.Begin("Costs"); var costlist = new Cost[p.Costs.Count]; lock (p.Costs) p.Costs.CopyTo(costlist, 0); foreach (var c in costlist) { f.Begin(c, ids); f.Begin("Options"); var optionslist = new CostOptions[c.Options.Count]; lock (c.Options) c.Options.CopyTo(optionslist, 0); foreach (var o in optionslist) { f.Write(o, ids); } f.End("Options"); f.End(c); } f.End("Costs"); f.End(p); f.Close(); } }
public void TestSerialise() { var id = new IdTable(); var props = new PropertyManager(); var lessees = new LesseeManager(); Xml.Write(props, "Properties.xml", id); Xml.Write(lessees, "Lessees.xml", id); var projects = new ProjectManager(); projects.Add(new Project()); projects.Current.Property = props[0]; projects.Current.CreateCost(); var fac = projects.Current.Assignments.First(a => a.Flat == props[0].Flats[0]); var assignment = new FlatAssignment(projects.Current); assignment.Start = DateTime.Now; assignment.End = DateTime.Now.AddMonths(3); assignment.Lessee = lessees[0]; fac.Add(assignment); Xml.Write(projects, "", id); }