public bool IsMatch(GovTalkMessageGovTalkDetailsError error) { if (error.Number.Equals("1000")) { return(true); } else { return(false); } }
/// <summary> /// Demonstrate using the message reader strategies to get results from a message reply /// </summary> /// <param name="loggingService"></param> /// <param name="messageToRead"></param> static void DemonstrateReadMessage(ILoggingService loggingService, XmlDocument messageToRead) { // Set up a message reading strategy IMessageReader messageReader = new DefaultMessageReader(loggingService, configurationRepository, messageToRead.ToXDocument()); messageReader.ReadMessage(); // We don't know what we've got back from the Gateway, but all replies are GovTalkMessages if (messageReader.HasErrors()) { //There are errors in the results file so we can deal with them // Get a DataTable of the results and have a look at that DataTable errorTable = messageReader.GetMessageResults <DataTable>(); // Or set up an error return strategy and do something with that IErrorReturnCalculator errorCalculator = new DefaultErrorReturnCalculator(); GovTalkMessageGovTalkDetailsError error = messageReader.GetMessageResults <GovTalkMessageGovTalkDetailsError>(); Console.WriteLine(errorCalculator.CalculateErrorReturn(error)); if (error.Number == "3001") { ErrorResponse errResponse = messageReader.GetMessageResults <ErrorResponse>(); } } else { // It's either an acknowledgement so we need to get the poll interval and URL, or a response. string[] results = messageReader.GetMessageResults <string[]>(); foreach (var result in results) { Console.WriteLine(result); } if (messageReader.GetQualifier() == "response") { string body = messageReader.GetBodyType(); if (body != null) { DataTable responseTable = messageReader.GetMessageResults <DataTable>(); LocalHelp.ConsolePrintDataTable(responseTable); } else { Console.WriteLine("No body content"); } } } GovTalkMessageFileName ReplyNamer = new GovTalkMessageFileName.FileNameBuilder() .AddLogger(loggingService) .AddConfigurationRepository(configurationRepository) .AddMessageIntention("ReplyMessage") .AddCorrelationId(messageReader.GetCorrelationId()) .AddFilePath(@"C:\Temp\") .BuildFileName(); string replyFileName = ReplyNamer.ToString(); messageToRead.Save(replyFileName); }
public bool IsMatch(GovTalkMessageGovTalkDetailsError error) { return(error.Number.Equals("1039") == true? true: false); }
public string ErrorResponse(GovTalkMessageGovTalkDetailsError error) { return(error.Text[0]); }
public string CalculateErrorReturn(GovTalkMessageGovTalkDetailsError error) { return(_errorRules.First(e => e.IsMatch(error)).ErrorResponse(error)); // @TODO: Handle situation where no rule is matched, or there is no errorResponse class }