Beispiel #1
0
            internal Handle(TeaTimerDefinition teaTimer, Action <ITeaTimerProcessingHandle> completed, Action <ITeaTimerProcessingHandle> tick, Action <ITeaTimerProcessingHandle> canceled)
            {
                TeaTimer       = teaTimer;
                _remainingTime = teaTimer.Time;
                _cancelHandler = canceled;

                _timer = new Timer(arg =>
                {
                    lock (this)
                    {
                        var remaining = _remainingTime.Previous();
                        if (remaining.IsError)
                        {
                            _timer.Dispose();
                            if (completed != null)
                            {
                                completed(this);
                            }
                        }
                        else
                        {
                            _remainingTime = remaining;
                            if (tick != null)
                            {
                                tick(this);
                            }
                        }
                    }
                }, null, 1000, 1000);
            }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        public IEntry <TeaTimerDefinition> Add(TeaTimerDefinition value)
        {
            var entry = new Entry <TeaTimerDefinition>(value);
            var pos   = _entries.Values.Count > 0 ? _entries.Values.Select(m => m.Position).Max() + 1 : 0;

            _entries.Add(entry, new EntryMetaData()
            {
                Position = pos
            });
            var key = _reg.CreateSubKey(_entries[entry].Key.ToString("B"));

            WriteRegistryKey(key, value.Name, value.Time.Minute, value.Time.Second, pos);
            NormalizePositions();
            return(entry);
        }
Beispiel #4
0
        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();
        }
Beispiel #5
0
        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));
            }
        }
Beispiel #6
0
 public ITeaTimerProcessingHandle Process(TeaTimerDefinition teaTimer, Action <ITeaTimerProcessingHandle> completed, Action <ITeaTimerProcessingHandle> tick, Action <ITeaTimerProcessingHandle> canceled)
 {
     return(new Handle(teaTimer, completed, tick, canceled));
 }
Beispiel #7
0
 public ITeaTimerProcessingHandle Process(TeaTimerDefinition teaTimer, Action <ITeaTimerProcessingHandle> completed, Action <ITeaTimerProcessingHandle> tick)
 {
     return(Process(teaTimer, completed, tick, null));
 }
Beispiel #8
0
 public ITeaTimerProcessingHandle Process(TeaTimerDefinition teaTimer)
 {
     return(Process(teaTimer, null));
 }
Beispiel #9
0
 private void ShowTeaNotification(TeaTimerDefinition value)
 {
     _notification.ShowNotification(
         string.Format("{0} is ready.", value.Name),
         string.Format("It brewed for {0} minutes.", value.Time));
 }