/// <summary>
        /// If a TaskSequence was interrupted, it is possible to continue
        /// from the last loaded trial before the interruption.
        /// </summary>
        /// <returns>Current sequence index after load.</returns>
        public virtual int LoadPartiallyFinishedTaskSequence()
        {
            if (!File.Exists(Path.Combine(MmTaskUserData.DirPath, PartialDataFile)))
            {
                return(0);
            }

            var reader = new StreamReader(Path.Combine(MmTaskUserData.DirPath,
                                                       PartialDataFile),
                                          Encoding.UTF8);

            string line = reader.ReadLine();

            if (line == null)
            {
                MmLogger.LogError("Partial Sequence File Empty");
                return(-1);
            }

            var curSequenceIndex = int.Parse(line.Split(',')[1]);

            reader.Close();

            return(curSequenceIndex);
        }
Esempio n. 2
0
        /// <summary>
        /// Prepare the tasks that were loaded by the
        /// TaskInfoCollectionLoader.
        /// </summary>
        public virtual void PrepareTasks()
        {
            int taskLoadStatus = taskInfoCollectionLoader.PrepareTasks(
                ref TaskInfos, MmTaskUserData.UserId);

            if (taskLoadStatus >= 0)
            {
                currentTaskInfo = GetNodeAt(taskLoadStatus);
            }
            else
            {
                MmLogger.LogError("Task Load Failed");
            }

            ApplySequenceID();
        }
        /// <summary>
        /// Given a collection of task infos, load
        /// the task sequence from file into the collection.
        /// </summary>
        /// <param name="taskInfos">Collection filled by task sequence from
        /// file. Can be empty if file unloaded.</param>
        public virtual void LoadTaskSequence(ref LinkedList <U> taskInfos)
        {
            var filename = MmTaskUserData.BaseDirectory + "/" + TaskSeqFilename;

            try
            {
                using (var sr = new StreamReader(filename, Encoding.UTF8))
                {
                    // Skip header line
                    var line = sr.ReadLine();

                    if (string.IsNullOrEmpty(line))
                    {
                        return;
                    }

                    taskInfos = new LinkedList <U>();

                    while ((line = sr.ReadLine()) != null)
                    {
                        var t = new U();
                        t.Parse(line);

                        // Only load current user
                        if (t.UserId != MmTaskUserData.UserId)
                        {
                            continue;
                        }

                        taskInfos.AddLast(t);
                    }
                }
            }
            catch (Exception e)
            {
                MmLogger.LogError("The file could not be read:");
                MmLogger.LogError(e.Message);
            }
        }