예제 #1
0
        public static void TestGovTalkCompressedMessageCreation()
        {
            DataTableRepaymentPopulater.GiftAidDonations = DataHelpers.GetDataTableFromCsv(@"C:\enterprise_tfs\GAVIN\CO\test_data\sample2.csv", true);
            DataTableRepaymentPopulater.OtherIncome      = DataHelpers.GetDataTableFromCsv(@"C:\Temp\OtherInc.csv", true);

            // C:\Temp\Donations.csv

            ReferenceDataManager.SetSource(ReferenceDataManager.SourceTypes.ConfigFile);

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

            GovTalkMessageCreator compressedSubmissionCreator = new GovTalkMessageCreator(new SubmitRequestCompressedMessageBuilder(loggingService), loggingService);

            compressedSubmissionCreator.CreateGovTalkMessage();

            XmlDocument xd = compressedSubmissionCreator.SerializeGovTalkMessage();

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

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

            finalXd.Save(filename.ToString());
        }
예제 #2
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());
        }
예제 #3
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;
            }
        }
예제 #4
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;
            }
        }
예제 #5
0
        public static void TestFileNaming(ILoggingService loggingService, IConfigurationRepository configurationRepository)
        {
            GovTalkMessageFileName filename = (new GovTalkMessageFileName.FileNameBuilder()
                                               .AddLogger(loggingService)
                                               .AddFilePath(@"")
                                               .AddEnvironment("Test")
                                               .AddMessageIntention("RequestMessage")
                                               .AddTimestamp(DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss", System.Globalization.CultureInfo.InvariantCulture))
                                               .AddCustomNamePart("File" + 1)
                                               .BuildFileName()
                                               );

            Console.WriteLine(filename.ToString());

            Console.WriteLine(filename.Environment);

            filename.Environment = "production_";

            Console.WriteLine(filename.ToString());

            string timestamp    = DateTime.Now.ToString("yyyyMMddHHmmss");
            int    FileSequence = 0;

            GovTalkMessageFileName FileNamer = new GovTalkMessageFileName.FileNameBuilder()
                                               .AddConfigurationRepository(configurationRepository)
                                               .AddLogger(loggingService)
                                               .AddEnvironment("localtest")
                                               .AddFilePath(@"C:\Temp\")
                                               .AddMessageIntention("SubmitRequest")
                                               .AddTimestamp(timestamp)
                                               .AddCustomNamePart(String.Concat("152", (FileSequence > 0 ? "_" + FileSequence.ToString() : "")))
                                               .BuildFileName();

            Console.WriteLine(FileNamer.ToString());


            Console.ReadKey();
        }
예제 #6
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));
        }