public void Delete(TimeLogger inClock) { if (inClock.Active) { ClockState(inClock, false); } _clocks.Remove(inClock); }
public void Archive(TimeLogger inClock) { if (inClock.Active) { ClockState(inClock, false); } inClock.Archived = true; }
public void AddClock() { TimeLogger newClock = new TimeLogger(); newClock.Name = newClock.NiceName = GetUniqueName(newClock.Name); List <int> priorities = new List <int>() { -1 }; foreach (TimeLogger clock in _clocks) { priorities.Add(clock.Priority); } priorities.Sort(); priorities.Reverse(); newClock.Priority = priorities[0] + 1; _clocks.Add(newClock); }
public void ClockState(TimeLogger inClock, bool inActivate) { bool newValue = inActivate; List <TimeLogger> toActivate = new List <TimeLogger>(); List <TimeLogger> toDeActivate = new List <TimeLogger>(); (inActivate ? toActivate : toDeActivate).Add(inClock); bool allDeactivated = !inActivate; foreach (TimeLogger clock in _clocks) { if (clock == inClock) { continue; } if (inActivate) { if (clock.Active) { if (inClock.Solo || clock.Solo) { toDeActivate.Add(clock); } else if (allDeactivated) { allDeactivated = false; } } } else if (clock.Active && allDeactivated) { allDeactivated = false; } } if (allDeactivated) { List <TimeLogger> autoStartCandidates = new List <TimeLogger>(); foreach (TimeLogger clock in _clocks) { if (clock.AutoStart) { autoStartCandidates.Add(clock); } } //Reactivate an available TimeLogger if (autoStartCandidates.Count > 0) { autoStartCandidates.Sort(); toActivate.Add(autoStartCandidates[0]); } else { //Reactivate the same logger //toDeActivate.Remove(inClock); } } foreach (TimeLogger clock in toActivate) { clock.Activate(); } foreach (TimeLogger clock in toDeActivate) { clock.DeActivate(); } }