コード例 #1
0
 public bool SaveAudioClip()
 {
     return(FileAccessUtil.SaveWordAudio(CurrentClip, WordName));
 }
コード例 #2
0
    /// <summary>
    /// Creates a new word list entry and saves it to the database and the word list dictionary.
    /// Additionally, it saves any new audio or picture files.
    /// Returns true if saving data to the data base is successful.
    /// </summary>
    /// <param name="word"></param>
    /// <returns>bool</returns>
    public bool CreateNewDbEntry(string word, string wordTags)
    {
        string img;
        string sound;
        string tags;
        int    rowsInserted;
        bool   audioSuccess = true;
        bool   photoSuccess = true;

        // Check if the audio file path and photo file paths are active
        if (CurrentClip != null)
        {
            //TODO: Fix false positive when overwriting existing files
            // Maybe a check between the files date metadata and the current time?
            audioSuccess = FileAccessUtil.SaveWordAudio(CurrentClip, word);

            if (!audioSuccess)
            {
                //TODO: add error checking
            }
        }

        if (CurrentTexture != null)
        {
            //TODO: Fix false positive when overwriting existing files
            // Maybe a check between the files date metadata and the current time?

            /*
             * photoSuccess = FileAccessUtil.SaveWordPic(CurrentTexture, word);
             *
             * if (!photoSuccess)
             * {
             *  //TODO: add error checking
             * }
             */

            SaveTextures(word);
        }

        //Save word to DB
        string category = "custom";

        //int diff = (int)Math.Round(difficultySlider.value);

        //Preset Image and sound entries - This will need to be changed when adding features for an image/audio path
        img   = word + ".png";
        sound = word + ".wav";
        tags  = wordTags;

        if (audioSuccess && photoSuccess)
        {
            //Call to DB to insert the word
            rowsInserted = dataService.CreateWord(word, category, tags, sound, img);

            if (rowsInserted == 1)
            {
                // Get the newly created id of the word entry from the data base
                IEnumerable <Words> rows = dataService.GetLastById();
                int    id    = 0;
                string check = "";

                foreach (var row in rows)
                {
                    id    = row.word_id;
                    check = row.word_name;
                }

                if (check.Equals(word))
                {
                    // Create a new word data object and add a new entry into the static word/WordDO dictionary
                    WordDO dataObject = new WordDO(id, word, category, tags, sound, img);
                    wordList[word] = dataObject;
                    return(true);
                }
                else
                {
                    //TODO: THROW AN ERROR
                }
            }
        }

        return(false);
    }