예제 #1
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;
        }
예제 #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);
        }
예제 #3
0
        static void Main(string[] args)
        {
            try
            {
                // The configurationRepository is intended to abstract the configurationManager type and allow
                // for different configuration options to be applied. For example, a DatabaseConfigurationRepository could be provided
                // if the requirement is to take reference values from a database.
                configurationRepository = new ConfigFileConfigurationRepository();
                loggingService          = new Log4NetLoggingService(configurationRepository, new ThreadContextService());

                GovernmentGatewayEnvironment gatewayEnv = GovernmentGatewayEnvironment.localtestservice;

                //GovTalkMessageHelper helper = new GovTalkMessageHelper(configurationRepository, loggingService);

                //////// Optionally, set this to a valid filepath for a CSV that contains GiftAid data in an acceptable format.
                string csvFile = configurationRepository.GetConfigurationValue <string>("TempFolder") + "testdata.csv";

                #region Testing
                //TestGovTalkMessageCreation(csvFile, outputFilename);

                //XmlDocument LiveXml = new XmlDocument();
                //LiveXml.PreserveWhitespace = true;
                //LiveXml.Load(outputFilename);
                //XmlDocument LocalTestXml = new XmlDocument();
                //LocalTestXml.PreserveWhitespace = true;
                //LocalTestXml = helper.UpdateMessageForLocalTest(LiveXml);
                //LocalTestXml.Save(@"C:\Temp\Localsend.xml");
                #endregion Testing

                //// Create a GovTalkMessage and save the Xml to disk

                string outputFilename = DemonstrateCreateSubmitRequest(loggingService, configurationRepository, csvFile);

                XmlDocument submitMessageXml = new XmlDocument();

                ////// It is important if the XML message is being loaded from disk to preserve whitespace, otherwise the IRmark will be out for non-compressed files
                submitMessageXml.PreserveWhitespace = true;
                submitMessageXml.Load(outputFilename);


                XmlDocument submitMessageReply = DemonstrateSendMessage(loggingService, submitMessageXml, gatewayEnv);
                //XmlDocument submitMessageReply = new XmlDocument();
                //pollMessageReply.Load(@"C:\Temp\20151020110837.xml");

                DemonstrateReadMessage(loggingService, submitMessageReply);
            }
            catch (System.Net.WebException wex)
            {
                loggingService.LogError(wex.Source, "Exception occured in connecting to remote machine", wex);

                //Console.WriteLine("Exception occured in connecting to remote machine");
                //Console.WriteLine(wex.InnerException.Message);
                //Console.WriteLine(wex.Message);
            }
            catch (Exception ex)
            {
                loggingService.LogError(ex.Source, ex.Message, ex);
                //Console.WriteLine(ex);
            }
            finally
            {
                Console.ReadKey();
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            try
            {
                // The configurationRepository is intended to abstract the configurationManager type and allow
                // for different configuration options to be applied. For example, a DatabaseConfigurationRepository could be provided
                // if the requirement is to take reference values from a database.
                configurationRepository = new ConfigFileConfigurationRepository();
                loggingService          = new Log4NetLoggingService(configurationRepository, new ThreadContextService());

                //string filein = @"C:\Temp\RND15PAPERSPON9_SubmitRequest_20160811172825.xml";
                //string fileout = @"C:\Temp\decompressed_" + DateTime.Now.ToString("yyyymddhhmm") + ".xml";
                //DoDecompress(filein, fileout);
                //return;

                //TestReadMessage();
                //return;

                //TestAdjustment();
                //return;

                //TestDonorError();
                //return;

                // This sets the endpoint to the Local Test Service - see https://www.gov.uk/government/publications/local-test-service-and-lts-update-manager

                GovernmentGatewayEnvironment gatewayEnv = GovernmentGatewayEnvironment.localtestservice;

                //GovTalkMessageHelper helper = new GovTalkMessageHelper(configurationRepository, loggingService);

                //////// Optionally, set this to a valid filepath for a CSV that contains GiftAid data in an acceptable format.
                string csvFile = configurationRepository.GetConfigurationValue <string>("TempFolder") + "sample_other_inc.csv";

                #region Testing
                //TestGovTalkMessageCreation(csvFile, outputFilename);

                //XmlDocument LiveXml = new XmlDocument();
                //LiveXml.PreserveWhitespace = true;
                //LiveXml.Load(outputFilename);
                //XmlDocument LocalTestXml = new XmlDocument();
                //LocalTestXml.PreserveWhitespace = true;
                //LocalTestXml = helper.UpdateMessageForLocalTest(LiveXml);
                //LocalTestXml.Save(@"C:\Temp\Localsend.xml");
                #endregion Testing

                //// Create a GovTalkMessage and save the Xml to disk

                string outputFilename = DemonstrateCreateSubmitRequest(loggingService, configurationRepository, csvFile);

                Console.Write("File created for Sample2.csv: " + outputFilename);

                ////// If the LTS is running, comment this line
                return;

                ///// Send the file to the gatewayEnv endpoint

                XmlDocument submitMessageXml = new XmlDocument();

                ////// It is important if the XML message is being loaded from disk to preserve whitespace, otherwise the IRmark will be out for non-compressed files
                submitMessageXml.PreserveWhitespace = true;
                submitMessageXml.Load(outputFilename);


                XmlDocument submitMessageReply = DemonstrateSendMessage(loggingService, submitMessageXml, gatewayEnv);
                //XmlDocument submitMessageReply = new XmlDocument();
                //pollMessageReply.Load(@"C:\Temp\20151020110837.xml");

                DemonstrateReadMessage(loggingService, submitMessageReply);
            }
            catch (System.Net.WebException wex)
            {
                loggingService.LogError(wex.Source, "Exception occured in connecting to remote machine", wex);

                //Console.WriteLine("Exception occured in connecting to remote machine");
                //Console.WriteLine(wex.InnerException.Message);
                //Console.WriteLine(wex.Message);
            }
            catch (Exception ex)
            {
                loggingService.LogError(ex.Source, ex.Message, ex);
                //Console.WriteLine(ex);
            }
            finally
            {
                Console.ReadKey();
            }
        }