Esempio n. 1
0
 protected override void OnStop()
 {
     FdrCommon.LogEvent("FDR Service gracefully shutting down");
     _mneRequestProvider.TerminateConnections();
     _cbcDeclaration.TerminateConnections();
     _fileProvider.TerminateConnections();
 }
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
 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. 4
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. 5
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. 6
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. 7
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. 8
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. 9
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. 10
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");
                }
            }
        }
Esempio n. 11
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);
            }
        }