Пример #1
0
        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);
        }
Пример #2
0
        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);
        }