Esempio n. 1
0
        public uint GetCurrentIdle()
        {
            var ticks = new LASTINPUTINFO();

            ticks.cbSize = (uint)Marshal.SizeOf(ticks);
            if (!IdleTracker.GetLastInputInfo(ref ticks))
            {
                throw new Exception(GetLastError().ToString());
            }

            return(ticks.dwTime);
        }
Esempio n. 2
0
        private TrayContext()
        {
            this.contextMenuStrip1        = new ContextMenuStrip();
            this.exitToolStripMenuItem    = new ToolStripMenuItem();
            this.refreshToolStripMenuItem = new ToolStripMenuItem();
            this.goHomeToolStripMenuItem  = new ToolStripMenuItem();
            this.push15MenuItem           = new ToolStripMenuItem();
            this.push30MenuItem           = new ToolStripMenuItem();
            this.push60MenuItem           = new ToolStripMenuItem();
            this.adjustPtoMenuItem        = new ToolStripMenuItem();
            this.pomodoroMenuItem         = new ToolStripMenuItem();
            this.reportMenuItem           = new ToolStripMenuItem();

            this.contextMenuStrip1.SuspendLayout();
            //
            // contextMenuStrip1
            //
            this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
            var sep = new ToolStripMenuItem();

            this.contextMenuStrip1.Items.AddRange(new ToolStripItem[] {
                reportMenuItem,
                this.pomodoroMenuItem,
                this.push15MenuItem,
                this.push30MenuItem,
                this.push60MenuItem,
                this.adjustPtoMenuItem,
                this.goHomeToolStripMenuItem,
                this.refreshToolStripMenuItem,
                this.exitToolStripMenuItem,
            });
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            this.contextMenuStrip1.Size = new System.Drawing.Size(211, 56);
            //
            // exitToolStripMenuItem
            //
            this.exitToolStripMenuItem.Name   = "exitToolStripMenuItem";
            this.exitToolStripMenuItem.Size   = new System.Drawing.Size(210, 24);
            this.exitToolStripMenuItem.Text   = "Exit";
            this.exitToolStripMenuItem.Click += new System.EventHandler(this.ExitToolStripMenuItem_Click);

            //
            // goHomeToolStripMenuItem
            //
            this.goHomeToolStripMenuItem.Name   = "goHomeToolStripMenuItem";
            this.goHomeToolStripMenuItem.Size   = new System.Drawing.Size(210, 24);
            this.goHomeToolStripMenuItem.Text   = "Go Home";
            this.goHomeToolStripMenuItem.Click += new System.EventHandler((o, a) => {
                Data.AddEntry(new TimeEntry {
                    What = TimeEntryEvent.EndOfDay, When = DateTime.UtcNow
                });
            });

            this._calc = new TimeCalculator();
            //
            // refreshToolStripMenuItem
            //
            this.refreshToolStripMenuItem.Name   = "refreshToolStripMenuItem";
            this.refreshToolStripMenuItem.Size   = new System.Drawing.Size(210, 24);
            this.refreshToolStripMenuItem.Text   = "Refresh";
            this.refreshToolStripMenuItem.Click += new EventHandler(this._calc.OnRequestStartCalculation);

            this.push15MenuItem.Name   = "push15MenuItem";
            this.push15MenuItem.Size   = new System.Drawing.Size(210, 24);
            this.push15MenuItem.Text   = "Push 15";
            this.push15MenuItem.Click += new System.EventHandler((o, a) =>
                                                                 Data.AddEntries(new TimeEntry[] {
                new TimeEntry {
                    What = TimeEntryEvent.StartOfBreak, When = DateTime.UtcNow.AddMinutes(-15)
                },
                new TimeEntry {
                    What = TimeEntryEvent.EndOfBreak, When = DateTime.UtcNow
                }
            })
                                                                 );

            this.push30MenuItem.Name   = "push30MenuItem";
            this.push30MenuItem.Size   = new System.Drawing.Size(210, 24);
            this.push30MenuItem.Text   = "Push 30";
            this.push30MenuItem.Click += new System.EventHandler((o, a) =>
                                                                 Data.AddEntries(new TimeEntry[] {
                new TimeEntry {
                    What = TimeEntryEvent.StartOfBreak, When = DateTime.UtcNow.AddMinutes(-30)
                },
                new TimeEntry {
                    What = TimeEntryEvent.EndOfBreak, When = DateTime.UtcNow
                }
            })
                                                                 );

            this.push60MenuItem.Name   = "push60MenuItem";
            this.push60MenuItem.Size   = new System.Drawing.Size(210, 24);
            this.push60MenuItem.Text   = "Push Hour";
            this.push60MenuItem.Click += new System.EventHandler((o, a) =>
                                                                 Data.AddEntries(new TimeEntry[] {
                new TimeEntry {
                    What = TimeEntryEvent.StartOfBreak, When = DateTime.UtcNow.AddHours(-1)
                },
                new TimeEntry {
                    What = TimeEntryEvent.EndOfBreak, When = DateTime.UtcNow
                }
            })
                                                                 );

            this.adjustPtoMenuItem.Name   = "adjustPtoMenuItem";
            this.adjustPtoMenuItem.Size   = new System.Drawing.Size(210, 24);
            this.adjustPtoMenuItem.Text   = "Adjust PTO";
            this.adjustPtoMenuItem.Click += new EventHandler((o, a) => {
                var frm = new AdjustPto(week =>
                {
                    if (week != null)
                    {
                        Data.BulkUpsertPto(week);
                    }
                })
                {
                    StartPosition = FormStartPosition.CenterScreen
                };
                frm.Show();
            });

            this.pomodoroMenuItem.Name   = "pomodoroMenuItem";
            this.pomodoroMenuItem.Size   = new System.Drawing.Size(210, 24);
            this.pomodoroMenuItem.Text   = "Start Pomodoro";
            this.pomodoroMenuItem.Click += this.TogglePomodoro;

            this.reportMenuItem.Name   = "reportMenuItem";
            this.reportMenuItem.Size   = new System.Drawing.Size(210, 24);
            this.reportMenuItem.Text   = "Generate Report";
            this.reportMenuItem.Click += this.GenerateReport;

            this.contextMenuStrip1.ResumeLayout(false);
            this._icon = new NotifyIcon()
            {
                ContextMenuStrip = contextMenuStrip1,
                Icon             = Properties.Resources.TrayIcon,
                Text             = "Time Handler",
                Visible          = true,
            };
            this._icon.MouseClick          += this.OnClick;
            this._calc.CalculationComplete += this.OnWeekUpdated;
            this.TimerExpired            += this._calc.OnRequestStartCalculation;
            this._timer                   = new System.Threading.Timer(this.TimerCB, null, 0, Timeout.Infinite);
            this.idler                    = new IdleTracker((int)TimeSpan.FromHours(2).TotalMinutes, 15);
            this.idler.IdleLimitReached  += this.IdleLimitReached;
            this.idler.BreakLimitReached += this.BreakLimitReached;
            this.idler.WokeUp            += new EventHandler <SleepState>(this.Wake);
            this.pomodoro                 = new Pomodoro();
            this.pomodoro.Switch         += (s, m) => this.ShowMessage(m);
            Data.DataChanged             += this._calc.OnRequestStartCalculation;
        }