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); }
public void AddImg_adds_img_to_db() { var id = Guid.NewGuid(); var img = new Img(id, File.OpenRead(@"img/0.png"), "png"); _imgRepository.AddImg(img); _dbContext.DbImg.Local.Clear(); var found = _dbContext.DbImg.Find(id); found.Should().BeEquivalentTo(img, opt => opt.Excluding(img1 => img1.ImageStream)); Assert.True(TestHelpers.CompareStreams(new MemoryStream(found.Image), File.OpenRead(@"img/0.png"))); }
/// <summary> /// 廠商暫存案件 /// </summary> /// <param name="input"></param> /// <returns></returns> public Boolean VendorScratch(Tcallog input) { _logger.Info($"案件暫存-公司別:{input.CompCd},案件編號:{input.Sn}"); string SapAssetKind = _ImgRepo.GetSpcAssetKind(input.CompCd, input.AssetCd); var con = new Conditions <DataBase.TCALLOG>(); con.And(g => g.Sn == input.Sn); con.And(g => g.Comp_Cd == input.CompCd); con.Allow(g => g.TimePoint); con.Allow(g => g.Arrive_Date); con.Allow(g => g.Update_User); con.Allow(g => g.Update_Date); if (SapAssetKind == "1") { con.Allow(g => g.Coffee_Cup); } con.Allow(g => g.Work_Desc); List <TCallLogDateRecord> AddCDR = new List <TCallLogDateRecord>(); if (input.TcallLogDateRecords != null) { AddCDR = input.TcallLogDateRecords.Where(x => x.Seq == 0).ToList(); } //檢查是否已有既有紀錄,若有則進行更新就好 TCALINV sqlCALINV = GetTCALINV(input.CompCd, input.Sn); var conINV = new Conditions <DataBase.TCALINV>(); conINV.And(g => g.Comp_Cd == input.CompCd); conINV.And(g => g.Sn == input.Sn); if (sqlCALINV != null) { conINV.Allow(g => g.Work_Id); conINV.Allow(g => g.Pre_Amt); conINV.Allow(g => g.Update_User); conINV.Allow(g => g.Update_Date); } using (TransactionScope scope = new TransactionScope()) { _logger.Info($"案件暫存-準備更新資料"); #region 儲存資料 _callogRepo.Update(con, input); if (input.TCALINV != null) { if (sqlCALINV == null) { _CALINVRepo.Add(conINV, input.TCALINV); } else { _CALINVRepo.Update(conINV, input.TCALINV); } } if (AddCDR != null) { _callogFactory.AddDateRecords(AddCDR); } #endregion _logger.Info($"案件暫存-準備儲存照片"); #region 儲存照片 _ImgRepo.AddImg(input); #endregion scope.Complete(); } return(true); }