Example #1
0
        /// <summary>
        /// <code>info</code>  can be a simple string message or an error code of type WinService.ErrorCode.
        /// If info == string message ==> do nothing or return -1 in the Main() or _commandExitCode = -1
        /// If info == WinService.ErrorCode simply return, exit code is stored in global _commandExitCode.
        /// </summary>
        /// <param name="info"></param>
        private static void ManageErrors(object info)
        {
            // Who call me
            StackTrace stackTrace = new StackTrace();
            StackFrame stackFrame = stackTrace.GetFrame(1);
            MethodBase methodBase = stackFrame.GetMethod();

            var infoType = info.GetType();

            if (infoType == typeof(string))
            {
                string mesPlus = string.Format("[{0}] [{1}] {2}", DateTime.Now, methodBase.Name, info.ToString());
                System.Console.WriteLine(info.ToString());
                Trace.WriteLine(mesPlus);
            }
            else if (infoType == typeof(WinService.ErrorCode))
            {
                WinService.ErrorCode code = (WinService.ErrorCode)info;
                string message            = WinService.LessError.GetEnumDescription(code);
                string mesPlus            = string.Format("[{0}] [{1}] {2}", DateTime.Now, methodBase.Name, message);
                System.Console.WriteLine(message);
                Trace.WriteLine(mesPlus);
                _commandExitCode = (int)code;
            }
        }
Example #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="errorCode"></param>
 /// <param name="type">true = message false = error</param>
 private static void SetAndShowError(string source, WinService.ErrorCode errorCode, bool type)
 {
     _commandExitCode = (int)errorCode;
     ShowMessage(source, WinService.LessError.GetEnumDescription(errorCode), type);
 }