/// <summary>
        /// To validate the call data against the xsd schema
        /// </summary>
        /// <param name="callData">IVR Call Data</param>
        /// <param name="callId">IVR Call ID</param>
        /// <param name="appId">IVR Application ID</param>
        /// <param name="response">To hold the call data imporation response</param>
        /// <returns></returns>
        private bool HasValidCallData(string callData, string callId, string appId, ref ValidataionResponse response)
        {
            Stopwatch sWatch  = new Stopwatch();
            bool      isValid = false;
            string    message = string.Empty;

            if (InitailContext._dataConfigSetting.AppConfigSettings[appId].XsdValidationRequired)
            {
                _validationErrMsgs.Clear();
                sWatch.Start();
                isValid = _xsdValidator.Validate(callData, InitailContext._appXsd[appId], ref _validationErrMsgs);
                sWatch.Stop();
                _log.InfoFormat("Total time taken to validate the call data : {0}", sWatch.Elapsed);

                if (isValid)
                {
                    _log.InfoFormat("Call data schema validation successfull for call Id : {0}", callId);
                }
                else
                {
                    message = _validationErrMsgs.Count == 0 ? string.Empty : string.Format("Invalid Call Data Against XSD. Call ID : {0}, \n Validation Error : {1}", callId, string.Join("\n", _validationErrMsgs.ToArray()));
                    response.FailureMode  = ValidationFailureMode.InvalidXml;
                    response.ErrorCode    = (int)ValidationFailureMode.InvalidXml;
                    response.ErrorMessage = message;
                    _log.InfoFormat("Validation Error", message);
                    return(false);
                }
            }
            else
            {
                _log.InfoFormat("Call data schema validation is not enabled. Call ID : {0}", callId);
            }
            return(true);
        }
        /// <summary>
        /// To import the call data into reporting database
        /// </summary>
        /// <param name="callId">Call ID from IVR</param>
        /// <param name="appId">Application ID from IVR</param>
        /// <param name="callData">IVR Call Data</param>
        /// <returns></returns>
        public ValidataionResponse ValidateData(string callId, string sessionId, string appId, string callData, DateTime callDateTime)
        {
            ValidataionResponse response = new ValidataionResponse();
            string message = string.Empty;

            try
            {
                _log.Info("Inside Method ");

                if (!HasBasicCallInfo(callData, appId, callId, ref response))
                {
                    return(response);
                }

                if (!HasAppConfigSetings(callId, appId, ref response))
                {
                    return(response);
                }

                if (!HasValidCallData(callData, callId, appId, ref response))
                {
                    return(response);
                }

                if (response.FailureMode == ValidationFailureMode.None)
                {
                    if (InitailContext._dataConfigSetting.AppConfigSettings[appId].ThreadSleepRequired)
                    {
                        Thread.Sleep(InitailContext.time);
                        _log.InfoFormat("Thread sleep for {0} milliseconds", InitailContext.time);
                    }
                    _log.InfoFormat("Pushing data into queue for callid :{0}", callId);
                    _queueInsert.PutMessageOnMSQ(Convert.ToString(InitailContext._dataConfigSetting.AppConfigSettings[appId].QueueName), callId, callData, appId, ref response);
                    _log.InfoFormat("Enqueued data into queue for callid :{0}", callId);
                }
            }
            catch (Exception ex)
            {
                message = string.Format("{0}, Call ID : {1}", ex.Message, callId);
                response.FailureMode  = ValidationFailureMode.ApplicationFailed;
                response.ErrorCode    = (int)ValidationFailureMode.ApplicationFailed;
                response.ErrorMessage = message;
                _log.ErrorFormat("ValidateData Error : Failure Code : {0}, Error Code : {1}, Error Desc : {2}", response.FailureMode, response.ErrorCode, response.ErrorMessage);

                try
                {
                    delWriteFileIntoRecovery objwriteFile = new delWriteFileIntoRecovery(WriteIntoRecovery);
                    objwriteFile.BeginInvoke(callData, callId, null, null);
                }
                catch (Exception exp)
                {
                    _log.ErrorFormat("Error while writing File :{0}", exp);
                }
            }
            return(response);
        }
        /// <summary>
        /// To verify the appliation specific importation settings available for the call data
        /// </summary>
        /// <param name="callId">IVR Call ID</param>
        /// <param name="appId">IVR Application ID</param>
        /// <param name="response">To hold the call data imporation response</param>
        /// <returns></returns>
        private bool HasAppConfigSetings(string callId, string appId, ref ValidataionResponse response)
        {
            string message = string.Empty;

            if (InitailContext._dataConfigSetting.AppConfigSettings[appId] == null)
            {
                message = string.Format("App config setting missing in configuration. App ID : {0}, Call ID : {1}", appId, callId);
                response.FailureMode  = ValidationFailureMode.InvalidConfig;
                response.ErrorCode    = (int)ValidationFailureMode.InvalidConfig;
                response.ErrorMessage = message;
                _log.Error(message);
                return(false);
            }
            return(true);
        }
Beispiel #4
0
        public void PutMessageOnMSQ(string queueName, string callId, string callData, string appid, ref ValidataionResponse response)
        {
            #region private variables
            string   message            = string.Empty;
            DateTime startTime          = DateTime.Now;
            System.Messaging.Message mm = null;
            #endregion

            log.InfoFormat("Started Enqueue Process -Start Time in:{0}  \n\n", startTime);
            try
            {
                if (InitailContext.mq == null)
                {
                    if (!MessageQueue.Exists(queueName))
                    {
                        log.DebugFormat("{0} - Queue does not exist", queueName);
                        MessageQueue.Create(queueName, true);
                    }
                    InitailContext.mq = new System.Messaging.MessageQueue(queueName);
                    InitailContext.mq.SetPermissions("Users", MessageQueueAccessRights.FullControl, AccessControlEntryType.Allow);
                    InitailContext.mq.Authenticate = false;
                }
                mm       = new System.Messaging.Message();
                mm.Body  = callData;
                mm.Label = "QueueData";
                log.InfoFormat("Enqueued Details:{0}", mm.Body.ToString());
                //mm.TimeToReachQueue = new TimeSpan(0, 0,InitailContext.queueTimeout);
                //log.InfoFormat("Timeout {0} seconds", InitailContext.queueTimeout);
                if (InitailContext._dataConfigSetting.AppConfigSettings[appid].IsTransactionEnabled.ToString().ToUpper() == "Y")
                {
                    log.Debug("Transaction Enabled");
                    InitailContext.mq.Send(mm, "QueueData", MessageQueueTransactionType.Single);
                }
                else
                {
                    log.Debug("Transaction not Enabled");
                    InitailContext.mq.Send(mm);
                }
                response.HasQueued    = true;
                response.ErrorCode    = 0;
                response.ErrorMessage = "Success";
                response.FailureMode  = ValidationFailureMode.None;
                InitailContext.mq.Close();
                log.InfoFormat("Completed Enquee Process,Total Time taken:{0} milliseconds \n\n", DateTime.Now.Subtract(startTime).Milliseconds);
            }
            catch (Exception ex)
            {
                message               = string.Format("{0}, Call ID : {1}", ex.Message, callId);
                response.HasQueued    = false;
                response.ErrorCode    = (int)ValidationFailureMode.QueueInsertFailed;
                response.FailureMode  = ValidationFailureMode.QueueInsertFailed;
                response.ErrorMessage = message;
                log.ErrorFormat("Error : Failure Code : {0}, Error Code : {1}, Error Desc : {2} \n\n", response.FailureMode, response.ErrorCode, response.ErrorMessage);

                try
                {
                    //log.Info("Start writing file into Recovery folder");
                    //string folder = string.Format("{0}\\{1}\\{2}", ConfigurationManager.AppSettings["RecoveryFolder"].ToString(), DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HH"));
                    //log.Debug("finished getting folder path");
                    //if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);

                    ////int fileCount = Directory.GetFiles(folder).Length + 1;
                    //log.Debug("finished getting file count");

                    //string filePath = string.Format("{0}\\{1}_{2}_{3}.txt", folder, "MSMQ",DateTime.Now.Ticks.ToString(), (new Random()).Next(1000, 99999));
                    //log.Debug("finished writing file path");
                    //if (!File.Exists(filePath))
                    //{
                    //    log.Info("File is Exists");
                    //    File.WriteAllText(filePath, callData);
                    //    log.InfoFormat("Call Data with Callid : {0} , has Written to the file File Path : {1}", callId, filePath);
                    //}
                    //else
                    //{
                    //    log.DebugFormat("Filepath is not Exists {0}", filePath);
                    //}

                    //log.Debug("finished writing teh file into recovery folder");

                    MSMQ_RFService.CallDataValidation.delWriteFileIntoRecovery objwriteFile = new MSMQ_RFService.CallDataValidation.delWriteFileIntoRecovery(WriteIntoRecovery);
                    objwriteFile.BeginInvoke(callData, callId, null, null);
                }
                catch (Exception exp)
                {
                    log.ErrorFormat("Error while writing File :{0}", exp);
                }
            }
            finally
            {
                mm.Dispose();
                mm      = null;
                message = string.Empty;
            }
        }
Beispiel #5
0
        public MsmqResponse InsertCallDataToQueue(string callData)
        {
            //  string callData = objcallData.callData;

            /*-------------------This is for Thai character testing-----------------------*/
            log.Info("Inside Method");

            #region private variables
            string              message          = string.Empty;
            CallDataValidation  dataValidation   = null;
            MsmqResponse        _msmqresponse    = null;
            ValidataionResponse validateResponse = null;
            #endregion

            try
            {
                log.Info("Inside Method-Before Invoking PutMessageOnMSQ Method");
                #region private variables
                _msmqresponse  = new MsmqResponse();
                dataValidation = new CallDataValidation();
                startTime      = DateTime.Now;
                log.InfoFormat("Start Date & Time : {0} , Start Time : {1} in milliseconds \n\n", startTime, startTime.Millisecond);
                #endregion
                //validateResponse = dataValidation.Validate(callData.Replace("<?xml version=\"1.0\" encoding=\"UTF-16\"", ""));
                callData = callData.Replace("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>", "").Replace("<?xml version=\"1.0\" encoding=\"UTF-16\"?>", "");
                log.InfoFormat("calldata replaced by encoding format with empty value, calldata - {0}", callData);
                validateResponse = dataValidation.Validate(callData);
                if (validateResponse.HasQueued)
                {
                    _msmqresponse.errorCode = validateResponse.ErrorCode;
                    _msmqresponse.errorDesc = validateResponse.ErrorMessage;
                    _msmqresponse.errorMode = validateResponse.FailureMode.ToString();
                    log.InfoFormat("Call Data Queued Successfull in msmq. Failure Mode: {0}, Error Code : {1}, Error Message : {2}", validateResponse.FailureMode, validateResponse.ErrorCode, validateResponse.ErrorMessage);
                }
                else
                {
                    _msmqresponse.errorCode = validateResponse.ErrorCode;
                    _msmqresponse.errorDesc = validateResponse.ErrorMessage;
                    _msmqresponse.errorMode = validateResponse.FailureMode.ToString();
                    log.InfoFormat("Call Data Failed to Queue in msmq. Failure Mode : {0}, Error Code : {1}, Error Message : {2}", validateResponse.FailureMode, validateResponse.ErrorCode, validateResponse.ErrorMessage);
                }
                return(_msmqresponse);
            }
            catch (Exception ex)
            {
                message = string.Format("{0}, Call Data : {1} \n\n", ex.Message, callData);
                _msmqresponse.errorCode = (int)ValidationFailureMode.ApplicationFailed;
                _msmqresponse.errorDesc = message;
                _msmqresponse.errorMode = ValidationFailureMode.ApplicationFailed.ToString();
                log.ErrorFormat("Error. Failure Mode : {0},Error Code : {1}, Error Message : {2}", _msmqresponse.errorMode, _msmqresponse.errorCode, _msmqresponse.errorDesc);

                // This will write the file into recovery path
                return(_msmqresponse);
            }
            finally
            {
                _msmqresponse    = null;
                dataValidation   = null;
                validateResponse = null;
                message          = string.Empty;
                log.InfoFormat("Total time taken to complete process : {0} milliseconds \n\n", DateTime.Now.Subtract(startTime).TotalMilliseconds);
            }
        }
        /// <summary>
        /// To validate the call data received from Msmq Service
        /// </summary>
        /// <param name="callData">call data read from Msmq Service</param>
        /// <returns></returns>
        public ValidataionResponse Validate(string callData)
        {
            ValidataionResponse response = new ValidataionResponse();
            string   message             = string.Empty;
            string   callId     = string.Empty;
            string   sessionId  = string.Empty;
            string   appId      = string.Empty;
            DateTime callDtTime = System.DateTime.Now;

            try
            {
                _log.Info("Inside Method");

                // string regExPattern =string.Empty;
                //Regex regEx = new Regex(regExPattern, RegexOptions.Multiline);
                //MatchCollection mc = regEx.Matches(callData);

                //appId = string.IsNullOrEmpty(ConfigurationManager.AppSettings["ApplicationId"].ToString()) ? "1" : ConfigurationManager.AppSettings["ApplicationId"].ToString();

                string          regExPattern = @"<APP_ID>(?<APP_ID>.*?)</APP_ID>";
                Regex           regEx        = new Regex(regExPattern, RegexOptions.Multiline);
                MatchCollection mc           = regEx.Matches(callData);

                if (mc.Count > 0)
                {
                    appId = mc[0].Groups["APP_ID"].Value.Trim();
                }

                regExPattern = @"<CALLID>(?<CallID>.*?)</CALLID>";
                regEx        = new Regex(regExPattern, RegexOptions.Multiline);
                mc           = regEx.Matches(callData);

                if (mc.Count > 0)
                {
                    callId = mc[0].Groups["CallID"].Value.Trim();
                }

                regExPattern = @"<SESSION_ID>(?<SESSION_ID>.*?)</SESSION_ID>";
                regEx        = new Regex(regExPattern, RegexOptions.Multiline);
                mc           = regEx.Matches(callData);

                if (mc.Count > 0)
                {
                    sessionId = mc[0].Groups["SESSION_ID"].Value.Trim();
                }

                response = ValidateData(callId, sessionId, appId, callData, callDtTime);
            }
            catch (Exception ex)
            {
                message               = string.Format("{0}, Call ID : {1}", ex.Message, callId);
                response.ErrorCode    = (int)ValidationFailureMode.ApplicationFailed;
                response.FailureMode  = ValidationFailureMode.ApplicationFailed;
                response.ErrorMessage = message;
                _log.ErrorFormat("Validate Error : Failure Code : {0}, Error Code : {1}, Error Desc : {2}", response.FailureMode, response.ErrorCode, response.ErrorMessage);

                delWriteFileIntoRecovery objwriteFile = new delWriteFileIntoRecovery(WriteIntoRecovery);
                objwriteFile.BeginInvoke(callData, callId, null, null);
            }
            return(response);
        }
        /// <summary>
        /// To verify the basic call information in ivr call data
        /// </summary>
        /// <param name="callData">IVR Call Data</param>
        /// <param name="appId">IVR Application ID</param>
        /// <param name="callId">IVR Call ID</param>
        /// <param name="response">To hold the call data imporation response</param>
        /// <returns></returns>
        private bool HasBasicCallInfo(string callData, string appId, string callId, ref ValidataionResponse response)
        {
            _log.Info("Inside Method");
            string message            = string.Empty;
            string appIdFromCallData  = string.Empty;
            string callIdFromCallData = string.Empty;

            if (string.IsNullOrEmpty(callData))
            {
                message = string.Format("Call ID is empty, App ID : {0}, Call Data : {1}", appId, callData);
                response.FailureMode  = ValidationFailureMode.InvalidData;
                response.ErrorCode    = (int)ValidationFailureMode.InvalidData;
                response.ErrorMessage = message;
                _log.Error(message);
                return(false);
            }

            if (string.IsNullOrEmpty(appId))
            {
                message = string.Format("Application ID is empty, Call ID : {0}", callId);
                response.FailureMode  = ValidationFailureMode.InvalidData;
                response.ErrorCode    = (int)ValidationFailureMode.InvalidData;
                response.ErrorMessage = message;
                _log.Error(message);
                return(false);
            }

            if (string.IsNullOrEmpty(callData))
            {
                message = string.Format("Call Data is empty, Call ID : {0}", callId);
                response.FailureMode  = ValidationFailureMode.InvalidXml;
                response.ErrorCode    = (int)ValidationFailureMode.InvalidXml;
                response.ErrorMessage = message;
                _log.Error(message);
                return(false);
            }

            string          regExPattern = string.Empty;
            Regex           regEx        = new Regex(regExPattern, RegexOptions.Multiline);
            MatchCollection mc           = regEx.Matches(callData);

            //string regExPattern = @"<APP_ID>(?<AppID>.*?)</APP_ID>";
            //Regex regEx = new Regex(regExPattern, RegexOptions.Multiline);
            //MatchCollection mc = regEx.Matches(callData);


            //if (mc.Count == 0)
            //{
            //    message = "App ID missing in xml packet";
            //    response.FailureMode = ValidationFailureMode.InvalidData;
            //    response.ErrorCode = (int)ValidationFailureMode.InvalidData;
            //    response.ErrorMessage = message;
            //    _log.Error(message);
            //    return false;
            //}

            //appIdFromCallData = mc[0].Groups["AppID"].Value.Trim();

            //if (string.IsNullOrEmpty(appIdFromCallData))
            //{
            //    message = "App ID Node is empty in xml packet";
            //    response.FailureMode = ValidationFailureMode.InvalidData;
            //    response.ErrorCode = (int)ValidationFailureMode.InvalidData;
            //    response.ErrorMessage = message;
            //    _log.Error(message);
            //    return false;
            //}

            //if (!appIdFromCallData.Equals(appId))
            //{
            //    message = "App ID mismatch with xml packet";
            //    response.FailureMode = ValidationFailureMode.InvalidData;
            //    response.ErrorCode = (int)ValidationFailureMode.InvalidData;
            //    response.ErrorMessage = message;
            //    _log.Error(message);
            //    return false;
            //}

            regExPattern = @"<CALLID>(?<CallID>.*?)</CALLID>";
            regEx        = new Regex(regExPattern, RegexOptions.Multiline);
            mc           = regEx.Matches(callData);

            if (mc.Count == 0)
            {
                message = "Call ID missing in xml packet";
                response.FailureMode  = ValidationFailureMode.InvalidData;
                response.ErrorCode    = (int)ValidationFailureMode.InvalidData;
                response.ErrorMessage = message;
                _log.Error(message);
                return(false);
            }

            callIdFromCallData = mc[0].Groups["CallID"].Value.Trim();

            if (string.IsNullOrEmpty(callIdFromCallData))
            {
                message = "Call ID Node is empty";
                response.FailureMode  = ValidationFailureMode.InvalidData;
                response.ErrorCode    = (int)ValidationFailureMode.InvalidData;
                response.ErrorMessage = message;
                _log.Error(message);
                return(false);
            }

            if (!callIdFromCallData.Equals(callId))
            {
                message = "Call ID mismatch with xml packet";
                response.FailureMode  = ValidationFailureMode.InvalidData;
                response.ErrorCode    = (int)ValidationFailureMode.InvalidData;
                response.ErrorMessage = message;
                _log.Error(message);
                return(false);
            }

            return(true);
        }