public string CheckAudio()
        {
            VmWord[] words;

            using (var db = new WordContext())
            {
                words = db.Words.Where(p => p.Name_ru.IndexOf(' ') < 0).ToArray();
            }

            FileChecker fileChecker = new FileChecker();

            foreach (VmWord word in words)
            {
                var path = Path.Combine(audioPath, word.Name_ru) + ".wav";
                if (!fileChecker.CheckIfExist(path))
                {
                    Console.WriteLine("File doesn't exist, path: {0}", path);
                    //throw new ArgumentNullException("missed audio file");
                }
            }
            return(null);
        }
        public List <VmDictor> GetDictors(string wordPath, string lang, string wordNameInLocal)
        {
            var             defaultAudioPath = Path.Combine(audioPath, "default");
            List <VmDictor> dictors          = new List <VmDictor>();

            try
            {
                FileChecker fileChecker = new FileChecker();
                var         langPath    = Path.Combine(wordPath, lang);

                if (!Directory.Exists(langPath))
                {
                    Console.WriteLine("Directory not found: {0}", langPath);

                    var wavePath = Path.Combine(audioPath, defaultAudioPath, lang, wordNameInLocal + ".wav");
                    var mp3Path  = Path.Combine(audioPath, defaultAudioPath, lang, wordNameInLocal + ".mp3");

                    if (fileChecker.CheckIfExist(wavePath))
                    {
                        dictors.Add(new VmDictor
                        {
                            username  = "******",
                            sex       = "",
                            country   = "",
                            langname  = lang,
                            AudioType = ".wav"
                        });
                    }
                    else if (fileChecker.CheckIfExist(mp3Path))
                    {
                        dictors.Add(new VmDictor
                        {
                            username  = "******",
                            sex       = "",
                            country   = "",
                            langname  = lang,
                            AudioType = ".mp3"
                        });
                    }
                    return(dictors);
                }

                List <string> dirs = new List <string>(Directory.EnumerateDirectories(langPath));

                foreach (var dir in dirs)
                {
                    var mp3Path = Path.Combine(dir, wordNameInLocal + ".mp3");
                    var wavPath = Path.Combine(dir, wordNameInLocal + ".wav");

                    if (fileChecker.CheckIfExist(mp3Path))
                    {
                        var dictor = new VmDictor
                        {
                            username  = dir.Substring(dir.LastIndexOf(lang + "/") + 3),
                            sex       = "",
                            country   = "",
                            langname  = lang,
                            AudioType = ".mp3"
                        };
                        dictors.Add(dictor);
                    }
                    else if (fileChecker.CheckIfExist(wavPath))
                    {
                        var dictor = new VmDictor
                        {
                            username  = dir.Substring(dir.LastIndexOf(lang + "/") + 3),
                            sex       = "",
                            country   = "",
                            langname  = lang,
                            AudioType = ".wav"
                        };
                        dictors.Add(dictor);
                    }
                }
                Console.WriteLine("{0} dictor(s) found for word {1}.", dirs.Count, wordNameInLocal);
            }
            catch (PathTooLongException PathEx)
            {
                Console.WriteLine(PathEx.Message);
            }
            return(dictors);
        }
        public async Task <List <VmWordWithDictors> > GetWords()
        {
            VmWord[]             words;
            List <VmCollocation> collocations;
            DateTime             dateToday = DateTime.Now;
            int?dailyRepeatAmount          = 0;

            UpdateSchedule();

            using (var db = new WordContext())
            {
                if (db.Settings.First().DailyRepeatAmount != null)
                {
                    dailyRepeatAmount = db.Settings.First().DailyRepeatAmount;
                }
                words = db.Words.Where(p => (p.Name_ru.IndexOf(' ') < 0) &&
                                       (p.Name_en.IndexOf(' ') < 0) &&
                                       (p.NextRepeatDate <= dateToday))
                        .OrderBy(p => p.RepeatIterationNum).ToArray();

                collocations = db.Collocations.Where(p => p.NextRepeatDate <= dateToday).ToList();
            }

            List <VmWordWithDictors> wordsWithDictors = new List <VmWordWithDictors>();

            FileChecker fileChecker = new FileChecker();

            var collocationsUrl_en = Directory.GetFiles(Path.Combine(audioPath, "collocations", "en")).ToList();

            // Check It
            //List<VmCollocation> collocationsWithAudio = collocations
            //.Where(p => collocationsUrl_en.FirstOrDefault(z =>
            //z.Substring(z.LastIndexOf("/audio/")) == p.AudioUrl).Any()).ToList();

            // Temp Fix
            List <VmCollocation> collocationsWithAudio = collocations;

            List <VmCollocation> availableCollocations;
            int repeatCount = 0;

            foreach (VmWord word in words)
            {
                if (dailyRepeatAmount != 0 &&
                    repeatCount >= dailyRepeatAmount)
                {
                    break;
                }

                var path       = Path.Combine(audioPath, word.Name_ru);
                var dictors_en = GetDictors(path, "en", word.Name_en);
                var dictors_ru = GetDictors(path, "ru", word.Name_ru);

                //List<VmDictor> tempDictors_en = (dictors_en.Any()) ? dictors_en : new List<VmDictor>();
                //List<VmDictor> tempDictors_ru = (dictors_ru.Any()) ? dictors_ru : new List<VmDictor>();

                //var pathTempRu = Path.Combine(audioPath, word.Name_en) + ".wav";
                // TODO: add english words
                //if (!tempDictors_en.Any()
                //   && !fileChecker.ChecIfExist(pathTempEn))
                //{
                //    break;
                //}

                // TODO: check for mp3 too
                if (!dictors_ru.Any())
                {
                    Console.WriteLine("Word has no ru dictors: {0}", word.Name_ru);
                }
                else if (!dictors_en.Any())
                {
                    Console.WriteLine("Word has no en dictors: {0}", word.Name_en);
                }
                else
                {
                    //var availableCollocationsUrls = collocationsUrl_en.Where(p => p.IndexOf(word.Name_en) > 0);
                    //var availableCollocationsUrls = collocations.Where(p => p.AudioUrl.IndexOf(word.Name_en) > 0);

                    // TODO: check if audio exists
                    availableCollocations = collocationsWithAudio
                                            .Where(p => CheckIfContainsPattern(word.Name_en, p.AudioUrl)).ToList();

                    wordsWithDictors.Add(new VmWordWithDictors
                    {
                        Id                      = word.Id,
                        Name_en                 = word.Name_en,
                        Name_ru                 = word.Name_ru,
                        FourDaysLearnPhase      = word.FourDaysLearnPhase,
                        LearnDay                = word.LearnDay,
                        RepeatIterationNum      = word.RepeatIterationNum,
                        NextRepeatDate          = word.NextRepeatDate,
                        DailyReapeatCountForEng = word.DailyReapeatCountForEng,
                        DailyReapeatCountForRus = word.DailyReapeatCountForRus,
                        Dictors_en              = dictors_en,
                        Dictors_ru              = dictors_ru,
                        Collocation             = availableCollocations
                    });

                    if (dailyRepeatAmount != 0)
                    {
                        if (word.FourDaysLearnPhase)
                        {
                            repeatCount = repeatCount + 2 * minReapeatCountPerDayFourDayPhase;
                        }
                        else
                        {
                            repeatCount = repeatCount + 2 * minReapeatCountPerDayIteration;
                        }
                    }
                }
            }

            return(await Task <List <VmWordWithDictors> > .Factory.StartNew(() =>
            {
                return wordsWithDictors;
            }));
        }