Ejemplo n.º 1
0
        /// <summary>
        /// Reacquires the list of sound files in the data repository
        /// </summary>
        private void refreshSoundData()
        {
            cboxGroups.Items.Clear();
            //foreach(System.IO.Directory.GetFiles(SoundPath, "*.mp3"))
            String[]         filePaths   = System.IO.Directory.GetFiles(SoundPath, "*", SearchOption.AllDirectories).Where(file => file.Contains(".mp3") || file.Contains(".wav")).ToArray();
            SoundFileFactory fileCreator = new SoundFileFactory(filePaths);

            SoundData = new SoundRepository(fileCreator.constructSoundFiles());
            if (firstLoadUp)
            {
                //Now load the sound Shortcuts now that everything else is ready to go
                SoundData.setShortcutDictionary(SoundData.loadShortcutDictionary());
            }
            //lblTest.Text = SoundData.SoundFiles.Keys.ToString
            try
            {
                cboxGroups.Items.AddRange(SoundData.getGroupNames());
                //While the rest of this code doesn't throw an exception - don't want to execute if no files
                cboxGroups.SelectedIndex = 0;
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Error - unable to find files in directory :\n" + SoundPath, "Files Not Found");
            }
        }
Ejemplo n.º 2
0
    public void InitializeSingleton()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
            return;
        }

        Instance = this;
    }
Ejemplo n.º 3
0
    public void InitializeSingleton()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
            return;
        }

        Instance = this;
    }
Ejemplo n.º 4
0
        public MusicResult UpdateSound(Sound sound)
        {
            using (_context)
            {
                try
                {
                    string id     = Convert.ToString(sound.Id);
                    Sound  record = SoundRepository.FindBy(x => x.Id == id).FirstOrDefault();

                    if (record == null)
                    {
                        MusicResult errorResult = new MusicResult
                        {
                            Id           = record.Id,
                            IsSuccessful = false,
                            Message      = $"An unexpected error on finding the sound. Can't find the sound with id : {id}"
                        };

                        return(errorResult);
                    }

                    record.Id       = sound.Id;
                    record.FileName = sound.FileName;
                    record.FilePath = sound.FilePath;
                    record.FileSize = sound.FileSize;
                    record.Modified = DateTime.Now;

                    _context.Update(record);

                    _context.SaveChanges();

                    MusicResult result = new MusicResult
                    {
                        Id           = id,
                        IsSuccessful = true,
                        Message      = "Update sound successfully"
                    };

                    return(result);
                }
                catch (Exception exception)
                {
                    MusicResult result = new MusicResult
                    {
                        Id           = sound.Id,
                        IsSuccessful = false,
                        Message      = $"An unexpected error on updating sound: {exception.Message}"
                    };

                    return(result);
                }
            }
        }
Ejemplo n.º 5
0
        public MusicResult DeleteSound(string id)
        {
            using (_context)
            {
                try
                {
                    var record = SoundRepository.FindBy(x => x.Id == id).FirstOrDefault();
                    if (record == null)
                    {
                        MusicResult errorResult = new MusicResult
                        {
                            Id           = record.Id,
                            IsSuccessful = false,
                            Message      = "There isn't a record in the database. "
                        };
                        return(errorResult);
                    }
                    _context.Remove(record);

                    _context.SaveChanges();

                    MusicResult result = new MusicResult
                    {
                        Id           = id,
                        IsSuccessful = true,
                        Message      = "Delete sound successful"
                    };

                    return(result);
                }
                catch (Exception exception)
                {
                    MusicResult result = new MusicResult
                    {
                        Id           = id,
                        IsSuccessful = false,
                        Message      = $"An unexpected error on deleting sound: {exception.Message}"
                    };

                    return(result);
                }
            }
        }