Ejemplo n.º 1
0
        public static MDSourceFile WriteSourceFileDefault(
            this LitOptions LO,
            LitNovel novel,
            LitSceneMetadata metadata,
            LitAuthor author
            )
        {
            //Write all of the lines of the file
            var lines = LO.WriteMetadata(metadata, author);
            var query = novel.Scenes
                        .Where(s => s.Metadata == metadata)
                        .Select(s => LO.WriteElmSourceLines(s, author));

            foreach (var scenelines in query)
            {
                lines.AddRange(scenelines);
            }
            //Create the file
            var SourceFile = new MDSourceFile()
            {
                Metadata = metadata,
                Author   = author,
                Lines    = lines
            };

            return(SourceFile);
        }
Ejemplo n.º 2
0
 public String this[LitAuthor author] {
     get {
         return(this.Text[author] != null ? Text[author] : "");
     }
     set {
         this.Text[author] = value;
     }
 }
Ejemplo n.º 3
0
 public static void ParseElmTextDefault(
     this LitOptions LO,
     LitNovel novel,
     LitElm elm,
     LitAuthor author,
     IEnumerable <String> lines
     )
 {
     elm.Source[author] = LO.SourceLinesToString(lines);
 }
Ejemplo n.º 4
0
        public static LitAuthor ParseAuthorDefault(
            this LitOptions LO,
            LitNovel novel,
            IEnumerable <String> metadatalines
            )
        {
            var retVal = new LitAuthor();
            var links  = metadatalines.Select(l => LO.ParseLink(l)).Where(link => link != null);

            retVal.Author = links.Where(link => link.Link.Equals("Author")).Select(link => link.Tag.ToLower()).FirstOrDefault();
            return(novel.AddAuthorDistinct(retVal));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Will add a new source info to the novel, and return the current source info
 /// </summary>
 /// <param name="novel"></param>
 /// <param name="info"></param>
 /// <returns></returns>
 public static LitAuthor AddAuthorDistinct(this LitNovel novel, LitAuthor info)
 {
     foreach (var currentSourceInfo in novel.Authors)
     {
         if (currentSourceInfo.IsSourceInfoIntersection(info))
         {
             return(currentSourceInfo);
         }
     }
     novel.Authors.Add(info);
     return(info);
 }
Ejemplo n.º 6
0
        public static String AllText(
            this LitElm elm,
            LitAuthor author
            )
        {
            var retVal = new StringBuilder();

            retVal.AppendLine(elm.Source[author]);
            foreach (var child in elm.Children)
            {
                retVal.AppendLine(child.AllText(author));
            }
            return(retVal.ToString());
        }
Ejemplo n.º 7
0
 public static String ToShortFilenameDefault(
     this LitOptions LO,
     MDAnnSourceInfo info,
     LitSceneMetadata metadata,
     LitAuthor author
     )
 {
     return(ToShortFilenameDefault(
                LO,
                info.Prefix,
                metadata.Descriptor,
                author.Author
                ));
 }
        //TODO
        //Make a LitOptionsFactory
        public static List <MDSourceFile> WriteSourceFileNovel(
            this LitOptions LO,
            IEnumerable <String> HeaderAcc,
            IEnumerable <String> MetadataAcc,
            LitElm sourceElm,
            LitAuthor author
            )
        {
            var retVal = new List <MDSourceFile>();

            //Base Case
            if (sourceElm.Children.Count == 0)
            {
                var sourcefile = new MDSourceFile();
                sourcefile.Metadata = new LitSceneMetadata()
                {
                    Text       = MetadataAcc.ToList(),
                    Descriptor = sourceElm.TreeTag.Tag.TrimStart('.'),
                    Header     = String.Join(" - ", HeaderAcc)
                };
                sourcefile.Author = author;

                //This is an inelegent way to force the treetag to be the first scene of the novel
                sourceElm.TreeTag.Tag = String.Format("{0}.01", sourceElm.TreeTag.Tag);
                sourcefile.Lines      = new List <String>(
                    LO.WriteMetadata(sourcefile.Metadata, sourcefile.Author)
                    .Concat(LO.WriteElmSourceLines(sourceElm, author))
                    );
                retVal.Add(sourcefile);
            }
            //Inductive Case
            else
            {
                foreach (var child in sourceElm.Children)
                {
                    var newHeaderAcc   = HeaderAcc.Concat(new [] { child.Header });
                    var newMetadataAcc = MetadataAcc.Concat(
                        LO.WriteElmTextDefault(sourceElm.Source[author])
                        );
                    retVal.AddRange(WriteSourceFileNovel(
                                        LO,
                                        newHeaderAcc,
                                        newMetadataAcc,
                                        child,
                                        author
                                        ));
                }
            }
            return(retVal);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="lines"></param>
        /// <returns></returns>
        public static LitElm ParseToElmDefault(
            this LitOptions LO,
            LitNovel novel,
            LitSceneMetadata metadata,
            LitAuthor author,
            IEnumerable <String> lines
            )
        {
            var retVal = new LitElm();

            //Some checks
            if (!novel.Authors.Contains(author))
            {
                throw new Exception(String.Format("Novel does not contain source info. {0}", author.Author));
            }
            if (!novel.SceneMetadata.Contains(metadata))
            {
                throw new Exception(String.Format("Novel does not contain metadata. {0}", metadata.Descriptor));
            }

            //Parse the header
            LO.ParseElmHeader(novel, retVal, lines);

            var PartitionedLines = LO.ExtractSubElms(lines);

            LO.ParseElmLinks(
                novel,
                retVal,
                LO.ExtractElmLinkLines(PartitionedLines.First())
                );

            LO.ParseElmText(novel, retVal, author, PartitionedLines.First());

            foreach (var eventLines in PartitionedLines.Skip(1))
            {
                var litEvent = LO.ParseToElm(novel, metadata, author, eventLines);
                retVal.AddElm(litEvent);
            }

            retVal.Metadata = metadata;
            return(retVal);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Takes a litelm and writes all of the lines for that elm that go into the source for a particular Author
        /// </summary>
        /// <param name="LO"></param>
        /// <param name="litElm"></param>
        /// <param name="author"></param>
        /// <param name="headerlevel"></param>
        /// <returns></returns>
        public static List <String> WriteSourceLinesDefault(
            this LitOptions LO,
            LitElm litElm,
            LitAuthor author,
            int headerlevel
            )
        {
            var retVal = new List <String>();

            retVal.Add(LO.WriteElmHeader(litElm, headerlevel));
            retVal.AddRange(LO.WriteElmLinks(litElm));
            try {
                retVal.AddRange(LO.WriteElmText(litElm.Source[author]));
            }
            catch (KeyNotFoundException) { }
            foreach (var child in litElm.Children)
            {
                retVal.AddRange(WriteSourceLinesDefault(LO, child, author, headerlevel + 1));
            }
            return(retVal);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Takes a litelm and writes all of the lines for that elm that go into the source for a particular Author
 /// </summary>
 /// <param name="LO"></param>
 /// <param name="litElm"></param>
 /// <param name="author"></param>
 /// <returns></returns>
 public static List <String> WriteSourceLinesDefault(this LitOptions LO, LitElm litElm, LitAuthor author)
 {
     return(ParsingTools.WriteSourceLinesDefault(LO, litElm, author, 1));
 }
        public static List <String> WriteMetadataDefault(this LitOptions LO, LitSceneMetadata metadata, LitAuthor sourceinfo)
        {
            var retVal = new List <String>();

            retVal.Add(String.Format("# {0}", metadata.Header));
            retVal.Add(MakeLinkLine("Metadata", metadata.Descriptor));
            retVal.Add(MakeLinkLine("Descriptor", metadata.Descriptor));
            retVal.Add(sourceinfo.ToSourceLine());
            retVal.AddRange(metadata.Text);
            return(retVal);
        }
Ejemplo n.º 13
0
 public static String ToSourceLine(this LitAuthor sourceinfo)
 {
     return(ParsingTools.MakeLinkLine("Author", sourceinfo.Author));
 }
Ejemplo n.º 14
0
 public static bool IsSourceInfoIntersection(this LitAuthor info1, LitAuthor info2)
 {
     return(info1.Author.Equals(info2.Author));
 }