示例#1
0
        private static bool LoadModels(string fileName)
        {
            List <string> models = null;

            try
            {
                models = new List <string>();
                string[] lines = System.IO.File.ReadAllLines(fileName);
                int      i     = 0;
                while (i <= lines.Length)
                {
                    HaikuModel model = new HaikuModel();
                    model.FirstVerseModel  = lines[i];
                    model.SecondVerseModel = lines[i + 1];
                    model.ThirdVerseModel  = lines[i + 2];

                    HaikuDBAccess.SaveHaikuModel(model);
                    i += 4;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            return(true);
        }
示例#2
0
        private static bool LoadWords(string fileName)
        {
            List <string> words = null;

            try
            {
                words = new List <string>();
                string[]      lines          = System.IO.File.ReadAllLines(fileName);
                List <string> withDuplicates = lines.ToList();
                words = withDuplicates.Distinct().ToList();
                List <HaikuWord> haikuWords = new List <HaikuWord>();

                foreach (var word in words)
                {
                    HaikuWord haikuWord = new HaikuWord();
                    if (!HaikuDBAccess.IsAlreadyInDatabase(word))
                    {
                        haikuWord = MakeHaikuWordFromWordString(word);
                        if (haikuWord != null)
                        {
                            HaikuDBAccess.SaveHaikuWord(haikuWord);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            return(true);
        }