Esempio n. 1
0
 public ProjectChangeProcessorNewDay(ProjectChangeHandler handler,
                                     WorktimeAnalyzer worktimeAnalyzer,
                                     WorktrackerUpdater worktrackerUpdater) : base(handler)
 {
     WorktimeAnalyzer   = worktimeAnalyzer;
     WorktrackerUpdater = worktrackerUpdater;
 }
Esempio n. 2
0
        public void onInitCompleted()
        {
            Form.currentOvertime.Text = WorktimeAnalyzer.sumTimespans(storage.getOvertimes().Values.ToList()).FormatForOvertime();
            Form.correctProjectCombobox.Items.AddRange(ProjectHandler.getAvailableProjects().Cast <string>().ToArray());

            var t = new Thread(() => {
                var waitingTime = 3;
                while (String.IsNullOrEmpty(ProjectHandler.currentProject))
                {
                    System.Threading.Thread.Sleep(1000 * waitingTime);
                    waitingTime *= 10;

                    if (String.IsNullOrEmpty(ProjectHandler.currentProject))
                    {
                        waitForHandleCreated(Form);
                        Form.Invoke(new MethodInvoker(delegate() {
                            showNotification("Initialize project", "ProjectTracker is not yet initialized with a project");
                        }));
                    }
                }
            });

            t.Name = "ProjectInitializedChecker";
            t.Start();
        }
Esempio n. 3
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Form1   form      = new Form1();
            Overlay overlay   = new Overlay();
            var     presenter = new Presenter(form, overlay);

            form.Presenter = presenter;

            ProjectChangeHandler mainHandler = new ProjectChangeHandler();
            var worktimebreakHandler         = new ProjectChangeProcessorWorktimebreaks(mainHandler);
            var projectCorrectionHandler     = new ProjectChangeNotifierCorrection(mainHandler);
            var projectAnalysisHandler       = new ProjectChangeNotifierAnalysis(mainHandler);
            var storageEngine      = new WorktimeRecordStorageNoSQL();
            var worktimeAnalyzer   = new WorktimeAnalyzer(storageEngine, mainHandler);
            var worktrackerUpdater = new WorktrackerUpdater();

            //Change notifiers
            mainHandler.addProjectChangeNotifier(new ProjectChangeNotifierDexpot(mainHandler, presenter));
            mainHandler.addProjectChangeNotifier(new ProjectChangeNotifierTimeular(mainHandler, presenter));
            mainHandler.addProjectChangeNotifier(new ProjectChangeNotifierLockscreen(mainHandler));
            mainHandler.addProjectChangeNotifier(new ProjectChangeNotifierAppExit(mainHandler));
            mainHandler.addProjectChangeNotifier(new ProjectChangeNotifierUpcomingAppointment(mainHandler, presenter));
            mainHandler.addProjectChangeNotifier(projectAnalysisHandler);
            mainHandler.addProjectChangeNotifier(projectCorrectionHandler);

            //Change processors
            mainHandler.addProjectChangeProcessor(new ProjectChangeProcessorAppStart(mainHandler));
            mainHandler.addProjectChangeProcessor(new ProjectChangeProcessorNewDay(mainHandler, worktimeAnalyzer, worktrackerUpdater));
            mainHandler.addProjectChangeProcessor(new ProjectChangeProcessorLockscreen(mainHandler));
            mainHandler.addProjectChangeProcessor(worktimebreakHandler);
            //mainHandler.addProjectChangeProcessor(new ProjectChangeProcessorLongerThan10secs(mainHandler));

            //Change subscribers
            mainHandler.addProjectChangeSubscriber(new ProjectChangeSubscriberFormUpdater(presenter));
            mainHandler.addProjectChangeSubscriber(new ProjectChangeSubscriberBalloonInformant(presenter.showNotification));
            mainHandler.addProjectChangeSubscriber(new ProjectChangeSubscriberOverlayUpdater(overlay.setOverlayText));
            mainHandler.addProjectChangeSubscriber(new ProjectChangeSubscriberLogger());

            //Storages
            mainHandler.addWorktimeRecordStorage(new WorktimeRecordStorageCSV());
            mainHandler.addWorktimeRecordStorage(storageEngine);
            mainHandler.RaiseStorageExceptionEvent += new StorageExceptionBalloonInformant(presenter.showNotification).handleStorageException;

            //Presenter
            presenter.WorktimeAnalyzer         = worktimeAnalyzer;
            presenter.WorktimebreakHandler     = worktimebreakHandler;
            presenter.ProjectCorrectionHandler = projectCorrectionHandler;
            presenter.ProjectHandler           = mainHandler;
            presenter.storage   = storageEngine;
            presenter.wtUpdater = worktrackerUpdater;

            presenter.onInitCompleted();

            Application.Run(form);
        }
Esempio n. 4
0
        private void SetInWT_Click(object sender, EventArgs e)
        {
            WorktimeStatistics projectStatistics;

            try
            {
                projectStatistics = WorktimeAnalyzer.AnalyzeWorkday(Form.dateTimePicker1.Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }

            if (isHoliday(Form.dateTimePicker1.Value))
            {
                var dialogResult = MessageBox.Show("You should only do this at the end of the day! When done multiple times, overtimes will be wrong.\nAre you sure you want to log the worktime now?",
                                                   "ProjectTracker",
                                                   MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Exclamation);
                WorktimeAnalyzer.takeAllProjectimeAsOvertime(projectStatistics);
                if (dialogResult == DialogResult.No)
                {
                    return;
                }

                Form.currentOvertime.Text = WorktimeAnalyzer.sumTimespans(storage.getOvertimes().Values.ToList()).FormatForOvertime();
                MessageBox.Show("As it is a holiday, all project time was considered as overtime",
                                "ProjectTracker",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            try //it's a normal workday (and not a weekend/holiday)
            {
                if (!wtUpdater.WorktrackerConnect())
                {
                    throw new Exception("Could not connect to Worktracker");
                }

                if (Form.finishWTday.Checked)
                {
                    wtUpdater.finishDayNow(Form.dateTimePicker1.Value, projectStatistics.totalPausetime);
                }

                if (Form.flagConsiderOvertime.Checked)
                {
                    var projectStatisticsAdapted = WorktimeAnalyzer.considerOvertimeUndertime(projectStatistics);

                    DateTime from, to;
                    ProjectUtilities.getWorkDayByDate(Form.dateTimePicker1.Value, out from, out to);
                    var wtrs    = storage.getAllWorktimeRecords(from, to);
                    var maxDate = wtrs.Max(wtr => wtr.End);
                    var wtrsEnd = wtrs.First(wtr => wtr.End == maxDate).End;

                    wtUpdater.updateFullDay(Form.dateTimePicker1.Value, projectStatisticsAdapted, wtrsEnd); //unfortunately if something fails here, the overtime-db was updated anyways
                    wtUpdater.updateProjectEntries(Form.dateTimePicker1.Value, projectStatisticsAdapted);

                    Form.currentOvertime.Text = WorktimeAnalyzer.sumTimespans(storage.getOvertimes().Values.ToList()).FormatForOvertime();
                    MessageBox.Show("Day with under-/overtime and project entries were successfully set",
                                    "Worktracker",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                else
                {
                    wtUpdater.updateProjectEntries(Form.dateTimePicker1.Value, projectStatistics);

                    MessageBox.Show("Project entries were successfully set",
                                    "Worktracker",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Worktracker-Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 5
0
        //------------------------------------------------
        //------------------------------------------------

        private void AnalyzeWorktimes()
        {
            if (WorktimeAnalyzer == null)
            {
                return;
            }

            try
            {
                var projectStatistics = WorktimeAnalyzer.AnalyzeWorkday(Form.dateTimePicker1.Value);

                WorktimeStatistics projectStatisticsReal = null;
                if (Form.flagConsiderOvertime.Checked)
                {
                    Dictionary <string, TimeSpan> newOvertimes = null;
                    WorktimeAnalyzer.calculateOvertimeUndertime(projectStatistics, storage.getOvertimes(), out projectStatisticsReal, out newOvertimes);
                }
                else
                {
                    projectStatisticsReal = projectStatistics;
                }

                Form.currentOvertime.Text = WorktimeAnalyzer.sumTimespans(storage.getOvertimes().Values.ToList()).FormatForOvertime();
                Form.ProjectTimesSummary.Series.Clear();

                Series series = new Series
                {
                    Name = "projects",
                    IsVisibleInLegend = false,
                    ChartType         = SeriesChartType.Column
                };
                Form.ProjectTimesSummary.Series.Add(series);

                foreach (var project in projectStatisticsReal.projectTimes)
                {
                    series.Points.Add(project.Value.TotalMinutes);
                    var p = series.Points.Last();
                    p.AxisLabel = project.Key;
                    p.Label     = Math.Round(projectStatisticsReal.relativeProjectTimes[project.Key]).ToString() + "%";

                    if (projectStatisticsReal.projectComments.ContainsKey(project.Key)) //can happen for overtime, probably not the most appropriate solution
                    {
                        p.ToolTip = "Total: " + Math.Round(project.Value.TotalHours, 1) + "h\n" +
                                    String.Join("\n",
                                                projectStatisticsReal.projectComments[project.Key]
                                                .OrderByDescending(s => s.Value.Ticks) //order by comment timespan-sum
                                                .Select(s => Math.Round(s.Value.TotalHours, 1) + "h: " + s.Key)
                                                );
                    }
                }
                Form.ProjectTimesSummary.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0;
                Form.ProjectTimesSummary.ChartAreas[0].AxisY.MajorGrid.LineWidth = 0;
                Form.ProjectTimesSummary.ChartAreas[0].BackColor = System.Drawing.SystemColors.Control;
                Form.ProjectTimesSummary.ChartAreas[0].RecalculateAxesScale();
                Form.ProjectTimesSummary.Invalidate();
                Form.ProjectTimesSummary.Visible = true;

                Form.totalTime.Text     = projectStatisticsReal.totalTime.ToString(@"hh\:mm\:ss");
                Form.PrivateTime.Text   = projectStatisticsReal.totalPrivateTime.ToString(@"hh\:mm\:ss");
                Form.PauseTime.Text     = projectStatisticsReal.totalPausetime.ToString(@"hh\:mm\:ss");
                Form.Worktime.Text      = projectStatisticsReal.totalWorktime.ToString(@"hh\:mm\:ss");
                Form.ProjectTime.Text   = projectStatisticsReal.totalProjectTime.ToString(@"hh\:mm\:ss");
                Form.Workbreaktime.Text = projectStatisticsReal.totalWorkbreaktime.ToString(@"hh\:mm\:ss");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }