Skip to content

Commit

Permalink
Sprint 1. Usable. Nags every 1/minute you're over time.
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertaylor committed Feb 19, 2015
1 parent e99290f commit 8161eb7
Showing 1 changed file with 146 additions and 0 deletions.
146 changes: 146 additions & 0 deletions lameover/lameover/Diversion.cs
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);
}
}
}
}

0 comments on commit 8161eb7

Please sign in to comment.