Example #1
0
        private ArticleInfo GetArticleInfo(string file)
        {
            ArticleInfo articleInfo = new ArticleInfo();

            // Using stream reader to read article info from file to an ArticleInfo object
            using (StreamReader sr = new StreamReader(file))
            {
                articleInfo.Category = GetNextNonEmptyLine(sr);
                articleInfo.Title    = GetNextNonEmptyLine(sr);
                articleInfo.Author   = GetNextNonEmptyLine(sr);
                articleInfo.ID       = Path.GetFileNameWithoutExtension(file);
            }

            return(articleInfo);
        }
Example #2
0
        public bool Parse()
        {
            string[] allFiles = Directory.GetFiles(InputFolder);
            foreach (string file in allFiles)
            {
                if (Path.GetFileNameWithoutExtension(file) == "metadata")
                {
                    // Read metadata file into a dictionary of key value pairs
                    ReadMetadata(file);
                }
                else if (Path.GetExtension(file) == ".txt")
                {
                    // Check for the version of the file, it is the suffix of the file, either a 's', 't' or 'e'.
                    string[] tokens  = Path.GetFileNameWithoutExtension(file).Split('_');
                    string   version = tokens.LastOrDefault();
                    int      index;
                    int.TryParse(tokens.First(), out index);

                    // Generate the JSON file for this file
                    GenerateJSONFile(file, version);

                    ArticleInfo articleInfo = GetArticleInfo(file);

                    // Add file to dictionaries bases on its version.
                    if (version == "s" || version == "e")
                    {
                        simplifiedTOC.AddNewArticleInfo(articleInfo, index);
                    }

                    if (version == "t" || version == "e")
                    {
                        traditionalTOC.AddNewArticleInfo(articleInfo, index);
                    }
                }
            }

            // Generate table of content for both dictionaries.
            simplifiedTOC.GenerateJSON(OutputFolder + "\\table_of_content_s.json");
            traditionalTOC.GenerateJSON(OutputFolder + "\\table_of_content_t.json");

            return(true);
        }