/// ----------------------------------------------------------------------------- /// <summary> /// This function overrides the object.toString method. /// This function formats the error message by filling the place holders with the /// context parameters /// </summary> /// <returns>Formatted error String </returns> /// <remarks> /// </remarks> /// ----------------------------------------------------------------------------- public override string ToString() { //This needs to get the message bode using the message code string formattedMessage; if (MessageParams != null) { var msgParams = MessageParams.ToArray(); MessageParams.CopyTo(msgParams); try { formattedMessage = string.Format(MessageBody, msgParams); } catch (Exception ex) { var stackTrace = PayflowConstants.EmptyString; PayflowUtility.InitStackTraceOn(); if (PayflowConstants.TraceOn.Equals(PayflowConstants.Trace)) { stackTrace = " " + ex; } formattedMessage = PayflowConstants.MessageFormattingError + stackTrace; } } else { formattedMessage = MessageBody; } return(formattedMessage); }
private void InitializeStream() { try { if ( (mFileInfo == null) || (mWriteToFile == null)) { mFileInfo = new FileInfo(mLogFileName); if (mFileInfo.Extension.Length == 0) { mLogFileName = mLogFileName+".Log"; mFileInfo = new FileInfo(mLogFileName); } if (!Directory.Exists(mFileInfo.DirectoryName)) { Directory.CreateDirectory(mFileInfo.DirectoryName); } mWriteToFile = new StreamWriter(mLogFileName,true); mWriteToFile.AutoFlush = true; } } catch(Exception Ex) { String StackTrace = PayflowConstants.EMPTY_STRING; PayflowUtility.InitStackTraceOn(); if(PayflowConstants.TRACE_ON.Equals(PayflowConstants.TRACE)) { StackTrace = ": " + Ex.StackTrace; } String RespMessage = PayflowConstants.PARAM_RESULT + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorCodes[PayflowConstants.E_LOG_ERROR] + PayflowConstants.DELIMITER_NVP + PayflowConstants.PARAM_RESPMSG + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorMessages[PayflowConstants.E_LOG_ERROR] + PayflowConstants.MESSAGE_LOG_ERROR + " " +Ex.Message + " " +StackTrace; ErrorObject Err = new ErrorObject( PayflowConstants.SEVERITY_ERROR, "", RespMessage); mLoggerErrs.Add(Err); mErrInLogger = true; } }
private void InitializeStream() { try { if (_mFileInfo == null || _mWriteToFile == null) { _mFileInfo = new FileInfo(_mLogFileName); if (_mFileInfo.Extension.Length == 0) { _mLogFileName = _mLogFileName + ".Log"; _mFileInfo = new FileInfo(_mLogFileName); } if (!Directory.Exists(_mFileInfo.DirectoryName)) Directory.CreateDirectory(_mFileInfo.DirectoryName); _mWriteToFile = new StreamWriter(_mLogFileName, true) { AutoFlush = true }; } } catch (Exception ex) { var stackTrace = PayflowConstants.EmptyString; PayflowUtility.InitStackTraceOn(); if (PayflowConstants.TraceOn.Equals(PayflowConstants.Trace)) stackTrace = ": " + ex.StackTrace; var respMessage = PayflowConstants.ParamResult + PayflowConstants.SeparatorNvp + (string) PayflowConstants.CommErrorCodes[PayflowConstants.ELogError] + PayflowConstants.DelimiterNvp + PayflowConstants.ParamRespmsg + PayflowConstants.SeparatorNvp + (string) PayflowConstants.CommErrorMessages[PayflowConstants.ELogError] + PayflowConstants.MessageLogError + " " + ex.Message + " " + stackTrace; var err = new ErrorObject( PayflowConstants.SeverityError, "", respMessage); _mLoggerErrs.Add(err); _mErrInLogger = true; } }
/// ----------------------------------------------------------------------------- /// <summary> /// This function overrides the object.toString method. /// This function formats the error message by filling the place holders with the /// context parameters /// </summary> /// <returns>Formatted error String </returns> /// <remarks> /// </remarks> /// ----------------------------------------------------------------------------- public override String ToString() { //This needs to get the message bode using the message code String FormattedMessage = PayflowConstants.EMPTY_STRING; if (mMsgCodeParams != null) { //Convert the arraylist mMsgCodeparams to an array of String String[] MsgParams = new String[mMsgCodeParams.Count]; mMsgCodeParams.CopyTo(MsgParams); try { FormattedMessage = String.Format(mMsgBody, MsgParams); } catch(Exception Ex) { String StackTrace = PayflowConstants.EMPTY_STRING; PayflowUtility.InitStackTraceOn(); if(PayflowConstants.TRACE_ON.Equals(PayflowConstants.TRACE)) { StackTrace = " " + Ex.ToString(); } FormattedMessage = PayflowConstants.MESSAGE_FORMATTING_ERROR + StackTrace; } //catch //{ // FormattedMessage = PayflowConstants.MESSAGE_FORMATTING_ERROR; //} } else { FormattedMessage = mMsgBody; } return FormattedMessage; }
/// ----------------------------------------------------------------------------- /// <summary> /// This method used to log the data in a file.Different type of severity level are logged here. /// The levels that can be logged are decided by the configuration settings in the /// Application config file. /// </summary> /// <param name="message">String value that needs to be logged</param> /// <param name="severityLvl"> /// Severity level of the message.This could be one of the following: /// 1 (Debug) /// 2 (Info) /// 3 (Warn) /// 4 (Error) /// 5 (Fatal) /// </param> /// <return></return> /// <remarks> /// </remarks> /// ----------------------------------------------------------------------------- public void Log(string message, int severityLvl) { var strDebugLevel = string.Empty; var messageToLog = string.Empty; if (_mLogLevel != 0 && !_mErrInLogger) if (severityLvl >= _mLogLevel) try { switch (severityLvl) { case PayflowConstants.SeverityDebug: strDebugLevel = "DEBUG"; break; case PayflowConstants.SeverityInfo: strDebugLevel = "INFO"; break; case PayflowConstants.SeverityWarn: strDebugLevel = "WARN"; break; case PayflowConstants.SeverityError: strDebugLevel = "ERROR"; break; case PayflowConstants.SeverityFatal: strDebugLevel = "FATAL"; break; default: return; } InitializeStream(); //int nProcessID = System.Diagnostics.Process.GetCurrentProcess().Id; messageToLog = "[" + DateTime.Now + ":" + GlobalClass.GlobalVar + ":[" + strDebugLevel + "]-" + message; _mFileInfo.Refresh(); _mFileLength = _mFileInfo.Length + messageToLog.Length + 1; _mWriteToFile.WriteLine(messageToLog); if (_mFileLength >= _mFileSize) if (ArchivedLogFile()) _mFileLength = 0; } catch (Exception ex) { var stackTrace = PayflowConstants.EmptyString; PayflowUtility.InitStackTraceOn(); if (PayflowConstants.TraceOn.Equals(PayflowConstants.Trace)) stackTrace = ": " + ex.StackTrace; var respMessage = PayflowConstants.ParamResult + PayflowConstants.SeparatorNvp + (string) PayflowConstants.CommErrorCodes[PayflowConstants.ELogError] + PayflowConstants.DelimiterNvp + PayflowConstants.ParamRespmsg + PayflowConstants.SeparatorNvp + (string) PayflowConstants.CommErrorMessages[PayflowConstants.ELogError] + PayflowConstants.MessageLogError + ex.Message + stackTrace; var err = new ErrorObject( PayflowConstants.SeverityWarn, "", respMessage); _mLoggerErrs.Add(err); _mErrInLogger = true; } }
/// ----------------------------------------------------------------------------- /// <summary> /// This method used to log the data in a file.Different type of severity level are logged here. /// The levels that can be logged are decided by the configuration settings in the /// Application config file. /// </summary> /// <param name="Message">String value that needs to be logged</param> /// <param name="SeverityLvl">Severity level of the message.This could be one of the following: /// 1 (Debug) /// 2 (Info) /// 3 (Warn) /// 4 (Error) /// 5 (Fatal) /// </param> /// <return></return> /// <remarks> /// </remarks> /// ----------------------------------------------------------------------------- public void Log(String Message, int SeverityLvl) { String StrDebugLevel = String.Empty; String MessageToLog = String.Empty; if ( mLogLevel != 0 && ! mErrInLogger ) { if (SeverityLvl >= mLogLevel) { try { switch (SeverityLvl) { case PayflowConstants.SEVERITY_DEBUG: StrDebugLevel = "DEBUG"; break; case PayflowConstants.SEVERITY_INFO: StrDebugLevel = "INFO"; break; case PayflowConstants.SEVERITY_WARN: StrDebugLevel = "WARN"; break; case PayflowConstants.SEVERITY_ERROR: StrDebugLevel = "ERROR"; break; case PayflowConstants.SEVERITY_FATAL: StrDebugLevel = "FATAL"; break; default: return; } InitializeStream(); //int nProcessID = System.Diagnostics.Process.GetCurrentProcess().Id; MessageToLog = "[" + DateTime.Now +":" + GlobalClass.GlobalVar.ToString() + ":[" + StrDebugLevel + "]-" + Message; mFileInfo.Refresh(); mFileLength = mFileInfo.Length + MessageToLog.Length +1; mWriteToFile.WriteLine(MessageToLog); if(mFileLength >= mFileSize ) { if (ArchivedLogFile()) mFileLength= 0; } } catch(Exception Ex) { String StackTrace = PayflowConstants.EMPTY_STRING; PayflowUtility.InitStackTraceOn(); if(PayflowConstants.TRACE_ON.Equals(PayflowConstants.TRACE)) { StackTrace = ": " + Ex.StackTrace; } String RespMessage = PayflowConstants.PARAM_RESULT + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorCodes[PayflowConstants.E_LOG_ERROR] + PayflowConstants.DELIMITER_NVP + PayflowConstants.PARAM_RESPMSG + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorMessages[PayflowConstants.E_LOG_ERROR] + PayflowConstants.MESSAGE_LOG_ERROR + Ex.Message + StackTrace; ErrorObject Err = new ErrorObject( PayflowConstants.SEVERITY_WARN, "", RespMessage); mLoggerErrs.Add(Err); mErrInLogger = true; } } } }
/// <summary> /// Initializes the default values /// </summary> private void InitDefaultValues() { //Check if the values held //in the PayPal server //connection related params //if they are passed null or //0 (for int values) then //initialize them to appropriate //default values. //set the timeout to default timeout. if (mTimeOut == 0) { mTimeOut = PayflowConstants.DEFAULT_TIMEOUT; } try { if (mHostAddress == null || mHostAddress.Length == 0) { String HostAddress = PayflowUtility.AppSettings(PayflowConstants.INTL_PARAM_PAYFLOW_HOST); if (HostAddress != null && HostAddress.Length > 0) { HostAddress = HostAddress.TrimStart().TrimEnd(); if (HostAddress.Length == 0) { String RespMessage = PayflowConstants.PARAM_RESULT + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorCodes[PayflowConstants.E_CONFIG_ERROR] + PayflowConstants.DELIMITER_NVP + PayflowConstants.PARAM_RESPMSG + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorMessages[PayflowConstants.E_CONFIG_ERROR] + "Tag " + PayflowConstants.INTL_PARAM_PAYFLOW_HOST + " is not present in the config file or config file is missing."; ErrorObject Error = new ErrorObject(PayflowConstants.SEVERITY_FATAL, "", RespMessage); Context.AddError(Error); } else { mHostAddress = HostAddress; } } else { String RespMessage = PayflowConstants.PARAM_RESULT + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorCodes[PayflowConstants.E_CONFIG_ERROR] + PayflowConstants.DELIMITER_NVP + PayflowConstants.PARAM_RESPMSG + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorMessages[PayflowConstants.E_CONFIG_ERROR] + "Tag " + PayflowConstants.INTL_PARAM_PAYFLOW_HOST + " is not present in the config file or config file is missing."; ErrorObject Error = new ErrorObject(PayflowConstants.SEVERITY_FATAL, "", RespMessage); Context.AddError(Error); } } } catch (Exception Ex) { String StackTrace = PayflowConstants.EMPTY_STRING; PayflowUtility.InitStackTraceOn(); if (PayflowConstants.TRACE_ON.Equals(PayflowConstants.TRACE)) { StackTrace = ": " + Ex.Message + Ex.StackTrace; } String RespMessage = PayflowConstants.PARAM_RESULT + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorCodes[PayflowConstants.E_CONFIG_ERROR] + PayflowConstants.DELIMITER_NVP + PayflowConstants.PARAM_RESPMSG + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorMessages[PayflowConstants.E_CONFIG_ERROR] + "Tag " + PayflowConstants.INTL_PARAM_PAYFLOW_HOST + " is not present in the config file or config file is missing." + StackTrace; ErrorObject Error = new ErrorObject(PayflowConstants.SEVERITY_FATAL, "", RespMessage); Context.AddError(Error); } }
/// <summary> /// Initializes the default values /// </summary> private void InitDefaultValues() { //Check if the values held //in the PayPal server //connection related params //if they are passed null or //0 (for int values) then //intialize them to appropriate //default values. //set the timeout to default timeout. if (TimeOut == 0) { TimeOut = PayflowConstants.DefaultTimeout; } /** * // ToInt32 can throw FormatException or OverflowException. * try * { * mTimeOut = Convert.ToInt32(PayflowUtility.AppSettings(PayflowConstants.INTL_PARAM_PAYFLOW_TIMEOUT)); * } * catch (FormatException Ex) * { * String StackTrace = PayflowConstants.EMPTY_STRING; * PayflowUtility.InitStackTraceOn(); * if (PayflowConstants.TRACE_ON.Equals(PayflowConstants.TRACE)) * { * StackTrace = ": " + Ex.Message + Ex.StackTrace; * } * String RespMessage = PayflowConstants.PARAM_RESULT + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorCodes[PayflowConstants.E_CONFIG_ERROR] + PayflowConstants.DELIMITER_NVP + PayflowConstants.PARAM_RESPMSG + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorMessages[PayflowConstants.E_CONFIG_ERROR] + "Tag " + PayflowConstants.INTL_PARAM_PAYFLOW_TIMEOUT + + " is not valid, using default value." + StackTrace; + ErrorObject Error = new ErrorObject(PayflowConstants.SEVERITY_FATAL, "", RespMessage); + Context.AddError(Error); + } + catch (OverflowException Ex) + { + String StackTrace = PayflowConstants.EMPTY_STRING; + PayflowUtility.InitStackTraceOn(); + if (PayflowConstants.TRACE_ON.Equals(PayflowConstants.TRACE)) + { + StackTrace = ": " + Ex.Message + Ex.StackTrace; + } + String RespMessage = PayflowConstants.PARAM_RESULT + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorCodes[PayflowConstants.E_CONFIG_ERROR] + PayflowConstants.DELIMITER_NVP + PayflowConstants.PARAM_RESPMSG + PayflowConstants.SEPARATOR_NVP + (String)PayflowConstants.CommErrorMessages[PayflowConstants.E_CONFIG_ERROR] + "Tag " + PayflowConstants.INTL_PARAM_PAYFLOW_TIMEOUT + + " is not valid, using default value." + StackTrace; + ErrorObject Error = new ErrorObject(PayflowConstants.SEVERITY_FATAL, "", RespMessage); + Context.AddError(Error); + } + + } + mHostPort = PayflowConstants.DEFAULT_HOSTPORT; + }*/ try { if (HostAddress == null || HostAddress.Length == 0) { var hostAddress = PayflowUtility.AppSettings(PayflowConstants.IntlParamPayflowHost); if (hostAddress != null && hostAddress.Length > 0) { hostAddress = hostAddress.TrimStart().TrimEnd(); if (hostAddress.Length == 0) { var respMessage = PayflowConstants.ParamResult + PayflowConstants.SeparatorNvp + (string)PayflowConstants.CommErrorCodes[PayflowConstants.EConfigError] + PayflowConstants.DelimiterNvp + PayflowConstants.ParamRespmsg + PayflowConstants.SeparatorNvp + (string)PayflowConstants.CommErrorMessages[ PayflowConstants.EConfigError] + "Tag " + PayflowConstants.IntlParamPayflowHost + " is not present in the config file or config file is missing."; var error = new ErrorObject(PayflowConstants.SeverityFatal, "", respMessage); Context.AddError(error); } else { HostAddress = hostAddress; } } else { var respMessage = PayflowConstants.ParamResult + PayflowConstants.SeparatorNvp + (string)PayflowConstants.CommErrorCodes[PayflowConstants.EConfigError] + PayflowConstants.DelimiterNvp + PayflowConstants.ParamRespmsg + PayflowConstants.SeparatorNvp + (string)PayflowConstants.CommErrorMessages[PayflowConstants.EConfigError] + "Tag " + PayflowConstants.IntlParamPayflowHost + " is not present in the config file or config file is missing."; var error = new ErrorObject(PayflowConstants.SeverityFatal, "", respMessage); Context.AddError(error); } } } catch (Exception ex) { var stackTrace = PayflowConstants.EmptyString; PayflowUtility.InitStackTraceOn(); if (PayflowConstants.TraceOn.Equals(PayflowConstants.Trace)) { stackTrace = ": " + ex.Message + ex.StackTrace; } var respMessage = PayflowConstants.ParamResult + PayflowConstants.SeparatorNvp + (string)PayflowConstants.CommErrorCodes[PayflowConstants.EConfigError] + PayflowConstants.DelimiterNvp + PayflowConstants.ParamRespmsg + PayflowConstants.SeparatorNvp + (string)PayflowConstants.CommErrorMessages[PayflowConstants.EConfigError] + "Tag " + PayflowConstants.IntlParamPayflowHost + " is not present in the config file or config file is missing." + stackTrace; var error = new ErrorObject(PayflowConstants.SeverityFatal, "", respMessage); Context.AddError(error); } }