Пример #1
0
        public Guid CreateEditTask(Stream imgStream, string imgFormat, ImgTaskCreationParams[] taskCreationParams)
        {
            var image = new Img(Guid.NewGuid(), imgStream, imgFormat);

            _imgRepository.AddImg(image);
            var groupId = Guid.NewGuid();

            var tasks = taskCreationParams.Select(taskCreationParam =>
            {
                var task = ImgTaskFactoryRegistry.GetImgTask(groupId, image.ImgId, taskCreationParam.TaskName,
                                                             taskCreationParam.TaskParams);
                return(task);
            }).ToArray();

            foreach (var task in tasks)
            {
                var imgTaskResult = ImgTaskResult.FromTask(task, null, null);
                _imgTaskResultRepository.AddTaskResult(imgTaskResult);
            }

            foreach (var task in tasks)
            {
                var progress = ImgTaskProgress.FromTask(task);
                _imgTaskProgressRepository.AddTaskProgress(progress);
            }

            foreach (var task in tasks)
            {
                _messageQueueService.QueueTaskAsync(task).Wait();
            }

            return(groupId);
        }
Пример #2
0
        public void AddTaskResult_when_task_progress_exist_saves_task_result()
        {
            var groupId = Guid.NewGuid();
            var taskId  = Guid.NewGuid();

            var result = new ImgTaskResult(taskId, groupId, new MemoryStream(new byte[] { 1, 2, 3 }), "png");

            _imgTaskResultRepository.AddTaskResult(result);

            _dbContext.DbImgTaskResult.Count().Should().Be(1);
        }