private void SaveBtn_Click(object sender, EventArgs e) { var idx = TeaRepositoryView.SelectedIndex; var item = TeaRepositoryView.Items[idx]; var newDefinition = TeaTimerDefinition.Create(NameTextBox.Text, (int)MinuteUpDown.Value, (int)SecondUpDown.Value); if (newDefinition.IsError) { MessageBox.Show(this, ((Error)newDefinition).Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } TeaRepositoryView.BeginUpdate(); if (item is IEntry <TeaTimerDefinition> ) { var entry = (IEntry <TeaTimerDefinition>)item; entry.Value = newDefinition; _setup.Repository.Update(entry); TeaRepositoryView.Items[idx] = entry; } else { var entry = _setup.Repository.Add(newDefinition); TeaRepositoryView.Items.Insert(TeaRepositoryView.Items.Count - 1, entry); SaveBtn.Text = "Save"; } TeaRepositoryView.SelectedIndex = idx; TeaRepositoryView.EndUpdate(); }
public TeaTimerRepository() { using (var sw = Registry.CurrentUser.CreateSubKey("Software")) { using (var palmenIt = sw.CreateSubKey("PalmenIt")) { _reg = palmenIt.CreateSubKey("DnTeaTime"); } } _entries = _reg.GetSubKeyNames() .Select(x => { using (var key = _reg.OpenSubKey(x)) { try { var def = TeaTimerDefinition.Create( (string)key.GetValue("Name", "<unknown>"), (int)key.GetValue("Minutes", 4), (int)key.GetValue("Seconds", 0)); if (def.IsError) { return(null); } IEntry <TeaTimerDefinition> entry = new Entry <TeaTimerDefinition>(def); var meta = new EntryMetaData(Guid.Parse(x)); meta.Position = (int)key.GetValue("Pos", 0); return(new KeyValuePair <IEntry <TeaTimerDefinition>, EntryMetaData>(entry, meta)); } catch { return((KeyValuePair <IEntry <TeaTimerDefinition>, EntryMetaData>?)null); } } }) .Where(x => x.HasValue) .Select(x => x.Value) .ToDictionary(x => x.Key, x => x.Value); NormalizePositions(); }
static void Main() { if (mutex.WaitOne(TimeSpan.Zero, true)) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (VersionCheck.HasWinRT && !InstalledCheck.IsInstalled) { if (MessageBox.Show(null, "You are running DnTeaTime directly without installing it." + Environment.NewLine + "Due to the way notifications work on Windows 8 and later," + Environment.NewLine + "You won't get notified when your tea is ready. Please" + Environment.NewLine + "install DnTeaTime first!" + Environment.NewLine + Environment.NewLine + "Click Cancel to exit now or OK to continue anyways.", "DnTeaTime Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Cancel) { return; } } var repository = new TeaTimerRepository(); if (repository.Count == 0) { repository.Add(TeaTimerDefinition.Create("Black Tea", 4, 0)); repository.Add(TeaTimerDefinition.Create("Earl Grey", 4, 30)); repository.Add(TeaTimerDefinition.Create("Herbal Tea", 10, 0)); repository.Add(TeaTimerDefinition.Create("Green Tea", 2, 30)); } var processor = new TeaTimerProcessor(); TrayApp.Run(new App(repository, processor)); } }