protected override void ObservingThread() { while (true) { // Wait signal from timer WaitHandler.WaitOne(); // Check if there are any channels to check new content Program.Log(Tag, "Checking new videos on channels"); if (SettingsManager.Config.ChannelList.Count < 1) { Program.Log(Tag, "Nothing to check"); } foreach (var chatChannel in SettingsManager.Config.ChannelList) { try { // If chat muted, skip it if (SettingsManager.Config.MutedServers.Contains(chatChannel.DiscordChatId)) { continue; } //If not YotubeService, skip it if (chatChannel.ServiceType != typeof(YouTubeClient)) { continue; } var reflectionSingletonGetter = (IClient)chatChannel.ServiceType.GetMethod("GetInstance")?.Invoke(null, null); var youTubeTask = reflectionSingletonGetter?.GetLast(chatChannel.ServiceChannel); youTubeTask?.Wait(); var video = (Video)youTubeTask?.Result; // If video found and not already sent to text chat channel if (video != null && reflectionSingletonGetter.AddLast(chatChannel.DiscordChatId, chatChannel.ServiceChannel, video.Id)) { Task <DiscordChannel> discordChatTask = Program.Discord.GetChannelAsync(chatChannel.DiscordChatId); discordChatTask.Wait(); var notifyMessage = string.Format( Resources.Resource.ResourceManager.GetString("youtube-notify-text", discordChatTask.Result.GetCultureInfo()), video.Author, video.Id); Program.Discord.SendMessageAsync(discordChatTask.Result, notifyMessage); Program.Log(Tag, $"New video for YouTube channel <{video.Author}> found. Sending it to discord chat <{discordChatTask.Result.Name}>"); } else { Program.Log(Tag, video == null ? $"No video found or it's null" : $"New YouTube video skipped '{video.Title}'", LogLevel.Debug); } } catch (Exception ex) { Program.Log(Tag, ex, DSharpPlus.LogLevel.Error); } } Program.Log(Tag, $"All channels checked. \nNext check:{DateTime.Now.AddMilliseconds(SettingsManager.Config.ObserveCheckInterval)}"); } }
protected override void JobThread(CancellationToken token) { var position = 0; while (_nextCheck.IsNext(position)) { token.ThrowIfCancellationRequested(); var readingPart = _queue.Next(); if (readingPart == null) { WaitHandler.WaitOne(); continue; } WaitHandler.Set(); var bytes = readingPart.Data; _writer.Write(bytes); position++; } }
protected override void JobThread(CancellationToken token) { var index = 0; while (Reader.LeftBytes > 0) { token.ThrowIfCancellationRequested(); if (_queue.Count() > Settings.ThreadPoolSize) { WaitHandler.WaitOne(); continue; } WaitHandler.Set(); var bytes = Read(); _queue.Add(index, bytes); index++; } _count = index; }