Exemplo n.º 1
0
        /// <summary>
        /// refreshes cache with the current version of the box; call this after saving changes to a box
        /// </summary>
        public void UpdateCacheAfterSave(Box box, BoxEditingPool.Item changes, bool propagateToUI)
        {
            //determine what was changed
            bool newIsHighlighted = box.Visibility == Constants.VISIBILITY_HIGHLIGHT;

            //update cache
            (bool _, bool oldWasHighlighted) = ForgetAbout(box.RowId);
            if (box.BoxTime != null && box.DoneDate == null)
            {
                var cb = FullBoxToCachedBox(box);
                ScheduledBoxes.Add(cb);
                var projector = new RepeatProjector();
                Agenda.AddRange(projector.Project(cb, true, true));
                SortAgenda();
            }
            else if (box.BoxTime == null && box.ParentId == null && box.IsUnclass == 0 && box.DoneDate == null)
            {
                var cb = FullBoxToCachedBox(box);
                TopNotes.Add(cb);
                SortTopNotes();
            }

            //propagate changes to UI
            if (oldWasHighlighted || newIsHighlighted)
            {
                AssignHighlights();
            }
            if (propagateToUI)
            {
                Globals.UIAction.BoxCacheChanged(changes);
            }
        }
Exemplo n.º 2
0
        readonly List <AgendaEntry> Agenda = new List <AgendaEntry>(); //always keep this sorted by time

        /// <summary>
        /// Load cache
        /// </summary>
        public void Initialize()
        {
            using (var db = new SystematizerContext())
            {
                ScheduledBoxes = DBUtil.LoadForCaching(db.Box.Where(r => r.BoxTime != null && r.DoneDate == null));
                //note code duplication with next line and UpdateCacheAfterSave
                TopNotes = DBUtil.LoadForCaching(db.Box.Where(r => r.BoxTime == null && r.ParentId == null && r.IsUnclass == 0 && r.DoneDate == null));
            }

            var projector = new RepeatProjector();

            foreach (var box in ScheduledBoxes)
            {
                box.Repeats = ParsedRepeatInfo.Build(box.RepeatInfo);
                Agenda.AddRange(projector.Project(box, true, true));
            }
            AssignHighlights();
            SortAgenda();
            SortTopNotes();
        }