public void TestLimitDisabled() { var xmlSettings = new UserSettingsService(); xmlSettings.Initialize(); var logger = new Mock <ILogger>(); var mediator = new Mock <Mediator>(); var shutdownService = new Mock <IShutdownService>(); var limitHandler = new LimitHandler(mediator.Object, xmlSettings, logger.Object, shutdownService.Object); var app = new Aplication() { WinName = "test app" }; var limit = new AppLimit() { LimitReachedAction = LimitReachedAction.Warn, Application = app, ID = 1 }; xmlSettings.LimitsSettings.DontShowLimits.Add(limit.ID); limitHandler.Handle(limit); mediator.Verify(m => m.NotifyColleagues(MediatorMessages.APP_LIMIT_REACHED, limit), Times.Never()); }
private async void OnAppLimitReached(AppLimit limit) { currentLimit = limit; await DisplayAppDuration(); ShowWindow(); }
public AppLimitModel(AppLimit appLimit) { ID = appLimit.ID; ApplicationID = appLimit.ApplicationID; Limit = appLimit.Limit; LimitSpan = appLimit.LimitSpan; LimitReachedAction = appLimit.LimitReachedAction; }
private void ShowWarning(AppLimit limit) { if (userSettingsService.LimitsSettings.DontShowLimits.Any(l => l == limit.ID)) { return; } mediator.NotifyColleagues(MediatorMessages.APP_LIMIT_REACHED, limit); }
private void CheckDuration(AppLimit limit, Int64 duration) { if (duration >= limit.Limit) { limitHandler.Handle(limit); } else if (activeAppName != limit.Application.Name) { return; } else { var notifer = limitNotifiers.Single(l => l.LimitSpan == limit.LimitSpan); notifer.Setup(limit, new TimeSpan(limit.Limit - duration)); } }
private void CloseWindow() { this.Topmost = false; this.Opacity = 0.5; timer.Stop(); if (cbDontShow.IsChecked.HasValue && cbDontShow.IsChecked.Value) { userSettingsService.LimitsSettings.DontShowLimits.Add(currentLimit.ID); currentLimit = null; } var bounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds; var newTop = bounds.Bottom + 5; AnimateWindowTopPosition(newTop); }
public async Task TestLimitEvent() { var notifier = new LimitNotifier(syncContext, LimitSpan.Day); var limit = new AppLimit(); AppLimit limitInEvent = null; var eventFired = false; notifier.LimitReached += (s, e) => { Volatile.Write(ref eventFired, true); Volatile.Write(ref limitInEvent, e.Limit); }; notifier.Setup(limit, TimeSpan.FromMilliseconds(100)); await Task.Delay(150); Assert.IsTrue(Volatile.Read(ref eventFired)); Assert.AreSame(Volatile.Read(ref limitInEvent), limit); }
private Aplication CreateAppDailyLimit(int limitAmount) { var app = new Aplication(); app.ID = 7; app.Name = "some app"; app.WinName = "some name"; var limit = new AppLimit(); limit.ApplicationID = 7; limit.Application = app; limit.Limit = TimeSpan.FromMilliseconds(limitAmount).Ticks; limit.LimitReachedAction = LimitReachedAction.Warn; limit.LimitSpan = LimitSpan.Day; app.Limits = new List <AppLimit>() { limit }; return(app); }
public void Handle(AppLimit limit) { Ensure.NotNull(limit, "limit"); switch (limit.LimitReachedAction) { case LimitReachedAction.Warn: ShowWarning(limit); break; case LimitReachedAction.Shutdown: ShutdownApp(limit.Application); break; case LimitReachedAction.WarnAndShutdown: ShowWarning(limit); ShutdownApp(limit.Application); break; case LimitReachedAction.None: break; } }
public void TestShutdownAndWarn() { var xmlSettings = new UserSettingsService(); xmlSettings.Initialize(); var logger = new Mock <ILogger>(); var mediator = new Mock <Mediator>(); var shutdownService = new Mock <IShutdownService>(); var limitHandler = new LimitHandler(mediator.Object, xmlSettings, logger.Object, shutdownService.Object); var app = new Aplication() { WinName = "test app" }; var limit = new AppLimit() { LimitReachedAction = LimitReachedAction.WarnAndShutdown, Application = app }; limitHandler.Handle(limit); mediator.Verify(m => m.NotifyColleagues(MediatorMessages.APP_LIMIT_REACHED, limit), Times.Once()); shutdownService.Verify(s => s.Shutdown(app.WinName), Times.Once()); }
public LimitReachedArgs(AppLimit limit) { Limit = limit; }
public void Setup(AppLimit limit, TimeSpan duration) { Limit = limit; timer.Change(duration, Timeout.InfiniteTimeSpan); }