public ResponseId ExecuteAsync(Request request) { try { SetRequestCode(request); Message message = new Message { RequestBody = request.Body, RequestCodeId = request.Code, ExternalSystemId = _externalSystem.Id, RequestUser = request.UserName, IsSyncRequest = false }; _dbContext.Messages.Add(message); _dbContext.SaveChanges(); using (RabbitClient client = new RabbitClient()) { client.PullMessage(message.RequestCodeId, message.Id); } ResponseId response = new ResponseId(); response.Id = message.Id; return(response); } catch (Exception ex) { return(ResponseGenerator.GenerateByException(ex)); } }
public Response FileUpload(UploadFileRequest uploadFileRequest, string filename, byte[] fileAsArray) { var response = new Response(); // Создаем сообщение без тела var uploadMessage = new Message { RequestBody = "wait for file", RequestCodeId = uploadFileRequest.RequestCode, ExternalSystemId = _externalSystem.Id, RequestUser = "******", IsSyncRequest = false }; _dbContext.Messages.Add(uploadMessage); _dbContext.SaveChanges(); // Сохраняем файл FileStore fileStore = new FileStore { MessageId = uploadMessage.Id, FileName = filename, CreatedOn = DateTime.Now, Data = fileAsArray.ToArray() }; _dbContext.FileStores.Add(fileStore); _dbContext.SaveChanges(); // Добавляем тело сообщения, чтобы плагин смог найти файл и услугу uploadMessage.RequestBody = uploadFileRequest.ToXmlString(); _dbContext.SaveChanges(); using (RabbitClient client = new RabbitClient()) { client.PullMessage(uploadMessage.RequestCodeId, uploadMessage.Id); } response.Id = uploadMessage.Id; response.IsError = false; return(response); }
public Response Execute(Request request) { try { Response response = new Response(); SetRequestCode(request); Message message = new Message { RequestBody = request.Body, RequestCodeId = request.Code, ExternalSystemId = _externalSystem.Id, RequestUser = request.UserName, IsSyncRequest = true }; _dbContext.Messages.Add(message); _dbContext.SaveChanges(); using (RabbitClient client = new RabbitClient()) { client.Execute(message.RequestCodeId, message.Id); } _dbContext.Entry(message).Reload(); response = new Response { Id = message.Id, Body = message.ResponseBody }; if (!string.IsNullOrEmpty(message.ErrorMessage)) { response.IsError = true; response.Error = message.ErrorMessage; } return(response); } catch (Exception ex) { return(ResponseGenerator.GenerateByException(ex)); } }