RefreshStimuli() public method

Reloads all stimuli from disk
public RefreshStimuli ( ) : void
return void
Esempio n. 1
0
        /// <summary>
        /// Returns true if a stimulus class was successfully loaded from path
        /// </summary>
        public static bool TryLoad(string path, out StimulusClass stimulusClass)
        {
            if (Directory.Exists(path))
            {
                var saveFile = Directory.EnumerateFiles(path)
                               .Where(f => Path.GetExtension(f) == EXTENSION)
                               .FirstOrDefault();

                // try to load a saved version
                if (saveFile != null && Utils.TryDeserializeFile(saveFile, out stimulusClass))
                {
                    stimulusClass.RefreshStimuli();
                    // this should always be true, so we'll assure it just in case
                    // a serialization versioning issue messed things up
                    foreach (var pair in stimulusClass.stimuli)
                    {
                        pair.Value.PathOrText = pair.Key;
                    }
                    return(true);
                }

                // load a new config from the directory
                stimulusClass = new StimulusClass(path);
                return(true);
            }

            // else attempt to deserialize path as a save file
            if (Utils.TryDeserializeFile(path, out stimulusClass))
            {
                return(true);
            }

            stimulusClass = null;
            return(false);
        }
        /// <summary>
        /// Returns true if a stimulus class was successfully loaded from path
        /// </summary>
        public static bool TryLoad(string path, out StimulusClass stimulusClass)
        {
            if (Directory.Exists(path))
            {
                var saveFile = Directory.EnumerateFiles(path)
                    .Where(f => Path.GetExtension(f) == EXTENSION)
                    .FirstOrDefault();

                // try to load a saved version
                if (saveFile != null && Utils.TryDeserializeFile(saveFile, out stimulusClass))
                {
                    stimulusClass.RefreshStimuli();
                    // this should always be true, so we'll assure it just in case
                    // a serialization versioning issue messed things up
                    foreach (var pair in stimulusClass.stimuli)
                        pair.Value.PathOrText = pair.Key;
                    return true;
                }

                // load a new config from the directory
                stimulusClass = new StimulusClass(path);
                return true;
            }

            // else attempt to deserialize path as a save file
            if (Utils.TryDeserializeFile(path, out stimulusClass))
                return true;

            stimulusClass = null;
            return false;
        }