using System; using System.Collections; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using schedulable; using System.Collections.Generic; namespace director { public class ShowHandler { private Scheduled todo; private string outputPath; public ShowHandler(Scheduled todo, string outputPath) { this.todo = todo; this.outputPath = outputPath; } internal void StartHandling() { Console.WriteLine("start handling"); CreateChecklist(); var napLength = (todo.Showtime - todo.Configuration.LeadTimeDesired) - DateTime.Now; Console.WriteLine($"napping until {todo.Showtime - todo.Configuration.LeadTimeDesired} ({napLength})"); if (napLength.TotalMinutes > 0) { Task.WaitAll(Task.Delay(napLength)); } Console.WriteLine("nap done, begin the checklist. which to us effectively means SHOWTIME"); //or do I want to split the checklists in the config file? consider later. try { HandleChecklist(); } catch (Exception e) { HumanCommunication.Instance.Say($"error in show handler! Panicking!\n{JsonConvert.SerializeObject(e)}", HumanCommunication.LogLevel.Showstopper); } } private void CreateChecklist() { Console.WriteLine($"begin the pre-pre show by creating a checklist."); Directory.CreateDirectory(outputPath); var text = new StringBuilder(); text.AppendLine($"# {todo.Occurrence._event.Description}"); #region share with humans var allItems = checklistFlattened(); if(allItems?.FirstOrDefault(pl => pl.type == "manual") != null) { Console.WriteLine($"nothing manual, not sharing with humans."); } else { //TODO: share } #endregion } private IEnumerable checklistFlattened() { if (todo.Configuration.checklist?.Count() > 0) { var toReturn = new List(); foreach(var line in todo.Configuration.checklist) { toReturn.AddRange(recurseChecklist(line)); } return toReturn; } return null; } private IEnumerable recurseChecklist(ProcessionLine line) { var asContainer = line as container; if (asContainer == null || asContainer.subitems?.Count() == 0) { return new List() { line }; } else { var toReturn = new List(); toReturn.AddRange(recurseChecklist(line)); return toReturn; } } internal void HandleChecklist() { Console.WriteLine($"should now be at the desired lead time. showtime: {todo.Showtime}"); } } }