Example #1
0
        static XmlDocument TestSend(string filename = "")
        {
            IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository();
            ILoggingService          loggingService          = new Log4NetLoggingService(configurationRepository, new ThreadContextService());

            string uri = configurationRepository.GetConfigurationValue <string>("SendURIDev");

            XmlDocument xd = new XmlDocument();

            xd.PreserveWhitespace = true;

            if (filename == "")
            {
                filename = @"C:\Temp\test_GatewaySubmission_20150818163247_EmptyRepayment.xml";
            }

            xd.Load(filename);

            CharitiesOnline.MessageService.Client client = new MessageService.Client(loggingService);

            XmlDocument reply = client.SendRequest(xd, uri);

            Console.WriteLine(reply.InnerXml);

            return(reply);
        }
Example #2
0
        /// <summary>
        /// Demonstrate using the MessageSendingService to send a GovTalkMessage to the Government Gateway and receive a reply.
        /// </summary>
        /// <param name="loggingService"></param>
        /// <param name="sendMessage"></param>
        static XmlDocument DemonstrateSendMessage(ILoggingService loggingService, XmlDocument sendMessage, GovernmentGatewayEnvironment gatewayEnv)
        {
            string uri = LocalHelp.GetSendURI("Send", gatewayEnv, configurationRepository);

            // Create a client to send the file to the target gateway
            CharitiesOnline.MessageService.Client client = new MessageService.Client(loggingService);

            // Create an XmlDocument of the reply from the endpoint
            XmlDocument reply = client.SendRequest(sendMessage, uri);

            return(reply);
        }
Example #3
0
        static XmlDocument TestSend(string filename = "")
        {
            IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository();
            ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService());

            string uri = configurationRepository.GetConfigurationValue<string>("SendURIDev");

            XmlDocument xd = new XmlDocument();
            xd.PreserveWhitespace = true;

            if(filename == "")
            {
                filename = @"C:\Temp\test_GatewaySubmission_20150818163247_EmptyRepayment.xml";
            }

            xd.Load(filename);

            CharitiesOnline.MessageService.Client client = new MessageService.Client(loggingService);

            XmlDocument reply = client.SendRequest(xd, uri);

            Console.WriteLine(reply.InnerXml);

            return reply;
        }
Example #4
0
        /// <summary>
        /// Demonstrate using the MessageSendingService to send a GovTalkMessage to the Government Gateway and receive a reply.
        /// </summary>
        /// <param name="loggingService"></param>
        /// <param name="sendMessage"></param>
        static XmlDocument DemonstrateSendMessage(ILoggingService loggingService, XmlDocument sendMessage, GovernmentGatewayEnvironment gatewayEnv)
        {
            string uri = LocalHelp.GetSendURI("Send", gatewayEnv, configurationRepository);

            // Create a client to send the file to the target gateway
            CharitiesOnline.MessageService.Client client = new MessageService.Client(loggingService);

            // Create an XmlDocument of the reply from the endpoint
            XmlDocument reply = client.SendRequest(sendMessage, uri);

            return reply;
        }
Example #5
0
        public static void DemonstrateLocalProcess()
        {
            // Set up the logging
            IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository();
            ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService());

            DataTableRepaymentPopulater.SetLogger(loggingService);

            // Create a file of donations records
            DataTableRepaymentPopulater.GiftAidDonations = DataHelpers.GetDataTableFromCsv(@"C:\Temp\Donations.csv", true);

            // Set up app.config as a source for the reference data
            ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile);

            // Build a GovTalkMessage
            GovTalkMessageCreator submitMessageCreator = new GovTalkMessageCreator(new SubmitRequestMessageBuilder(loggingService), loggingService);
            submitMessageCreator.CreateGovTalkMessage();

            // Get the GovTalkMessage that has been built
            GovTalkMessage submitMessage = submitMessageCreator.GetGovTalkMessage();

            // Serialize the GovTalkMessage to an XmlDocument
            XmlDocument xd = submitMessageCreator.SerializeGovTalkMessage();

            // Set the IRmark for the GovTalkMessage XmlDocument
            GovTalkMessageHelper gtmHelper = new GovTalkMessageHelper(configurationRepository, loggingService);
            XmlDocument finalXd = gtmHelper.SetIRmark(xd);

            // Set the URI to send the file to
            string uri = configurationRepository.GetConfigurationValue<string>("SendURILocal");

            // Create a client to send the file to the target gateway
            CharitiesOnline.MessageService.Client client = new MessageService.Client(loggingService);

            // Create an XmlDocument of the reply from the endpoint
            XmlDocument reply = client.SendRequest(xd, uri);

            // Set up a message reading strategy
            IMessageReader _messageReader = new DefaultMessageReader(loggingService,configurationRepository,reply.ToXDocument());
            _messageReader.ReadMessage();

            string[] results = _messageReader.GetMessageResults<string[]>();

            //int correlationIdIndex = Array.IndexOf(results, "CorrelationId");
            int correlationIdPosition = Array.FindIndex(results, element => element.StartsWith("CorrelationId"));
            if (correlationIdPosition < 0)
                throw new ArgumentNullException("CorrelationId");

            int qualifierPosition = Array.FindIndex(results, element => element.StartsWith("Qualifier"));

            if (qualifierPosition < 0)
                throw new ArgumentNullException("Qualifier");

            Console.WriteLine(string.Join("\n", results));

            #region old
            // This bit, bunch of if-thens, should be covered by the reader strategy ...
            //string bodytype = _messageReader.GetBodyType(reply.ToXDocument());

            //if(bodytype == null)
            //{
            //    //acknowledgment
            //    Console.WriteLine("CorrelationId is {0}",_messageReader.ReadMessage<string>(reply.ToXDocument()));
            //}
            //else if(bodytype == "hmrcclasses.SuccessResponse")
            //{
            //    //success
            //    string[] success = _messageReader.ReadMessage<string[]>(reply.ToXDocument());
            //    Console.WriteLine(string.Join("\n", success));
            //}
            //else if(bodytype == "hmrcclasses.ErrorResponse")
            //{
            //    //error
            //    string[] error = _messageReader.ReadMessage<string[]>(reply.ToXDocument());
            //    Console.WriteLine(string.Join("\n", error));
            //}

            #endregion old

            // Need to get correlationId

            GovTalkMessageFileName fileNamer = new GovTalkMessageFileName.FileNameBuilder()
            .AddLogger(loggingService)
            .AddFilePath(configurationRepository.GetConfigurationValue<string>("TempFolder"))
            .AddEnvironment("local")
            .AddMessageIntention("reply")
            .AddCorrelationId(results[correlationIdPosition].Substring(results[correlationIdPosition].IndexOf("::") + 2))
            .AddMessageQualifier(results[qualifierPosition].Substring(results[qualifierPosition].IndexOf("::") + 2)) //could check for < 0 here and pass empty string
            .BuildFileName();

            string filename = fileNamer.ToString();

            reply.Save(filename);

            // reply.Save(@"C:\Temp\localreply.xml");
        }
Example #6
0
        public static void DemonstrateLocalProcess()
        {
            // Set up the logging
            IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository();
            ILoggingService          loggingService          = new Log4NetLoggingService(configurationRepository, new ThreadContextService());

            DataTableRepaymentPopulater.SetLogger(loggingService);

            // Create a file of donations records
            DataTableRepaymentPopulater.GiftAidDonations = DataHelpers.GetDataTableFromCsv(@"C:\Temp\Donations.csv", true);

            // Set up app.config as a source for the reference data
            ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile);

            // Build a GovTalkMessage
            GovTalkMessageCreator submitMessageCreator = new GovTalkMessageCreator(new SubmitRequestMessageBuilder(loggingService), loggingService);

            submitMessageCreator.CreateGovTalkMessage();

            // Get the GovTalkMessage that has been built
            GovTalkMessage submitMessage = submitMessageCreator.GetGovTalkMessage();

            // Serialize the GovTalkMessage to an XmlDocument
            XmlDocument xd = submitMessageCreator.SerializeGovTalkMessage();

            // Set the IRmark for the GovTalkMessage XmlDocument
            GovTalkMessageHelper gtmHelper = new GovTalkMessageHelper(configurationRepository, loggingService);
            XmlDocument          finalXd   = gtmHelper.SetIRmark(xd);

            // Set the URI to send the file to
            string uri = configurationRepository.GetConfigurationValue <string>("SendURILocal");

            // Create a client to send the file to the target gateway
            CharitiesOnline.MessageService.Client client = new MessageService.Client(loggingService);

            // Create an XmlDocument of the reply from the endpoint
            XmlDocument reply = client.SendRequest(xd, uri);

            // Set up a message reading strategy
            IMessageReader _messageReader = new DefaultMessageReader(loggingService, configurationRepository, reply.ToXDocument());

            _messageReader.ReadMessage();

            string[] results = _messageReader.GetMessageResults <string[]>();

            //int correlationIdIndex = Array.IndexOf(results, "CorrelationId");
            int correlationIdPosition = Array.FindIndex(results, element => element.StartsWith("CorrelationId"));

            if (correlationIdPosition < 0)
            {
                throw new ArgumentNullException("CorrelationId");
            }

            int qualifierPosition = Array.FindIndex(results, element => element.StartsWith("Qualifier"));

            if (qualifierPosition < 0)
            {
                throw new ArgumentNullException("Qualifier");
            }

            Console.WriteLine(string.Join("\n", results));

            #region old
            // This bit, bunch of if-thens, should be covered by the reader strategy ...
            //string bodytype = _messageReader.GetBodyType(reply.ToXDocument());

            //if(bodytype == null)
            //{
            //    //acknowledgment
            //    Console.WriteLine("CorrelationId is {0}",_messageReader.ReadMessage<string>(reply.ToXDocument()));
            //}
            //else if(bodytype == "hmrcclasses.SuccessResponse")
            //{
            //    //success
            //    string[] success = _messageReader.ReadMessage<string[]>(reply.ToXDocument());
            //    Console.WriteLine(string.Join("\n", success));
            //}
            //else if(bodytype == "hmrcclasses.ErrorResponse")
            //{
            //    //error
            //    string[] error = _messageReader.ReadMessage<string[]>(reply.ToXDocument());
            //    Console.WriteLine(string.Join("\n", error));
            //}

            #endregion old

            // Need to get correlationId

            GovTalkMessageFileName fileNamer = new GovTalkMessageFileName.FileNameBuilder()
                                               .AddLogger(loggingService)
                                               .AddFilePath(configurationRepository.GetConfigurationValue <string>("TempFolder"))
                                               .AddEnvironment("local")
                                               .AddMessageIntention("reply")
                                               .AddCorrelationId(results[correlationIdPosition].Substring(results[correlationIdPosition].IndexOf("::") + 2))
                                               .AddMessageQualifier(results[qualifierPosition].Substring(results[qualifierPosition].IndexOf("::") + 2)) //could check for < 0 here and pass empty string
                                               .BuildFileName();

            string filename = fileNamer.ToString();

            reply.Save(filename);

            // reply.Save(@"C:\Temp\localreply.xml");
        }