예제 #1
0
        public byte[] Generate(Models.WordList wordList)
        {
            MemoryStream mem = new MemoryStream();

            Encoding encoding = new UTF8Encoding(false);

            using (StreamWriter streamWriter = new StreamWriter(mem, encoding))
            {
                using (HtmlTextWriter writer = new HtmlTextWriter(streamWriter))
                {
                    writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                    writer.WriteLine("<!DOCTYPE html>");
                    writer.WriteLine("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
                    writer.WriteLine("<head>");
                    WriteStyleSection(writer);
                    writer.WriteLine("</head>");
                    writer.WriteLine("<body>");

                    foreach (WordForm wordForm in wordList.GetAllForms().OrderBy(wf => wf.Title))
                    {
                        WriteWordForm(writer, wordForm);
                    }

                    writer.WriteLine("</body>");
                    writer.WriteLine("</html>");
                    writer.Flush();
                }
            }

            return(mem.ToArray());
        }
예제 #2
0
 public void GenerateZip(Models.WordList wordList, Stream outputStream)
 {
     using (ZipArchive zip = new ZipArchive(outputStream, ZipArchiveMode.Create, true))
     {
         ZipArchiveEntry wordsEntry = zip.CreateEntry(ZipWordListEntryName);
         GenerateXml(wordList, wordsEntry.Open());
     }
 }
예제 #3
0
        public static Models.WordList ConvertToObject(WordListXml wordListXml)
        {
            var words = new List<Word>();

            foreach (WordXml wordXml in wordListXml.Words)
            {
                words.Add(ConvertToObject(wordXml));
            }

            var wordList = new Models.WordList();
            wordList.Populate(words);

            return wordList;
        }
예제 #4
0
        public void GenerateXml(Models.WordList wordList, Stream outputStream)
        {
            WordList.WordListXml wordsXml = WordListXmlConverter.ConvertToXml(wordList);

            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.Encoding = new UTF8Encoding(false);
            xmlWriterSettings.Indent   = true;
            using (XmlWriter writer = XmlWriter.Create(outputStream, xmlWriterSettings))
            {
                serializer.Serialize(writer, wordsXml);
                writer.Flush();
            }
        }
예제 #5
0
        public static Models.WordList ConvertToObject(WordListXml wordListXml)
        {
            var words = new List <Word>();

            foreach (WordXml wordXml in wordListXml.Words)
            {
                words.Add(ConvertToObject(wordXml));
            }

            var wordList = new Models.WordList();

            wordList.Populate(words);

            return(wordList);
        }
예제 #6
0
        public static WordListXml ConvertToXml(Models.WordList wordList)
        {
            var         wordListXml = new WordListXml();
            List <Word> words       = wordList.GetAllWords().Select(w => w.Word).ToList();

            wordListXml.Words = new WordXml[words.Count];

            int idx = 0;

            foreach (Word word in words)
            {
                wordListXml.Words[idx++] = ConvertToXml(word);
            }

            return(wordListXml);
        }