Beispiel #1
0
        public static void TestOtherIncome()
        {
            DataTableRepaymentPopulater.GiftAidDonations = DataHelpers.GetDataTableFromCsv(@"C:\Temp\Donations.csv", true);
            DataTableRepaymentPopulater.OtherIncome      = DataHelpers.GetDataTableFromCsv(@"C:\Temp\OtherInc.csv", true);

            ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile);

            IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository();
            ILoggingService          loggingService          = new Log4NetLoggingService(configurationRepository, new ThreadContextService());

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

            submitMessageCreator.CreateGovTalkMessage();
            hmrcclasses.GovTalkMessage submitMessage = submitMessageCreator.GetGovTalkMessage();

            XmlDocument xd = submitMessageCreator.SerializeGovTalkMessage();

            GovTalkMessageHelper gtmHelper = new GovTalkMessageHelper(configurationRepository, loggingService);
            XmlDocument          finalXd   = gtmHelper.SetIRmark(xd);

            GovTalkMessageFileName filename = (new GovTalkMessageFileName.FileNameBuilder()
                                               .AddFilePath(@"C:\Temp\")
                                               .AddEnvironment("Test")
                                               .AddMessageIntention("GovTalkMsgWithOtherIncome")
                                               .AddTimestamp(DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss", System.Globalization.CultureInfo.InvariantCulture))
                                               .BuildFileName()
                                               );

            finalXd.Save(filename.ToString());
        }
Beispiel #2
0
        public static void SerializeToFile(hmrcclasses.GovTalkMessage gtMsg, string outputFile)
        {
            string filename = outputFile;

            using (StreamWriter output =
                       new StreamWriter(new FileStream(outputFile, FileMode.Create), Encoding.UTF8))
            {
                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                // Need to change the namespace declarations in the GovTalkMessage attributes
                ns.Add(String.Empty, "http://www.govtalk.gov.uk/CM/envelope");

                XmlSerializer serializer =
                    new XmlSerializer(typeof(hmrcclasses.GovTalkMessage));
                serializer.Serialize(output, gtMsg, ns);
            }
        }
        /// <summary>
        /// Set a password within a GovTalkMessage object
        /// </summary>
        /// <param name="govTalkMessage"></param>
        /// <param name="userPassword"></param>
        /// <param name="passwordMethod"></param>
        public void SetPassword(GovTalkMessage govTalkMessage, string userPassword, string passwordMethod = "")
        {
            _loggingService.LogInfo(this, "Setting password.");

            if((passwordMethod == "MD5" || _configurationRepository.GetConfigurationValue<string>("SenderAuthenticationMethod") == "MD5") && passwordMethod.ToLower() != "clear")
            {
                CommonUtilityHelper helper = new CommonUtilityHelper(_configurationRepository,_loggingService);

                govTalkMessage.Header.SenderDetails.IDAuthentication.Authentication[0].Method = GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthenticationMethod.MD5;

                userPassword = helper.MD5Hash(userPassword);

                _loggingService.LogDebug(this, "MD5 Hashed password.");
            }
            if(passwordMethod.ToLower() == "clear")
            {
                govTalkMessage.Header.SenderDetails.IDAuthentication.Authentication[0].Method = GovTalkMessageHeaderSenderDetailsIDAuthenticationAuthenticationMethod.clear;
            }

            govTalkMessage.Header.SenderDetails.IDAuthentication.Authentication[0].Item = userPassword;

            _loggingService.LogInfo(this, "Password set.");
        }
        /// <summary>
        /// Controls serialization of objects to Xml
        /// </summary>
        /// <param name="gtMsg"></param>
        /// <param name="OutputFile"></param>
        public static void SerializeObjectToFile(GovTalkMessage gtMsg, string OutputFile)
        {
            try
            {
                string filename = OutputFile;

                using (Stream stream = File.Open(filename, FileMode.Create))
                {
                    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                    // Need to change the namespace declarations in the GovTalkMessage attributes
                    ns.Add(String.Empty, "http://www.govtalk.gov.uk/CM/envelope");

                    XmlSerializer serializer =
                                new XmlSerializer(typeof(GovTalkMessage));
                    serializer.Serialize(stream, gtMsg, ns);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }
        }
        public static XmlDocument SerializeInMemory(GovTalkMessage gtm)
        {
            try
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                    ns.Add(string.Empty, "http://www.govtalk.gov.uk/CM/envelope");

                    XmlSerializer serializer =
                                    new XmlSerializer(typeof(GovTalkMessage));

                    XmlTextWriter tw = new XmlTextWriter(memStream, UTF8Encoding.UTF8);
                    XmlDocument doc = new XmlDocument();
                    tw.Formatting = Formatting.Indented;
                    tw.IndentChar = ' ';
                    serializer.Serialize(memStream, gtm, ns);

                    memStream.Seek(0, SeekOrigin.Begin);
                    doc.Load(memStream);

                    log.Debug("GovTalkMsg serialized in memory");

                    return doc;
                }
            }
            catch (Exception ex)
            {
                log.Debug("GovTalkMsg not serialized in memory");
                log.Error(ex);
                throw;
            }
        }
        /// <summary>
        /// Reads Government Gateway Xml responses
        /// </summary>
        /// <param name="xmlresp"></param>
        public static void ReadResponse(XmlDocument xmlresp)
        {
            HMRCDataTable ResponseTable = new HMRCDataTable();

            try
            {
                GovTalkGateway ResponseReader = new GovTalkGateway();
                GovTalkMessage Message = new GovTalkMessage();
                Message = ResponseReader.ReadAcknowledgementAndResponse(xmlresp);

               if (String.IsNullOrEmpty(_correlationId))
                    _correlationId = ResponseReader.CorrelationId;

                _resp = ResponseReader.GatewayResponse;

                // Set the poll URI
                PollURI = Message.Header.MessageDetails.ResponseEndPoint.Value;

                if (_resp == "error")
                {
                    ResponseTable.AddErrorResponseColumns();
                    ResponseTable.AddErrorResponseRow(Message);
                }

                if (ResponseReader.PollInterval > 0)
                    _pollInterval = ResponseReader.PollInterval;

                log.Info(String.Format("Response received and read. Response type is {0}. CorrelationID is {1}", _resp, String.IsNullOrEmpty(_correlationId) ? "Nothing": _correlationId));

                if (ResponseReader.SuccessResponse != null)
                {
                    string message = "";
                    for (int i = 0; i < ResponseReader.SuccessResponse.Message.Length; i++)
                    {
                        message += "Message " + (i+1).ToString() + ": Code = "
                            +ResponseReader.SuccessResponse.Message[i].code.ToString() + "; "
                            + ResponseReader.SuccessResponse.Message[i].Value.ToString() + "; \n";
                    }

                    string FinalMessage = String.Format("Success Response with IRreceipt: {0}, Accepted time: {1}, Message Code: {2}, Message body: {3}",
                        ResponseReader.SuccessResponse.IRmarkReceipt.Message.Value.ToString(), ResponseReader.SuccessResponse.AcceptedTime,
                        ResponseReader.SuccessResponse.IRmarkReceipt.Message.code,
                        message
                        );
                    log.Info(FinalMessage);
                }

                // DataResponse case
                if (Message.Body.StatusReport != null)
                {
                    ResponseTable.AddGatewayColumns();
                    ResponseTable.AddStatusReportColumns();
                    ResponseTable.AddStatusReportRow(Message);
                }

                Data = ResponseTable.GetTable();
            }
            catch (Exception ex)
            {
                log.Error(ex.ToString());
            }
        }
        public void InitialiseGovTalkMessage(ILoggingService loggingService)
        {
            _govTalkMessage = new GovTalkMessage();
            _loggingService = loggingService;

            loggingService.LogInfo(this, "Initialised GovTalkMessage.");
        }