Exemple #1
0
        private void handleInputMessage(MQMessage message, OfacStatus status)
        {
            Request request = new Request();

            request.Name        = System.Text.ASCIIEncoding.ASCII.GetString(message.MessageId);
            request.MessageBody = message.ReadString(message.DataLength);

            WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();

            if (windowsIdentity != null)
            {
                request.CreateOper = windowsIdentity.Name;
            }
            RequestHeader header = new RequestHeader();


            header.correlationId = System.Text.ASCIIEncoding.ASCII.GetString(message.CorrelationId);


            request.Header      = header.ToString();
            request.InterfaceId = _interfaceId;
            _dbUtils.addRequest(request);
            //queue the work with the thread pool

            lock (syncLock)
            {
                currentMessagesToBeProcessed++;
            }


            ThreadPool.QueueUserWorkItem(new WaitCallback(startTranslation), request);
        }
Exemple #2
0
        public void processOfacResponse(String name, String filename, OfacStatus ofacStatus)
        {
            lock (syncLock)
            {
                if (pendingStop)
                {
                    return;
                }
                currentMessagesToBeProcessed++;
            }
            try
            {
                LogUtil.logInfo("Processing Response file :" + filename);
                String message = ReadFile(filename);
                if (message == null)
                {
                    return;
                }

                int    index         = name.LastIndexOf('.');
                String fileRequestId = name.Substring(0, index);
                index = fileRequestId.IndexOf('-');
                if (index != -1)
                {
                    fileRequestId = fileRequestId.Substring(0, index);
                }
                //string extension = name.Substring(index + 1);


                int requestId = Int32.Parse(fileRequestId);

                _dbUtils.addOfacResponse(requestId, name, message, ofacStatus);
                File.Delete(filename);
                _manager.processResponse(requestId, _interfaceId, name, message, ofacStatus);
                updateStatistics();
            }
            catch (Exception e)
            {
                LogUtil.log("Error in processOfacResponse for file:" + filename, e);
            }
            finally
            {
                lock (syncLock)
                {
                    currentMessagesToBeProcessed--;
                }
            }
        }
Exemple #3
0
        public void startResponse(object objMessage, OfacStatus ofacStatus)
        {
            try
            {
                OfacResponse response = (OfacResponse)objMessage;

                _manager.processResponse(response.requestId, _interfaceId, response.name, response.message, ofacStatus);
                updateStatistics();
                lock (syncLock)
                {
                    currentMessagesToBeProcessed--;
                }
            }
            catch (Exception e)
            {
                LogUtil.log("startReponse", e);
            }
        }
        public void changeStatus(int requestId, Status status, bool isError, OfacStatus ofacStatus)
        {
            try
            {
                DbCommand cmd = _weidb.GetStoredProcCommand("Wei_ChangeStatus");

                _weidb.AddInParameter(cmd, "@requestid", DbType.Int32, requestId);
                _weidb.AddInParameter(cmd, "@status", DbType.Int32, status);
                _weidb.AddInParameter(cmd, "@iserror", DbType.Boolean, isError);
                _weidb.AddInParameter(cmd, "@ofacStatus", DbType.Int32, ofacStatus);

                _weidb.ExecuteScalar(cmd);
            }
            catch (SqlException ex)
            {
                LogUtil.logError("Error while changing status on the request: " + ex.ToString());
                throw new Exception("Error while changing request status: ", ex);
            }
        }
Exemple #5
0
        private void handleResponseMessage(MQMessage message, OfacStatus status)
        {
            try
            {
                String requestId   = System.Text.ASCIIEncoding.ASCII.GetString(message.CorrelationId);
                String name        = System.Text.ASCIIEncoding.ASCII.GetString(message.MessageId);
                String messageText = message.ReadString(message.DataLength);


                OfacResponse response = new OfacResponse();
                response.message   = messageText;
                response.requestId = Convert.ToInt32(requestId);
                response.name      = name;


                _dbUtils.addOfacResponse(response.requestId, name, messageText, status);

                lock (syncLock)
                {
                    currentMessagesToBeProcessed++;
                }

                //queue the work with the thread pool
                if (status == OfacStatus.Confirm)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(startConfirmResponse), response);
                }
                else
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(startOkResponse), response);
                }
            }
            catch (MQException e)
            {
                LogUtil.log("Error while adding response after watchlist filtering check:", e);
            }
        }
        public void addOfacResponse(int requestId, String identifier, String responseBody, OfacStatus ofacStatus)
        {
            try
            {
                DbCommand cmd = _weidb.GetStoredProcCommand("Wei_AddOfacResponse");
                _weidb.AddInParameter(cmd, "@requestid", DbType.Int32, requestId);
                _weidb.AddInParameter(cmd, "@responsebody", DbType.String, responseBody);
                _weidb.AddInParameter(cmd, "@identifier", DbType.String, identifier);

                _weidb.ExecuteScalar(cmd);
            }
            catch (SqlException ex)
            {
                LogUtil.logError("Error while adding OFAC response to the request: " + ex.ToString());
                throw new Exception("Error while adding OFAC response to the request: ", ex);
            }
        }
Exemple #7
0
        private void listen(MQQueue queue, MQQueueManager manager, string queueName, HandleMessage handler, OfacStatus status)
        {
            while (!pendingStop)
            {
                while (!pendingStop && currentMessagesToBeProcessed >= maxNoOfMessagesToProcess)
                {
                    Thread.Sleep(5000);
                }

                if (pendingStop)
                {
                    return;
                }
                try
                {
                    MQMessage message = getMessage(queue);
                    if (message == null)
                    {
                        continue;
                    }

                    handler(message, status);

                    manager.Commit();
                }
                catch (MQException e)
                {
                    LogUtil.log("Error when getting message from the " + queueName + " queue", e);
                    manager.Backout();
                    Thread.Sleep(30000);
                    throw;
                }
            }
        }
Exemple #8
0
        public void processResponse(int requestId, int interfaceId, String identifier, String responseBody, OfacStatus ofacStatus)
        {
            AuditUtil.getInstance().audit(requestId, AuditLevel.Info, "Received " + ofacStatus.ToString() + " response");

            bool      bLocked  = false;
            bool      bSuccess = false;
            Request   request  = null;
            Interface i        = InterfaceManager.getInterface(interfaceId);

            try
            {
                bLocked = _dbUtils.acquireLock(requestId);
                if (bLocked)
                {
                    request = _dbUtils.getRequest(requestId);

                    if (request == null)
                    {
                        LogUtil.logError("Cannot retrieve the message:" + requestId);
                        return;
                    }

                    if (request.Status != Status.SentForOfacCheck)
                    {
                        LogUtil.logError("Cannot process response for the message :" + requestId + " . Current status is " + request.Status + ". Expecting " + Status.SentForOfacCheck);
                        return;
                    }

                    request.Status     = Status.OfacResponseReceived;
                    request.IsError    = false;
                    request.OfacStatus = ofacStatus;

                    _dbUtils.changeStatus(request);


                    request.ResponseMessage = i.Handler.getRepackagedResponseString(request.MessageBody, responseBody);

                    if (i.Driver.sendResponse(request, identifier))
                    {
                        request.Status  = Status.Processed;
                        request.IsError = false;

                        _dbUtils.addResponseMessage(request);
                        bSuccess = true;
                        AuditUtil.getInstance().audit(requestId, AuditLevel.Info, "Sent response for the message ");
                    }
                }
            }
            catch (Exception e)
            {
                bSuccess = false;
                LogUtil.log("Cannot process response for the message :" + requestId, e);
                AuditUtil.getInstance().audit(requestId, AuditLevel.Error, "Error processing response for the message ");
            }
            finally
            {
                try
                {
                    if (!bSuccess)
                    {
                        _dbUtils.markRequestError(requestId);
                        //send it to error
                        if (request != null && i.Driver.shouldMoveToError())
                        {
                            i.Driver.moveToError(request);
                        }
                    }
                    if (bLocked)
                    {
                        _dbUtils.releaseLock(request.RequestId);
                    }
                }
                catch (Exception e)
                {
                    LogUtil.log("Exception when trying to backout of another exception for message:" + requestId, e);
                }
            }
        }