public bool SendMessage() { if (!this.Transaction.Headers.ContainsKey(Headers.AUTOCLEAN)) { this.Transaction.Headers[Headers.AUTOCLEAN] = this.Params[Headers.AUTOCLEAN]; } this.Transaction.ResponseMessage.Destiny = Path.Combine(this.Endpoint, this.Transaction.ResponseMessage.Name); try { using (var OutputFile = new StreamWriter(this.Transaction.ResponseMessage.Destiny)) { OutputFile.WriteLine(this.Transaction.ResponseMessage.Content); } } catch (DirectoryNotFoundException DNotFoundEx) { EndpointTools.SetErrorReason(this.Transaction, "", $"Endpoint not found: {DNotFoundEx.Message}", DNotFoundEx.StackTrace, _Logger); } catch (ArgumentException ArgEx) { EndpointTools.SetErrorReason(this.Transaction, "", $"Incorrect endpoint (value -> {this.Endpoint}): {ArgEx.Message}", ArgEx.StackTrace, _Logger); } catch (UnauthorizedAccessException NotAllowedEx) { EndpointTools.SetErrorReason(this.Transaction, "", $"Endpoint '{this.Endpoint}' cannot be reached: {NotAllowedEx.Message}", NotAllowedEx.StackTrace, _Logger); } this.Success = System.IO.File.Exists(this.Transaction.ResponseMessage.Destiny); this.CleanFilesAfterProcessing(this.Success, this.Transaction.Headers); return(this.Success); }
public List <TransactionDTO> ReceiveMessages() { this.Transaction = new TransactionDTO(); var Result = new List <TransactionDTO>(); try { this.Success = this.Connector.GetData(this.Endpoint, this.Params, out string StatusCode, out List <TransmissionMessageDTO> DataResult); if (this.Success) { for (int i = 0; i < DataResult.Count; i++) { Result.Add(base.CreateTransaction(i + 1, this.Endpoint, DataResult[i].Name, this.Params, DataResult[i].Content)); } } else { Result.AddRange(this.HandleErrorMessages(DataResult, StatusCode)); } } catch (WebException WebEx) { EndpointTools.SetErrorReason(this.Transaction, "", $"Incorrect endpoint (value -> {this.Endpoint}): {WebEx.Message}", WebEx.StackTrace, _Logger); Result.Add(this.Transaction); } catch (Exception Ex) { EndpointTools.SetErrorReason(this.Transaction, "", $"Unable to get response from {this.Endpoint}: {Ex.Message}", Ex.StackTrace, _Logger); Result.Add(this.Transaction); } return(Result); }
private List <TransactionDTO> HandleErrorMessages(List <TransmissionMessageDTO> Messages, string StatusCode) { var ErrorMessages = Messages.Where(x => x.Error != null && !string.IsNullOrEmpty(x.Error.Reason) && !string.IsNullOrWhiteSpace(x.Error.Reason)); var Result = new List <TransactionDTO>(); foreach (var ErrorMsg in ErrorMessages) { var ErrorTransaction = new TransactionDTO() { RequestMessage = ErrorMsg, ResponseMessage = ErrorMsg }; EndpointTools.SetErrorReason(ErrorTransaction, StatusCode, $"Message couldn't be sent: {ErrorMsg.Error.Reason}", "", _Logger); Result.Add(ErrorTransaction); } return(Result); }
public void TestResolveEndpoint() { // var TestExitProtocol = "FOO"; var TestExitUri = "bar"; var TestEndpointNoParams = $"{TestExitProtocol}->{TestExitUri}"; var TestEndpointOneParam = $"{TestExitProtocol}->{TestExitUri}->param1=ban"; var TestEndpointMultiParam = $"{TestExitProtocol}->{TestExitUri}->param1=ban¶m2=baz"; var TestEndpointError = $"{TestExitProtocol}:{TestExitUri}"; // Execution EndpointTools.ResolveEndpoint(TestEndpointNoParams, out string TestProtocolNoParams, out string TestUriNoParams, out Dictionary <string, object> TestNoParams); EndpointTools.ResolveEndpoint(TestEndpointOneParam, out string TestProtocolOneParam, out string TestUriOneParam, out Dictionary <string, object> TestOneParam); EndpointTools.ResolveEndpoint(TestEndpointMultiParam, out string TestProtocolMultiParam, out string TestUriMultiParam, out Dictionary <string, object> TestMultipleParam); EndpointTools.ResolveEndpoint(TestEndpointError, out string TestProtocolError, out string TestUriError, out Dictionary <string, object> TestErrorParams); // Assertions Assert.AreEqual(TestExitProtocol, TestProtocolNoParams); Assert.AreEqual(TestExitUri, TestUriNoParams); Assert.AreEqual(1, TestNoParams.Count); Assert.AreEqual(TestExitProtocol.ToLower(), TestNoParams["protocol"]); Assert.AreEqual(TestExitProtocol, TestProtocolOneParam); Assert.AreEqual(TestExitUri, TestUriOneParam); Assert.AreEqual(2, TestOneParam.Count); Assert.AreEqual(TestExitProtocol.ToLower(), TestOneParam["protocol"]); Assert.AreEqual("ban", TestOneParam["param1"]); Assert.AreEqual(TestExitProtocol, TestProtocolMultiParam); Assert.AreEqual(TestExitUri, TestUriMultiParam); Assert.AreEqual(3, TestMultipleParam.Count); Assert.AreEqual(TestExitProtocol.ToLower(), TestMultipleParam["protocol"]); Assert.AreEqual("ban", TestMultipleParam["param1"]); Assert.AreEqual("baz", TestMultipleParam["param2"]); Assert.AreEqual("", TestProtocolError); Assert.AreEqual("", TestUriError); Assert.AreEqual(0, TestErrorParams.Count); }