-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sprint 1. Usable. Nags every 1/minute you're over time.
- Loading branch information
1 parent
e99290f
commit 8161eb7
Showing
1 changed file
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace lameover | ||
{ | ||
public class Diversions | ||
{ | ||
public ObservableCollection<Diversion> Processes; | ||
public uint MaxMinutes = 60; | ||
|
||
public Diversions() | ||
{ | ||
Processes = new ObservableCollection<Diversion>() | ||
{ | ||
new Diversion() | ||
{ | ||
Process = "Total", | ||
Parent = this | ||
} | ||
}; | ||
} | ||
|
||
public void AddDiversion(string process, uint seconds) | ||
{ | ||
lock (this) | ||
{ | ||
Processes.Insert(Processes.Count - 1, new Diversion() | ||
{ | ||
Parent = this, | ||
Process = process, | ||
ElapsedSeconds = seconds | ||
}); | ||
} | ||
} | ||
|
||
public void RemoveDiversion(int index) | ||
{ | ||
lock (this) | ||
{ | ||
Processes.RemoveAt(index); | ||
} | ||
} | ||
|
||
public void SetMaxTime(uint minutes) | ||
{ | ||
lock (this) | ||
{ | ||
MaxMinutes = minutes; | ||
} | ||
} | ||
|
||
public void AddTime(List<string> process, uint seconds) | ||
{ | ||
lock (this) | ||
{ | ||
foreach (Diversion diversion in Processes) | ||
{ | ||
foreach (string name in process) | ||
{ | ||
if (diversion.Process == name) | ||
{ | ||
diversion.ElapsedSeconds += seconds; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public List<string> GetDiversions() | ||
{ | ||
lock (this) | ||
{ | ||
return Processes.Select(diversion => diversion.Process).ToList(); | ||
} | ||
} | ||
} | ||
|
||
public class Diversion : INotifyPropertyChanged | ||
{ | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
public Diversions Parent; | ||
public string Process { get; set; } | ||
public uint Completion | ||
{ | ||
set | ||
{ | ||
ElapsedSeconds = 1; | ||
} | ||
get | ||
{ | ||
return (uint)(100.0 * ElapsedSeconds / 60 / Parent.MaxMinutes); | ||
} | ||
} | ||
private uint elapsedSeconds = 0; | ||
public uint ElapsedSeconds | ||
{ | ||
get | ||
{ | ||
return elapsedSeconds; | ||
} | ||
set | ||
{ | ||
elapsedSeconds = value; | ||
|
||
if (Process == "Total") | ||
{ | ||
if (Completion >= 100) | ||
{ | ||
if (ElapsedSeconds % 60 == 0) | ||
{ | ||
System.Windows.MessageBox.Show("lameover says: You're over time for diversions."); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
uint totalElapsed = 0; | ||
foreach (var diversion in Parent.Processes) | ||
{ | ||
if (diversion.Process == "Total") | ||
{ | ||
continue; | ||
} | ||
totalElapsed += diversion.elapsedSeconds; | ||
} | ||
Parent.Processes[Parent.Processes.Count - 1].ElapsedSeconds = totalElapsed; | ||
} | ||
|
||
OnPropertyChanged(new PropertyChangedEventArgs("Completion")); | ||
} | ||
} | ||
|
||
public void OnPropertyChanged(PropertyChangedEventArgs e) | ||
{ | ||
if (PropertyChanged != null) | ||
{ | ||
PropertyChanged(this, e); | ||
} | ||
} | ||
} | ||
} |