コード例 #1
0
        /// <summary>
        /// Parse the buffer file, enqueue all tasks it has and delete it
        /// </summary>
        private void ParseBufferFile()
        {
            // If the file doesn't exist - return
            if (!File.Exists(FileSystem.TaskBufferFilePath))
            {
                return;
            }

            // Silence the watcher temporarily
            _watcher.EnableRaisingEvents = false;

            // Get the data
            var bufferLines = File.ReadAllLines(FileSystem.TaskBufferFilePath);

            // Enqueue everything
            foreach (string bufferLine in bufferLines.Distinct())
            {
                string taskType   = bufferLine.SubstringUntil(Constants.UniformSeparator);
                string taskTarget = bufferLine.SubstringAfter(Constants.UniformSeparator);
                _taskExecutionService.EnqueueTask(new Task(taskType.ParseEnum <TaskType>(), taskTarget));
            }

            // Clear file
            File.WriteAllText(FileSystem.TaskBufferFilePath, string.Empty);

            // Resume the watcher
            _watcher.EnableRaisingEvents = true;
        }
コード例 #2
0
ファイル: TaskFileBufferService.cs プロジェクト: SAoME/Modboy
        /// <summary>
        /// Parse the buffer file, enqueue all tasks it has and delete it
        /// </summary>
        private void ParseBufferFile()
        {
            // If the file doesn't exist - return
            if (!File.Exists(FileSystem.TaskBufferFilePath))
            {
                return;
            }

            // Silence the watcher temporarily
            _watcher.EnableRaisingEvents = false;

            // Get the data
            var bufferLines = File.ReadAllLines(FileSystem.TaskBufferFilePath);

            // Enqueue everything
            foreach (string bufferLine in bufferLines.Distinct())
            {
                var parts    = bufferLine.SplitTrim(Constants.UniformSeparator);
                var taskType = parts[0];
                var subType  = parts[1];
                var subId    = parts[2];
                var fileId   = parts[3];

                SubmissionType parsedSubType;
                try
                {
                    parsedSubType = subType.ParseEnum <SubmissionType>();
                }
                catch (ArgumentException ex)
                {
                    // Resume the watcher
                    _watcher.EnableRaisingEvents = true;
                    _windowService.ShowErrorWindowAsync(Localization.Current.Task_UnknownInstallationProcess).GetResult();
                    return;
                }

                _taskExecutionService.EnqueueTask(
                    new Task(
                        taskType.ParseEnum <TaskType>(),
                        parsedSubType,
                        subId,
                        fileId
                        )
                    );
            }

            // Clear file
            File.WriteAllText(FileSystem.TaskBufferFilePath, string.Empty);

            // Resume the watcher
            _watcher.EnableRaisingEvents = true;
        }