public bool SendDocumentCommand(DocumentCommand command) { string serverUrl = ConfigurationManager.AppSettings["WSURL"]; var client = new HttpClient(); client.BaseAddress = new Uri(serverUrl ); HttpResponseMessage response = client.PostAsync("api/command/run", command, new JsonMediaTypeFormatter()).Result; return response.IsSuccessStatusCode; }
protected void _AddCommand(DocumentCommand command) { if (_CanAddCommands) _pcommandsToExecute.Add(command); }
CommandEnvelope CommandsToEnvelope(Guid envelopeId, Guid documentId, DocumentType documentType, long generatedTick, Guid parentId, Guid? recipientCCId, DocumentCommand[] commands) { DocumentCommand refC = commands.First(); List<CommandEnvelopeItem> cei = commands.Select((n, i) => new CommandEnvelopeItem(i + 1, n)).ToList(); var ce = new CommandEnvelope { Id = envelopeId, DocumentId = documentId, DocumentTypeId = (int)documentType, GeneratedByCostCentreId = refC.CommandGeneratedByCostCentreId, RecipientCostCentreId = recipientCCId ?? Guid.Empty, GeneratedByCostCentreApplicationId = refC.CommandGeneratedByCostCentreApplicationId, ParentDocumentId = parentId, CommandsList = cei, EnvelopeGeneratedTick = generatedTick, EnvelopeArrivedAtServerTick = generatedTick }; return ce; }
public CommandEnvelopeItem(int order, DocumentCommand command) { Command = command; Order = order; }
public async Task<bool> SendCommandAsync(DocumentCommand command) { bool success = false; string urlSuffix = "api/command/run"; HttpClient client = setupClient(); _log.InfoFormat("Attempting to post command with id {0} to {1}", command.CommandId, client.BaseAddress + urlSuffix); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { //var response = client.PostAsJsonAsync(urlSuffix, command).Result; var response = await client.PostAsJsonAsync(urlSuffix, command); response.EnsureSuccessStatusCode(); ResponseBasic _response = await response.Content.ReadAsAsync<ResponseBasic>(); if (_response == null) { _log.InfoFormat("Sent command id {0} Failed", command.CommandId); return success; } if (_response.Result.Equals("Command Processed") && response.IsSuccessStatusCode) { _log.InfoFormat("Sent command id {0} success", command.CommandId); success = true; } else { _log.InfoFormat("Sent command id {0} Failed, ResultInfo= {1}, ErrorInfo= {2} ", command.CommandId, _response.ResultInfo, _response.ErrorInfo); } } catch (Exception ex) { _log.ErrorFormat("Failed to send command {0}", command.CommandId); _log.Error("Failed to send command", ex); throw ex; } return success; }