Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="recordingFile"></param>
        public void AddOrUpdateRecordingFile(String recordingFile)
        {
            try
            {
                NameParser parser = new NameParser();
                parser.SingleFileInitialise(recordingFile);

                Speaker spk = this.Speaker.SingleOrDefault(x => x.Name == parser.Speaker);
                if (spk == null)
                {
                    spk = new Speaker()
                    {
                        Name = parser.Speaker
                    };
                    this.Speaker.AddOrUpdate(x => x.Name, spk);
                    this.SaveChanges();
                }

                Category cty = this.Category.SingleOrDefault(x => x.Name == parser.Category);
                if (cty == null)
                {
                    cty = new Category()
                    {
                        // Vocal tract videos are of vowel sounds, and so need to be categorised as such.
                        // However, the category section of the filename is also used to differentiate between videos and vocal tracts.
                        Name = parser.Category.Equals("vocaltract") ? "vowel" : parser.Category
                    };
                    this.Category.AddOrUpdate(x => x.Name, cty);
                    this.SaveChanges();
                }

                Word word = this.Word.SingleOrDefault(x => x.Name == parser.Word);
                if (word == null)
                {
                    word = new Word()
                    {
                        Name       = parser.Word,
                        CategoryId = cty.CategoryId
                    };
                    this.Word.AddOrUpdate(x => x.Name, word);
                    this.SaveChanges();
                }

                Recording rd = this.Recording.SingleOrDefault(x => x.Name == parser.Recording);;
                if (rd == null)
                {
                    rd = new Recording()
                    {
                        Name      = parser.Recording,
                        SpeakerId = spk.SpeakerId,
                        WordId    = word.WordId
                    };
                    this.Recording.AddOrUpdate(x => x.Name, rd);
                    this.SaveChanges();
                }

                SingleFile sf = this.SingleFile.SingleOrDefault(x => x.Name == parser.FullName);
                if (sf == null)
                {
                    sf = new SingleFile()
                    {
                        Name    = parser.FullName,
                        Address = parser.Address,
                    };
                    if (parser.MediaFormat.Equals("audio"))
                    {
                        sf.Audio = rd;
                    }
                    else if (parser.MediaFormat.Equals("video"))
                    {
                        sf.Video = rd;
                    }
                    else if (parser.MediaFormat.Equals("vocaltract"))
                    {
                        sf.VocalTract = rd;
                    }
                    this.SingleFile.AddOrUpdate(x => x.Name, sf);
                    this.SaveChanges();
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }