using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using director; using franz; using Newtonsoft.Json; using Schedulable.Show; namespace ShowHandlers { public class YoutubeHandler : ShowHandler { private YoutubeRelease config; private List agentsPresent = new List(); private bool essentialChecksPassed = false; private bool allChecksPassed = false; private readonly AutoResetEvent checkSignal = new AutoResetEvent(false); public override void Handle(iCalHoopJumping.CalendarOccurrence evt) { config = JsonConvert.DeserializeObject(Program.conf.show_template_yt_release); config.PreShow.AgentsNeeded = config.PreShow.AgentsNeeded.Select(s => s.ToLower()); Telefranz.Instance.addHandler(agentReports); Task.Run(() => PreShow(evt)); if(evt.OccurrenceStart > DateTime.Now) { Task.WaitAll(Task.Delay(evt.OccurrenceStart - DateTime.Now)); } PostShow(evt); } ~YoutubeHandler() { Telefranz.Instance.removeHandler(agentReports); } protected void PreShow(iCalHoopJumping.CalendarOccurrence evt) { Console.WriteLine($"it's the pre-show, showtime at: {evt.OccurrenceStart}"); agentsPresent.Clear(); essentialChecksPassed = false; allChecksPassed = false; Task.WaitAny( Task.Delay(10) ); Telefranz.Instance.ProduceMessage(new silver_messages.global.sound_off()); while(agentsPresent.Where(ap => !config.PreShow.AgentsNeeded.Contains(ap))?.Count() > 0) { checkSignal.WaitOne(TimeSpan.FromSeconds(45)); } // //await sound offs for some timeout // config.PreShow.AgentsNeeded; // //once that's ok, await checks // config.PreShow.Checks; // //once that's ok, await first command, then start running them // config.PreShow.Commands; } protected void agentReports(silver_messages.global.report r) { if(config.PreShow.AgentsNeeded?.FirstOrDefault(an => an.ToLower() == r.name.ToLower()) != null) { lock(agentsPresent) { agentsPresent.Add(r.name.ToLower()); checkSignal.Set(); } } } protected void PostShow(iCalHoopJumping.CalendarOccurrence evt) { Console.WriteLine("can't do this bit without understanding when a show ends, sooo."); } } }