예제 #1
0
 /// <summary>
 /// Opens a console window for debug output
 /// </summary>
 private static void OpenDebugConsole()
 {
     try
     {
         if (DebugReporter._isConsoleOpen == false)
         {
             DebugReporter.AllocConsole();
             //Console.SetWindowSize(120, 60);
             //Console.SetBufferSize(120, 80);
             Console.Title = DebugReporter.Name + " Debug Output Console";
             Console.WriteLine("##########################################");
             Console.WriteLine(DebugReporter.Name + " Debug Output Console.");
             Console.WriteLine("DO NOT close this console by any other means than CONTROL-C!");
             Console.WriteLine("Closing this console with the Close Button will exit the application.");
             Console.WriteLine("##########################################");
             Console.WriteLine("");
             DebugReporter.SetConsoleCtrlHandler(DebugReporter._consoleCtrlDel, true);
             DebugReporter._isConsoleOpen = true;
         }
     }
     catch (Exception ex)
     {
         throw new ApplicationException("Failed to open the debug console for output:\n" + ex.Message);
     }
 }
예제 #2
0
        private static void ReportToConsole(MessageType messageType, string timestamp, string File, string Method, string Linenumber, string TypeName, string title, string body)
        {
            try
            {
                if (DebugReporter._isConsoleOpen == false)
                {
                    DebugReporter.OpenDebugConsole();
                }

                if (messageType == MessageType.Error)
                {
                    Console.WriteLine("*****************");
                }
                Console.WriteLine(messageType.ToString());
                Console.WriteLine(timestamp);
                Console.WriteLine("File: " + File);
                Console.WriteLine("Type: " + TypeName);
                Console.WriteLine("Method: " + Method);
                Console.WriteLine("Line: " + Linenumber);
                Console.WriteLine(title);
                Console.WriteLine(body);
                if (messageType == MessageType.Error)
                {
                    Console.WriteLine("*****************");
                }
                Console.WriteLine("");
            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #3
0
 /// <summary>
 /// Kills the debug reporter, stops all reporting
 /// </summary>
 /// <param name="reason">Reason to kill the reporter.</param>
 private static void KillDebugReporter(string reason)
 {
     if (DebugReporter._dManagerStatus == ReporterStatus.OK)
     {
         DebugReporter.DebugMode = DebugMode.Output;
         DebugReporter.Report(MessageType.Internal,
                              "Error", reason);
         DebugReporter._dManagerStatus = ReporterStatus.Dead;
     }
     else
     {
         DebugReporter._dManagerStatus = ReporterStatus.Dead;
         return;
     }
 }
예제 #4
0
        /// <summary>
        /// Writes the report to the designated receiver.
        /// </summary>
        private static void WriteReport(MessageType DebugMessageType, string Title, string Body)
        {
            //Test for the current Filter.
            bool shouldReport = false;

            //We always report internal messages...
            if (DebugMessageType == MessageType.Internal)
            {
                shouldReport = true;
            }
            else
            {
                switch (DebugMessageType)
                {
                case MessageType.Information:
                    if ((DebugLevels.Information & DebugReporter._outPutFilter) > 0)
                    {
                        shouldReport = true;
                    }
                    break;

                case MessageType.Warning:
                    if ((DebugLevels.Warning & DebugReporter._outPutFilter) > 0)
                    {
                        shouldReport = true;
                    }
                    break;

                case MessageType.Error:
                    if ((DebugLevels.Error & DebugReporter._outPutFilter) > 0)
                    {
                        shouldReport = true;
                    }
                    break;

                default:
                    break;
                }
            }

            if (!shouldReport)
            {
                return;
            }

            if (DebugReporter._dManagerStatus != ReporterStatus.OK)
            {
                throw new ApplicationException(DebugReporter.Name +
                                               " - The Debug Reporter is no longer alive. Cannot Write Report.");
            }

            //Get some additional data on the current stack frame.
            StackFrame frame    = new StackFrame(2, true);
            string     method   = frame.GetMethod().Name;
            string     file     = frame.GetFileName();
            string     line     = frame.GetFileLineNumber().ToString();
            string     typename = frame.GetMethod().DeclaringType.FullName;

            string TimeStamp = DateTimeStringBuilder.GetDateTimeString();

            try
            {
                switch (DebugReporter._debugMode)
                {
                case DebugMode.None:
                    break;

                case DebugMode.File:
                    DebugReporter.ReportToFile(DebugMessageType, TimeStamp, file, method, line, typename, Title, Body);
                    break;

                case DebugMode.Email:
                    DebugReporter.ReportToEmail(DebugMessageType, TimeStamp, file, method, line, typename, Title, Body);
                    break;

                case DebugMode.Console:
                    DebugReporter.ReportToConsole(DebugMessageType, TimeStamp, file, method, line, typename, Title, Body);
                    break;

                case DebugMode.Output:
                    DebugReporter.ReportToOutput(DebugMessageType, TimeStamp, file, method, line, typename, Title, Body);
                    break;

                case DebugMode.Wreq_v1:
                    DebugReporter.ReportToWreq_v1(DebugMessageType, TimeStamp, file, method, line, typename, Title, Body);
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                DebugReporter.KillDebugReporter("Failed to Write Report.\nException:\n" + ex.Message);

                throw new ApplicationException(TimeStamp + DebugReporter.Name +
                                               "Unhandled Excpetion:\n" + ex.Message);
            }
        }
예제 #5
0
 public static void Report(MessageType DebugMessageType, string Title, string Body)
 {
     DebugReporter.WriteReport(DebugMessageType,
                               Title, Body);
 }
예제 #6
0
 public static void ReportMethodLeave()
 {
     DebugReporter.WriteReport(MessageType.Information,
                               "Leaving Method", "Execution leaving method.");
 }
예제 #7
0
 public static void ReportMethodEnter()
 {
     DebugReporter.WriteReport(MessageType.Information,
                               "Entering Method", "Execution entering method.");
 }
예제 #8
0
        private static void SetDebugMode(DebugMode mode)
        {
            //Perform Setup for the new mode...
            switch (mode)
            {
            case DebugMode.File:
                try
                {
                    FileInfo fi = new FileInfo(DebugReporter._outputFilePath);

                    if (!Directory.Exists(fi.Directory.FullName))
                    {
                        Directory.CreateDirectory(fi.Directory.FullName);
                    }

                    if (File.Exists(DebugReporter._outputFilePath))
                    {
                        break;
                    }
                    else
                    {
                        File.CreateText(DebugReporter._outputFilePath).Close();
                    }

                    DebugReporter._debugMode = mode;
                }
                catch (Exception ex)
                {
                    DebugReporter.KillDebugReporter("Failed to set DebugMode File.\nException:\n" + ex.Message);
                    return;
                }
                break;

            case DebugMode.Email:
                throw new NotImplementedException("This feature is not available in this project...");

            case DebugMode.Console:
                try
                {
                    DebugReporter.OpenDebugConsole();
                    DebugReporter._debugMode = mode;
                }
                catch (Exception ex)
                {
                    DebugReporter.KillDebugReporter("Failed to set DebugMode Console.\nException:\n" + ex.Message);
                    return;
                }

                break;

            case DebugMode.Wreq_v1:
                throw new NotImplementedException("This feature is not available in this project...");

            case DebugMode.None:
                DebugReporter._debugMode = mode;
                break;

            default:
                break;
            }

            DebugReporter.Report(MessageType.Internal,
                                 "Debug mode changed.",
                                 "DebugReporter Debug Mode changed to:\n" +
                                 DebugReporter._debugMode.ToString());
        }