Esempio n. 1
0
        protected override void OnStart(string[] args)
        {
            try
            {
                FdrCommon.LogEvent("FDR Service started");
                var oMneProviderDelegate = new MNEProviderDelegate(_mneRequestProvider.ListenForMneRequests);
                var mneResults           = oMneProviderDelegate.BeginInvoke(null, null);
                oMneProviderDelegate.EndInvoke(mneResults);

                var oCbcProviderDelegate = new CBCProviderDelegate(_cbcDeclaration.ListenForCbcRequests);
                var cbcResults           = oCbcProviderDelegate.BeginInvoke(null, null);
                oCbcProviderDelegate.EndInvoke(cbcResults);


                var oFileProviderDelegate = new MasterLocalFileProviderDelegate(_fileProvider.ListenMasterLocalFilesRequests);
                var fileResults           = oFileProviderDelegate.BeginInvoke(null, null);
                oFileProviderDelegate.EndInvoke(fileResults);

                FdrCommon.LogEvent("NO ISSUES REPORTED");
            }
            catch (Exception esException)
            {
                FdrCommon.LogEvent(esException, EventLogEntryType.Error);
            }
        }
Esempio n. 2
0
 public void TerminateConnections()
 {
     if (_mqMessageConsumer != null)
     {
         try
         {
             _mqMessageConsumer.Close();
             _mqMessageConsumer.Dispose();
         }
         catch (Exception exception)
         {
             FdrCommon.LogEvent(exception, EventLogEntryType.Error);
         }
     }
     if (_mqDestination != null)
     {
         _mqDestination.Dispose();
         _mqDestination = null;
     }
     if (_mqConnection != null)
     {
         _mqConnection.Close();
         _mqConnection.Dispose();
     }
     if (_newSesstion != null)
     {
         _newSesstion.Close();
         _newSesstion.Dispose();
     }
 }
Esempio n. 3
0
        private static DataValidations IsMasterLocalFileRequestValid(string message)
        {
            var contentManagementRequest = FdrCommon.SelectNode(message, "ContMgt", "http://www.sars.gov.za/enterpriseMessagingModel/ContentManagement/xml/schemas/version/1.8", "ContentManagementRequest");

            var validations = new DataValidations(contentManagementRequest)
            {
                SchemaList = new List <InternalSchemaData>()
            };

            var contMgt           = File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "ML", "SARSContentManagement.xsd"));
            var sarsgmdFbasetypes = File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "ML", "SARSGMD_BaseTypes.xsd"));

            validations.SchemaList.AddRange(
                new List <InternalSchemaData>
            {
                new InternalSchemaData {
                    TargetNamespace = "http://www.sars.gov.za/enterpriseMessagingModel/ContentManagement/xml/schemas/version/1.8", SchemaContent = contMgt
                },
                new InternalSchemaData {
                    TargetNamespace = "http://www.sars.gov.za/enterpriseMessagingModel/GMD/BaseTypes/xml/schemas/version/54.8", SchemaContent = sarsgmdFbasetypes
                }
            }
                );

            validations.ValidateSchema();
            return(validations);
        }
Esempio n. 4
0
 private static void RespondToDocumentNotify(string qMessage, string messageId)
 {
     try
     {
         var queueInfo = new QueueInfo
         {
             Manager        = LMApplicationConfigurationdetails.ResponseManger,
             Channel        = LMApplicationConfigurationdetails.ResponseChannel,
             UseManagerName = false,
             Port           = LMApplicationConfigurationdetails.ResponsePort,
             HostName       = LMApplicationConfigurationdetails.ResponseHostName,
             QueueName      = LMApplicationConfigurationdetails.ResponseQueueName,
             CorrelationId  = messageId,
             Message        = qMessage
         };
         FdrMessaging.SendMessageToQueue(queueInfo);
         try
         {
             FdrCommon.SaveMessage(qMessage, @"\\ptadviis06\TaxDirectives\FDR\FILES\OUT");
         }
         catch (Exception exception)
         {
             FdrCommon.LogEvent(exception, EventLogEntryType.Error);
         }
     }
     catch (Exception exception)
     {
         FdrCommon.LogEvent(exception, EventLogEntryType.Error);
     }
 }
Esempio n. 5
0
        private static void SendNotification(decimal submissionId)
        {
            var submission = DBReadManager.GeFileSubmissionById(submissionId);

            if (submission == null)
            {
                return;
            }
            var files = DBReadManager.GetFilesPerSubmission(submissionId.ToString(CultureInfo.InvariantCulture));
            var roles = DbReader.GetRolesToNotify();

            if (roles.HasRows)
            {
                var x = (from s in roles.Tables[0].Rows.OfType <DataRow>()
                         select s["EmailAddress"].ToString()).ToArray();

                var fileList = new StringBuilder();
                //fileList.Append("<ul>");
                foreach (DataRow file in files.Tables[0].Rows)
                {
                    fileList.AppendFormat("<li>{0} - {1}</li>", file["Category"], file["Classification"]);
                }

                //fileList.Append("</ul>");

                var messageBody = string.Format(
                    File.ReadAllText("FileArrivalNotification.htm")
                    , submission.TaxRefNo
                    , submission.Year
                    , fileList
                    , SARSDataSettings.Settings.ApplicationName);
                FdrCommon.SendEmail(x, messageBody, "CBC Declaration");
            }
        }
Esempio n. 6
0
        private static DataValidations IsMneRequestValid(string message)
        {
            var thirdPartyDataActivityManagementRequest = FdrCommon.SelectNode(message, "pnsb", "http://www.sars.gov.za/enterpriseMessagingModel/ThirdPartyData/ThirdPartyDataActivityManagement/xml/schemas/version/1.1",
                                                                               "ThirdPartyDataActivityManagementRequest");

            var validations = new DataValidations(thirdPartyDataActivityManagementRequest)
            {
                SchemaList = new List <InternalSchemaData>()
            };

            var sarsgmdBasetypes               = File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "MNE", "SARSGMD_BaseTypes.xsd"));
            var sarsThirdPartyDataActivity     = File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "MNE", "SARSThirdPartyDataActivityManagement.xsd"));
            var sarsthirdpartysubmissionheader = File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "MNE", "SARSThirdPartySubmissionHeader.xsd"));

            validations.SchemaList.AddRange(
                new List <InternalSchemaData>
            {
                new InternalSchemaData {
                    TargetNamespace = "http://www.sars.gov.za/enterpriseMessagingModel/GMD/BaseTypes/xml/schemas/version/55.2", SchemaContent = sarsgmdBasetypes
                },
                new InternalSchemaData {
                    TargetNamespace = "http://www.sars.gov.za/enterpriseMessagingModel/ThirdPartyData/ThirdPartyDataActivityManagement/xml/schemas/version/1.1", SchemaContent = sarsThirdPartyDataActivity
                },
                new InternalSchemaData {
                    TargetNamespace = "http://www.sars.gov.za/enterpriseMessagingModel/ThirdPartySubmissionHeader/xml/schemas/version/1.17", SchemaContent = sarsthirdpartysubmissionheader
                }
            }
                );
            validations.ValidateSchema();
            return(validations);
        }
Esempio n. 7
0
 public void ListenForCbcRequests()
 {
     try{
         _xffReadFactory    = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
         _connectionFactory = _xffReadFactory.CreateConnectionFactory();
         _connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, CBCApplicationConfigurationdetails.RequestConnection);
         _connectionFactory.SetIntProperty(XMSC.WMQ_PORT, CBCApplicationConfigurationdetails.RequestPort);
         _connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, CBCApplicationConfigurationdetails.RequestChannel);
         _connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
         _connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, CBCApplicationConfigurationdetails.RequestManger);
         _connectionFactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);
         _connectionFactory.SetStringProperty(XMSC.WMQ_PROVIDER_VERSION, MQConfigurationSettings.WMQ_PROVIDER_VERSION);
         _mqConnection      = _connectionFactory.CreateConnection();
         _mqSession         = _mqConnection.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
         _mqDestination     = _mqSession.CreateQueue(string.Format("queue://{0}/{1}", CBCApplicationConfigurationdetails.RequestManger, CBCApplicationConfigurationdetails.RequestQueueName));
         _mqMessageConsumer = _mqSession.CreateConsumer(_mqDestination);
         MessageListener ml = OnMessage;
         _mqMessageConsumer.MessageListener = ml;
         _mqConnection.Start();
         //Thread.Sleep(100000);
     }
     catch (Exception exception) {
         FdrCommon.LogEvent(exception, EventLogEntryType.Error);
     }
 }
Esempio n. 8
0
 protected override void OnStop()
 {
     FdrCommon.LogEvent("FDR Service gracefully shutting down");
     _mneRequestProvider.TerminateConnections();
     _cbcDeclaration.TerminateConnections();
     _fileProvider.TerminateConnections();
 }
Esempio n. 9
0
        private static DataValidations IsCbcValid(string message)
        {
            var submitCountryByCountryDeclarationRequest = FdrCommon.SelectNode(message, "tnsf",
                                                                                "http://www.sars.gov.za/enterpriseMessagingModel/ThirdPartyData/SubmitCountryByCountryDeclaration/xml/schemas/version/1.2",
                                                                                "SubmitCountryByCountryDeclarationRequest");

            var validations = new DataValidations(submitCountryByCountryDeclarationRequest)
            {
                SchemaList = new List <InternalSchemaData>()
            };

            var cbcSchema   = File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "CBC", "CbcXML.xsd"));
            var isocbctypes = File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "CBC", "isocbctypes.xsd"));
            var declaration =
                File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "CBC", "SARSCountryByCountryDeclaration.xsd"));
            var oecdtypes        = File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "CBC", "oecdtypes.xsd"));
            var sarsgmdBase      = File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "CBC", "SARSGMD_BaseTypes.xsd"));
            var sarsgmdFormtypes = File.ReadAllText(string.Format(AppConfig.SchemBaseFolder, "CBC", "SARSGMD_FormTypes.xsd"));

            validations.SchemaList.AddRange(
                new List <InternalSchemaData>
            {
                new InternalSchemaData {
                    TargetNamespace = "urn:oecd:ties:cbc:v1", SchemaContent = cbcSchema
                },
                new InternalSchemaData {
                    TargetNamespace = "urn:oecd:ties:isocbctypes:v1", SchemaContent = isocbctypes
                },
                new InternalSchemaData
                {
                    TargetNamespace =
                        "http://www.sars.gov.za/enterpriseMessagingModel/ThirdPartyData/CountryByCountryDeclaration/xml/schemas/version/1.2",
                    SchemaContent = declaration
                },
                new InternalSchemaData {
                    TargetNamespace = "urn:oecd:ties:stf:v4", SchemaContent = oecdtypes
                },
                new InternalSchemaData
                {
                    TargetNamespace =
                        "http://www.sars.gov.za/enterpriseMessagingModel/GMD/BaseTypes/xml/schemas/version/55.2",
                    SchemaContent = sarsgmdBase
                },
                new InternalSchemaData
                {
                    TargetNamespace =
                        "http://www.sars.gov.za/enterpriseMessagingModel/GMD/FormTypes/xml/schemas/version/1.6",
                    SchemaContent = sarsgmdFormtypes
                }
            }
                );

            validations.ValidateSchema();
            return(validations);
        }
Esempio n. 10
0
        private static void NotifyFdrUsers(string taxRefNo, string year)
        {
            var body =
                string.Format(
                    "Good day, </br> this is to inform you about new file submission that just arrived for {0} for year {1}",
                    taxRefNo, year);
            const string subject        = "Files arriving";
            var          users          = DbReader.GetUsersInARole(AppConfig.NotifyRole);
            var          emailAddresses = users.Select(u => u.EmailAddress).ToArray();

            FdrCommon.SendEmail(emailAddresses, body, subject);
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
        public static void SendMessageToQueue(QueueInfo queueInfo)
        {
            try
            {
                var xmsFactoryInstance = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
                var connectionFactory  = xmsFactoryInstance.CreateConnectionFactory();
                connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, queueInfo.HostName);
                connectionFactory.SetIntProperty(XMSC.WMQ_PORT, queueInfo.Port);
                connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, queueInfo.Channel);
                connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
                connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, queueInfo.NoManager);
                connectionFactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);
                var connection = connectionFactory.CreateConnection();
                using (var connectionSession = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge))
                {
                    using (var destination = connectionSession.CreateQueue(queueInfo.QueueConnection))
                    {
                        destination.SetIntProperty(XMSC.DELIVERY_MODE, MQConfigurationSettings.DELIVERY_MODE);
                        destination.SetIntProperty(XMSC.WMQ_TARGET_CLIENT, XMSC.WMQ_TARGET_DEST_MQ);
                        destination.SetBooleanProperty(XMSC.WMQ_MQMD_READ_ENABLED, true);
                        destination.SetBooleanProperty(XMSC.WMQ_MQMD_WRITE_ENABLED, true);

                        using (var producer = connectionSession.CreateProducer(destination))
                        {
                            var textMessage = connectionSession.CreateTextMessage(queueInfo.Message);
                            textMessage.SetIntProperty(XMSC.JMS_IBM_ENCODING, MQConfigurationSettings.JMS_IBM_ENCODING);
                            textMessage.SetIntProperty(XMSC.JMS_IBM_CHARACTER_SET,
                                                       MQConfigurationSettings.JMS_IBM_CHARACTER_SET);
                            if (!string.IsNullOrEmpty(queueInfo.CorrelationId))
                            {
                                textMessage.JMSCorrelationID = queueInfo.CorrelationId;
                            }
                            producer.Send(textMessage);
                            producer.Close();
                            connectionSession.Close();
                            connectionSession.Dispose();
                        }
                    }
                }
            }

            catch (Exception exception)
            {
                FdrCommon.LogEvent(exception, EventLogEntryType.Error);
            }
        }
Esempio n. 13
0
        private static void RespondToCbc(string qMessage, string correlationId)
        {
            try
            {
                var xmsFactoryInstance = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
                var connectionFactory  = xmsFactoryInstance.CreateConnectionFactory();
                connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME,
                                                    MQConfigurationSettings.MNE_Equire_OUT_QConnection);
                connectionFactory.SetIntProperty(XMSC.WMQ_PORT, MQConfigurationSettings.MNE_Equire_OUT_PortNumber);
                connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL,
                                                    MQConfigurationSettings.MNE_Equire_OUT_QChannelName);
                connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
                connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, string.Empty);
                connectionFactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);

                //_connectionFactory.SetStringProperty(XMSC.WMQ_MESSAGE_BODY, XMSC.messa);

                var connection        = connectionFactory.CreateConnection();
                var connectionSession = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
                var destination       =
                    connectionSession.CreateQueue(string.Format("queue://{0}/{1}", string.Empty, MQConfigurationSettings.CBC_Declaration_OUT_QName));

                destination.SetIntProperty(XMSC.DELIVERY_MODE, MQConfigurationSettings.DELIVERY_MODE);
                destination.SetIntProperty(XMSC.WMQ_TARGET_CLIENT, XMSC.WMQ_TARGET_DEST_MQ);
                destination.SetBooleanProperty(XMSC.WMQ_MQMD_READ_ENABLED, true);
                destination.SetBooleanProperty(XMSC.WMQ_MQMD_WRITE_ENABLED, true);

                var producer = connectionSession.CreateProducer(destination);

                var textMessage = connectionSession.CreateTextMessage(qMessage);
                textMessage.SetIntProperty(XMSC.JMS_IBM_ENCODING, MQConfigurationSettings.JMS_IBM_ENCODING);
                textMessage.SetIntProperty(XMSC.JMS_IBM_CHARACTER_SET, MQConfigurationSettings.JMS_IBM_CHARACTER_SET);
                textMessage.JMSCorrelationID = correlationId;
                producer.Send(textMessage);
                producer.Close();
                producer.Dispose();
                destination.Dispose();
                connectionSession.Close();
                connectionSession.Dispose();
            }
            catch (Exception exception)
            {
                FdrCommon.LogEvent(exception, EventLogEntryType.Error);
            }
        }
Esempio n. 14
0
        private static string CreateXml(string header, string message)
        {
            var applicationInformationStructure = new Sars.ESBSchema.ApplicationInformation.v000002.applicationInformation
            {
                applicationInformationResult =
                    new Sars.ESBSchema.ApplicationInformation.v000002.applicationInformationApplicationInformationResult[1]
            };

            applicationInformationStructure.applicationInformationResult[0] =

                new Sars.ESBSchema.ApplicationInformation.v000002.applicationInformationApplicationInformationResult
            {
                MessageType = Sars.ESBSchema.ApplicationInformation.v000002.MessageTypeEnum.Information,
                applicationInformationCode        = "0000",
                applicationInformationDescription = "Processed",
                applicationInformationState       = "OK"
            };

            var applicationInformationStructureXml = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(applicationInformationStructure, "FDR", "http://www.sars.gov.za/services/esb/v000002/applicationInformation");

            var xmlBuilder = new StringBuilder();

            xmlBuilder.Append(
                "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> " +
                "<soap12:Envelope xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\" " +
                "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                "xmlns:esb=\"http://www.egovernment.gov.za/GMD/MessageIdentification/xml/schemas/version/7.1\">"

                );
            xmlBuilder.AppendFormat(
                "{0}" +
                " <soap12:Body>" +
                "{1}" +
                "{2}" +
                "</soap12:Body>" +
                "</soap12:Envelope>",
                header,
                applicationInformationStructureXml,
                message
                );
            return(FdrCommon.FormatXml(xmlBuilder.ToString()));
        }
Esempio n. 15
0
        public void ValidateSchema()
        {
            if (SchemaList == null || !SchemaList.Any())
            {
                return;
            }

            var settings = new XmlReaderSettings();

            settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
            settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
            settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;


            SchemaList.ForEach(
                s => settings.Schemas.Add(s.TargetNamespace, XmlReader.Create(new StringReader(s.SchemaContent))));

            settings.ValidationType          = ValidationType.Schema;
            settings.ValidationEventHandler += settings_ValidationEventHandler;
            var reader = XmlReader.Create(new StringReader(XmlToValidate), settings);

            while (reader.Read())
            {
            }
            if (string.IsNullOrEmpty(ErrorXml))
            {
                IsValid = true;
            }
            var errorBuilder = new StringBuilder();

            if (_errors.Any())
            {
                errorBuilder.Append("<errors>");
                _errors.ForEach(e => errorBuilder.AppendFormat("<Error>{0}</Error>", e));
                errorBuilder.Append("</errors>");
                ErrorXml = FdrCommon.FormatXml(errorBuilder.ToString());
            }

            IsValid = !_errors.Any();
        }
Esempio n. 16
0
        public static string CreateFaultXml(string header, string errors)
        {
            var applicationInformationStructure = new Sars.ESBSchema.ApplicationInformation.v31.ApplicationInformationStructure
            {
                ApplicationInformationResult = new Sars.ESBSchema.ApplicationInformation.v31.ApplicationInformationStructureApplicationInformationResult[1]
            };

            applicationInformationStructure.ApplicationInformationResult[0] =
                new Sars.ESBSchema.ApplicationInformation.v31.ApplicationInformationStructureApplicationInformationResult
            {
                Code        = "9999",
                Description = errors,
                MessageType = Sars.ESBSchema.ApplicationInformation.v31.MessageTypeEnum.ERROR
            };

            var applicationInformationStructureXml = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(applicationInformationStructure, "fdri", "http://www.egovernment.gov.za/GMD/ApplicationInformation/xml/schemas/version/3.1");

            var xmlBuilder = new StringBuilder();

            xmlBuilder.Append(
                "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> " +
                "<soap12:Envelope xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\" " +
                "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
                "xmlns:esb=\"http://www.egovernment.gov.za/GMD/MessageIdentification/xml/schemas/version/7.1\">"

                );
            xmlBuilder.AppendFormat(
                "{0}" +
                " <soap12:Body>" +
                "{1}" +
                "</soap12:Body>" +
                "</soap12:Envelope>",
                header,
                applicationInformationStructureXml
                );
            return(FdrCommon.FormatXml(xmlBuilder.ToString()));
        }
Esempio n. 17
0
        private static void OnFilesReceived(IMessage msg)
        {
            try
            {
                var textMsg = (ITextMessage)msg;
                FdrCommon.SaveMessage(textMsg.Text, @"\\ptadviis06\TaxDirectives\FDR\FILES\IN");
                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("ContMgt", "http://www.sars.gov.za/enterpriseMessagingModel/ContentManagement/xml/schemas/version/1.8");

                var header  = doc.SelectSingleNode("//soap12:Header", ns);
                var request = doc.SelectSingleNode("//ContMgt:ContentManagementRequest", ns);
                if (header == null || request == null)
                {
                    FdrCommon.LogEvent("header == null || request == null", EventLogEntryType.Warning);
                    return;
                }

                var dataValidation = IsMasterLocalFileRequestValid(message);
                if (!dataValidation.IsValid)
                {
                    var xml = FdrCommon.FormatXml(CreateFaultXml(header.OuterXml, dataValidation.ErrorXml));
                    RespondToDocumentNotify(xml, msg.JMSMessageID);
                    return;
                }


                var supportingDocs =
                    Sars.Systems.Serialization.XmlObjectSerializer.ConvertXmlToObject <SupportingDocumentManagementRequestStructure>(request.OuterXml);
                var xmlToSend    = string.Empty;
                var deserialized = supportingDocs != null && supportingDocs.Contents != null &&
                                   supportingDocs.Contents.Any();
                if (deserialized)
                {
                    var responseStructure = new SupportingDocumentManagementResponseStructure
                    {
                        Contents = supportingDocs.Contents
                    };
                    xmlToSend = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(responseStructure, "ContMgt", "http://www.sars.gov.za/enterpriseMessagingModel/ContentManagement/xml/schemas/version/1.8");
                }
                if (!string.IsNullOrEmpty(xmlToSend))
                {
                    var messageToSend = CreateXml(header.OuterXml, xmlToSend);
                    messageToSend = FdrCommon.RemoveEmptyElements(messageToSend);
                    RespondToDocumentNotify(messageToSend, msg.JMSMessageID);
                }
                if (deserialized)
                {
                    if (!supportingDocs.Contents[0].ContentLocation.ToUpper().EndsWith(AppConfig.SecondaryFileLocation))
                    {
                        var submissionId = ContentManagementRequest(message);
                        if (submissionId > 0)
                        {
                            SendNotification(submissionId);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                FdrCommon.LogEvent(exception, EventLogEntryType.Error);
            }
        }
Esempio n. 18
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. 19
0
        private static void SaveIncomingCbcDeclaration(string message)
        {
            var properXml = Sars.Systems.Serialization.XmlObjectSerializer.GetXmlWithNoDeclaration(message);

            using (var data = new RecordSet()){
                data.ReadXml(new StringReader(properXml));
                var messageIdentification = data.Tables["MessageIdentification"];
                var messageSpec           = data.Tables["MessageSpec"];
                var contactDetails        = data.Tables["ContactDetails"];

                if (!data.Tables.Contains("MessageIdentification") || !data.Tables.Contains("MessageSpec") ||
                    !data.Tables.Contains("ContactDetails"))
                {
                    FdrCommon.LogEvent("MessageIdentification OR  FormInfo OR ContactDetails is not in this XML");
                    return;
                }
                if (messageIdentification.Rows.Count == 0)
                {
                    FdrCommon.LogEvent("MessageIdentification has no data");
                    return;
                }

                if (messageSpec.Rows.Count == 0)
                {
                    FdrCommon.LogEvent("FormInfo has no data");
                    return;
                }

                if (contactDetails.Rows.Count == 0)
                {
                    FdrCommon.LogEvent("ContactDetails has no data");
                    return;
                }
                var reportingYear = messageSpec.Rows[0]["ReportingPeriod"].ToString().Trim();

                var taxRefNo     = messageIdentification.Rows[0]["externalReferenceID"].ToString().Trim();
                var taxYear      = Convert.ToInt32(reportingYear.Length > 4 ? reportingYear.Substring(0, 4) : reportingYear);
                var surname      = contactDetails.Rows[0]["Surname"].ToString().Trim();
                var firstNames   = contactDetails.Rows[0]["FirstNames"].ToString().Trim();
                var busTelNo1    = contactDetails.Rows[0]["BusTelNo1"].ToString().Trim();
                var cellNo       = contactDetails.Rows[0]["CellNo"].ToString().Trim();
                var emailAddress = contactDetails.Rows[0]["EmailAddress"].ToString().Trim();
                //string postalAddress = null;
                DbReader.SaveCBCRequest(properXml,
                                        taxRefNo,
                                        taxYear,
                                        surname,
                                        firstNames,
                                        busTelNo1,
                                        cellNo,
                                        emailAddress,
                                        null);

                var roles = DbReader.GetRolesToNotify();
                if (roles.HasRows)
                {
                    var x = (from s in roles.Tables[0].Rows.OfType <DataRow>()
                             select s["EmailAddress"].ToString()).ToArray();

                    var messageBody = string.Format(
                        File.ReadAllText("CBCArrivalNotification.htm")
                        , taxRefNo
                        , reportingYear
                        , SARSDataSettings.Settings.ApplicationName);
                    FdrCommon.SendEmail(x, messageBody, "CBC Declaration");
                }
            }
        }