Exemplo n.º 1
0
        public static XmlDocument TestDeserializeAndDecompress(XmlDocument xd)
        {
            GovTalkMessage gtm = XmlSerializationHelpers.DeserializeMessage(xd);

            XmlElement xelement = gtm.Body.Any[0];

            // XmlDocument bodyDoc = xelement.OwnerDocument;
            XmlDocument bodyDoc = new XmlDocument();

            bodyDoc.LoadXml(xelement.OuterXml);

            IRenvelope ire = XmlSerializationHelpers.DeserializeIRenvelope(bodyDoc);

            R68CompressedPart compressedPart = (R68CompressedPart)ire.R68.Items[0];

            string decompressedClaim    = CommonUtilityHelper.DecompressData(compressedPart.Value);
            string decompressedR68Claim = decompressedClaim.Replace("Claim", "R68Claim");

            XmlDocument r68claim = new XmlDocument();

            r68claim.LoadXml(decompressedR68Claim);
            r68claim.DocumentElement.SetAttribute("xmlns", "http://www.govtalk.gov.uk/taxation/charities/r68/2");

            R68Claim uncompressedR68 = XmlSerializationHelpers.Deserialize <R68Claim>(r68claim.OuterXml, "R68Claim");

            // XmlSerializationHelpers.DeserializeR68Claim(r68claim);

            ire.R68.Items[0] = uncompressedR68;

            gtm.Body.Any[0] = XmlSerializationHelpers.SerializeIREnvelope(ire);

            XmlDocument SerializedDecompressedGovTalkMessage = XmlSerializationHelpers.SerializeGovTalkMessage(gtm);

            return(SerializedDecompressedGovTalkMessage);
        }
Exemplo n.º 2
0
        public static void TestDeserializeClaim()
        {
            XmlDocument claimXml = new XmlDocument();

            claimXml.Load(@"C:\Temp\R68Claim.xml");

            // Add namesapce to Xml
            // e.g. claimXml.DocumentElement.SetAttribute("xmlns","http://www.govtalk.gov.uk/taxation/charities/r68/2");

            // R68Claim r68claim = XmlSerializationHelpers.DeserializeR68Claim(claimXml);

            R68Claim otherway = XmlSerializationHelpers.Deserialize <R68Claim>(claimXml.OuterXml, "R68Claim");
        }
Exemplo n.º 3
0
        public static R68Claim DeserializeR68Claim(XmlDocument xmlElement)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(R68Claim));
            MemoryStream  xmlStream  = new MemoryStream();

            xmlElement.Save(xmlStream);
            xmlStream.Seek(0, SeekOrigin.Begin);

            var      LocalR68Claim = serializer.Deserialize(xmlStream);
            R68Claim r68claim      = (R68Claim)LocalR68Claim;

            return(r68claim);
        }
Exemplo n.º 4
0
        public override void SetItems()
        {
            RepaymentBuilder dtRepaymenBuilder = new RepaymentBuilder(_loggingService);

            R68ClaimCreator r68ClaimCreator = new R68ClaimCreator(dtRepaymenBuilder);

            r68ClaimCreator.CreateR68Claim();

            // one way ..

            R68Claim[] r68claim = new R68Claim[1];
            r68claim[0] = r68ClaimCreator.GetR68Claim();

            R68.Items = r68claim;
        }
Exemplo n.º 5
0
        public T GetMessageResults <T>()
        {
            if (!_messageRead)
            {
                throw new Exception("Message not read. Call ReadMessage first.");
            }

            R68Claim r68claim = GetClaim(_body.R68.Items);

            if (typeof(T) == typeof(DataTable))
            {
                DataTable dt = GetDataTableGiftAidDonations(r68claim.Repayment.GAD);

                return((T)Convert.ChangeType(dt, typeof(T)));
            }
            if (typeof(T) == typeof(DataSet))
            {
                // Get GiftAidDonations
                DataTable dataTableGiftAidDonations = GetDataTableGiftAidDonations(r68claim.Repayment.GAD);

                // Get OtherIncome
                DataTable dataTableOtherIncome = GetDataTableOtherInc(r68claim.Repayment.OtherInc);

                DataSet ds = new DataSet();
                ds.Tables.Add(dataTableGiftAidDonations);
                ds.Tables.Add(dataTableOtherIncome);

                return((T)Convert.ChangeType(ds, typeof(T)));
            }
            if (typeof(T) == typeof(string))
            {
                string messageForUser = "******";

                return((T)Convert.ChangeType(messageForUser, typeof(T)));
            }

            _loggingService.LogWarning(this, "No valid type specified for ReadSubmitRequest. Returning default (probably null).");

            return(default(T));
        }
Exemplo n.º 6
0
        public override void SetItems()
        {
            RepaymentBuilder dtRepaymenBuilder = new RepaymentBuilder(_loggingService);

            R68ClaimCreator r68ClaimCreator = new R68ClaimCreator(dtRepaymenBuilder);

            r68ClaimCreator.CreateR68Claim();

            R68Claim[] r68claim = new R68Claim[1];
            r68claim[0] = r68ClaimCreator.GetR68Claim();

            R68.Items = r68claim;

            // Serialize R68 to get XmlDocument with Claim element

            System.Xml.XmlDocument r68xmlDoc = XmlSerializationHelpers.SerializeItem(R68);

            // Then extract Claim itself

            System.Xml.XmlDocument claimXmlDoc = GovTalkMessageHelper.GetClaim(r68xmlDoc);

            // Reset R68 Items

            R68.Items = null;

            // Gzip compress

            R68CompressedPart compressedPart = new R68CompressedPart();

            compressedPart.Type  = R68CompressedPartType.gzip;
            compressedPart.Value = CommonUtilityHelper.CompressData(claimXmlDoc.OuterXml, _loggingService);

            R68CompressedPart[] compressedParts = new R68CompressedPart[1];
            compressedParts[0] = compressedPart;

            R68.Items = compressedParts;
        }
Exemplo n.º 7
0
 public void InitialiseR68Claim(ILoggingService loggingService)
 {
     _r68Claim       = new R68Claim();
     _loggingService = loggingService;
 }
Exemplo n.º 8
0
        public static void TestSerialize()
        {
            R68ClaimGASDS gasds = new R68ClaimGASDS();

            gasds.ConnectedCharities = r68_YesNoType.no;
            gasds.CommBldgs          = r68_YesNoType.no;

            R68ClaimRepaymentOtherInc otherinc = new R68ClaimRepaymentOtherInc();

            otherinc.Payer  = "Peter Other";
            otherinc.Gross  = 13.12M;
            otherinc.OIDate = Convert.ToDateTime("2014-10-31");
            otherinc.Tax    = 2.62M;

            R68ClaimRepaymentOtherInc[] OtherIncs = new R68ClaimRepaymentOtherInc[1];
            OtherIncs[0] = otherinc;

            R68ClaimRepaymentGADDonor donor = new R68ClaimRepaymentGADDonor();

            donor.Fore  = "Jane";
            donor.Sur   = "Smith";
            donor.House = "1";
            donor.Item  = "BA23 9CD";

            R68ClaimRepaymentGAD gad = new R68ClaimRepaymentGAD();

            gad.Item        = donor;
            gad.TotalString = "12.00";
            gad.Date        = Convert.ToDateTime("2014-10-03");

            XmlDocument xmlGad =
                XmlSerializationHelpers.SerializeItem(gad);

            byte[] bytes = Encoding.UTF8.GetBytes(xmlGad.OuterXml);

            xmlGad.Save(@"C:\Temp\GAD.xml");

            R68ClaimRepaymentGAD[] GADS = new R68ClaimRepaymentGAD[1];
            GADS[0] = gad;

            R68ClaimRepayment repayment = new R68ClaimRepayment();

            repayment.EarliestGAdateSpecified = true;
            repayment.EarliestGAdate          = Convert.ToDateTime("2014-10-03");
            repayment.GAD      = GADS;
            repayment.OtherInc = OtherIncs;

            R68ClaimRegulator regulator = new R68ClaimRegulator();

            regulator.Item  = R68ClaimRegulatorRegName.CCEW;
            regulator.RegNo = "A1234";

            R68Claim claim = new R68Claim();

            claim.OrgName   = "My Organisation";
            claim.HMRCref   = "AA12345";
            claim.GASDS     = gasds;
            claim.Regulator = regulator;
            claim.Repayment = repayment;

            XmlDocument claimXml =
                XmlSerializationHelpers.SerializeItem(claim);

            claimXml.Save(@"C:\Temp\R68Claim.xml");
        }