private async Task ChatterJoinBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { List <ChatUserEventModel> usersToProcess = new List <ChatUserEventModel>(); await this.userJoinEventsSemaphore.WaitAndRelease(() => { usersToProcess = new List <ChatUserEventModel>(this.userJoinEvents.Values); this.userJoinEvents.Clear(); return(Task.FromResult(0)); }); if (usersToProcess.Count > 0) { IEnumerable <UserViewModel> processedUsers = await ChannelSession.ActiveUsers.AddOrUpdateUsers(usersToProcess.Select(u => u.GetUser())); foreach (UserViewModel user in processedUsers) { this.OnUserJoinOccurred(this, user); } } tokenSource.Token.ThrowIfCancellationRequested(); await Task.Delay(5000, tokenSource.Token); tokenSource.Token.ThrowIfCancellationRequested(); }); }
private async Task ChatUserRefreshBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { Dictionary <uint, ChatUserModel> chatUsers = new Dictionary <uint, ChatUserModel>(); foreach (ChatUserModel user in await ChannelSession.Connection.GetChatUsers(ChannelSession.Channel, Math.Max(ChannelSession.Channel.viewersCurrent, 1))) { if (user.userId.HasValue) { chatUsers[user.userId.GetValueOrDefault()] = user; } } foreach (UserViewModel user in await ChannelSession.ChannelUsers.GetAllUsers()) { if (chatUsers.ContainsKey(user.ID)) { user.SetChatDetails(chatUsers[user.ID]); chatUsers.Remove(user.ID); } else { await ChannelSession.ChannelUsers.RemoveUser(user.ID); } } foreach (ChatUserModel chatUser in chatUsers.Values) { await ChannelSession.ChannelUsers.AddOrUpdateUser(chatUser); } await Task.Delay(30000); }); }
/// <summary> /// Initializes a new instance of the <see cref="TimeOffController"/> class. /// </summary> /// <param name="appSettings">Application Settings DI.</param> /// <param name="telemetryClient">ApplicationInsights DI.</param> /// <param name="userMappingProvider">The User Mapping Provider DI.</param> /// <param name="timeOffActivity">Time Off Activity DI.</param> /// <param name="timeOffReasonProvider">Time Off Reason Provider DI.</param> /// <param name="azureTableStorageHelper">Azure Storage Helper DI.</param> /// <param name="timeOffMappingEntityProvider">Time Off Mapping Provider DI.</param> /// <param name="utility">Utility DI.</param> /// <param name="teamDepartmentMappingProvider">Team Department Mapping Provider DI.</param> /// <param name="httpClientFactory">HttpClientFactory DI.</param> /// <param name="taskWrapper">Wrapper class instance for BackgroundTask.</param> public TimeOffController( AppSettings appSettings, TelemetryClient telemetryClient, IUserMappingProvider userMappingProvider, ITimeOffActivity timeOffActivity, ITimeOffReasonProvider timeOffReasonProvider, IAzureTableStorageHelper azureTableStorageHelper, ITimeOffMappingEntityProvider timeOffMappingEntityProvider, Utility utility, ITeamDepartmentMappingProvider teamDepartmentMappingProvider, IHttpClientFactory httpClientFactory, BackgroundTaskWrapper taskWrapper) { this.appSettings = appSettings; this.telemetryClient = telemetryClient; this.userMappingProvider = userMappingProvider; this.timeOffActivity = timeOffActivity; this.timeOffReasonProvider = timeOffReasonProvider; this.azureTableStorageHelper = azureTableStorageHelper; this.timeOffMappingEntityProvider = timeOffMappingEntityProvider ?? throw new ArgumentNullException(nameof(timeOffMappingEntityProvider)); this.utility = utility; this.teamDepartmentMappingProvider = teamDepartmentMappingProvider; this.httpClientFactory = httpClientFactory; this.taskWrapper = taskWrapper; }
private async Task TimerBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (token) => { await Task.Delay(1000); if (this.timeLeft > 0) { this.timeLeft--; if (this.timeLeft == 0) { this.SendHide(); } else { this.SendUpdateRequired(); } } else { if (this.stackedTime > 0) { this.stackedTime--; } } }); }
/// <summary> /// Initializes a new instance of the <see cref="TimeOffRequestsController"/> class. /// </summary> /// <param name="appSettings">Configuration DI.</param> /// <param name="telemetryClient">Telemetry Client.</param> /// <param name="userMappingProvider">User To User Mapping Provider.</param> /// <param name="createTimeOffActivity">Create time off activity.</param> /// <param name="timeOffReasonProvider">Paycodes to Time Off Reasons Mapping provider.</param> /// <param name="utility">The local Utility DI.</param> /// <param name="azureTableStorageHelper">The Azure table storage helper.</param> /// <param name="timeOffReqMappingEntityProvider">time off entity provider.</param> /// <param name="teamDepartmentMappingProvider">TeamDepartmentMapping provider DI.</param> /// <param name="httpClientFactory">http client.</param> /// <param name="taskWrapper">Wrapper class instance for BackgroundTask.</param> public TimeOffRequestsController( AppSettings appSettings, TelemetryClient telemetryClient, ICreateTimeOffActivity createTimeOffActivity, IUserMappingProvider userMappingProvider, ITimeOffReasonProvider timeOffReasonProvider, IAzureTableStorageHelper azureTableStorageHelper, ITimeOffRequestProvider timeOffReqMappingEntityProvider, ITeamDepartmentMappingProvider teamDepartmentMappingProvider, Utility utility, IHttpClientFactory httpClientFactory, BackgroundTaskWrapper taskWrapper) { this.appSettings = appSettings; this.telemetryClient = telemetryClient; this.createTimeOffActivity = createTimeOffActivity; this.userMappingProvider = userMappingProvider; this.timeOffReasonProvider = timeOffReasonProvider; this.azureTableStorageHelper = azureTableStorageHelper; this.timeOffReqMappingEntityProvider = timeOffReqMappingEntityProvider; this.teamDepartmentMappingProvider = teamDepartmentMappingProvider; this.utility = utility; this.httpClientFactory = httpClientFactory; this.taskWrapper = taskWrapper; }
private async Task TimerCommandsBackground() { int timerCommandIndex = 0; await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { DateTimeOffset startTime = DateTimeOffset.Now; int startMessageCount = this.Messages.Count; tokenSource.Token.ThrowIfCancellationRequested(); await Task.Delay(1000 * 60 * ChannelSession.Settings.TimerCommandsInterval); tokenSource.Token.ThrowIfCancellationRequested(); if (ChannelSession.Settings.TimerCommands.Count > 0) { TimerCommand command = ChannelSession.Settings.TimerCommands[timerCommandIndex]; while ((this.Messages.Count - startMessageCount) < ChannelSession.Settings.TimerCommandsMinimumMessages) { tokenSource.Token.ThrowIfCancellationRequested(); await Task.Delay(1000 * 10); } await command.Perform(); timerCommandIndex++; timerCommandIndex = timerCommandIndex % ChannelSession.Settings.TimerCommands.Count; } }); }
private async Task ChannelRefreshBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); await ChannelSession.RefreshChannel(); await Task.Delay(30000, tokenSource.Token); tokenSource.Token.ThrowIfCancellationRequested(); await ChannelSession.RefreshChannel(); await Task.Delay(30000, tokenSource.Token); tokenSource.Token.ThrowIfCancellationRequested(); foreach (UserViewModel user in await ChannelSession.ActiveUsers.GetAllWorkableUsers()) { user.UpdateMinuteData(); } foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values) { await currency.UpdateUserData(); } await ChannelSession.SaveSettings(); tokenSource.Token.ThrowIfCancellationRequested(); }); }
/// <summary> /// Initializes a new instance of the <see cref="OpenShiftRequestController"/> class. /// </summary> /// <param name="appSettings">The key/value application settings DI.</param> /// <param name="telemetryClient">ApplicationInsights DI.</param> /// <param name="openShiftActivity">The open shift activity DI.</param> /// <param name="userMappingProvider">The user mapping provider DI.</param> /// <param name="teamDepartmentMappingProvider">The Team Department Mapping DI.</param> /// <param name="openShiftRequestMappingEntityProvider">The Open Shift Request Mapping DI.</param> /// <param name="httpClientFactory">http client.</param> /// <param name="openShiftMappingEntityProvider">The Open Shift Mapping DI.</param> /// <param name="utility">The common utility methods DI.</param> /// <param name="shiftMappingEntityProvider">Shift entity mapping provider DI.</param> /// <param name="taskWrapper">Wrapper class instance for BackgroundTask.</param> public OpenShiftRequestController( AppSettings appSettings, TelemetryClient telemetryClient, IOpenShiftActivity openShiftActivity, IUserMappingProvider userMappingProvider, ITeamDepartmentMappingProvider teamDepartmentMappingProvider, IOpenShiftRequestMappingEntityProvider openShiftRequestMappingEntityProvider, IHttpClientFactory httpClientFactory, IOpenShiftMappingEntityProvider openShiftMappingEntityProvider, Utility utility, IShiftMappingEntityProvider shiftMappingEntityProvider, BackgroundTaskWrapper taskWrapper) { if (appSettings is null) { throw new ArgumentNullException(nameof(appSettings)); } this.appSettings = appSettings; this.telemetryClient = telemetryClient; this.openShiftActivity = openShiftActivity; this.userMappingProvider = userMappingProvider; this.teamDepartmentMappingProvider = teamDepartmentMappingProvider; this.openShiftRequestMappingEntityProvider = openShiftRequestMappingEntityProvider; this.openShiftMappingEntityProvider = openShiftMappingEntityProvider; this.httpClientFactory = httpClientFactory; this.openShiftQueryDateSpan = $"{this.appSettings.ShiftStartDate}-{this.appSettings.ShiftEndDate}"; this.utility = utility; this.shiftMappingEntityProvider = shiftMappingEntityProvider; this.taskWrapper = taskWrapper; }
/// <summary> /// Initializes a new instance of the <see cref="OpenShiftController"/> class. /// </summary> /// <param name="appSettings">Configuration DI.</param> /// <param name="telemetryClient">Telemetry Client.</param> /// <param name="openShiftActivity">OpenShift activity.</param> /// <param name="utility">Unique ID utility DI.</param> /// <param name="openShiftMappingEntityProvider">Open Shift Entity Mapping DI.</param> /// <param name="teamDepartmentMappingProvider">Team Department Mapping Provider DI.</param> /// <param name="httpClientFactory">http client.</param> /// <param name="openShiftRequestMappingEntityProvider">Open Shift Request Entity Mapping DI.</param> /// <param name="taskWrapper">Wrapper class instance for BackgroundTask.</param> public OpenShiftController( AppSettings appSettings, TelemetryClient telemetryClient, IOpenShiftActivity openShiftActivity, Utility utility, IGraphUtility graphUtility, IOpenShiftMappingEntityProvider openShiftMappingEntityProvider, ITeamDepartmentMappingProvider teamDepartmentMappingProvider, IHttpClientFactory httpClientFactory, IOpenShiftRequestMappingEntityProvider openShiftRequestMappingEntityProvider, BackgroundTaskWrapper taskWrapper) { if (appSettings is null) { throw new ArgumentNullException(nameof(appSettings)); } this.appSettings = appSettings; this.telemetryClient = telemetryClient; this.openShiftActivity = openShiftActivity; this.utility = utility; this.graphUtility = graphUtility; this.openShiftMappingEntityProvider = openShiftMappingEntityProvider; this.teamDepartmentMappingProvider = teamDepartmentMappingProvider; this.httpClientFactory = httpClientFactory; this.openShiftRequestMappingEntityProvider = openShiftRequestMappingEntityProvider; this.taskWrapper = taskWrapper; }
private async Task TimerCommandsBackground() { int timerCommandIndex = 0; await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { DateTimeOffset startTime = DateTimeOffset.Now; int startMessageCount = this.Messages.Count; tokenSource.Token.ThrowIfCancellationRequested(); await Task.Delay(1000 * 60 * ChannelSession.Settings.TimerCommandsInterval); tokenSource.Token.ThrowIfCancellationRequested(); IEnumerable <TimerCommand> timers = ChannelSession.Settings.TimerCommands.Where(c => c.IsEnabled); if (timers.Count() > 0) { timerCommandIndex = timerCommandIndex % timers.Count(); TimerCommand command = timers.ElementAt(timerCommandIndex); while ((this.Messages.Count - startMessageCount) < ChannelSession.Settings.TimerCommandsMinimumMessages) { tokenSource.Token.ThrowIfCancellationRequested(); await Task.Delay(1000 * 10); } await command.Perform(); timerCommandIndex++; } }); }
private async Task WidgetsBackgroundUpdate() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); UserViewModel user = await ChannelSession.GetCurrentUser(); foreach (var widgetGroup in ChannelSession.Settings.OverlayWidgets.GroupBy(ow => ow.OverlayName)) { IOverlayService overlay = this.GetOverlay(widgetGroup.Key); if (overlay != null) { overlay.StartBatching(); foreach (OverlayWidget widget in widgetGroup) { try { if (widget.IsEnabled) { bool isInitialized = widget.Item.IsInitialized; if (!isInitialized) { await widget.Item.Initialize(); } if (!isInitialized || !widget.DontRefresh) { OverlayItemBase item = await widget.Item.GetProcessedItem(user, new List <string>(), new Dictionary <string, string>()); if (item != null) { await overlay.SendItem(item, widget.Position, new OverlayItemEffects()); } } } else { await widget.Item.Disable(); } } catch (Exception ex) { Logger.Log(ex); } } await overlay.EndBatching(); } } await Task.Delay(ChannelSession.Settings.OverlayWidgetRefreshTime * 1000); }); }
private async Task BackgroundSongMaintainer(CancellationTokenSource cancellationTokenSource) { int failedStatusAttempts = 0; await BackgroundTaskWrapper.RunBackgroundTask(cancellationTokenSource, async (tokenSource) => { await Task.Delay(backgroundInterval, tokenSource.Token); await SongRequestService.songRequestLock.WaitAndRelease(async() => { if (this.Status != null && this.Status.State == SongRequestStateEnum.Playing) { this.Status.Progress += backgroundInterval; } if (this.forceStateQuery || this.Status == null || (this.Status.Length > 0 && this.Status.Progress >= this.Status.Length)) { this.forceStateQuery = false; SongRequestCurrentlyPlayingModel newStatus = await this.GetStatus(); if (newStatus == null || newStatus.State == SongRequestStateEnum.NotStarted) { this.forceStateQuery = true; failedStatusAttempts++; if (failedStatusAttempts >= 3) { await this.SkipInternal(); } } else { failedStatusAttempts = 0; this.Status.State = newStatus.State; this.Status.Progress = newStatus.Progress; this.Status.Length = newStatus.Length; this.Status.Volume = newStatus.Volume; if (this.Status.State == SongRequestStateEnum.Ended) { await this.SkipInternal(); } else if (this.Status.Volume != ChannelSession.Settings.SongRequestVolume) { await this.RefreshVolumeInternal(); } } } }); }); }
/// <summary> /// Initializes a new instance of the <see cref="PersonalGoalNoteController"/> class. /// </summary> /// <param name="confidentialClientApp">Instance of ConfidentialClientApplication class.</param> /// <param name="logger">Instance to send logs to the Application Insights service.</param> /// <param name="azureAdOptions">Instance of IOptions to read data from application configuration.</param> /// <param name="personalGoalNoteStorageProvider">Storage provider for working with team goal data in Microsoft Azure Table storage</param> /// <param name="tokenAcquisitionHelper">Instance of token acquisition helper to access token.</param> /// <param name="cardHelper">Instance of class that handles card create/update helper methods.</param> /// <param name="backgroundTaskWrapper">Instance of backgroundTaskWrapper to run a background task.</param> public PersonalGoalNoteController( IConfidentialClientApplication confidentialClientApp, ILogger <PersonalGoalNoteController> logger, IOptions <AzureAdOptions> azureAdOptions, IPersonalGoalNoteStorageProvider personalGoalNoteStorageProvider, TokenAcquisitionHelper tokenAcquisitionHelper, CardHelper cardHelper, BackgroundTaskWrapper backgroundTaskWrapper) : base(confidentialClientApp, azureAdOptions, logger, tokenAcquisitionHelper) { this.logger = logger; this.personalGoalNoteStorageProvider = personalGoalNoteStorageProvider; this.cardHelper = cardHelper; this.backgroundTaskWrapper = backgroundTaskWrapper; }
private async Task RefreshInteractiveUsers() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { foreach (InteractiveParticipantModel participant in await this.GetRecentParticipants()) { if (await ChannelSession.ActiveUsers.HasUser(participant.userID)) { await ChannelSession.ActiveUsers.AddOrUpdateUser(participant); } } await Task.Delay(30000); }); }
private async Task BackgroundSongMaintainer(CancellationTokenSource cancellationTokenSource) { int totalLoops = 0; await BackgroundTaskWrapper.RunBackgroundTask(cancellationTokenSource, async (tokenSource) => { await Task.Delay(backgroundInterval, tokenSource.Token); await SongRequestService.songRequestLock.WaitAndRelease(async() => { if (this.Status != null && this.Status.Length > 0) { totalLoops++; if (this.Status.State == SongRequestStateEnum.Playing) { this.Status.Progress += backgroundInterval; if (totalLoops >= 30) { SongRequestCurrentlyPlayingModel newStatus = await this.GetStatus(); if (newStatus != null) { this.Status.State = newStatus.State; this.Status.Progress = newStatus.Progress; this.Status.Length = newStatus.Length; this.Status.Volume = newStatus.Volume; } totalLoops = 0; } } if (this.Status.Progress >= this.Status.Length || this.Status.State == SongRequestStateEnum.Ended) { await this.SkipInternal(); } } else { SongRequestCurrentlyPlayingModel newStatus = await this.GetStatus(); if (newStatus != null) { this.Status.State = newStatus.State; this.Status.Progress = newStatus.Progress; this.Status.Length = newStatus.Length; this.Status.Volume = newStatus.Volume; } } }); }); }
private async Task WidgetsBackgroundUpdate() { long updateSeconds = 0; await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); UserViewModel user = await ChannelSession.GetCurrentUser(); foreach (var widgetGroup in ChannelSession.Settings.OverlayWidgets.GroupBy(ow => ow.OverlayName)) { IOverlayService overlay = this.GetOverlay(widgetGroup.Key); if (overlay != null) { overlay.StartBatching(); foreach (OverlayWidgetModel widget in widgetGroup) { try { if (widget.IsEnabled) { if (!widget.Item.IsInitialized) { await widget.Initialize(); } else if (widget.SupportsRefreshUpdating && widget.RefreshTime > 0 && (updateSeconds % widget.RefreshTime) == 0) { await widget.UpdateItem(); } } else { if (widget.Item.IsInitialized) { await widget.Disable(); } } } catch (Exception ex) { Logger.Log(ex); } } await overlay.EndBatching(); } } await Task.Delay(1000); updateSeconds++; }); }
private async Task ChatterRefreshBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { await Task.Delay(300000, tokenSource.Token); tokenSource.Token.ThrowIfCancellationRequested(); IEnumerable <ChatUserModel> chatUsers = await ChannelSession.Connection.GetChatUsers(ChannelSession.Channel, int.MaxValue); chatUsers = chatUsers.Where(u => u.userId.HasValue); HashSet <uint> chatUserIDs = new HashSet <uint>(chatUsers.Select(u => u.userId.GetValueOrDefault())); IEnumerable <UserViewModel> existingUsers = await ChannelSession.ActiveUsers.GetAllUsers(); HashSet <uint> existingUsersIDs = new HashSet <uint>(existingUsers.Select(u => u.ID)); Dictionary <uint, ChatUserModel> usersToAdd = chatUsers.ToDictionary(u => u.userId.GetValueOrDefault(), u => u); List <uint> usersToRemove = new List <uint>(); foreach (uint userID in existingUsersIDs) { usersToAdd.Remove(userID); if (!chatUserIDs.Contains(userID)) { usersToRemove.Add(userID); } } foreach (ChatUserModel user in usersToAdd.Values) { this.ChatClient_OnUserJoinOccurred(this, new ChatUserEventModel() { id = user.userId.GetValueOrDefault(), username = user.userName, roles = user.userRoles, }); } foreach (uint userID in usersToRemove) { this.ChatClient_OnUserLeaveOccurred(this, new ChatUserEventModel() { id = userID }); } tokenSource.Token.ThrowIfCancellationRequested(); }); }
private async Task ChatRefreshBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); await this.Dispatcher.InvokeAsync <Task>(async() => { await this.RefreshUserList(); }); tokenSource.Token.ThrowIfCancellationRequested(); await Task.Delay(1000 * 30); }); }
private async Task ChatterJoinLeaveBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { List <ChatUserEventModel> joinsToProcess = new List <ChatUserEventModel>(); await this.userJoinLeaveEventsSemaphore.WaitAndRelease(() => { for (int i = 0; i < userJoinLeaveEventsTotalToProcess && i < this.userJoinEvents.Count(); i++) { ChatUserEventModel chatUser = this.userJoinEvents.Values.First(); joinsToProcess.Add(chatUser); this.userJoinEvents.Remove(chatUser.id); } return(Task.FromResult(0)); }); if (joinsToProcess.Count > 0) { IEnumerable <UserViewModel> processedUsers = await ChannelSession.ActiveUsers.AddOrUpdateUsers(joinsToProcess.Select(u => u.GetUser())); this.OnUsersJoinOccurred(this, processedUsers); } List <ChatUserEventModel> leavesToProcess = new List <ChatUserEventModel>(); await this.userJoinLeaveEventsSemaphore.WaitAndRelease(() => { for (int i = 0; i < userJoinLeaveEventsTotalToProcess && i < this.userLeaveEvents.Count(); i++) { ChatUserEventModel chatUser = this.userLeaveEvents.Values.First(); leavesToProcess.Add(chatUser); this.userLeaveEvents.Remove(chatUser.id); } return(Task.FromResult(0)); }); if (leavesToProcess.Count > 0) { IEnumerable <UserViewModel> processedUsers = await ChannelSession.ActiveUsers.RemoveUsers(leavesToProcess.Select(u => u.id)); this.OnUsersLeaveOccurred(this, processedUsers); } tokenSource.Token.ThrowIfCancellationRequested(); await Task.Delay(2500, tokenSource.Token); tokenSource.Token.ThrowIfCancellationRequested(); }); }
private async Task ChannelRefreshBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); await ChannelSession.RefreshChannel(); await Task.Delay(30000); tokenSource.Token.ThrowIfCancellationRequested(); await ChannelSession.RefreshChannel(); await Task.Delay(30000); tokenSource.Token.ThrowIfCancellationRequested(); List <UserCurrencyViewModel> currenciesToUpdate = new List <UserCurrencyViewModel>(); foreach (UserCurrencyViewModel currency in ChannelSession.Settings.Currencies.Values) { if (currency.IsActive) { currenciesToUpdate.Add(currency); } } await this.UpdateEachUser((user) => { user.Data.ViewingMinutes++; foreach (UserCurrencyViewModel currency in currenciesToUpdate) { if ((user.Data.ViewingMinutes % currency.AcquireInterval) == 0) { user.Data.AddCurrencyAmount(currency, currency.AcquireAmount); if (user.Roles.Contains(UserRole.Subscriber)) { user.Data.AddCurrencyAmount(currency, currency.SubscriberBonus); } } } return(Task.FromResult(0)); }); tokenSource.Token.ThrowIfCancellationRequested(); await ChannelSession.SaveSettings(); }); }
private async Task PlayerBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); bool shouldSkip = false; await DesktopSongRequestService.songRequestLock.WaitAsync(); SongRequestItem current = this.allRequests.FirstOrDefault(); if (current != null) { if (current.Type == SongRequestServiceTypeEnum.Spotify) { if (ChannelSession.Services.Spotify != null) { SpotifyCurrentlyPlaying currentlyPlaying = await ChannelSession.Services.Spotify.GetCurrentlyPlaying(); if (currentlyPlaying == null || currentlyPlaying.ID == null || !currentlyPlaying.ID.Equals(current.ID) || (!currentlyPlaying.IsPlaying && currentlyPlaying.CurrentProgress == 0)) { shouldSkip = true; } } } else if (current.Type == SongRequestServiceTypeEnum.YouTube || current.Type == SongRequestServiceTypeEnum.SoundCloud) { if (this.overlaySongFinished) { this.overlaySongFinished = false; shouldSkip = true; } } } DesktopSongRequestService.songRequestLock.Release(); if (shouldSkip) { await this.SkipToNextSong(); } await Task.Delay(2000); }); }
private async Task ChatRefreshBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); await this.Dispatcher.InvokeAsync <Task>(async() => { await this.RefreshUserList(); this.ViewersCountTextBlock.Text = ChannelSession.Channel.viewersCurrent.ToString(); this.ChatCountTextBlock.Text = ChannelSession.Chat.ChatUsers.Count.ToString(); }); tokenSource.Token.ThrowIfCancellationRequested(); await Task.Delay(1000 * 30); }); }
/// <summary> /// Initializes a new instance of the <see cref="ShiftController"/> class. /// </summary> /// <param name="userMappingProvider">user Mapping Provider.</param> /// <param name="upcomingShiftsActivity">upcoming Shifts Activity.</param> /// <param name="telemetryClient">ApplicationInsights DI.</param> /// <param name="utility">UniqueId Utility DI.</param> /// <param name="shiftEntityMappingProvider">ShiftEntityMapper DI.</param> /// <param name="appSettings">app settings.</param> /// <param name="teamDepartmentMappingProvider">Team department mapping provider.</param> /// <param name="httpClientFactory">The HTTP Client DI.</param> /// <param name="taskWrapper">Wrapper class instance for BackgroundTask.</param> public ShiftController( IUserMappingProvider userMappingProvider, IUpcomingShiftsActivity upcomingShiftsActivity, TelemetryClient telemetryClient, Utility utility, IShiftMappingEntityProvider shiftEntityMappingProvider, ITeamDepartmentMappingProvider teamDepartmentMappingProvider, AppSettings appSettings, IHttpClientFactory httpClientFactory, BackgroundTaskWrapper taskWrapper) { this.userMappingProvider = userMappingProvider; this.upcomingShiftsActivity = upcomingShiftsActivity; this.telemetryClient = telemetryClient; this.utility = utility; this.shiftMappingEntityProvider = shiftEntityMappingProvider; this.appSettings = appSettings; this.teamDepartmentMappingProvider = teamDepartmentMappingProvider; this.httpClientFactory = httpClientFactory; this.taskWrapper = taskWrapper; }
/// <summary> /// Initializes a new instance of the <see cref="SyncKronosToShiftsController"/> class. /// </summary> /// <param name="telemetryClient">ApplicationInsights DI.</param> /// <param name="configurationProvider">The Configuration Provider DI.</param> /// <param name="openShiftController">OpenShiftController DI.</param> /// <param name="openShiftRequestController">OpenShiftRequestController DI.</param> /// <param name="swapShiftController">SwapShiftController DI.</param> /// <param name="timeOffController">TimeOffController DI.</param> /// <param name="timeOffReasonController">TimeOffReasonController DI.</param> /// <param name="timeOffRequestsController">TimeOffRequestsController DI.</param> /// <param name="shiftController">ShiftController DI.</param> /// <param name="taskWrapper">Wrapper class instance for BackgroundTask.</param> public SyncKronosToShiftsController( TelemetryClient telemetryClient, IConfigurationProvider configurationProvider, OpenShiftController openShiftController, OpenShiftRequestController openShiftRequestController, SwapShiftController swapShiftController, TimeOffController timeOffController, TimeOffReasonController timeOffReasonController, TimeOffRequestsController timeOffRequestsController, ShiftController shiftController, BackgroundTaskWrapper taskWrapper) { this.telemetryClient = telemetryClient; this.configurationProvider = configurationProvider; this.openShiftController = openShiftController; this.openShiftRequestController = openShiftRequestController; this.swapShiftController = swapShiftController; this.timeOffController = timeOffController; this.timeOffReasonController = timeOffReasonController; this.timeOffRequestsController = timeOffRequestsController; this.shiftController = shiftController; this.taskWrapper = taskWrapper; }
private async Task TimerCommandsBackground() { this.timerCommandIndexes = new Dictionary <string, int>(); int groupTotalTime = 0; int nonGroupTotalTime = 0; int startTotalMessages = ChannelSession.Chat.Messages.Count; timerCommandIndexes[string.Empty] = 0; await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); await Task.Delay(1000 * 60, tokenSource.Token); tokenSource.Token.ThrowIfCancellationRequested(); if (!ChannelSession.Settings.DisableAllTimers) { Dictionary <string, List <TimerCommand> > commandGroups = new Dictionary <string, List <TimerCommand> >(); commandGroups[string.Empty] = new List <TimerCommand>(); foreach (var kvp in ChannelSession.Settings.CommandGroups) { commandGroups[kvp.Key] = new List <TimerCommand>(); } foreach (TimerCommand command in ChannelSession.Settings.TimerCommands) { if (string.IsNullOrEmpty(command.GroupName)) { commandGroups[string.Empty].Add(command); } else if (ChannelSession.Settings.CommandGroups.ContainsKey(command.GroupName)) { if (ChannelSession.Settings.CommandGroups[command.GroupName].TimerInterval == 0) { commandGroups[string.Empty].Add(command); } else { commandGroups[command.GroupName].Add(command); } } } groupTotalTime++; foreach (var kvp in ChannelSession.Settings.CommandGroups) { if (kvp.Value.TimerInterval > 0 && groupTotalTime % kvp.Value.TimerInterval == 0) { if (!timerCommandIndexes.ContainsKey(kvp.Key)) { timerCommandIndexes[kvp.Key] = 0; } if (commandGroups.ContainsKey(kvp.Key)) { await this.RunTimerFromGroup(kvp.Key, commandGroups[kvp.Key]); } } } if (nonGroupTotalTime >= ChannelSession.Settings.TimerCommandsInterval) { if ((ChannelSession.Chat.Messages.Count - startTotalMessages) >= ChannelSession.Settings.TimerCommandsMinimumMessages) { await this.RunTimerFromGroup(string.Empty, commandGroups[string.Empty]); startTotalMessages = ChannelSession.Chat.Messages.Count; nonGroupTotalTime = 0; } } else { nonGroupTotalTime++; } } }); }
private async Task PlayerBackground() { await BackgroundTaskWrapper.RunBackgroundTask(this.backgroundThreadCancellationTokenSource, async (tokenSource) => { tokenSource.Token.ThrowIfCancellationRequested(); bool changeOccurred = false; await SongRequestService.songRequestLock.WaitAndRelease(async() => { Logger.LogDiagnostic("Current Song: " + this.currentSong); Logger.LogDiagnostic("Spotify Status: " + this.spotifyStatus); Logger.LogDiagnostic("YouTube Status: " + this.youTubeStatus); if (this.currentSong == null) { await this.SkipToNextSongInternal(); changeOccurred = true; } else { SongRequestItem status = null; if (this.currentSong.Type == SongRequestServiceTypeEnum.Spotify) { status = this.spotifyStatus = await this.GetSpotifyStatus(); } else if (this.currentSong.Type == SongRequestServiceTypeEnum.YouTube) { status = await this.GetYouTubeStatus(); } if (status != null) { if (status.Volume != ChannelSession.Settings.SongRequestVolume) { await this.RefreshVolumeInternal(); } if (this.currentSong.Type == status.Type && this.currentSong.ID.Equals(status.ID)) { this.currentSong.Progress = status.Progress; this.currentSong.State = status.State; } } if (currentSong.State == SongRequestStateEnum.NotStarted) { await this.RefreshVolumeInternal(); await this.PlaySongInternal(this.currentSong); changeOccurred = true; } else if (this.currentSong.State == SongRequestStateEnum.Ended) { await this.RefreshVolumeInternal(); await this.SkipToNextSongInternal(); changeOccurred = true; } } }); if (changeOccurred) { GlobalEvents.SongRequestsChangedOccurred(); await Task.Delay(2500, tokenSource.Token); } await Task.Delay(1000, tokenSource.Token); }); }