Beispiel #1
0
        private void ExportPresence(string filename)
        {
            var log = LogManager.GetLog(GetType());
            var exportTime = DateTime.Now;
            log.Info("Start presence export ({0}) : {1}.{2:D3}", filename, exportTime, exportTime.Millisecond);

            using (var db = new PetoeterDb(PetoeterDb.FileName))
            {
                var settings = db.GetSettings();
                var lastExportTime = settings.ExporTimeStamp;

                using (var export = new PetoeterDb(filename))
                {
                    var presence = (from p in db.Presences.Find(p => p.Updated < lastExportTime) select p).ToList();

                    presence.ForEach(p =>
                    {
                        p.Updated = exportTime;
                        log.Info("Export presence: {0}. [{1}] {2}", p.Id, p.Date.ToShortDateString(), p.Child.GetFullName());

                        //export.Children.Insert(p.Child);

                        //if (export.Members.Exists(m => m.Id == p.BroughtBy.Id) == false)
                        //{
                        //	export.Members.Insert(p.BroughtBy);
                        //}

                        //if (export.Members.Exists(m => m.Id == p.TakenBy.Id) == false)
                        //{
                        //	export.Members.Insert(p.TakenBy);
                        //}
                    });

                    export.Presences.Insert(presence);
                }

                settings.ExporTimeStamp = exportTime;
                db.UpdateSystemSettings();
            }
        }
Beispiel #2
0
        private void ExportAdministration(string filename)
        {
            var log = LogManager.GetLog(GetType());
            var exportTime = DateTime.Now;
            log.Info("Start administration export ({0}) : {1}.{2:D3}", filename, exportTime, exportTime.Millisecond);

            using (var db = new PetoeterDb(PetoeterDb.FileName))
            {
                var settings = db.GetSettings();
                var lastExportTime = settings.ExporTimeStamp;

                using (var export = new PetoeterDb(filename))
                {
                    var children = (from c in db.Children.FindAll()
                                                    where c.Updated < lastExportTime
                                                    select c).ToList();

                    children.ForEach(c =>
                    {
                        c.Updated = exportTime;
                        log.Info("Export child: {0}. {1}", c.Id, c.GetFullName());
                    });

                    db.Children.Update(children);
                    export.Children.Insert(children);

                    children.ForEach(c =>
                    {
                        if (c.FileId != null)
                        {
                            var file = db.FileStorage.FindById(c.FileId);
                            if (file != null)
                            {
                                export.FileStorage.Upload(c.FileId, file.OpenRead());
                            }
                        }
                    });

                    var members = (from m in db.Members.FindAll()
                                                 where m.Updated < lastExportTime
                                                 select m).ToList();

                    members.ForEach(m =>
                    {
                        m.Updated = exportTime;
                        log.Info("Export member: {0}. {1}", m.Id, m.GetFullName());
                    });

                    db.Members.Update(members);
                    export.Members.Insert(members);

                    var accounts = (from a in db.Accounts.FindAll()
                                                    where a.Updated < lastExportTime
                                                    select a).ToList();

                    accounts.ForEach(a =>
                    {
                        a.Updated = exportTime;
                        log.Info("Export account: {0}. {1}", a.Id, a.Name);
                    });

                    db.Accounts.Update(accounts);
                    export.Accounts.Insert(accounts);

                    var holidays = (from h in db.Holidays.FindAll()
                                                    where h.Updated < lastExportTime
                                                    select h).ToList();

                    holidays.ForEach(h =>
                    {
                        h.Updated = exportTime;
                        log.Info("Export holiday: {0}. {1}", h.Id, h.Day);
                    });

                    db.Holidays.Update(holidays);
                    export.Holidays.Insert(holidays);
                }

                settings.ExporTimeStamp = exportTime;
                db.UpdateSystemSettings();
            }
        }