/// <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 ImportationResponse Import(string callId, string sessionId, string appId, string callData, DateTime callDateTime) { ImportationResponse response = new ImportationResponse(); string message = string.Empty; try { _log.Info("Inside Method "); if (!HasBasicCallInfo(callData, appId, callId, ref response)) { return(response); } if (!HasAppImportSetings(callId, appId, ref response)) { return(response); } if (!HasValidCallData(callData, callId, appId, ref response)) { return(response); } IvrReportData ivrData = ParseCallData(callData, appId, callId, ref response); if (response.FailureMode == ImportationFailureMode.None) { ImportCallData(callId, appId, sessionId, callData, callDateTime, ivrData, ref response); } } catch (Exception ex) { message = string.Format("{0}, Call ID : {1}", ex.Message, callId); response.FailureMode = ImportationFailureMode.ApplicationFailed; response.ErrorMessage = message; _log.Error(ex); } finally { UpdateIvrCallDataStatus(callData, string.Empty, appId, callId, sessionId, callDateTime, response.FailureMode); } return(response); }
/// <summary> /// To parse the 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 IvrReportData ParseCallData(string callData, string appId, string callId, ref ImportationResponse response) { IvrData ivrData = null; IvrReportData reportData = null; System.Xml.Serialization.XmlSerializer xmlSerialize = null; Stopwatch sWatch = new Stopwatch(); try { sWatch.Start(); xmlSerialize = new System.Xml.Serialization.XmlSerializer(typeof(IvrData)); ivrData = (IvrData)xmlSerialize.Deserialize(new System.IO.StringReader(callData)); reportData = new IvrReportData(ivrData); reportData.AdditionalCallInformation.ApplicationName = _applicationName; reportData.AdditionalCallInformation.ApplicationThreadName = _applicationThreadName; reportData.AdditionalCallInformation.ApplicationServer = _applicationServer; sWatch.Stop(); if (_isDebugLogEnabled) { _log.DebugFormat("Total time taken to parse the call data {0}", sWatch.Elapsed); } } catch (Exception ex) { response.HasImported = false; response.FailureMode = ImportationFailureMode.ParserFailed; response.ErrorMessage = ex.Message; _log.Error("Error occured while parsing the process", ex); } finally { xmlSerialize = null; sWatch = null; } return(reportData); }
/// <summary> /// To import the parsed 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> /// <param name="ivrReportData">Parsed Ivr Report Data (i.e. Call Data)</param> /// <param name="response">To hold the call data imporation response</param> private void ImportCallData(string callId, string appId, string sessionId, string callData, DateTime callDateTime, IvrReportData ivrReportData, ref ImportationResponse response) { int errorCode = 0; string errorDesc = string.Empty; string importStatus = string.Empty; string message = string.Empty; string procName = string.Empty; System.Xml.Serialization.XmlSerializer xmlSerialize = null; Dictionary <string, string> dicParams = null; Stopwatch sWatch = new Stopwatch(); System.Text.StringBuilder sbSummary = null; try { if (!_dataImportSetting.AppImportSettings[appId].DataImportRequired) { _log.Info("Call DataImportRequired flag set to false. So the call data will not be imported into db"); return; } sbSummary = new System.Text.StringBuilder(); xmlSerialize = new System.Xml.Serialization.XmlSerializer(typeof(IvrReportData)); xmlSerialize.Serialize(new System.IO.StringWriter(sbSummary), ivrReportData); procName = _dataImportSetting.AppImportSettings[appId].DataImportProcedureName; dicParams = new Dictionary <string, string>(); dicParams.Add("CALL_ID", callId); dicParams.Add("APP_ID", appId); dicParams.Add("SESSION_ID", sessionId); dicParams.Add("CALL_DATA", callData); dicParams.Add("CALL_DATETIME", callDateTime.ToString("MM/dd/yyyy hh:mm:ss")); dicParams.Add("REPORT_DATA", sbSummary.ToString()); sWatch.Start(); _dbHelper.ImportIvrCallData(procName, dicParams, out importStatus, out errorCode, out errorDesc); sWatch.Stop(); _log.InfoFormat("Total time taken for insertion of data into database :{0}, Status :{1}", sWatch.Elapsed, importStatus); if (importStatus.Equals("IMPORTED", StringComparison.InvariantCultureIgnoreCase)) { response.HasImported = true; } else { response.HasImported = false; response.ErrorMessage = errorDesc; response.ErrorCode = errorCode; response.FailureMode = ImportationFailureMode.ImportFailed; } } catch (Exception ex) { message = string.Format("{0}, Call ID : {1}", ex.Message, callId); response.FailureMode = ImportationFailureMode.ImportFailed; response.ErrorMessage = message; _log.Error(ex); } finally { UpdateIvrCallDataStatus(callData, sbSummary.ToString(), appId, callId, sessionId, callDateTime, response.FailureMode); if (dicParams != null) { dicParams.Clear(); } sbSummary.Remove(0, sbSummary.Length); dicParams = null; sWatch = null; } }