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);
        }
Exemple #2
0
        public Task ProcessTask(ConvertImgTask task)
        {
            var image = _imgRepository.GetImg(task.ImgId);

            var resultImg = task.Execute(image);

            var newProgress = ImgTaskProgress.FromTask(task);

            newProgress.ImgTaskState = ImgTaskState.Completed;

            _imgTaskProgress.UpdateTaskProgress(newProgress);

            var taskResult = ImgTaskResult.FromTask(task, resultImg.ImageStream, resultImg.Extension);

            _imgTaskResultRepository.UpdateTaskResult(taskResult);

            return(Task.CompletedTask);
        }