public virtual void Handle(
            StatisticsUi ui)
        {
            var r = this.runner;

            r?.Run <UiReaderWriter>(uiRW =>
            {
                var currentStart = uiRW.Read(
                    ui,
                    () => ui.StartDate);
                var currentEnd = uiRW.Read(
                    ui,
                    () => ui.EndDate);
                r.Run <SettingsHolder>(settings =>
                {
                    var weekLength = settings.WeekLength;
                    var newStart   = currentStart.Add(-weekLength);
                    var newEnd     = currentEnd.Add(-weekLength);

                    uiRW.Write(
                        ui,
                        () =>
                    {
                        ui.StartDate = newStart;
                        ui.EndDate   = newEnd;
                    });
                });
            });
        }
Exemple #2
0
 public SetupStatisticsCommand(
     StatisticsUi ui,
     ShellUi shell,
     MethodWeb web)
 {
     this.ui    = ui;
     this.shell = shell;
     this.web   = web;
 }
 public StatisticsPresenter(
     StatisticsUi ui,
     ShellUi shell,
     MethodRunner runner)
     : base(ui, shell)
 {
     this.ui     = ui;
     this.runner = runner;
 }
        public virtual void Handle(
            StatisticsUi ui)
        {
            var r = this.runner;

            r?.Run <TimerHandler>(handler =>
            {
                handler.Handle(ui);
            });
        }
Exemple #5
0
        void UiReader.ReadStatistics(
            out StatisticsUi ui)
        {
            var nav = this.runner?.Run <Navigator>();

            if (nav == null)
            {
                ui = null;
                return;
            }

            ui = nav.GetUi <StatisticsPresenter, StatisticsUi>();
        }
        public virtual void Handle(
            TimestampsUi ui,
            HomeNavUi homeNavUi,
            StatisticsUi statsUi)
        {
            var r = this.runner;

            r?.Run <StartHandler>(handler =>
            {
                handler.Handle(
                    ui,
                    homeNavUi,
                    statsUi);
            });
        }
        public virtual void Handle(
            StatisticsUi ui)
        {
            var r = this.runner;

            r?.Run <DateCalculator, UiReaderWriter>(
                (calc, uiRW) =>
            {
                var startOfWeek = calc.StartOfWeek();
                var endOfWeek   = calc.Friday();
                uiRW.WriteSync(
                    ui,
                    () =>
                {
                    ui.StartDate = startOfWeek;
                    ui.EndDate   = endOfWeek;
                });
            });
        }
        public virtual void Handle(
            TimestampsUi ui,
            HomeNavUi homeNavUi,
            StatisticsUi statsUi)
        {
            var r = this.runner;

            r?.Run <SettingsHolder>(settings =>
            {
                settings.ShowCurrent = true;
            });

            r?.Run <StartHandler>(handler =>
            {
                handler.Handle(
                    ui,
                    homeNavUi,
                    statsUi);
            });
        }
        public virtual void Handle(
            TimestampsUi ui,
            HomeNavUi homeNavUi,
            StatisticsUi statsUi,
            bool shouldShow)
        {
            var r = this.runner;

            r?.Run <SettingsHolder>(settings =>
            {
                settings.ShowDurations = shouldShow;
            });
            r?.Run <StartHandler>(handler =>
            {
                handler.Handle(
                    ui,
                    homeNavUi,
                    statsUi);
            });
        }
        public virtual void Handle(
            StatisticsUi ui)
        {
            var r = this.runner;

            r?.Run <
                UiReaderWriter,
                StatisticsCalculator,
                TimeSpanViewer>(
                (uiRW, calc, viewer) =>
            {
                var start = uiRW.Read(
                    ui,
                    () => ui.StartDate);
                var end = uiRW.Read(
                    ui,
                    () => ui.EndDate).AddDays(1);

                var timeWorked = viewer.ReadableString(
                    calc.TimeWorked(start, end));
                var avgDaily = viewer.ReadableString(
                    calc.AverageDailyTimeWorked(start, end));
                var minDaily = viewer.ReadableString(
                    calc.MinDailyTimeWorked(start, end));
                var maxDaily = viewer.ReadableString(
                    calc.MaxDailyTimeWorked(start, end));

                uiRW.Write(
                    ui,
                    () =>
                {
                    ui.TimeWorked         = timeWorked;
                    ui.AvgDailyTimeWorked = avgDaily;
                    ui.MinDailyTimeWorked = minDaily;
                    ui.MaxDailyTimeWorked = maxDaily;
                });
            });
        }
        public virtual void Handle(
            StatisticsUi ui,
            HomeNavUi hnUi)
        {
            var r = this.runner;

            r?.Run <UiReaderWriter>(uiRW =>
            {
                uiRW.Write(
                    hnUi,
                    () =>
                {
                    hnUi.ActiveKeyLabel =
                        NavKeyLabels.Statistics;
                });
            });

            r?.Run <TimerHandler>(handler =>
            {
                handler.Handle(
                    ui);
            });

            r?.Run <xofz.Framework.Timer, GlobalSettingsHolder>(
                (t, settings) =>
            {
                var interval = settings.TimerIntervalSeconds;
                if (interval < 1)
                {
                    interval = 1;
                }

                t.Start(interval * 1000);
            },
                DependencyNames.Timer);
        }
Exemple #12
0
        protected virtual void onBootstrap()
        {
            var s = this.mainShell;

            if (s == null)
            {
                return;
            }

            var m = this.newMessenger?.Invoke();

            if (m != null)
            {
                m.Subscriber = s;
            }

            var e = this.executor;

            e?.Execute(new SetupMethodWebCommand(
                           new MethodWebV2(),
                           m,
                           this.newConfigSaver,
                           this.newSettingsProvider));

            var w = e?.Get <SetupMethodWebCommand>()?.W;

            w?.Run <EventSubscriber>(sub =>
            {
                var cd = AppDomain.CurrentDomain;
                UnhandledExceptionEventHandler handler = this.handleException;
                sub.Subscribe(
                    cd,
                    nameof(cd.UnhandledException),
                    handler);
            });
            w?.RegisterDependency(s);

            HomeUi          homeUi       = null;
            HomeNavUi       homeNavUi    = null;
            StatisticsUi    statsUi      = null;
            TimestampsUi    timestampsUi = null;
            TimestampEditUi editUi       = null;
            DailyUi         dailyUi      = null;
            ConfigUi        configUi     = null;
            LicenseUi       licenseUi    = null;

            w?.Run <UiReaderWriter, Lotter>(
                (uiRW, lotter) =>
            {
                uiRW.WriteSync(
                    s,
                    () =>
                {
                    homeUi       = this.newHomeUi?.Invoke();
                    homeNavUi    = this.newHomeNavUi?.Invoke(lotter);
                    statsUi      = this.newStatsUi?.Invoke();
                    timestampsUi = this.newTimestampsUi?.Invoke(lotter);
                    editUi       = this.newEditUi?.Invoke();
                    dailyUi      = this.newDailyUi?.Invoke(lotter);
                    configUi     = this.newConfigUi?.Invoke();
                    licenseUi    = this.newLicenseUi?.Invoke(s);
                });
            });

            var homeFinished       = new ManualResetEvent(false);
            var homeNavFinished    = new ManualResetEvent(false);
            var statsFinished      = new ManualResetEvent(false);
            var editFinished       = new ManualResetEvent(false);
            var timestampsFinished = new ManualResetEvent(false);
            var dailyFinished      = new ManualResetEvent(false);
            var mainFinished       = new ManualResetEvent(false);
            var shutdownFinished   = new ManualResetEvent(false);
            var licenseFinished    = new ManualResetEvent(false);
            var configFinished     = new ManualResetEvent(false);

            w?.Run <Do <Do> >(invoker =>
            {
                invoker.Invoke(
                    () =>
                {
                    e?.Execute(
                        new SetupHomeCommand(
                            homeUi,
                            s,
                            this.newReaderWriter,
                            this.newDataWatcher,
                            w));
                    homeFinished.Set();
                });

                invoker.Invoke(
                    () =>
                {
                    e?.Execute(
                        new SetupHomeNavCommand(
                            homeNavUi,
                            s.NavUi,
                            new NavigatorNavLogicReader(w),
                            w));
                    homeNavFinished.Set();
                });

                invoker.Invoke(
                    () =>
                {
                    e?.Execute(
                        new SetupStatisticsCommand(
                            statsUi,
                            homeUi,
                            w));
                    statsFinished.Set();
                });

                invoker.Invoke(
                    () =>
                {
                    e?.Execute(
                        new SetupTimestampEditCommand(
                            editUi,
                            homeUi,
                            w));
                    editFinished.Set();
                });

                invoker.Invoke(
                    () =>
                {
                    e?.Execute(
                        new SetupMainCommand(
                            s,
                            w,
                            new SettingsHolder()));
                    mainFinished.Set();
                });

                invoker.Invoke(
                    () =>
                {
                    e?.Execute(
                        new SetupShutdownCommand(
                            w));
                    shutdownFinished.Set();
                });

                invoker.Invoke(
                    () =>
                {
                    e?.Execute(
                        new SetupLicenseCommand(
                            licenseUi,
                            w));
                    licenseFinished.Set();
                });

                homeFinished.WaitOne();

                invoker.Invoke(
                    () =>
                {
                    e?.Execute(
                        new SetupTimestampsCommand(
                            timestampsUi,
                            homeUi,
                            w));
                    timestampsFinished.Set();
                });

                invoker.Invoke(
                    () =>
                {
                    e?.Execute(
                        new SetupDailyCommand(
                            dailyUi,
                            homeUi,
                            new NavigatorUiReader(w),
                            w));
                    dailyFinished.Set();
                });
            });

            // update to single-file format
            w?.Run <FileTimestampManager>(manager =>
            {
                manager.ConvertToSingleFile();
            });

            w?.Run <DataWatcher>(watcher =>
            {
                watcher.Start();
            });

            w?.Run <Navigator>(
                nav =>
            {
                nav.Present <HomePresenter>();

                w.Run <Do <Do> >(invoker =>
                {
                    homeNavFinished.WaitOne();
                });

                nav.PresentFluidly <HomeNavPresenter>();

                w.Run <Do <Do> >(invoker =>
                {
                    timestampsFinished.WaitOne();
                });

                nav.PresentFluidly <TimestampsPresenter>();
            });

            w?.Run <Do <Do> >(invoker =>
            {
                dailyFinished.WaitOne();
                invoker.Invoke(() =>
                {
                    e?.Execute(
                        new SetupConfigCommand(
                            configUi,
                            homeUi,
                            w));
                    configFinished.Set();
                });

                statsFinished.WaitOne();
                editFinished.WaitOne();
                mainFinished.WaitOne();
                shutdownFinished.WaitOne();
                licenseFinished.WaitOne();
                configFinished.WaitOne();
            });
        }
Exemple #13
0
        public virtual void Handle(
            DailyUi ui)
        {
            var r = this.runner;

            r?.Run <UiReaderWriter, UiReader>(
                (uiRW, reader) =>
            {
                reader.ReadHomeNav(
                    out var homeNavUi);
                uiRW.Write(
                    homeNavUi,
                    () =>
                {
                    homeNavUi.ActiveKeyLabel = NavKeyLabels.Daily;
                });
            });

            var showCurrent = true;

            r?.Run <SettingsHolder>(settings =>
            {
                showCurrent = settings.ShowCurrent;
            });

            StatisticsUi statsUi = null;

            r?.Run <UiReader>(reader =>
            {
                reader.ReadStatistics(
                    out var statisticsUi);
                statsUi = statisticsUi;
            });

            var ll = new XLinkedListLot <string>();

            r?.Run <
                StatisticsCalculator,
                DateCalculator,
                UiReaderWriter,
                TimeSpanViewer>(
                (statsCalc, dateCalc, uiRW, viewer) =>
            {
                DateTime currentDay, start, end;
                if (showCurrent)
                {
                    start = dateCalc.StartOfWeek();
                    end   = dateCalc.EndOfWeek();
                    goto afterComputeRange;
                }

                start = uiRW.Read(
                    statsUi,
                    () => statsUi.StartDate);
                end = uiRW.Read(
                    statsUi,
                    () => statsUi.EndDate);

                afterComputeRange:
                currentDay = start;
                while (currentDay <= end)
                {
                    var today    = currentDay.Date;
                    var tomorrow = today.AddDays(1);
                    ll.AddTail(
                        currentDay.Date.ToString(
                            @"yyyy/MM/dd ddd")
                        + @" ---- "
                        + viewer.ReadableString(
                            statsCalc.TimeWorked(
                                today,
                                tomorrow)));
                    currentDay = currentDay.AddDays(1);
                }
            });

            r?.Run <UiReaderWriter>(uiRW =>
            {
                uiRW.Write(
                    ui,
                    () =>
                {
                    ui.Info = ll;
                });
            });
        }
Exemple #14
0
        public virtual void Handle(
            TimestampsUi ui,
            HomeNavUi homeNavUi,
            StatisticsUi statsUi)
        {
            var        r   = this.runner;
            const byte one = 1;

            r?.Run <UiReaderWriter>(uiRW =>
            {
                uiRW.Write(
                    homeNavUi,
                    () =>
                {
                    homeNavUi.ActiveKeyLabel = NavKeyLabels.Timestamps;
                });
            });

            var showCurrent = true;

            r?.Run <SettingsHolder>(settings =>
            {
                showCurrent = settings.ShowCurrent;
            });
            var now   = DateTime.Now;
            var start = DateTime.Today;

            r?.Run <TimeProvider>(provider =>
            {
                now   = provider.Now();
                start = now.Date;
            });

            var end = start.AddDays(one);

            if (showCurrent)
            {
                r?.Run <DateCalculator>(
                    calc =>
                {
                    start = calc.StartOfWeek();
                    end   = calc.EndOfWeek().AddDays(one);
                });
                goto findAndSetTimesInRange;
            }

            r?.Run <UiReaderWriter>(uiRW =>
            {
                start = uiRW.Read(
                    statsUi,
                    () => statsUi.StartDate);
                end = uiRW.Read(
                    statsUi,
                    () => statsUi.EndDate)
                      .AddDays(1);
            });

findAndSetTimesInRange:
            r?.Run <
                TimestampReader,
                Lotter,
                EnumerableSplitter,
                UiReaderWriter>(
                (reader, lotter, splitter, uiRW) =>
            {
                var allTimes     = reader.ReadAll();
                var timesInRange = new XLinkedList <DateTime>();
                foreach (var time in allTimes)
                {
                    if (time < start)
                    {
                        continue;
                    }

                    if (time > end)
                    {
                        continue;
                    }

                    timesInRange.AddTail(time);
                }

                bool firstIn, lastIn;
                if (timesInRange.Count < one)
                {
                    firstIn = false;
                    lastIn  = false;
                    goto checkAdd;
                }

                firstIn = this.isInTime(
                    timesInRange.Head);
                lastIn = this.isInTime(
                    timesInRange.Tail);

                checkAdd:
                var inNow           = allTimes.Count % two == one;
                var oddTimesInRange = timesInRange.Count % two == one;
                if (oddTimesInRange)
                {
                    if (inNow && firstIn)
                    {
                        if (now > end.AddDays(one))
                        {
                            // was clocked in at end of range
                            timesInRange.AddTail(end);
                        }

                        // clocked in currently, do nothing
                        goto afterCheckClockedIn;
                    }

                    if (firstIn)
                    {
                        // clocked in at end of week
                        timesInRange.AddTail(end.Date);
                        goto afterCheckClockedIn;
                    }

                    // clocked out now but was clocked in at start of week
                    timesInRange.AddHead(start.Date);
                    goto afterCheckClockedIn;
                }

                if (timesInRange.Count > zero)
                {
                    if (!firstIn)
                    {
                        timesInRange.AddHead(start.Date);
                    }

                    if (lastIn && end < now)
                    {
                        timesInRange.AddTail(end.Date);
                    }
                }

                afterCheckClockedIn:
                var splitTimesThisWeek = splitter.Split(
                    timesInRange,
                    two);
                var inTimes   = splitTimesThisWeek[zero];
                var uiTimesIn = lotter.Materialize(
                    EnumerableHelpers.Select(
                        inTimes,
                        this.formatTimestamp));
                uiRW.Write(
                    ui,
                    () =>
                {
                    ui.InTimes = uiTimesIn;
                });

                var outTimes   = splitTimesThisWeek[one];
                var uiTimesOut = lotter.Materialize(
                    EnumerableHelpers.Select(
                        outTimes,
                        this.formatTimestamp));

                uiRW.Write(
                    ui,
                    () =>
                {
                    ui.OutTimes = uiTimesOut;
                });

                r.Run <EnumerableSplicer>(
                    splicer =>
                {
                    var splicedTimes = splicer.Splice(
                        new[]
                    {
                        inTimes,
                        outTimes
                    });
                    short indexer = zero;
                    DateTime
                    currentInTime = default,