Exemplo n.º 1
0
        public LimitObserver(ITrackingService trackingService,
                             IRepository repository,
                             IAppChangedNotifier appChangedNotifier,
                             IMidnightNotifier midnightNotifier,
                             ILimitHandler limitHandler,
                             IAppDurationCalc appDurationCalc,
                             Mediator mediator,
                             ISyncContext syncContext)
        {
            this.trackingService    = trackingService;
            this.repository         = repository;
            this.appChangedNotifier = appChangedNotifier;
            this.midnightNotifier   = midnightNotifier;
            this.limitHandler       = limitHandler;
            this.appDurationCalc    = appDurationCalc;
            this.mediator           = mediator;

            limitNotifiers.Add(new LimitNotifier(syncContext, LimitSpan.Day));
            limitNotifiers.Add(new LimitNotifier(syncContext, LimitSpan.Week));

            foreach (var notifier in limitNotifiers)
            {
                notifier.LimitReached += OnLimitReached;
            }

            mediator.Register(MediatorMessages.APP_LIMITS_CHANGIING, LoadAppLimits);
        }
Exemplo n.º 2
0
        public WindowTracker(ITrackingService trackingService,
                             IRepository repository,
                             IAppChangedNotifier appChangedNotifier,
                             IScreenshotTracker screenshotTracker,
                             Mediator mediator)
        {
            this.trackingService    = trackingService;
            this.repository         = repository;
            this.appChangedNotifier = appChangedNotifier;
            this.screenshotTracker  = screenshotTracker;
            this.mediator           = mediator;

            appChangedSubscription = appChangedNotifier.AppChangedObservable
                                     .Where(a => isTrackingEnabled)
                                     .Select(a => a.LogInfo.AppInfo == AppInfo.Empty ||
                                             string.IsNullOrEmpty(a.LogInfo.AppInfo.GetAppName()) ? LogInfo.Empty : a.LogInfo)
                                     .Do(i => FinishActiveLog())
                                     .Subscribe(CreateActiveLog);

            screenshotSubscription = screenshotTracker.ScreenshotObservable
                                     .Where(s => s != null && isTrackingEnabled && activeLog != null)
                                     .ObserveOn(DispatcherScheduler.Current)
                                     .Subscribe(async s =>
            {
                s.LogID = activeLog.ID;
                await repository.SaveNewEntityAsync(s);
                mediator.NotifyColleagues(MediatorMessages.SCREENSHOT_TAKEN);
            });
        }
Exemplo n.º 3
0
 private LimitObserver CreateObserver(IAppChangedNotifier appChangedNotifier)
 {
     return(new LimitObserver(trackingService.Object,
                              repository.Object,
                              appChangedNotifier,
                              midnightNotifier.Object,
                              limitHandler.Object,
                              appDurationCalc.Object,
                              mediator,
                              syncContext));
 }