示例#1
0
        private void WriteNationsToFile(string fileName, List <Nation> nations, out string formattedText)
        {
            // Get the text
            NationsExporter.ExportToCsvFile(nations, out formattedText);

            // open the write stream
            using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.UTF8))
            {
                // loop through the lines of text
                using (StringReader reader = new StringReader(formattedText))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        // write the line
                        sw.WriteLine(line);
                    }
                }

                // tidy up
                sw.Close();
            }
        }
示例#2
0
        public ExportText GetExportNationsCsvText(string userId)
        {
            ExportText exportText = new ExportText {
                Format = "text/plain"
            };

            User foundUser = _userDatabase.LoadedItems.FirstOrDefault(x => x.Id.ToString() == userId);

            if (foundUser == null)
            {
                return(exportText);
            }

            GeographyProvider geographyProvider;
            BooksReadProvider booksReadProvider;

            _books = new ObservableCollection <Book>();

            if (GetProviders(out geographyProvider, out booksReadProvider))
            {
                if (geographyProvider.Nations != null && geographyProvider.Nations.Any())
                {
                    List <Nation> nations =
                        geographyProvider.Nations.OrderBy(x => x.Name).ToList();

                    // Get the file export string
                    string formattedText;

                    NationsExporter.ExportToCsvFile(nations, out formattedText);

                    // Return the formatted text
                    exportText.FormattedText = formattedText;
                }
            }

            return(exportText);
        }