public IApiResultModel DoConvert([FromBody] ConvertDto dto) { if (string.IsNullOrWhiteSpace(dto.SolutionName)) { return(ApiResultModel.FromError("解决方案名称不能为空!")); } if (!convertService.IsProjectPreValid(dto.SolutionName)) { return(ApiResultModel.FromError("解决方案名称不合法,请更换!")); } if (dto.SolutionName.StartsWith("xLiAd.")) { return(ApiResultModel.FromError("解决方案名称不能以 xLiAd. 开头,请更换!")); } OptionsSelect optionsSelect = new OptionsSelect() { Items = dto.Items }; try { var fileItems = convertService.Convert(dto.SolutionName, optionsSelect); using (MemoryStream zipToOpen = new MemoryStream()) { using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create)) { foreach (var item in fileItems) { var en = archive.CreateEntry(item.FileFullName.TrimStart('/')); using (var stream = en.Open()) stream.Write(item.Content, 0, item.Content.Length); } } if (!Directory.Exists(configModel.ZipSavePath)) { Directory.CreateDirectory(configModel.ZipSavePath); } var fileName = $"{dto.SolutionName}.{DateTime.Now:yyyy-MM-dd-HH-mm-ss}.zip"; var fullName = Path.Combine(configModel.ZipSavePath, fileName); var bs = zipToOpen.ToArray(); using (var fs = new FileStream(fullName, FileMode.Create)) fs.Write(bs, 0, bs.Length); return(ApiResultModel.FromData(fileName)); } } catch (Exception ex) { return(ApiResultModel.FromError(ex.Message)); } }
public async Task <ConvertResponseDto> ExecuteAsync(ConvertDto convertDto) { int requestId = convertDto.OwnerId; var request = await Executor.GetQuery <GetRequestByIdQuery>().Process(q => q.ExecuteAsync(requestId)); var workflows = Executor.GetQuery <GetRequestWorkflowsByRequestIdQuery>().Process(q => q.Execute(requestId)); var result = new ConvertResponseDto(); var fullExamCodes = new[] { RouteStageCodes.TZFirstFullExpertizePerformerChoosing, RouteStageCodes.TZFirstFullExpertize, RouteStageCodes.TZSecondFullExpertizePerformerChoosing, RouteStageCodes.TZSecondFullExpertize }; #region Генерация уведомления string notificationCode; var hasBeenOnFullExam = workflows.Any(w => fullExamCodes.Contains(w.CurrentStage.Code)); var trademarkTypeCode = request.SpeciesTradeMark.Code; //Смерджили два справочника, получилось так, не стал трогать, мало ли прийдется вернуть if (hasBeenOnFullExam) { if (trademarkTypeCode == DicProtectionDocSubtypeCodes.CollectiveTrademark) { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } else { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } } else { if (trademarkTypeCode == DicProtectionDocSubtypeCodes.CollectiveTrademark) { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } else { notificationCode = DicDocumentTypeCodes.OUT_UV_Pred_preobr_zayav_TZ_na_KTZ_v1_19; } } var userInputDto = new UserInputDto { Code = notificationCode, Fields = new List <KeyValuePair <string, string> >(), OwnerId = requestId, OwnerType = Owner.Type.Request }; Executor.GetHandler <WorkflowBusinessLogic.Document.CreateDocumentHandler>().Process(h => h.Execute(requestId, Owner.Type.Request, notificationCode, DocumentType.Outgoing, userInputDto)); #endregion #region Преобразование заявки var protectionDocTypeCode = request.ProtectionDocType.Code; request = await Executor.GetQuery <GetRequestByIdQuery>().Process(q => q.ExecuteAsync(requestId)); switch (protectionDocTypeCode) { case DicProtectionDocTypeCodes.RequestTypeTrademarkCode: if (!string.IsNullOrEmpty(convertDto.ColectiveTrademarkParticipantsInfo)) { request.ColectiveTrademarkParticipantsInfo = convertDto.ColectiveTrademarkParticipantsInfo; } DicProtectionDocSubType newProtectionDocSubType = null; if (request.SpeciesTradeMark.Code == DicProtectionDocSubtypeCodes.CollectiveTrademark) { newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.RegularTradeMark)); } else { newProtectionDocSubType = Executor.GetQuery <GetDicProtectionDocSubTypeByCodeQuery>() .Process(q => q.Execute(DicProtectionDocSubtypeCodes.CollectiveTrademark)); } request.SpeciesTradeMark = newProtectionDocSubType; request.SpeciesTradeMarkId = newProtectionDocSubType.Id; Executor.GetCommand <WorkflowBusinessLogic.Requests.UpdateRequestCommand>().Process(c => c.Execute(request)); result.SpeciesTradeMarkId = request.SpeciesTradeMarkId; result.ColectiveTrademarkParticipantsInfo = request.ColectiveTrademarkParticipantsInfo; result.SpeciesTrademarkCode = request.SpeciesTradeMark?.Code; break; } #endregion return(result); }