Beispiel #1
0
        public static LitRef ParseToLitRefDefault(this LitOptions LO, LitNovel novel, IEnumerable <String> lines)
        {
            if (lines.Count() == 0)
            {
                return(null);
            }
            var PartitionedLines = ParsingTools.PartitionLines(lines, l => System.Text.RegularExpressions.Regex.IsMatch(l, @"^##[^#]"));
            var link             = PartitionedLines.First().Select(s => LO.ParseLink(s)).Where(l => l != null).First();

            var retVal = new LitRef();

            //Do the specific things for this style of reference
            if (link.Link.Equals("Reference"))
            {
                if (link.Tag.Equals("Character"))
                {
                    retVal = new LitChar();
                    (retVal as LitChar).ParseLitChar(PartitionedLines);
                }
                else if (link.Tag.Equals("Place"))
                {
                    retVal = new LitPlace();
                }
                else if (link.Tag.Equals("Myth"))
                {
                    retVal = new LitMyth();
                }
                else if (link.Tag.Equals("Object"))
                {
                    retVal = new LitObject();
                }
            }

            //Get the first tag of the reference
            string pattern = @"^# (.+)";
            var    match   = System.Text.RegularExpressions.Regex.Match(lines.First(), pattern);

            retVal.Tags.Add(new LitTag(match.Groups[1].Value));

            //Save the commentary
            retVal.Commentary = LO.SourceLinesToString(PartitionedLines.First());

            //Save the tags
            pattern = "^## Tags$";
            var tagsList = PartitionedLines.Where(list => System.Text.RegularExpressions.Regex.IsMatch(list.First(), pattern)).First();

            foreach (var tagline in tagsList.Where(s => LO.IsSourceLine(s)))
            {
                retVal.AddTag(new LitTag(tagline));
            }

            return(novel.AddReferenceDistinct(retVal));
        }
        /// <summary>
        /// Takes the lines of the notes, and populates the novel References and such appropiately
        /// </summary>
        /// <param name="novel"></param>
        /// <param name="lines"></param>
        public static void ParseNotesFileDefault(this LitOptions LO,
                                                 LitNovel novel,
                                                 MDNotesFile notesfile
                                                 )
        {
            var    PartitionedLines = LO.ExtractNotesRefs(notesfile);
            LitRef litref           = null;

            foreach (var refLines in PartitionedLines)
            {
                litref = LO.ParseToLitRef(novel, refLines);
                novel.AddReferenceDistinct(litref, false);
            }
        }
Beispiel #3
0
 public static void ParseElmLinksDefault(
     this LitOptions LO,
     LitNovel novel,
     LitElm elm,
     IEnumerable <MDLinkLine> links
     )
 {
     foreach (var link in links)
     {
         //I feel as though there is a way to use reflection to be super clever here,
         //But upon thinking about it, I think it would only create more confusion than it
         //would help, since the actual properties of the scene are not that numerous,
         //and to be honest there would probably me more exceptional cases than I am willing
         //To admit, so at this juncture, I will use a elseif chain to do what I want.
         //I don't like it, but at the same time I sort of do because it is more explicit and easier
         //To work with, and an if else chain makes sense.
         //I want to use reflection so bad, but it's probably for the best that I do this in
         //The concrete way for now, and if at some point down the road, I want to change this to use reflection,
         //It will be not terribly difficult to do (at least, only as difficult as reflection is)
         LitRef novelRef;
         if (link.Link.Equals("TreeTag"))
         {
             elm.TreeTag = new LitTag(link.Tag);
         }
         else if (link.Link.Equals("UserTag"))
         {
             //TODO UserTags must be unique, not only and that should be checked somewhere here
             elm.UserTags.Add(new LitTag(link.Tag));
         }
         else if (link.Link.Equals("Character"))
         {
             novelRef = novel.AddReferenceDistinct(new LitChar(link.Tag));
             elm.References.Add(novelRef as LitChar);
         }
         else if (link.Link.Equals("Place"))
         {
             novelRef = novel.AddReferenceDistinct(new LitPlace(link.Tag));
             elm.References.Add(novelRef as LitPlace);
         }
         else if (link.Link.Equals("Myth"))
         {
             novelRef = novel.AddReferenceDistinct(new LitMyth(link.Tag));
             elm.References.Add(novelRef as LitMyth);
         }
         else if (link.Link.Equals("Object"))
         {
             novelRef = novel.AddReferenceDistinct(new LitObject(link.Tag));
             elm.References.Add(novelRef as LitObject);
         }
         else if (link.Link.Equals("Actor"))
         {
             novelRef = novel.AddReferenceDistinct(new LitChar(link.Tag));
             elm.Actors.Add(novelRef as LitChar);
         }
         else if (link.Link.Equals("Location"))
         {
             novelRef = novel.AddReferenceDistinct(new LitPlace(link.Tag));
             elm.Locations.Add(novelRef as LitPlace);
         }
         else if (link.Link.Equals("Speaker"))
         {
             novelRef = novel.AddReferenceDistinct(new LitChar(link.Tag));
             elm.Speakers.Add(novelRef as LitChar);
         }
         else if (link.Link.Equals("Event"))
         {
             novelRef = novel.AddReferenceDistinct(new LitMyth(link.Tag));
             elm.Events.Add(novelRef as LitMyth);
         }
         else if (link.Link.Equals("Item"))
         {
             novelRef = novel.AddReferenceDistinct(new LitObject(link.Tag));
             elm.Items.Add(novelRef as LitObject);
         }
     }
 }
Beispiel #4
0
 /// <summary>
 /// Will add a new reference to the list of references of the novel, or,
 /// if the novel has the reference already, will add any new tags that the
 /// current reference might not have.
 /// </summary>
 /// <param name="novel"></param>
 /// <param name="reference"></param>
 /// <returns></returns>
 public static LitRef AddReferenceDistinct(this LitNovel novel, LitRef reference)
 {
     return(novel.AddReferenceDistinct(reference, true));
 }