コード例 #1
0
ファイル: Serializer.cs プロジェクト: Wolfury/nebenkosten
 public Serializer()
 {
     IdTable   = new IdTable();
     Interval  = 10000;
     Timestep  = 1000;
     IsRunning = false;
 }
コード例 #2
0
        public void Begin(object o, IdTable id)
        {
            var type = o.GetType();

            WriteLine("<" + type.Name + " id=\"" + id[o] + "\">");
            WriteProperties(o, id);
        }
コード例 #3
0
ファイル: ReferenceTable.cs プロジェクト: Wolfury/nebenkosten
 public void Update(IdTable idtable)
 {
     foreach (object o in idtable.Keys)
     {
         var id = idtable[o];
         if (ContainsKey(id))
         {
             foreach (Property property in this[id])
             {
                 property.Info.SetValue(property.Instance, o, null);
             }
             Remove(id);
         }
     }
 }
コード例 #4
0
ファイル: Xml.cs プロジェクト: Wolfury/nebenkosten
 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();
     }
 }
コード例 #5
0
 public void Scan(string path, IdTable ids)
 {
     foreach (var filepath in Directory.EnumerateFiles(path, "*.xml"))
     {
         var xml  = new XPathDocument(filepath).CreateNavigator();
         var node = xml.SelectSingleNode("/Project");
         if (node != null)
         {
             var project = new Project();
             var refs    = new ReferenceTable();
             Xml.AssignProperties(node, project, refs);
             refs.Update(ids);
             var timespan = project.StartDate.ToShortDateString() + " bis " + project.StartDate.AddYears(1).ToShortDateString();
             Add(new ProjectInfo(project.Name, project.Property.Name, timespan, filepath));
         }
     }
 }
コード例 #6
0
        void WriteProperties(object item, IdTable id)
        {
            foreach (var property in item.GetType().GetProperties())
            {
                if (!property.HasAttribute(typeof(SerializeAttribute)))
                {
                    continue;
                }
                var value = property.GetValue(item, null);

                if (property.PropertyType.HasInterface(typeof(INotifyPropertyChanged)))
                {
                    // Property type is a data model object, serialise its ID by looking it up
                    var idv = value == null ? "null" : id[value].ToString();
                    WriteLine("<" + property.Name + ">" + idv + "</" + property.Name + ">");
                }
                else
                {
                    // Integral data type, write down its string representation
                    WriteLine("<" + property.Name + ">" + value + "</" + property.Name + ">");
                }
            }
        }
コード例 #7
0
ファイル: Xml.cs プロジェクト: Wolfury/nebenkosten
        public static void Write(LesseeManager lessees, string filepath, IdTable ids)
        {
            var f = new XmlWriter(filepath);

            f.Begin("Lessees");
            var list = new Lessee[lessees.Count];

            lock (lessees) lessees.CopyTo(list, 0);
            foreach (var l in list)
            {
                f.Begin(l, ids);
                f.Begin("Payments");
                var paymentlist = new AdvancePayment[l.Payments.Count];
                lock (l.Payments) l.Payments.CopyTo(paymentlist, 0);
                foreach (var p in paymentlist)
                {
                    f.Write(p, ids);
                }
                f.End("Payments");
                f.End(l);
            }
            f.End("Lessees");
            f.Close();
        }
コード例 #8
0
ファイル: Xml.cs プロジェクト: Wolfury/nebenkosten
        public static void Write(PropertyManager properties, string filepath, IdTable ids)
        {
            var f = new XmlWriter(filepath);

            f.Begin("Properties");
            var list = new Olivia2.Model.Property[properties.Count];

            lock (properties) properties.CopyTo(list, 0);
            foreach (var p in list)
            {
                f.Begin(p, ids);
                f.Begin("Flats");
                var flatlist = new Flat[p.Flats.Count];
                lock (p.Flats) p.Flats.CopyTo(flatlist, 0);
                foreach (var flat in flatlist)
                {
                    f.Write(flat, ids);
                }
                f.End("Flats");
                f.End(p);
            }
            f.End("Properties");
            f.Close();
        }
コード例 #9
0
ファイル: Xml.cs プロジェクト: Wolfury/nebenkosten
        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);
        }
コード例 #10
0
ファイル: Xml.cs プロジェクト: Wolfury/nebenkosten
        public static void Read(string filepath, LesseeManager lessees, ReferenceTable references, IdTable ids)
        {
            var xml  = new XPathDocument(filepath).CreateNavigator();
            var li   = xml.Select("/Lessees/Lessee");
            var list = new List <Lessee>();

            while (li.MoveNext())
            {
                var lnode = li.Current;
                var l     = new Lessee();
                ids[l] = new Guid(lnode.GetAttribute("id", ""));
                AssignProperties(lnode, l, references);
                var pi = lnode.Select("Payments/AdvancePayment");
                while (pi.MoveNext())
                {
                    var pnode = pi.Current;
                    var p     = new AdvancePayment();
                    ids[p] = new Guid(pnode.GetAttribute("id", ""));
                    AssignProperties(pnode, p, references);
                    l.Payments.Add(p);
                }
                list.Add(l);
            }
            foreach (var i in list.OrderBy(item => item.Name))
            {
                lessees.Add(i);
            }
        }
コード例 #11
0
ファイル: Xml.cs プロジェクト: Wolfury/nebenkosten
        public static void Read(string filepath, PropertyManager properties, ReferenceTable references, IdTable ids)
        {
            var xml = new XPathDocument(filepath).CreateNavigator();
            var pi  = xml.Select("/Properties/Property");

            while (pi.MoveNext())
            {
                var pnode = pi.Current;
                var p     = properties.Create();
                ids[p] = new Guid(pnode.GetAttribute("id", ""));
                AssignProperties(pnode, p, references);
                var fi = pnode.Select("Flats/Flat");
                while (fi.MoveNext())
                {
                    var fnode = fi.Current;
                    var f     = p.CreateFlat();
                    ids[f] = new Guid(fnode.GetAttribute("id", ""));
                    AssignProperties(fnode, f, references);
                }
            }
        }
コード例 #12
0
 public void Write(object o, IdTable id)
 {
     Begin(o, id);
     End(o);
 }