Пример #1
0
        private void OnLog(string message, Log.Severity severity, string category)
        {
            lock (this)
            {
                if (this.logWriter == null)
                {
                    return;
                }

                this.logWriter.Write("[");
                this.logWriter.Write(DateTime.Now.ToString());
                this.logWriter.Write("]");

                if (!string.IsNullOrEmpty(category))
                {
                    this.logWriter.Write("[");
                    this.logWriter.Write(category);
                    this.logWriter.Write("] ");
                }

                this.logWriter.Write("[");
                this.logWriter.Write(severity);
                this.logWriter.Write("] ");
                this.logWriter.WriteLine(message);

                this.logWriter.Flush();
            }
        }
Пример #2
0
        private void OnException(ExceptionDispatchInfo exDispatch, Log.Severity severity, string category)
        {
            lock (this)
            {
                if (this.logWriter == null)
                {
                    return;
                }

                this.logWriter.Write("[");
                this.logWriter.Write(category);
                this.logWriter.Write("][");
                this.logWriter.Write(severity);
                this.logWriter.Write("] ");

                Exception ex = exDispatch.SourceException;

                while (ex != null)
                {
                    this.logWriter.WriteLine(ex.GetType().Name);
                    this.logWriter.WriteLine(ex.Message);
                    this.logWriter.WriteLine(ex.StackTrace);

                    ex = ex.InnerException;
                }

                this.logWriter.Flush();
            }
        }
Пример #3
0
 private void OnLog(string message, Log.Severity severity, string category)
 {
     if (severity >= Log.Severity.Error)
     {
         Services.Get <LogService>().OnLog(message, severity, category);
         Exception ex = new Exception(message);
         ErrorDialog.ShowError(ExceptionDispatchInfo.Capture(ex), severity == Log.Severity.Critical);
     }
 }
Пример #4
0
        private void OnException(ExceptionDispatchInfo ex, Log.Severity severity, string category)
        {
            Services.Get <LogService>().OnException(ex, severity, category);

            if (severity >= Log.Severity.Error)
            {
                ErrorDialog.ShowError(ex, severity == Log.Severity.Critical);
            }
        }
Пример #5
0
        private void OnException(Exception ex, Log.Severity severity, string category)
        {
            if (Application.Current == null)
            {
                return;
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                ErrorDialog dlg = new ErrorDialog(ex, severity == Log.Severity.Critical);
                dlg.Owner       = this.MainWindow;
                dlg.ShowDialog();
            });
        }
        public TrackedCodeBlock(
            Log.Severity enLogSeverity,
            string sMsgFormat,
            params object[] Params)
            : this(enLogSeverity, true, sMsgFormat, Params)
        {
            m_oStart = DateTime.Now;

            m_sMsg = String.Format(sMsgFormat, Params);

            m_enLogSeverity = enLogSeverity;

            WriteEnter();
        }
        public TrackedCodeBlock(
            Log.Severity enLogSeverity,
            bool writeEnter,
            string sMsgFormat,
            params object[] Params)
        {
            m_oStart = DateTime.Now;

            m_sMsg = String.Format(sMsgFormat, Params);

            m_enLogSeverity = enLogSeverity;

            if (writeEnter)
            {
                WriteEnter();
            }
        }
Пример #8
0
        private static void ParseArgs(string[] Args)
        {
            if (Args == null || Args.Length == 0)
            {
                return;
            }                                                 // Nothing to parse.
            for (int i = 0; i < Args.Length; i++)
            {
                if (Args.Length > i + 2) // Triple-part arguments
                {
                    if (Args[i] == "--music")
                    {
                        string MIDIFileName = Args[i + 1];
                        if (!int.TryParse(Args[i + 2], out int OctaveShift))
                        {
                            Console.WriteLine("Given octave shift is invalid. Must be integer."); continue;
                        }
                        if (!File.Exists(MIDIFileName))
                        {
                            Console.WriteLine("MIDI file not found."); continue;
                        }
                        MusicPlayer.MIDIFileName = MIDIFileName;
                        MusicPlayer.OctaveShift  = OctaveShift;
                        i += 2;
                    }
                }
                if (Args.Length > i + 1) // Dual-part arguments.
                {
                    if (Args[i] == "-s" || Args[i] == "--server")
                    {
                        IP = Args[i + 1]; i++;
                        if (!IPAddress.TryParse(IP, out IPAddress Addr))
                        {
                            IPHostEntry Entries = Dns.GetHostEntry(IP);
                            if (Entries.AddressList.Length > 0)
                            {
                                IP = Entries.AddressList[0].ToString();
                            }
                        }
                    }
                    if (Args[i] == "-pt" || Args[i] == "--port-tcp")
                    {
                        PortTCP = int.Parse(Args[i + 1]); i++;
                    }
                    if (Args[i] == "-pu" || Args[i] == "--port-udp")
                    {
                        PortUDP = int.Parse(Args[i + 1]); i++;
                    }
                    if (Args[i] == "-l" || Args[i] == "--log")
                    {
                        if (Args[i + 1].Equals("DEBUG", StringComparison.OrdinalIgnoreCase))
                        {
                            LogLevel = Log.Severity.DEBUG; i++;
                        }
                        else if (Args[i + 1].Equals("INFO", StringComparison.OrdinalIgnoreCase))
                        {
                            LogLevel = Log.Severity.INFO; i++;
                        }
                        else if (Args[i + 1].Equals("WARNING", StringComparison.OrdinalIgnoreCase))
                        {
                            LogLevel = Log.Severity.WARNING; i++;
                        }
                        else
                        {
                            Console.WriteLine("Unknown log level specified. Use 'DEBUG', 'INFO', or 'WARNING'."); i++;
                        }
                    }
                }
                // Single-part arguments
                if (Args[i] == "-?" || Args[i] == "/?" || Args[i] == "-h" || Args[i] == "/h" || Args[i] == "help" || Args[i] == "-help" || Args[i] == "--help")
                {
                    Console.WriteLine("Command-line paramters:");
                    Console.WriteLine("  -?|/?|-h|/h|help|-help|--help : Outputs this text.");
                    Console.WriteLine("  -l|--log <Level> : Sets the default log level to 'DEBUG', 'INFO', or 'WARNING'.");
                    Console.WriteLine(" Networking:");
                    Console.WriteLine("  -s|--server <IP> : Connects to the given server instead of the default.");
                    Console.WriteLine("  -pt|--port-tcp <Port> : Connects to the server via TCP using the given port instead of the default.");
                    Console.WriteLine("  -pu|--port-udp <Port> : Connects to the server via UDP using the given port instead of the default.");
                    Console.WriteLine(" Fun:");
                    Console.WriteLine("  --music <MIDI file> <Octave Shift> : Syntesizes a MIDI file using the drill motor.");

                    /*Console.WriteLine(" Device Tree (BBB):");
                     * Console.WriteLine("  --no-dt : Do not attempt to remove/add device tree overlays.");
                     * Console.WriteLine("  --replace-dt : Remove all Scarlet DT overlays, then apply the new one. DANGEROUS!");
                     * Console.WriteLine("  --add-dt : Add device tree overlay even if there is one already.");*/
                }

                /*if(Args[i] == "--no-dt") { ApplyDevTree = BBBPinManager.ApplicationMode.NO_CHANGES; }
                 * if(Args[i] == "--replace-dt") { ApplyDevTree = BBBPinManager.ApplicationMode.REMOVE_AND_APPLY; }
                 * if(Args[i] == "--add-dt") { ApplyDevTree = BBBPinManager.ApplicationMode.APPLY_REGARDLESS; }*/
            }
        }
Пример #9
0
 private static void ParseArgs(string[] Args)
 {
     if (Args == null || Args.Length == 0)
     {
         return;
     }                                                 // Nothing to parse.
     for (int i = 0; i < Args.Length; i++)
     {
         if (Args.Length > i + 1) // Dual-part arguments.
         {
             if (Args[i] == "-s" || Args[i] == "--server")
             {
                 IP = Args[i + 1]; i++;
             }
             if (Args[i] == "-pt" || Args[i] == "--port-tcp")
             {
                 PortTCP = int.Parse(Args[i + 1]); i++;
             }
             if (Args[i] == "-pu" || Args[i] == "--port-udp")
             {
                 PortUDP = int.Parse(Args[i + 1]); i++;
             }
             if (Args[i] == "-l" || Args[i] == "--log")
             {
                 if (Args[i + 1].Equals("DEBUG", StringComparison.OrdinalIgnoreCase))
                 {
                     LogLevel = Log.Severity.DEBUG; i++;
                 }
                 else if (Args[i + 1].Equals("INFO", StringComparison.OrdinalIgnoreCase))
                 {
                     LogLevel = Log.Severity.INFO; i++;
                 }
                 else if (Args[i + 1].Equals("WARNING", StringComparison.OrdinalIgnoreCase))
                 {
                     LogLevel = Log.Severity.WARNING; i++;
                 }
                 else
                 {
                     Console.WriteLine("Unknown log level specified. Use 'DEBUG', 'INFO', or 'WARNING'."); i++;
                 }
             }
         }
         // Single-part arguments
         if (Args[i] == "-?" || Args[i] == "/?" || Args[i] == "-h" || Args[i] == "/h" || Args[i] == "help" || Args[i] == "-help" || Args[i] == "--help")
         {
             Console.WriteLine("Command-line paramters:");
             Console.WriteLine("  -?|/?|-h|/h|help|-help|--help : Outputs this text.");
             Console.WriteLine("  -l|--log <Level> : Sets the default log level to 'DEBUG', 'INFO', or 'WARNING'.");
             Console.WriteLine(" Networking:");
             Console.WriteLine("  -s|--server <IP> : Connects to the given server instead of the default.");
             Console.WriteLine("  -pt|--port-tcp <Port> : Connects to the server via TCP using the given port instead of the default.");
             Console.WriteLine("  -pu|--port-udp <Port> : Connects to the server via UDP using the given port instead of the default.");
             Console.WriteLine(" Device Tree (BBB):");
             Console.WriteLine("  --no-dt : Do not attempt to remove/add device tree overlays.");
             Console.WriteLine("  --replace-dt : Remove all Scarlet DT overlays, then apply the new one. DANGEROUS!");
             Console.WriteLine("  --add-dt : Add device tree overlay even if there is one already.");
         }
         if (Args[i] == "--no-dt")
         {
             ApplyDevTree = BBBPinManager.ApplicationMode.NO_CHANGES;
         }
         if (Args[i] == "--replace-dt")
         {
             ApplyDevTree = BBBPinManager.ApplicationMode.REMOVE_AND_APPLY;
         }
         if (Args[i] == "--add-dt")
         {
             ApplyDevTree = BBBPinManager.ApplicationMode.APPLY_REGARDLESS;
         }
     }
 }
Пример #10
0
 public logItem(Log.Severity Level, string mssg, Object obj)
 {
     this.loggingLevel = Level;
     this.message      = mssg;
     this.obj          = obj;
 }
Пример #11
0
 private void OnException(ExceptionDispatchInfo ex, Log.Severity severity, string category)
 {
     ErrorDialog.ShowError(ex, severity == Log.Severity.Critical);
 }