Ejemplo n.º 1
0
        // read message into datatable of donations ?

        // what do we want to do when we read in a Submit Request - recreate the input datatables (donations & otherincome)
        // list of the reference values

        public void ReadMessage(XDocument inXD)
        {
            _message = XmlSerializationHelpers.DeserializeMessage(inXD.ToXmlDocument());

            _messageRead = true;

            _qualifier = _message.Header.MessageDetails.Qualifier.ToString();
            _function  = _message.Header.MessageDetails.Function.ToString();

            XmlElement xmlElement = _message.Body.Any[0];

            XmlDocument bodyDoc = new XmlDocument();

            bodyDoc.LoadXml(xmlElement.OuterXml);

            _body = XmlSerializationHelpers.DeserializeIRenvelope(bodyDoc);

            if (_body.R68.Items[0].GetType() == typeof(R68CompressedPart))
            {
                _hasCompressedPart = true;
            }
            else
            {
                _hasCompressedPart = false;
            }

            _loggingService.LogInfo(this, "Message read. Message is SubmitRequest.");
        }
Ejemplo n.º 2
0
        public static void TestDeserializeSuccessResponse(ILoggingService loggingService)
        {
            GovTalkMessageFileName FileNamer = new GovTalkMessageFileName.FileNameBuilder()
                                               .AddLogger(loggingService)
                                               .AddFilePath(@"C:\Temp\")
                                               .AddEnvironment("live")
                                               .AddMessageIntention("PollMessage")
                                               .AddTimestamp("2015_02_02_12_41")
                                               .AddCorrelationId("1853DE80F71CEF4C07B57CD5BDA969D577")
                                               .AddMessageQualifier("response")
                                               .AddCustomNamePart("20150202124118")
                                               .BuildFileName();

            string filename = FileNamer.ToString();

            XmlDocument successMessage = new XmlDocument();

            successMessage.Load(filename);

            GovTalkMessage success = XmlSerializationHelpers.DeserializeMessage(successMessage);

            XmlDocument successXml = new XmlDocument();

            successXml.LoadXml(success.Body.Any[0].OuterXml);

            SuccessResponse successResp = XmlSerializationHelpers.DeserializeSuccessResponse(successXml);

            loggingService.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, successResp.Message[0].Value);
        }
Ejemplo n.º 3
0
        private R68Claim GetClaim(object[] R68Items)
        {
            if (R68Items[0] is R68CompressedPart)
            {
                R68CompressedPart compressedPart = (R68CompressedPart)_body.R68.Items[0];

                string      decompressedData = CommonUtilityHelper.DecompressData(compressedPart.Value);
                XmlDocument decompressedXml  = new XmlDocument();
                decompressedXml.LoadXml(decompressedData);

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

                XmlDocument r68ClaimXmlDoc = new XmlDocument();
                XmlElement  r68root        = r68ClaimXmlDoc.CreateElement("R68Claim");
                r68root.SetAttribute("xmlns", "http://www.govtalk.gov.uk/taxation/charities/r68/2");
                r68ClaimXmlDoc.AppendChild(r68root);
                r68root.InnerXml = decompressedXml.DocumentElement.InnerXml;

                return(XmlSerializationHelpers.Deserialize <R68Claim>(r68ClaimXmlDoc.OuterXml, "R68Claim"));
            }
            else
            {
                return((R68Claim)R68Items[0]);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public override void BuildBody()
        {
            // do the building logic for the Body of a SubmitRequest

            #region old
            //GovTalkMessageBody Body = new GovTalkMessageBody();
            //IR68 ir68 = new IR68(_localData);
            //IRenvelope ire = new IRenvelope();
            //ire = ir68.CreateIRBody();
            #endregion old

            IRenvelopeCreator irEnvelopeCreator = new IRenvelopeCreator(new CompressedIRenvelopeBuilder(_loggingService), _loggingService);
            irEnvelopeCreator.CreateIRenvelope();

            hmrcclasses.IRenvelope ire = irEnvelopeCreator.GetIRenvelope();

            XmlElement   xe = XmlSerializationHelpers.SerializeIREnvelope(ire);
            XmlElement[] XmlElementIRenvelope = new XmlElement[1];
            XmlElementIRenvelope[0] = xe;

            Body.Any = XmlElementIRenvelope;

            _loggingService.LogInfo(this, "Built a SubmitRequestBody");

            // throw new NotImplementedException();
        }
Ejemplo n.º 6
0
        public override void ReadXml(XmlReader reader)
        {
            base.ReadXml(reader);

            var specFileListStr = reader.GetAttribute("SpecificationFileNames");
            var tempList        = (List <string>)XmlSerializationHelpers.XmlDeserializeFromString(specFileListStr, mSpecFileNames.GetType());

            mSpecFileNames.AddRange(tempList);

            // we used to record the Type.AssemblyQualifiedName but this is sensitive to the assembly version,
            // so we just record the type and resolve the type ourselves since we know that all batch related
            // parameters are in EllieWare.Common.dll
            var batchTypeStr = reader.GetAttribute("BatchType");
            var batchType    = Type.GetType(batchTypeStr, null, BatchTypeResolver);

            mBatchParam = (ISerializableBatchParameter)Activator.CreateInstance(batchType);
            mBatchParam.ReadXml(reader);

            UpdateUserInterface();

            if (mSpecs.Items.Count > 0)
            {
                // select first spec
                mSpecs.SelectedIndex = 0;
            }
        }
Ejemplo n.º 7
0
        public void ReadMessage(XDocument inMessage)
        {
            try
            {
                _message       = XmlSerializationHelpers.DeserializeMessage(inMessage.ToXmlDocument());
                _correlationId = _message.Header.MessageDetails.CorrelationID;
                _qualifier     = _message.Header.MessageDetails.Qualifier.ToString();
                _function      = _message.Header.MessageDetails.Function.ToString();
                if (_message.Header.MessageDetails.GatewayTimestampSpecified)
                {
                    _gatewayTimestamp = _message.Header.MessageDetails.GatewayTimestamp;
                }

                XmlDocument successXml = new XmlDocument();

                if (_message.Body.Any != null)
                {
                    successXml.LoadXml(_message.Body.Any[0].OuterXml);

                    _body = XmlSerializationHelpers.DeserializeSuccessResponse(successXml);
                }
                else
                {
                    MessageType messageType = new MessageType
                    {
                        Value = "No valid SuccessResponse contained in the Body element of this message. Contact Support."
                    };

                    SuccessResponse dummyResponse = new SuccessResponse
                    {
                        IRmarkReceipt = null,
                        Message       = new MessageType[] { messageType },
                        AcceptedTime  = (DateTime)_gatewayTimestamp
                    };

                    _body = dummyResponse;
                }

                _messageRead = true;

                _loggingService.LogInfo(this, "Message read. Response type is Response.");
            }
            catch (Exception ex)
            {
                _loggingService.LogError(this, "Message Reading Exception", ex);

                GovTalkMessageFileName FileNamer = new GovTalkMessageFileName(_loggingService, _configurationRepository);
                string filename = FileNamer.DefaultFileName();

                _loggingService.LogInfo(this, String.Concat("Attempting to save reply document to ", filename, "."));

                inMessage.Save(filename);

                throw ex;
            }
        }
Ejemplo n.º 8
0
        public void ReadMessage(XDocument inMessage)
        {
            _message = XmlSerializationHelpers.DeserializeMessage(inMessage.ToXmlDocument());

            _messageRead = true;

            _correlationId = _message.Header.MessageDetails.CorrelationID;
            _qualifier     = _message.Header.MessageDetails.Qualifier.ToString();
            _function      = _message.Header.MessageDetails.Function.ToString();
        }
Ejemplo n.º 9
0
        public void ReadMessage(XDocument inMessage)
        {
            _message       = XmlSerializationHelpers.DeserializeMessage(inMessage.ToXmlDocument());
            _messageRead   = true;
            _correlationId = _message.Header.MessageDetails.CorrelationID;
            _qualifier     = _message.Header.MessageDetails.Qualifier.ToString();
            _function      = _message.Header.MessageDetails.Function.ToString();

            _loggingService.LogInfo(this, "Message read. Response type is Response to Delete Request.");
        }
Ejemplo n.º 10
0
        string XmlEcho(string message)
        {
            var xmlString  = XmlSerializationHelpers.Serialize(message);
            var xmlContent = new StringContent(xmlString, Encoding.UTF8, "application/xml");

            using (var response = _httpClient.PostAsync($"xml/{_v0VersionUrl}echo", xmlContent).Result)
            {
                response.EnsureSuccessStatusCode();
                var content = response.Content.ReadAsStringAsync().Result;

                return(content);
            }
        }
Ejemplo n.º 11
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");
        }
Ejemplo n.º 12
0
        public override void WriteXml(XmlWriter writer)
        {
            base.WriteXml(writer);

            var specFileList = XmlSerializationHelpers.XmlSerializeToString(mSpecFileNames);

            writer.WriteAttributeString("SpecificationFileNames", specFileList);

            var batchType = mBatchParam.GetType();

            writer.WriteAttributeString("BatchType", batchType.ToString());
            mBatchParam.WriteXml(writer);
        }
Ejemplo n.º 13
0
        public void ReadMessage(XDocument inMessage)
        {
            try
            {
                _message = XmlSerializationHelpers.DeserializeMessage(inMessage.ToXmlDocument());

                _messageRead = true;

                _correlationId = _message.Header.MessageDetails.CorrelationID;
                _qualifier     = _message.Header.MessageDetails.Qualifier.ToString();
                _function      = _message.Header.MessageDetails.Function.ToString();

                if (_message.Body.Any != null)
                {
                    XmlDocument errorXml = new XmlDocument();
                    errorXml.LoadXml(_message.Body.Any[0].OuterXml);
                    _body      = XmlSerializationHelpers.DeserializeErrorResponse(errorXml);
                    _errorText = _body.Application.Any[0].Name + ":" + _body.Application.Any[0].InnerText;
                }

                if (_message.GovTalkDetails != null)
                {
                    if (_message.GovTalkDetails.GovTalkErrors != null)
                    {
                        _govTalkDetailsErrors = new List <GovTalkMessageGovTalkDetailsError>();

                        foreach (GovTalkMessageGovTalkDetailsError error in _message.GovTalkDetails.GovTalkErrors)
                        {
                            _govTalkDetailsErrors.Add(error);
                        }

                        _errorText = String.Format("There are {0} GovTalkDetailsErrors.", _govTalkDetailsErrors.Count);
                    }
                }

                _loggingService.LogInfo(this, string.Concat("Message read. Response type is Error."));
            }
            catch (Exception ex)
            {
                _loggingService.LogError(this, "Message Reading Exception", ex);

                GovTalkMessageFileName FileNamer = new GovTalkMessageFileName(_loggingService, _configurationRepository);
                string filename = FileNamer.DefaultFileName();

                _loggingService.LogInfo(this, String.Concat("Attempting to save reply document to ", filename, "."));

                inMessage.Save(filename);

                throw ex;
            }
        }
        public static ExpressRouteManagementClient GetProviderExpressRouteManagementClient()
        {
            string managementCertificate = "";
            string baseUri;
            string subscriptionId;

            if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                baseUri               = HttpMockServer.Variables["TEST_PROVIDER_BASE_URI"];
                subscriptionId        = HttpMockServer.Variables["TEST_PROVIDER_SUBSCRIPTION_ID"];
                managementCertificate = HttpMockServer.Variables["TEST_PROVIDER_MANAGEMENT_CERTIFICATE"];
            }
            else
            {
                string publishSettingsFile = Environment.GetEnvironmentVariable("TEST_PUBLISHSETTINGS_FILE_P");
                if (string.IsNullOrEmpty(publishSettingsFile))
                {
                    // Take default path
                    publishSettingsFile = @"C:\Powershell\PublishSettings\defaultProvider.publishsettings";
                }
                PublishData publishData = XmlSerializationHelpers.DeserializeXmlFile <PublishData>(publishSettingsFile);
                managementCertificate = Enumerable.First <PublishDataPublishProfile>((IEnumerable <PublishDataPublishProfile>)publishData.Items).ManagementCertificate;
                if (string.IsNullOrEmpty(managementCertificate))
                {
                    managementCertificate = Enumerable.First <PublishDataPublishProfileSubscription>((IEnumerable <PublishDataPublishProfileSubscription>)Enumerable.First <PublishDataPublishProfile>((IEnumerable <PublishDataPublishProfile>)publishData.Items).Subscription).ManagementCertificate;
                }
                if (string.IsNullOrEmpty(managementCertificate))
                {
                    throw new ArgumentException(string.Format("{0} is not a valid publish settings file, you must provide a valid publish settings file in the environment variable {1}", (object)publishSettingsFile, (object)"TEST_PROVIDER_PUBLISHSETTINGS_FILE"));
                }


                subscriptionId = Enumerable.First <PublishDataPublishProfileSubscription>((IEnumerable <PublishDataPublishProfileSubscription>)Enumerable.First <PublishDataPublishProfile>((IEnumerable <PublishDataPublishProfile>)publishData.Items).Subscription).Id;

                baseUri = Enumerable.First <PublishDataPublishProfileSubscription>(
                    (IEnumerable <PublishDataPublishProfileSubscription>)
                    Enumerable.First <PublishDataPublishProfile>(
                        (IEnumerable <PublishDataPublishProfile>)publishData.Items).Subscription)
                          .ServiceManagementUrl ?? publishData.Items[0].Url;

                HttpMockServer.Variables["TEST_PROVIDER_MANAGEMENT_CERTIFICATE"] = managementCertificate;
                HttpMockServer.Variables["TEST_PROVIDER_SUBSCRIPTION_ID"]        = subscriptionId;
                HttpMockServer.Variables["TEST_PROVIDER_BASE_URI"] = baseUri;
            }

            var credentials = new CertificateCloudCredentials(subscriptionId, new X509Certificate2(Convert.FromBase64String(managementCertificate), string.Empty));
            var client      = new ExpressRouteManagementClient(credentials, new Uri(baseUri));

            client.AddHandlerToPipeline(HttpMockServer.CreateInstance());
            return(client);
        }
Ejemplo n.º 15
0
        private async Task <EchoResponse> XmlEchoAsync(EchoRequest message)
        {
            var xmlString  = XmlSerializationHelpers.Serialize(message);
            var xmlContent = new StringContent(xmlString, Encoding.UTF8, "application/xml");

            using (var response = await _httpClient.PostAsync("v1/Echo", xmlContent))
            {
                response.EnsureSuccessStatusCode();
                var content = await response.Content.ReadAsStringAsync();

                var    xml      = XElement.Parse(content);
                string jsonText = JsonConvert.SerializeXNode(xml);
                return(JsonConvert.DeserializeObject <EchoResponse>(jsonText));
            }
        }
Ejemplo n.º 16
0
        public void ReadMessage(XDocument inMessage)
        {
            _message = XmlSerializationHelpers.DeserializeMessage(inMessage.ToXmlDocument());

            _messageRead = true;

            _qualifier = _message.Header.MessageDetails.Qualifier.ToString();
            _function  = _message.Header.MessageDetails.Function.ToString();

            XmlDocument listXml = new XmlDocument();

            listXml.LoadXml(_message.Body.Any[0].OuterXml);

            _statusReport = XmlSerializationHelpers.DeserializeStatusReport(listXml);

            _loggingService.LogInfo(this, "Message read. Response type is List Response.");
        }
        public void DoWork(IRequest request)
        {
            if (request.ContentType != Sage.Common.Syndication.MediaType.Atom)
            {
                throw new RequestException("Atom content type expected");
            }

            //read feed
            string    resourceKindName = _requestContext.ResourceKind.ToString();
            SyncFeed  feed             = new SyncFeed();
            XmlReader reader           = XmlReader.Create(request.Stream);

            feed.ReadXml(reader, ResourceKindHelpers.GetPayloadType(_requestContext.ResourceKind));

            /* iterate through all entries and store result information */
            ISyncResultInfoStore syncResultInfoStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetSyncResultStore(_requestContext.SdataContext);

            int    noOfEntries = feed.Entries.Count;
            string endpoint    = string.Empty;

            try
            {
                endpoint = new RequestContext(new Sage.Common.Syndication.SDataUri(feed.Id)).OriginEndPoint;
            }
            catch { }

            SyncResultEntryInfo[] syncResultEntries = new SyncResultEntryInfo[noOfEntries];
            for (int i = 0; i < noOfEntries; i++)
            {
                SyncFeedEntry entry      = (SyncFeedEntry)feed.Entries[i];
                string        httpMethod = entry.HttpMethod;
                int           httpStatus = -1;
                if (Enum.IsDefined(typeof(HttpStatusCode), entry.HttpStatusCode.ToString()))
                {
                    httpStatus = (int)Enum.Parse(typeof(HttpStatusCode), entry.HttpStatusCode.ToString(), true);
                }
                string httpLocation = entry.HttpLocation;
                string httpMessage  = entry.HttpMessage;
                string diagnosisXml = XmlSerializationHelpers.SerializeObjectToXml(entry.Diagnoses);
                string payloadXml   = XmlSerializationHelpers.SerializeObjectToXml(entry.Payload);

                syncResultEntries[i] = new SyncResultEntryInfo(httpMethod, httpStatus, httpLocation, httpMessage, diagnosisXml, payloadXml, DateTime.Now, endpoint);
            }

            syncResultInfoStore.Add(resourceKindName, syncResultEntries);
        }
        public void GetTrackingState(IRequest request)
        {
            lock (_asyncStateObj)
            {
                if (null == _asyncStateObj.Tracking)
                {
                    throw new InvalidOperationException("Performer has not been started.");
                }


                if (_asyncStateObj.Tracking.Phase == TrackingPhase.FINISH)
                {
                    request.Response.ContentType = MediaType.Atom;
                    int          startindex   = Convert.ToInt32(request.Uri.StartIndex);
                    int          count        = Convert.ToInt32(request.Uri.Count);
                    SdataContext sdataContext = _requestContext.SdataContext;
                    ICorrelatedResSyncInfoStore correlatedResSyncInfoStore = RequestReceiver.NorthwindAdapter.StoreLocator.GetCorrelatedResSyncStore(sdataContext);

                    request.Response.Serializer = new SyncFeedSerializer();
                    SyncFeed syncFeed = _asyncPerformer.GetFeed(_requestContext.Config, startindex, count);
                    syncFeed.FeedType     = FeedType.SyncSource;
                    request.Response.Feed = syncFeed;
                }
                else if (_asyncStateObj.Tracking.Phase == TrackingPhase.ERROR)
                {
                    request.Response.Xml         = XmlSerializationHelpers.SerializeObjectToXml(_asyncStateObj.Tracking);
                    request.Response.ContentType = MediaType.Xml;
                    request.Response.StatusCode  = HttpStatusCode.InternalServerError;
                    request.Response.Serializer  = new XmlSerializer();
                    request.Response.Protocol.SendUnknownResponseHeader("location", String.Format("{0}{1}/$syncSource('{2}')", _requestContext.DatasetLink, _requestContext.ResourceKind.ToString(), _requestContext.TrackingId));
                }
                else
                {
                    request.Response.Xml         = XmlSerializationHelpers.SerializeObjectToXml(_asyncStateObj.Tracking);
                    request.Response.ContentType = MediaType.Xml;
                    request.Response.StatusCode  = HttpStatusCode.Accepted;
                    request.Response.Serializer  = new XmlSerializer();
                    request.Response.Protocol.SendUnknownResponseHeader("location", String.Format("{0}{1}/$syncSource('{2}')", _requestContext.DatasetLink, _requestContext.ResourceKind.ToString(), _requestContext.TrackingId));
                }
            }
        }
Ejemplo n.º 19
0
        public XmlDocument CompressClaim()
        {
            _loggingService.LogInfo(this, "Compressing Claim.");

            XmlElement  bodyElement  = _govTalkMessageBuilder.GovTalkMessage.Body.Any[0];
            XmlDocument bodyDocument = new XmlDocument();

            bodyDocument.LoadXml(bodyElement.OuterXml);

            //deserialize body
            IRenvelope irEnvelope = XmlSerializationHelpers.DeserializeIRenvelope(bodyDocument);

            R68         uncompressedR68 = irEnvelope.R68;
            XmlDocument r68xmlDoc       = XmlSerializationHelpers.SerializeItem(uncompressedR68);

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

            irEnvelope.R68.Items = null;

            R68CompressedPart compressedPart = new R68CompressedPart();

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

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

            irEnvelope.R68.Items = compressedParts;

            bodyElement = XmlSerializationHelpers.SerializeIREnvelope(irEnvelope);

            _govTalkMessageBuilder.GovTalkMessage.Body.Any[0] = null;
            _govTalkMessageBuilder.GovTalkMessage.Body.Any[0] = bodyElement;

            XmlDocument compressedVersion = SerializeGovTalkMessage();

            return(compressedVersion);
        }
Ejemplo n.º 20
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;
        }
Ejemplo n.º 21
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");
        }
Ejemplo n.º 22
0
        public T GetMessageResults <T>()
        {
            try
            {
                if (!_messageRead)
                {
                    throw new Exception("Message not read. Call ReadMessage first.");
                }

                if (typeof(T) == typeof(string))
                {
                    string correlationId = _message.Header.MessageDetails.CorrelationID;

                    _loggingService.LogInfo(this, string.Concat("Error CorrelationId is ", correlationId));

                    return((T)Convert.ChangeType(correlationId, typeof(T)));
                }
                if (typeof(T) == typeof(string[]))
                {
                    string[] response = new string[5];
                    response[0] = string.Concat("CorrelationId::", _message.Header.MessageDetails.CorrelationID);
                    response[1] = string.Concat("Qualifier::", _message.Header.MessageDetails.Qualifier);
                    response[2] = string.Concat("ResponseEndPoint::", _message.Header.MessageDetails.ResponseEndPoint.Value);
                    response[3] = string.Concat("GatewayTimestamp::", _message.Header.MessageDetails.GatewayTimestamp.ToString());
                    response[4] = string.Concat("Error::", _errorText);

                    _loggingService.LogInfo(this, string.Concat("Error CorrelationId is ", response[0]));

                    return((T)Convert.ChangeType(response, typeof(T)));
                }
                if (typeof(T) == typeof(GovTalkMessageGovTalkDetailsError))
                {
                    return((T)Convert.ChangeType(GetGovTalkDetailsError(), typeof(T)));
                }

                if (typeof(T) == typeof(GovTalkMessageGovTalkDetailsError[]))
                {
                    return((T)Convert.ChangeType(GetGovTalkDetailsErrors(), typeof(T)));
                }

                if (typeof(T) == typeof(System.Data.DataTable))
                {
                    return((T)Convert.ChangeType(GetErrorTable(), typeof(T)));
                }

                if (typeof(T) == typeof(ErrorResponse))
                {
                    return((T)Convert.ChangeType(GetErrorResponse(), typeof(T)));
                }
            }
            catch (Exception ex)
            {
                _loggingService.LogError(this, "Message Reading Exception", ex);

                GovTalkMessageFileName FileNamer = new GovTalkMessageFileName(_loggingService, _configurationRepository);
                string filename = FileNamer.DefaultFileName();

                _loggingService.LogInfo(this, String.Concat("Attempting to save reply document to ", filename, "."));

                XmlSerializationHelpers.SerializeToFile(_message, filename);
            }

            return(default(T));
        }