コード例 #1
0
ファイル: DemoConsole.cs プロジェクト: LalithaSharma/gail
        /// <summary>
        /// Shows how to create a Submit Request GovTalkMessage, the basic type for submitting a GiftAid claim.
        /// If the message is very large it can be compressed, or compression can be chosen at the start of the process.
        /// Password and IRmark are added after the message is created.
        /// </summary>
        /// <param name="loggingService"></param>
        static string DemonstrateCreateSubmitRequest(ILoggingService loggingService, IConfigurationRepository configurationRepository, string giftAidDataSourceCsvFile)
        {
            // Assign a reference data source
            ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile);

            // Set logger for the repaymentPopulater
            DataTableRepaymentPopulater.SetLogger(loggingService);

            // Assign a source for the GiftAid repayments data
            // If a filepath has been passed in, the DataHelpers method will make a datatable from a CSV source
            // with a valid set of columns. Otherwise, grab a datatable from a database or some other source
            // If the repaymentpopulater is not given a datatable, the submission message will have no repayments in it
            if (!string.IsNullOrEmpty(giftAidDataSourceCsvFile))
                DataTableRepaymentPopulater.GiftAidDonations = DataHelpers.GetDataTableFromCsv(giftAidDataSourceCsvFile, true);

            GovTalkMessageCreator submitMessageCreator = new GovTalkMessageCreator(new SubmitRequestMessageBuilder(loggingService), loggingService);

            submitMessageCreator.CreateGovTalkMessage();

            GovTalkMessage submitMessage = submitMessageCreator.GetGovTalkMessage();

            // Set a password if not using the password hard-coded in the configuration source
            GovTalkMessageHelper helper = new GovTalkMessageHelper(configurationRepository, loggingService);
            helper.SetPassword(submitMessage, "weirdpassword");

            XmlDocument submitMessageXml = submitMessageCreator.SerializeGovTalkMessage();

            GovTalkMessageHelper gtmHelper = new GovTalkMessageHelper(configurationRepository, loggingService);

            XmlDocument irMarkedMessageXml = gtmHelper.SetIRmark(submitMessageXml);

            // If the message is too big, compress it

            // byte[] xmlDocumentSize = xd.XmlToBytes();

            // if (xmlDocumentSize.Length > 1000000)
            // {
            //    XmlDocument compressedVersion = submitMessageCreator.CompressClaim();
            //    outputXmlDocument = GovTalkMessageHelper.SetIRmark(compressedVersion);
            // }

            // Optionally, create a filename using this helper class

            string outputFilename;
            string tempDirectory = configurationRepository.GetConfigurationValue<string>("TempFolder");

            GovTalkMessageFileName FileNamer = new GovTalkMessageFileName.FileNameBuilder()
                .AddLogger(loggingService)
                .AddMessageIntention("GatewaySubmission")
                .AddFilePath(tempDirectory)
                .AddTimestamp(DateTime.Now.ToString("yyyyMMddHHmmss"))
                .AddEnvironment("local")
                .AddCustomNamePart("EmptyRepayment")
                .BuildFileName();

            outputFilename = FileNamer.ToString();

            irMarkedMessageXml.Save(outputFilename);

            return outputFilename;
        }
コード例 #2
0
ファイル: DemoConsole.cs プロジェクト: LalithaSharma/gail
        public static void TestGovTalkMessageCreation(string SourceDataFileName, string Filename = "")
        {
            IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository();
            ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, new ThreadContextService());

            ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile);
            ReferenceDataManager.governmentGatewayEnvironment = GovernmentGatewayEnvironment.localtestservice;

            DataTableRepaymentPopulater.SetLogger(loggingService);

            if (!string.IsNullOrEmpty(SourceDataFileName))
                DataTableRepaymentPopulater.GiftAidDonations = DataHelpers.GetDataTableFromCsv(@SourceDataFileName, true);

            GovTalkMessageCreator submitMessageCreator = new GovTalkMessageCreator(new SubmitRequestMessageBuilder(loggingService), loggingService);

            submitMessageCreator.CreateGovTalkMessage();

            GovTalkMessage submitMessage = submitMessageCreator.GetGovTalkMessage();

            GovTalkMessageHelper helper = new GovTalkMessageHelper(configurationRepository, loggingService);
            helper.SetPassword(submitMessage, "testing1");

            XmlDocument xd = submitMessageCreator.SerializeGovTalkMessage();
            xd.PreserveWhitespace = true;

            xd = helper.AddPassword(xd.ToXDocument(), "xdocpassword", "clear").ToXmlDocument();

            byte[] xmlDocumentSize = xd.XmlToBytes();

            Console.WriteLine("The document is {0} bytes big.", xmlDocumentSize.Length);

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

            //if (xmlDocumentSize.Length > 1000000)
            //{
            //    XmlDocument compressedVersion = submitMessageCreator.CompressClaim();
            //    outputXmlDocument = GovTalkMessageHelper.SetIRmark(compressedVersion);
            //}
            //else
            //{

            GovTalkMessageHelper gtmHelper = new GovTalkMessageHelper(configurationRepository, loggingService);
            outputXmlDocument = gtmHelper.SetIRmark(xd);
            //}

            string filename;

            if (Filename == "")
            {
                GovTalkMessageFileName FileNamer = new GovTalkMessageFileName.FileNameBuilder()
                .AddLogger(loggingService)
                .AddMessageIntention("GatewaySubmission")
                .AddFilePath(@"C:\Temp\")
                .AddTimestamp(DateTime.Now.ToString("yyyyMMddHHmmss"))
                .AddEnvironment(ReferenceDataManager.governmentGatewayEnvironment.ToString())
                .BuildFileName();

                filename = FileNamer.ToString();
            }
            else
            {
                filename = Filename;
            }

            outputXmlDocument.Save(filename);

            #region old
            //BodyCreator bodyCreator = new BodyCreator(new SubmitRequestBodyBuilder());
            //bodyCreator.CreateBody();
            //GovTalkMessageBody body = bodyCreator.GetBody();

            //BodyCreator pollBodyCreator = new BodyCreator(new SubmitPollBodyBuilder());
            //pollBodyCreator.CreateBody();
            //GovTalkMessageBody pollBody = pollBodyCreator.GetBody();
            #endregion old
        }