Esempio 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);
            }
        }
Esempio n. 2
0
        private static decimal ContentManagementRequest(string xmlMessage)
        {
            decimal submissionId = 0;
            var     doc          = new XmlDocument();

            doc.LoadXml(xmlMessage);
            var ns = new XmlNamespaceManager(doc.NameTable);

            ns.AddNamespace("ContMgt",
                            "http://www.sars.gov.za/enterpriseMessagingModel/ContentManagement/xml/schemas/version/1.8");
            ns.AddNamespace("esb", "http://www.sars.gov.za/esb/common/v000006/header");
            var contentManagementRequest = doc.SelectSingleNode("//ContMgt:ContentManagementRequest", ns);
            var messageIdentification    = doc.SelectSingleNode("//esb:MessageIdentification", ns);

            if (contentManagementRequest != null && messageIdentification != null)
            {
                var supportingDocs =
                    Sars.Systems.Serialization.XmlObjectSerializer
                    .ConvertXmlToObject <SupportingDocumentManagementRequestStructure>(
                        contentManagementRequest.OuterXml);
                var messageIdent =
                    Sars.Systems.Serialization.XmlObjectSerializer
                    .ConvertXmlToObject <Sars.ESBSchema.ApplicationInformation.MessageIdentification>(
                        messageIdentification.OuterXml);
                try
                {
                    DbWriter.UpdateMneViaFileNotification
                    (
                        messageIdent.externalReferenceID
                        , Convert.ToInt32(supportingDocs.Contents[0].YearOfAssessment)
                    );
                }
                catch (Exception)
                {
                    ;
                }

                submissionId = DbWriter.InsertFileSubmission(messageIdent.externalReferenceID, Convert.ToInt32(supportingDocs.Contents[0].YearOfAssessment));

                if (submissionId > 0)
                {
                    foreach (var documentStructure in supportingDocs.Contents)
                    {
                        string category       = null;
                        string classification = null;
                        string uniqueId       = null;
                        if (documentStructure.EntityIdentifiers != null &&
                            documentStructure.EntityIdentifiers.Length >= 2)
                        {
                            category       = documentStructure.EntityIdentifiers[0].Type;
                            classification = documentStructure.EntityIdentifiers[1].Type;
                        }

                        var categoryId = 3;
                        if (!string.IsNullOrEmpty(category))
                        {
                            categoryId = category.ToUpper().StartsWith("FDR_MASTER")
                                ? 1
                                : (category.ToUpper().StartsWith("FDR_LOCAL") ? 2 : 3);
                        }
                        if (categoryId == 3)
                        {
                            foreach (var identifier in documentStructure.DocumentIdentifiers)
                            {
                                if (identifier.Type.Contains("FDR_MASTER"))
                                {
                                    categoryId = 1;
                                    break;
                                }
                                if (identifier.Type.Contains("FDR_LOCAL"))
                                {
                                    categoryId = 2;
                                    break;
                                }
                            }
                        }
                        uniqueId = documentStructure.UniqueIdentifiers != null &&
                                   documentStructure.UniqueIdentifiers.Length > 0
                            ? documentStructure.UniqueIdentifiers[0]
                            : null;
                        DbWriter.SaveFile(
                            submissionId,
                            messageIdent.externalReferenceID,
                            categoryId,
                            documentStructure.ObjectName,
                            documentStructure.DocumentID,

                            documentStructure.ContentLocation,
                            documentStructure.Format,
                            documentStructure.YearOfAssessment,
                            documentStructure.Path,
                            documentStructure.SourceChannel,
                            documentStructure.DateOfReceipt.Equals(DateTime.MinValue)
                                ? string.Empty
                                : documentStructure.DateOfReceipt.ToString(CultureInfo.InvariantCulture),
                            classification,
                            uniqueId
                            );
                    }

                    DbWriter.LogIncomingFiles(submissionId, xmlMessage);
                }
            }
            return(submissionId);
        }