コード例 #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            RuleManager.Load();
            RefreshRules();

            monitor = new Monitor();
            monitor.Start();

            reportForm = new ReportForm(monitor.GetApp);

            List <string> errors = null;

            ActivityTracker.SetCurrentActivityLog(Log.Load(monitor.GetApp, DateTime.Now, out errors));

            if (errors != null && errors.Count != 0)
            {
                ReportErrorDuringLoading(errors);
            }

            ActivityTracker.CurrentLogExtended += this.CurrentLogExtended;
            ActivityTracker.CurrentLogChanged  += this.CurrentLogChanged;
            ActivityTracker.UserStatusChanged  += this.UserStatusChanged;

            CurrentLogChanged(DateTime.Now);
        }
コード例 #2
0
        public MainForm()
        {
            InitializeComponent();

            activitiesListView.SmallImageList = summaryListView.SmallImageList = new ImageList();
            mainTabControl.SelectedIndex      = 0;

            // Start the timer at a moment that guarantees maximum margin from the time unit boundaries, like this:
            //  --|--.----.----.--|--.----.----.--|--.----.----.--|--->
            // where:
            //   "-" is an interval, the time between samples are taken
            //   "." is a moment when a sample is taken
            //   "|" is a boundary of a time point
            timer.Interval = 1000 * ActivityTracker.LogTimeUnit / ActivityTracker.LogSamplingRate;
            DateTime currTimePoint = ActivityTracker.GetCurrentTimePoint();
            double   interval      = (double)Parameters.LogTimeUnit / Parameters.LogSamplingRate;
            double   interval_half = interval / 2.0; // [s] optimum tick shift relative to time point
            double   offset        = (DateTime.Now - currTimePoint).TotalSeconds;
            int      k             = (int)Math.Floor(offset / interval_half);
            double   phase_half    = offset - k * interval_half;
            double   required_wait = (interval_half - phase_half) + (k % 2 == 0 ? 0 : interval_half);

            System.Threading.Thread.Sleep((int)(required_wait * 1000.0));
            timer.Start();

            boldFont = new Font(SystemFonts.DefaultFont, FontStyle.Bold);
            UserStatusChanged(UserStatus.Active);
            autoScrollCheckBox.Checked = Parameters.AutoScroll;
        }
コード例 #3
0
 private void timer_Tick(object sender, EventArgs e)
 {
     if (Parameters.TrackActivity == true)
     {
         ActivitySnapshot snapshot = monitor.GetActivitySnapshot();
         ActivityTracker.RegisterSnapshot(snapshot);
         this.RefreshStatus(snapshot);
     }
 }
コード例 #4
0
 private void datePicker_ValueChanged(object sender, EventArgs e)
 {
     if (datePicker.Value.Date == DateTime.Now.Date)
     {
         ActivityTracker.SetCurrentActivityLog();
     }
     else
     {
         ActivityTracker.SetSelectedActivityLog(Persistence.Load(monitor.GetApp, datePicker.Value.Date));
     }
     RefreshActivitiesList();
     RefreshCategories();
     RefreshSummary();
     RefreshChart();
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: markuplab-tech/herring
        private void timer_Tick(object sender, EventArgs e)
        {
            if (!Parameters.TrackActivity)
            {
                return;
            }

            var snapshot = monitor.GetActivitySnapshot();

            ActivityTracker.RegisterSnapshot(snapshot);

            nextPoint.Text = ActivityTracker.GetTimePoint(snapshot.Time, 300).ToShortTimeString();

            RefreshStatus(snapshot);
        }
コード例 #6
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            RuleManager.Load();
            RefreshRules();

            monitor = new Monitor();
            monitor.Start();

            reportForm = new ReportForm(monitor.GetApp);

            ActivityTracker.SetCurrentActivityLog(Persistence.Load(monitor.GetApp));
            ActivityTracker.CurrentLogExtended += this.CurrentLogExtended;
            ActivityTracker.CurrentLogChanged  += this.CurrentLogChanged;
            ActivityTracker.UserStatusChanged  += this.UserStatusChanged;

            CurrentLogChanged(DateTime.Now);
        }
コード例 #7
0
        private void datePicker_ValueChanged(object sender, EventArgs e)
        {
            List <string> errors = null;

            if (datePicker.Value.Date == DateTime.Now.Date)
            {
                ActivityTracker.SetCurrentActivityLog();
            }
            else
            {
                ActivityTracker.SetSelectedActivityLog(Log.Load(monitor.GetApp, datePicker.Value.Date, out errors));
            }

            if (errors != null && errors.Count != 0)
            {
                ReportErrorDuringLoading(errors);
            }

            RefreshActivitiesList();
            RefreshCategories();
            RefreshSummary();
            RefreshChart();
        }
コード例 #8
0
        private void RefreshSummary(DateTime start, TimeSpan timeSpan)
        {
            summaryListView.Items.Clear();
            Dictionary <ActivityId, ActivityDaySummary> summaryItems = new Dictionary <ActivityId, ActivityDaySummary>();

            foreach (var summary in ActivityTracker.SelectedLog.Activities)
            {
                bool isFirst = true;
                foreach (var entry in summary.Entries)
                {
                    ActivityId id = new ActivityId
                    {
                        ProcessName      = entry.App.Path,
                        ApplicationTitle = entry.ApplicationTitle,
                        WindowTitle      = entry.WindowTitle
                    };

                    if (summaryItems.ContainsKey(id) == false)
                    {
                        summaryItems[id] =
                            new ActivityDaySummary
                        {
                            App = entry.App,
                            ApplicationTitle = entry.ApplicationTitle,
                            WindowTitle      = "",  // ignored in day summary
                            DocumentName     = entry.DocumentName
                        };
                    }
                    summaryItems[id].TotalTime += Parameters.LogTimeUnit * entry.Share / 100.0;
                    if (isFirst)
                    {
                        summaryItems[id].TopTime += Parameters.LogTimeUnit;
                    }
                    isFirst = false;
                }
            }

            List <ActivityDaySummary> summaryList1 = summaryItems.Values.ToList();

            summaryList1.Sort((a, b) => a.App.Name.CompareTo(b.App.Name));

            List <ActivityDaySummary> summaryList2 = new List <ActivityDaySummary>();

            // merge
            // FIXME: O(n^2) within an application
            bool[] done = new bool[summaryList1.Count];
            for (int i = 0; i < summaryList1.Count; ++i)
            {
                if (done[i] == false)
                {
                    string thisApp      = summaryList1[i].App.Name;
                    string thisTitle    = summaryList1[i].ApplicationTitle;
                    string thisDocument = summaryList1[i].ValidDocumentName;
                    string commonTitle;

                    ActivityDaySummary newSummary = summaryList1[i];

                    for (int j = i + 1; j < summaryList1.Count; ++j)
                    {
                        if (summaryList1[j].App.Name != thisApp)
                        {
                            break;
                        }
                        if (summaryList1[j].ValidDocumentName == thisDocument &&
                            ActivityTracker.AreTitlesNearlyEqual(summaryList1[j].ApplicationTitle, thisTitle, out commonTitle))
                        {
                            thisTitle = commonTitle;
                            newSummary.ApplicationTitle = commonTitle;
                            newSummary.TotalTime       += summaryList1[j].TotalTime;
                            newSummary.TopTime         += summaryList1[j].TopTime;
                            done[j] = true;
                        }
                    }
                    summaryList2.Add(newSummary);
                }
            }

            summaryList2.Sort((a, b) => (int)(a.TopTime != b.TopTime ? b.TopTime - a.TopTime : b.TotalTime - a.TotalTime));

            TimeSpan totalTime = TimeSpan.Zero;

            try
            {
                summaryListView.BeginUpdate();

                foreach (var ads in summaryList2)
                {
                    TimeSpan span    = TimeSpan.FromSeconds(ads.TotalTime);
                    TimeSpan topSpan = TimeSpan.FromSeconds(ads.TopTime);
                    string[] content = new string[]
                    {
                        ads.App.Name,
                        ads.ApplicationTitle,
                        ads.Subtitle,
                        span.ToString(),
                        topSpan.ToString()
                    };
                    ListViewItem item = new ListViewItem(content, GetIconIndex(ads.App));
                    summaryListView.Items.Add(item);
                    totalTime += span;
                }
            }
            finally
            {
                summaryListView.EndUpdate();
            }
        }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: markuplab-tech/herring
        private void RefreshSummary(DateTime start, TimeSpan timeSpan)
        {
            summaryListView.Items.Clear();
            Dictionary <ActivityId, ActivityDaySummary> summaryItems = new Dictionary <ActivityId, ActivityDaySummary>();

            foreach (var summary in ActivityTracker.SelectedLog.Activities)
            {
                bool isFirst = true;
                foreach (var entry in summary.Entries)
                {
                    ActivityId id = new ActivityId
                    {
                        ProcessName      = entry.App.Path,
                        ApplicationTitle = entry.ApplicationTitle
                    };

                    if (summaryItems.ContainsKey(id) == false)
                    {
                        summaryItems[id] =
                            new ActivityDaySummary
                        {
                            App = entry.App,
                            ApplicationTitle = entry.ApplicationTitle,
                            DocumentUrl      = entry.DocumentUrl
                        };
                    }
                    summaryItems[id].TotalTime += Parameters.LogTimeUnit * entry.Share / 100.0;
                    if (isFirst)
                    {
                        summaryItems[id].TopTime += Parameters.LogTimeUnit;
                    }
                    isFirst = false;
                }
            }

            List <ActivityDaySummary> summaryList1 = summaryItems.Values.ToList();

            summaryList1.Sort((a, b) => a.App.Name.CompareTo(b.App.Name));

            List <ActivityDaySummary> summaryList2 = new List <ActivityDaySummary>();

            // merge
            // FIXME: O(n^2) within an application
            bool[] done = new bool[summaryList1.Count];
            Dictionary <string, double> leaderTime = new Dictionary <string, double>();

            if (mergeSecondary)
            {
                for (int i = 0; i < summaryList1.Count; ++i)
                {
                    if (summaryList1[i].TopTime == 0)
                    {
                        if (summaryList1[i].DocumentUrl != "")
                        {
                            summaryList1[i].DocumentUrl = summaryList1[i].ValidDocumentSite + "/...";
                        }
                        summaryList1[i].ApplicationTitle = "(Other)";
                    }
                }
            }

            for (int i = 0; i < summaryList1.Count; ++i)
            {
                string thisProcess      = summaryList1[i].App.Name;
                string thisDocumentUrl  = summaryList1[i].ValidDocumentUrl;
                string thisDocumentSite = summaryList1[i].ValidDocumentSite;

                if (done[i] == false)
                {
                    string thisTitle = summaryList1[i].ApplicationTitle;

                    ActivityDaySummary newSummary = summaryList1[i].Clone();

                    for (int j = i + 1; j < summaryList1.Count; ++j)
                    {
                        if (summaryList1[j].App.Name != thisProcess)
                        {
                            break;
                        }

                        string commonTitle;
                        if (summaryList1[j].ValidDocumentSite == thisDocumentSite &&
                            ActivityTracker.AreTitlesNearlyEqual(summaryList1[j].ApplicationTitle, thisTitle, out commonTitle))
                        {
                            thisTitle       = commonTitle;
                            thisDocumentUrl = ActivityTracker.CommonUrlPart(thisDocumentUrl, summaryList1[j].DocumentUrl);

                            newSummary.ApplicationTitle = commonTitle;
                            newSummary.DocumentUrl      = thisDocumentUrl;
                            newSummary.TotalTime       += summaryList1[j].TotalTime;
                            newSummary.TopTime         += summaryList1[j].TopTime;

                            done[j] = true;
                        }
                    }
                    summaryList2.Add(newSummary);

                    string leaderName = (thisDocumentSite != "" ? thisDocumentSite : thisProcess);

                    if (leaderName != "")
                    {
                        if (leaderTime.ContainsKey(leaderName) == false ||
                            leaderTime[leaderName] < newSummary.TopTime * 100 + newSummary.TotalTime)
                        {
                            leaderTime[leaderName] = newSummary.TopTime * 100 + newSummary.TotalTime;
                        }
                    }
                }
            }

            summaryList2.Sort((a, b) =>
            {
                double leaderTimeA = a.TopTime * 100 + a.TotalTime;
                double leaderTimeB = b.TopTime * 100 + b.TotalTime;

                string leaderNameA = (a.ValidDocumentSite != "" ? a.ValidDocumentSite : a.App.Name);
                string leaderNameB = (b.ValidDocumentSite != "" ? b.ValidDocumentSite : b.App.Name);

                if (leaderNameA != "")
                {
                    leaderTimeA = Math.Max(leaderTimeA, leaderTime[leaderNameA]);
                }
                if (leaderNameB != "")
                {
                    leaderTimeB = Math.Max(leaderTimeB, leaderTime[leaderNameB]);
                }

                return((int)(leaderTimeA != leaderTimeB ? leaderTimeB - leaderTimeA : a.TopTime != b.TopTime ? b.TopTime - a.TopTime : b.TotalTime - a.TotalTime));
            });

            TimeSpan totalTime = TimeSpan.Zero;

            try
            {
                summaryListView.BeginUpdate();

                foreach (var ads in summaryList2)
                {
                    TimeSpan span    = TimeSpan.FromSeconds(ads.TotalTime);
                    TimeSpan topSpan = TimeSpan.FromSeconds(ads.TopTime);
                    string[] content = new string[]
                    {
                        ads.App.Name,
                        ads.ApplicationTitle,
                        ads.ValidDocumentUrl,
                        span.ToString(),
                        topSpan != TimeSpan.Zero ? topSpan.ToString() : ""
                    };

                    Color color =
                        ads.TopTime >= 600.0 ? Color.Black :
                        ads.TopTime >= 300.0 ? Color.FromArgb(80, 80, 80) :
                        Color.FromArgb(160, 160, 160);

                    ListViewItem item = new ListViewItem(content, GetIconIndex(ads.App));
                    item.ForeColor = color;
                    summaryListView.Items.Add(item);
                    totalTime += span;
                }
            }
            finally
            {
                summaryListView.EndUpdate();
            }
        }