コード例 #1
0
ファイル: QuoteRepository.cs プロジェクト: powli/Beta
        /// <summary>
        /// Load from disk
        /// </summary>
        /// <returns></returns>
        public static QuoteRepository LoadFromDisk()
        {
            QuoteRepository dictionary;

            if (File.Exists(_Filename))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(QuoteRepository));
                using (FileStream file = new FileStream(_Filename, FileMode.Open))
                {
                    dictionary = serializer.Deserialize(file) as QuoteRepository;
                }
            }
            else
            {
                dictionary = new QuoteRepository();
                dictionary.Save();
            }

            return(dictionary);
        }
コード例 #2
0
        ///Adds all quotes in the file to the Quotes.XML
        public void Convert(QuoteRepository convRepo)
        {
            if (!Directory.Exists(quoteDir))
            {
                Directory.CreateDirectory(quoteDir);
            }
            authorList = GetAuthors(quoteDir);

            

            for (int i = 0; i < authorList.Count; i++)
            {
                string author = authorList[i].Substring(0, (authorList[i].Length - 4));
                string[] quoteList = File.ReadAllLines(quoteDir + '\\' + authorList[i]);
                for (int j = 0; j < quoteList.Length; j++)
                {
                    convRepo.AddQuote(author, quoteList[j], "Automated Conversion");
                }
                File.Delete(quoteDir + '\\' + authorList[i]);
            }

            convRepo.Save();
        }