Beispiel #1
0
        private void GetData()
        {
            chart1.Series.Clear();

            using (var context = new WindowLoggingContext())
            {
                foreach (var log in context.WindowLogs.OrderBy(p => p.Start).ToList())
                {
                    var end = log.End;

                    if (end == null)
                    {
                        continue;
                    }

                    var series = new Series {
                        ChartType = SeriesChartType.RangeBar
                    };
                    chart1.Series.Add(series);
                    series.Points.AddXY(0, log.Start, end);
                    series.Points[0]["LogId"] = log.Id.ToString();
                    series.AxisLabel          = "Usage";
                    series.IsVisibleInLegend  = false;
                    series["DrawSideBySide"]  = "false";
                }
            }
        }
Beispiel #2
0
        private void Application_ApplicationExit(object sender, EventArgs e)
        {
            using (var context = new WindowLoggingContext())
            {
                var noEnd = context.WindowLogs.FirstOrDefault(p => !p.End.HasValue);

                if (noEnd != null)
                {
                    noEnd.End = DateTime.Now;
                    context.SaveChanges();
                }
            }
        }
Beispiel #3
0
        private void Chart1_MouseMove(object sender, MouseEventArgs e)
        {
            var result = chart1.HitTest(e.X, e.Y);

            if (picturePanel != null)
            {
                picturePanel.Hide();
                Controls.Remove(picturePanel);
                picturePanel.Dispose();
                picturePanel = null;
            }

            if (result.Object is DataPoint)
            {
                var          dataPoint = (DataPoint)result.Object;
                var          logId     = int.Parse(dataPoint["LogId"]);
                MemoryStream stream;

                using (var context = new WindowLoggingContext())
                {
                    var screenshot = context.WindowLogs
                                     .Join(context.Screenshots,
                                           w => w.Id,
                                           s => s.WindowLog_Id,
                                           (w, s) => new { w.Id, w.Start, w.End, w.ProgramName, s.Image })
                                     .FirstOrDefault(p => p.Id == logId);

                    if (screenshot == null)
                    {
                        return;
                    }

                    stream = new MemoryStream(screenshot.Image);
                }

                picturePanel = new PicturePanel(new Bitmap(stream));
                Controls.Add(picturePanel);
                picturePanel.Width    = 1280;
                picturePanel.Height   = 720;
                picturePanel.Location = e.Location;
                picturePanel.Show();
                picturePanel.BringToFront();
                return;
            }
        }
Beispiel #4
0
        void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            var imageBytes = TakeScreenshot();

            if (hwnd == IntPtr.Zero || imageBytes == null)
            {
                return;
            }

            string programName = GetWindowProgramName(hwnd);

            if (programName == null)
            {
                return;
            }

            using (var context = new WindowLoggingContext())
            {
                var now = DateTime.UtcNow;

                var prevLog = context.WindowLogs.FirstOrDefault(p => !p.End.HasValue);

                if (prevLog != null)
                {
                    prevLog.End = now;
                }

                var newLog = new WindowLog
                {
                    ProgramName = programName,
                    Start       = now
                };

                context.WindowLogs.Add(newLog);
                context.SaveChanges();

                context.Screenshots.Add(new Screenshot {
                    Image = imageBytes, WindowLog_Id = newLog.Id
                });
                context.SaveChanges();
            }

            GetData();
        }