예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
 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;
 }
예제 #5
0
 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);
     }
 }
예제 #6
0
        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();
        }