Exemplo n.º 1
0
        private static void OnMessageReceived(IMessage msg)
        {
            var textMsg = (ITextMessage)msg;

            var taxRefNo = "";
            var period   = "";
            var year     = "";

            try{
                var message = textMsg.Text;
                var doc     = new XmlDocument();
                doc.LoadXml(message);
                var ns = new XmlNamespaceManager(doc.NameTable);
                ns.AddNamespace("soap12", "http://www.w3.org/2003/05/soap-envelope");
                ns.AddNamespace("pnsb", "http://www.sars.gov.za/enterpriseMessagingModel/ThirdPartyData/ThirdPartyDataActivityManagement/xml/schemas/version/1.1");
                var header = doc.SelectSingleNode("//soap12:Header", ns);
                var thirdPartyDataActivityManagementRequest = doc.SelectSingleNode("//pnsb:ThirdPartyDataActivityManagementRequest", ns);
                if (thirdPartyDataActivityManagementRequest != null && header != null)
                {
                    var dataValidation = IsMneRequestValid(thirdPartyDataActivityManagementRequest.OuterXml);
                    if (!dataValidation.IsValid)
                    {
                        var faultXml = FdrCommon.CreateFaultXml(header.OuterXml, dataValidation.ErrorXml);
                        RespondToMneEnquire(faultXml, textMsg.JMSMessageID);
                        return;
                    }
                    foreach (XmlNode childNode in thirdPartyDataActivityManagementRequest.ChildNodes)
                    {
                        if (childNode.Name.Equals("pnsb:TaxRefNo"))
                        {
                            taxRefNo = childNode.InnerText;
                            continue;
                        }
                        if (childNode.Name.Equals("pnsb:Period"))
                        {
                            period = childNode.InnerText;
                            continue;
                        }
                        if (childNode.Name.Equals("pnsb:Year"))
                        {
                            year = childNode.InnerText;
                        }
                    }
                }
                else
                {
                    return;
                }
                var enquireResult                = DbReader.Enquire(taxRefNo, year);
                var correctCbCDeclarationInd     = DbReader.CanSubmitCbcDeclaration(taxRefNo, Convert.ToInt32(year));  //row["CorrectCbCDeclarationInd"].ToString();
                var correctMasterAndLocalFileInd = DbReader.CanSubmitFileDeclaration(taxRefNo, Convert.ToInt32(year)); //row["CorrectMasterAndLocalFileInd"].ToString();

                if (enquireResult.HasRows)
                {
                    var row = enquireResult[0];
                    var submitCbCDeclarationInd     = row["CbCReportRequiredInd"].ToString();
                    var submitMasterAndLocalFileInd = row["MasterLocalFileRequiredInd"].ToString();

                    var response = new ThirdPartyDataActivityManagementResponse
                    {
                        CBC = new ThirdPartyDataActivityManagementResponseCBC
                        {
                            CorrectCbCDeclarationInd     = correctCbCDeclarationInd ? YesNoIndType.Y : YesNoIndType.N,
                            CorrectMasterAndLocalFileInd =
                                correctMasterAndLocalFileInd ? YesNoIndType.Y : YesNoIndType.N,
                            SubmitCbCDeclarationInd =
                                submitCbCDeclarationInd.Equals("Y") ? YesNoIndType.Y : YesNoIndType.N,
                            SubmitMasterAndLocalFileInd =
                                submitMasterAndLocalFileInd.Equals("Y") ? YesNoIndType.Y : YesNoIndType.N
                        }
                    };
                    var xml = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(response);

                    var messageToSend = CreateXml(header.OuterXml, xml);
                    RespondToMneEnquire(messageToSend, textMsg.JMSMessageID);
                }
                else
                {
                    var response = new ThirdPartyDataActivityManagementResponse
                    {
                        CBC = new ThirdPartyDataActivityManagementResponseCBC
                        {
                            CorrectCbCDeclarationInd     = correctCbCDeclarationInd ? YesNoIndType.Y : YesNoIndType.N,
                            CorrectMasterAndLocalFileInd =
                                correctMasterAndLocalFileInd ? YesNoIndType.Y : YesNoIndType.N,
                            SubmitCbCDeclarationInd     = YesNoIndType.Y,
                            SubmitMasterAndLocalFileInd = YesNoIndType.Y
                        }
                    };
                    var xml           = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(response);
                    var messageToSend = CreateXml(header.OuterXml, xml);
                    RespondToMneEnquire(messageToSend, textMsg.JMSMessageID);
                }
                try
                {
                    var properXml = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(textMsg.Text);
                    DbWriter.SaveMneRequest(msg.JMSMessageID, properXml, taxRefNo, year);
                }
                catch (Exception exception)
                {
                    FdrCommon.LogEvent(exception, EventLogEntryType.Error);
                }
            }
            catch (Exception exception)
            {
                FdrCommon.LogEvent(exception, EventLogEntryType.Error);
            }
        }
Exemplo n.º 2
0
        private static void OnMessage(IMessage msg)
        {
            //var corId = FdrCommon.ByteArrayToString(msg.JMSCorrelationIDAsBytes);
            var message = string.Empty;

            try{
                var textMsg = (ITextMessage)msg;
                message = textMsg.Text;
                try{
                    message = FdrCommon.FormatXml(message);
                }
                catch (Exception) {
                    ;
                }
                var dataValidation = IsCbcValid(message);
                var header         = FdrCommon.SelectNode(message, "soap12", "http://www.w3.org/2003/05/soap-envelope", "Header");
                if (header != null)
                {
                    var messageToSend = dataValidation.IsValid ? CreateXml(header.OuterXml) : FdrCommon.CreateFaultXml(header.OuterXml, dataValidation.ErrorXml);
                    var queueInfo     = new QueueInfo {
                        Manager        = CBCApplicationConfigurationdetails.ResponseManger,
                        Channel        = CBCApplicationConfigurationdetails.ResponseChannel,
                        UseManagerName = false,
                        Port           = CBCApplicationConfigurationdetails.ResponsePort,
                        HostName       = CBCApplicationConfigurationdetails.ResponseHostName,
                        QueueName      = CBCApplicationConfigurationdetails.ResponseQueueName,
                        CorrelationId  = msg.JMSMessageID,
                        Message        = messageToSend
                    };
                    FdrMessaging.SendMessageToQueue(queueInfo);
                    if (!dataValidation.IsValid)
                    {
                        return;
                    }
                }
            }
            catch (Exception exception) {
                FdrCommon.LogEvent(exception, EventLogEntryType.Error);
            }
            try{
                if (!string.IsNullOrEmpty(message))
                {
                    SaveIncomingCbcDeclaration(message);
                }
            }
            catch (Exception exception) {
                FdrCommon.LogEvent(exception, EventLogEntryType.Error);
            }
        }