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); }