public void Lint(A3Log log) { ConvertIncomingYamlKeys(log); string tempFile = System.IO.Path.GetTempFileName(); File.WriteAllText(tempFile, Text); A3Yaml yaml = new A3Yaml(tempFile); bool returnedError = yaml.RunSyntaxLinter(log); if (returnedError) { Process.Start(log.Path); Process.Start(Path); // check to see if the user wants to retry DialogResult dialogResult = MessageBox.Show(AlertMessages[Alerts.SyntaxError], "YAML SYNTAX ERROR!", MessageBoxButtons.RetryCancel); if (dialogResult == DialogResult.Retry) { Lint(log); } else { A3Environment.QUIT_FROM_CURRENT_LOOP = true; } return; } return; }
public A3Outline Deserialize(A3Log log) { IDeserializer deserializer = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention()).Build(); A3Outline outline = new A3Outline(); try { outline = deserializer.Deserialize <A3Outline>(Text); return(outline); } catch (Exception ex) { log.Write(A3Log.Level.Error, ex.Message); Process.Start(log.Path); Process.Start(Path); DialogResult dialogResult = MessageBox.Show(AlertMessages[Alerts.DeserializationError].Replace("{}", ex.Message), "DESERIALIZATION ERROR!", MessageBoxButtons.RetryCancel); if (dialogResult == DialogResult.Retry) { A3Yaml a3Yaml = new A3Yaml(Path); a3Yaml.Lint(log); return(Deserialize(log)); } A3Environment.QUIT_FROM_CURRENT_LOOP = true; return(outline); } }
private bool RunSyntaxLinter(A3Log log) { Process process = new Process(); process.StartInfo.FileName = "yamllint"; process.StartInfo.Arguments = string.Concat("-c \"", A3Environment.YAML_LINT_CONFIG, "\" -f parsable \"", Path.Trim().Replace("\"", ""), "\""); process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.Start(); string text = process.StandardOutput.ReadToEnd(); process.WaitForExit(); bool error = false; text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).ToList().ForEach(l => { if (l.Contains("[error]")) { log.Write(A3Log.Level.Error, l); error = true; } else if (l.Contains("[warning]")) { log.Write(A3Log.Level.Warn, l); } }); return(error); }
private void btnPublish_Click(object sender, EventArgs e) { A3Environment.StartUp(); A3Log log = new A3Log(A3Log.Operations.Publish); A3Presentation presentation = new A3Presentation(Globals.ThisAddIn.Application.ActivePresentation); A3Outline outline = presentation.GenerateOutline(log); if (chkPNG.Checked) { presentation.PublishPNGs(); } if (chkMarkdown.Checked) { presentation.PublishMarkdown(); } if (chkPDF.Checked) { presentation.PublishPDF(); } if (chkYAML.Checked) { presentation.PublishYaml(); } Dispose(); }
private List <A3Chapter> GetChapters(A3Log log) { return(Slides?.Where(s => s.Type is A3Slide.Types.CHAPTER) .Select(c => { A3Chapter chapter = new A3Chapter(c); chapter.Subchapters.AddRange(GetSubChapters(log, chapter.Title)); return chapter; }).ToList()); }
private List <A3Subchapter> GetSubChapters(A3Log log, string chapterTitle) { return(Slides?.Where(s => (s.Type is A3Slide.Types.CONTENT) && string.Equals(s.Chapter, chapterTitle, StringComparison.OrdinalIgnoreCase)) .GroupBy(s => s.Subchapter).Select(sc => sc.ToList()).ToList() .Select(sub => { A3Subchapter subchapter = new A3Subchapter(sub[0]); subchapter.Slides = sub.Select(s => new A3Content(s)).ToList(); return subchapter; }).ToList()); }
public void NewBaseLine() { // Set Environment A3Environment.Clean(); A3Environment.ALLOW_INFER_FROM_SLIDE = true; A3Environment.ALLOW_DEFAULT_INFER_FROM_SLIDE = true; A3Environment.ENFORCE_CHAP_SUB_SPLITTING = false; // Setup logging A3Log log = new A3Log(A3Log.Operations.NewBaseline); SavePresentationAs("new_baseline"); string chapterName = null; foreach (A3Slide s in Slides) { if (A3Environment.QUIT_FROM_CURRENT_LOOP) { return; } if (!(s.Guid is null)) { s.HGuids.Add(s.Guid); } s.Guid = Guid.NewGuid().ToString(); s.FixMetadata(log, false); if (s.Type == A3Slide.Types.CHAPTER) { A3Environment.AFTER_CHAPTER = true; chapterName = s.Chapter; continue; } if (A3Environment.AFTER_CHAPTER && s.Type is A3Slide.Types.CONTENT) { s.Chapter = chapterName; s.Subchapter = "Contents"; s.WriteTag(A3Slide.Tags.CHAPSUB); continue; } if (s.Type == A3Slide.Types.QUESTION) { break; } } Presentation.Save(); // Cleanup environemnt A3Environment.Clean(); }
public void GenerateFromYaml(string yamlPath) { // Set global variables after starting with a clean slate A3Environment.Clean(); A3Environment.ALLOW_INFER_FROM_SLIDE = true; A3Environment.ALLOW_DEFAULT_INFER_FROM_SLIDE = true; // Setup logging A3Log log = new A3Log(A3Log.Operations.GenerateFromYaml); // Ingest the yaml file A3Yaml yaml = new A3Yaml(yamlPath); // Lint the YAML file before attempting to deserialize the outline and exit early if the user cancels the operation yaml.Lint(log); if (A3Environment.QUIT_FROM_CURRENT_LOOP) { A3Environment.Clean(); return; } // Create the outline from the YAML file and exit early if the user cancels the operation A3Outline outline = yaml.Deserialize(log); if (A3Environment.QUIT_FROM_CURRENT_LOOP) { A3Environment.Clean(); return; } // Open a copy of the model PowerPoint in the current PowerPoint context A3Presentation presentation = new A3Presentation(Globals.ThisAddIn.Application.Presentations.Open(A3Environment.MODEL_POWERPOINT, 0, 0, Microsoft.Office.Core.MsoTriState.msoTrue)); // Save the presentation to a unqiue location presentation.SavePresentationAs(outline.Course); // Generate the Presentation presentation.WriteFromOutline(outline); // Cleanup the initial slides for (int i = 0; i < 6; i++) { presentation.Presentation.Slides[1].Delete(); } // Save the generated presentation and handoff control back to the user presentation.Presentation.Save(); MessageBox.Show(A3Yaml.AlertMessages[A3Yaml.Alerts.YamlGenSuccess].Replace("{}", Path), "POWERPOINT GENERATION COMPLETE!", MessageBoxButtons.OK); A3Environment.Clean(); }
public A3Outline GenerateOutline(A3Log log) { // Set Enviornment A3Environment.Clean(); // Create new blank outline A3Outline outline = new A3Outline(); // Get the course info (outline.Course, outline.Filename, outline.HasLabs, outline.HasSlides, outline.HasVideos, outline.Weburl) = GetCourseInfo(log); // Retrieve each of the chapters contents. Each chapter will recurse its own internal tree to collect all the related content ie(subchapters and their content as well. ). outline.Chapters = GetChapters(log); // Return the outline return(outline); }
public void FixMetadata(bool allowInfer, bool allowDefault) { //Set Enviornment A3Environment.Clean(); A3Environment.ALLOW_INFER_FROM_SLIDE = allowInfer; A3Environment.ALLOW_DEFAULT_INFER_FROM_SLIDE = allowDefault; // Setup logging A3Log log = new A3Log(A3Log.Operations.FixMetadata); // Fix Metadata Slides?.ForEach(s => { if (A3Environment.QUIT_FROM_CURRENT_LOOP is false) { s.FixMetadata(log, false); } }); // Cleanup A3Environment.Clean(); }
public void FillSubChapters() { // Clean the global variables A3Environment.Clean(); // Setup logging A3Log log = new A3Log(A3Log.Operations.FillSubChapters); // Initialize variables string subchapter = "Contents"; int count = 1; Slides.ForEach(s => { subchapter = s.FillSubchapter(log, s, subchapter, count); count++; }); // Clean up the global variables state A3Environment.Clean(); }
public void FixMetadata(A3Log log, bool alert) { List<Alerts> alerts = AlertOrDefaultMetadataValues(); while (alerts.Count > 0 && A3Environment.QUIT_FROM_CURRENT_LOOP is false) { alerts.Insert(0, Alerts.SlideInfo); string message = string.Join(" ", alerts.Select(a => AlertMessages[a].Replace("{SN}", Slide.SlideNumber.ToString()) .Replace("{GUID}", Guid)) .ToList()); log.Write(A3Log.Level.Warn, message); if (alerts.All(a => a is Alerts.TypeDefaultInfered)) return; else if (alert) { Slide.Select(); message = string.Concat(message, AlertMessages[Alerts.Continue]); DialogResult dialogResult = MessageBox.Show(message, AlertMessages[Alerts.MessageInfo], MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) return; } ShowMetadataForm(); FixMetadata(log, true); } }
private void ConvertIncomingYamlKeys(A3Log log) { List <string> convertedLines = new List <string>() { }; for (int i = 0; i < Lines.Count; i++) { string line = Lines[i]; string word = line.Trim().TrimStart('-').Split(' ')[0]; if (KeyMappings.TryGetValue(word.ToLower(), out string replace)) { convertedLines.Add(ReplaceFirstOccurance(line, word, replace)); } else if (line.Split(':').Length > 1) { log.Write(A3Log.Level.Warn, AlertMessages[Alerts.YamlIncomingKeyMapWarn].Replace("{}", i.ToString())); } convertedLines.Add(line); } Lines = convertedLines; UpdateTextFromLines(); }
public string FillSubchapter(A3Log log, A3Slide slide, string subchapter, int count) { switch (slide.Type) { case Types.CHAPTER: log.Write(A3Log.Level.Info, "Slide number {} was identified as a Chapter slide.".Replace("{}", count.ToString())); subchapter = "Contents"; A3Environment.AFTER_CHAPTER = true; break; case Types.CONTENT: if (slide.Subchapter != subchapter && A3Environment.AFTER_CHAPTER) { if (string.Equals(slide.Subchapter, "Contents")) { slide.Subchapter = subchapter; slide.WriteTag(Tags.CHAPSUB); log.Write(A3Log.Level.Info, "Slide number {N} was identified as a Content slide which has a unique subchapter name: {SC}, which has overwritten the current \"Contents\" subchapter name.".Replace("{N}", count.ToString()).Replace("{SC}", subchapter)); } else { subchapter = slide.Subchapter; log.Write(A3Log.Level.Info, "Slide number {N} was identified as a Content slide which has a new subchapter name: {SC}.".Replace("{N}", count.ToString()).Replace("{SC}", subchapter)); } } else { log.Write(A3Log.Level.Info, "Slide number {N} was identified as a Content slide which matched the prvious subchapter: {SC}.".Replace("{N}", count.ToString()).Replace("{SC}", subchapter)); } break; case Types.QUESTION: A3Environment.Clean(); log.Write(A3Log.Level.Info, "Slide number {} was identified as a Question slide, no more slides will be parsed.".Replace("{}", count.ToString())); break; } return subchapter; }
private A3Slide GetCourse(A3Log log) { return(Slides?.FirstOrDefault(s => s.Type is A3Slide.Types.COURSE)); }
private (string name, string filename, bool haslabs, bool hasslides, bool hasvideos, string weburl) GetCourseInfo(A3Log log) { // Set the default values for the course info (string name, string filename, bool haslabs, bool hasslides, bool hasvideos, string weburl) = (null, null, false, false, false, null); // Find the course slide and log errors A3Slide course = GetCourse(log); // Split the notes section by the lines and then look for the specified metadata keys List <string> noteLines = new List <string>(course.Notes.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)); foreach (string line in noteLines) { List <string> map = new List <string>(line.Trim().Split(':')); if (Enum.TryParse(map[0].Remove('-').Trim().ToUpper(), out A3Outline.Metadata enumValue) && map.Count > 1) { switch (enumValue) { case A3Outline.Metadata.NAME: name = map[1]; break; case A3Outline.Metadata.FILENAME: filename = map[1]; break; case A3Outline.Metadata.HASLABS: try { haslabs = Convert.ToBoolean(map[1].ToLower()); } catch { log.Write(A3Log.Level.Warn, "Failed to convert has-labs value to a boolean. -- Defaulting to false."); } break; case A3Outline.Metadata.HASSLIDES: try { hasslides = Convert.ToBoolean(map[1].ToLower()); } catch { log.Write(A3Log.Level.Warn, "Failed to convert has-slides value to a boolean. -- Defaulting to false."); } break; case A3Outline.Metadata.HASVIDEOS: try { hasvideos = Convert.ToBoolean(map[1].ToLower()); } catch { log.Write(A3Log.Level.Warn, "Failed to convert has-videos value to a boolean. -- Defaulting to false."); } break; case A3Outline.Metadata.WEBURL: weburl = map[1]; break; } } } return(name, filename, haslabs, hasslides, hasvideos, weburl); }