Example #1
0
 private void LogMessageCreate(Logging.LogMessage message)
 {
     if (LogMessageCreated != null)
     {
         LogMessageCreated(this, new DnsClient.Logging.LogMessageEventArgs(message));
     }
 }
Example #2
0
 public RawLogMesgArray(int maxMessagesToKeep)
     : this()
 {
     rawLogMesgArray       = new Logging.LogMessage[maxMessagesToKeep];
     rawLogMesgArrayLength = rawLogMesgArray.Length;
     putIdx = getIdx = count = 0;
     lastMesgAddedSeqNum = new MosaicLib.Utils.AtomicInt64();
 }
Example #3
0
        public override void HandleLogMessage(Logging.LogMessage lm)
        {
            lock (rawLogMesgArrayMutex)
            {
                rawLogMesgArray.PutMessage(lm);
            }

            NoteMessagesAdded();
        }
Example #4
0
            public void PutMessage(Logging.LogMessage lm)
            {
                if (count >= rawLogMesgArrayLength)
                {
                    DropLastMessage();
                }

                rawLogMesgArray[putIdx++] = lm;
                if (putIdx >= rawLogMesgArrayLength)
                {
                    putIdx = 0;
                }

                lastMesgAddedSeqNum.Increment();

                count++;
            }
Example #5
0
        private void OnLogging(Logging.LogMessage message)
        {
            if (Dispatcher.Thread != Thread.CurrentThread)
            {
                // We want those messages displayed asap, because they're already delayed. Thanks!
                Dispatcher.BeginInvoke(DispatcherPriority.Send, new Logging.LoggingDelegate(OnLogging), message);
                return;
            }
            else
            {
                if (RichTextBox.LineCount >= 10000)
                {
                    RichTextBox.Clear();
                    Logging.Write("We've exceeded 10,000 lines - clearing the log window. Log files will be preserved!");
                }

                RichTextBox.AppendText(message.PlainMessage + Environment.NewLine);
                RichTextBox.ScrollToEnd();
            }
        }
Example #6
0
        private static void Logger_Log(object sender, Logging.LogMessage e)
        {
            switch (e.Severity)
            {
            case Logging.Severity.Error:
                _vaProxy.WriteToLog("EliteVA - " + e.Message, "red");
                break;

            case Logging.Severity.Warning:
                _vaProxy.WriteToLog("EliteVA - " + e.Message, "orange");
                break;

            case Logging.Severity.Success:
                _vaProxy.WriteToLog("EliteVA - " + e.Message, "green");
                break;

            case Logging.Severity.Info:
                _vaProxy.WriteToLog("EliteVA - " + e.Message, "blue");
                break;
            }
        }
Example #7
0
        private void Pulse_Main(object sender, EventArgs e)
        {
            try
            {
                if (!ZetaDia.Service.IsValid || !ZetaDia.Service.Platform.IsConnected)
                {
                    return;
                }

                if (!IsEnabled)
                {
                    ResetBotBehavior();
                }

                // Handle errors and other strange situations
                ErrorHandling();

                // YAR Health Check
                _pulseCheck   = true;
                _bs.LastPulse = DateTime.Now.Ticks;

                _bs.PluginPulse = DateTime.Now.Ticks;
                _bs.IsRunning   = BotMain.IsRunning;

                if (BotMain.IsPaused || BotMain.IsPausedForStateExecution)
                {
                    _bs.IsPaused = true;
                }
                else if (BotMain.IsRunning)
                {
                    _bs.IsPaused = false;
                    _bs.LastRun  = DateTime.Now.Ticks;
                }
                else
                {
                    _bs.IsPaused = false;
                }


                Queue <ReadOnlyCollection <Logging.LogMessage> > localQueue = new Queue <ReadOnlyCollection <Logging.LogMessage> >();
                lock (MessageQueue)
                    while (MessageQueue.Any())
                    {
                        localQueue.Enqueue(MessageQueue.Dequeue());
                    }

                foreach (var messages in localQueue)
                {
                    try
                    {
                        // Create new log buffer
                        if (_logBuffer == null)
                        {
                            _logBuffer = messages.ToArray();
                        }
                        else
                        {
                            // Append to existing log buffer
                            lock (_logBuffer)
                            {
                                var newbuffer = _logBuffer.Concat(messages.ToArray()).ToArray();
                                _logBuffer = newbuffer;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogException(ex);
                    }
                }

                // Keep Thread alive while log buffer is not empty
                while (_logBuffer != null)
                {
                    try
                    {
                        var duration = DateTime.Now;
                        Logging.LogMessage[] buffer;
                        // Lock buffer and copy to local variable for scanning
                        lock (_logBuffer)
                        {
                            buffer = new Logging.LogMessage[_logBuffer.Length + 1]; // set log new local log buffer size
                            _logBuffer.CopyTo(buffer, 0);                           // copy to local
                            _logBuffer = null;                                      // clear buffer
                        }
                        var count     = 0;                                          // Scan counter
                        var breakloop = false;
                        // Scan log items
                        foreach (Logging.LogMessage lm in buffer.Where(x => x != null))
                        {
                            string msg = lm.Message;
                            if (yarRegex.IsMatch(msg))
                            {
                                continue;
                            }

                            count++; // add to counter
                            // Log level specific scanning to prevent uneeded cpu usage
                            switch (lm.Level)
                            {
                            case LogLevel.Diagnostic:
                                var m = pluginsCompiled.Match(msg);
                                if (m.Success)
                                {
                                    Log("Plugins Compiled matched");
                                    _allPluginsCompiled = true;
                                    Send("AllCompiled");     // tell relogger about all plugin compile so the relogger can tell what to do next
                                    continue;
                                }
                                // Find all plugins compiled line
                                //if (!_allPluginsCompiled && FindPluginsCompiled(msg))
                                //    continue;

                                // Find Start stop button click
                                if (msg.Equals("Start/Stop Button Clicked!") && !BotMain.IsRunning)
                                {
                                    Send("UserStop");
                                }
                                break;     // case end

                            default:
                                //if (msg.Contains(d3Exit))
                                //{
                                //    Send("D3Exit");
                                //    Log("Attempting to safely close Demonbuddy");
                                //    SafeCloseProcess();
                                //    breakloop = true;
                                //    break;
                                //}

                                try
                                {
                                    if (!ZetaDia.IsInGame && FindStartDelay(msg))
                                    {
                                        continue;                                               // Find new start delay
                                    }
                                }
                                catch (AccessViolationException)
                                {
                                    if (ZetaDia.Memory.Process.HasExited)
                                    {
                                        Send("D3Exit");     // Proces has exited
                                        breakloop = true;   // break out of loop
                                        break;
                                    }
                                }
                                // Crash Tender check
                                if (ReCrashTender.Any(re => re.IsMatch(msg)))
                                {
                                    Send("CrashTender " + ProfileManager.CurrentProfile.Path); // tell relogger to "crash tender" :)
                                    breakloop = true;                                          // break out of loop
                                    break;
                                }
                                // YAR compatibility with other plugins
                                if (ReCompatibility.Any(re => re.IsMatch(msg)))
                                {
                                    Send("ThirdpartyStop");
                                }
                                break;     // case end
                            }
                            if (breakloop)
                            {
                                break;            // Check if we need to break out of loop
                            }
                        }

                        if (count > 1)
                        {
                            Logging.WriteDiagnostic("[YetAnotherRelogger] Scanned {0} log items in {1}ms", count, DateTime.Now.Subtract(duration).TotalMilliseconds);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogException(ex);
                    }
                }

                if (!pulseTimer.IsRunning)
                {
                    pulseTimer.Start();
                }

                if (pulseTimer.ElapsedMilliseconds <= 1000)
                {
                    return;
                }

                if (pulseTimer.ElapsedMilliseconds > 1000)
                {
                    pulseTimer.Restart();
                }
            }
            catch (Exception ex)
            {
                Log("Exception in Pulse_Main: {0}", ex);
            }
        }
Example #8
0
 private void Form_LogShowing(object?sender, Logging.LogMessage e)
 {
     this.TextBox.AppendText(e.Message);
 }
Example #9
0
 internal void ShowLog(Logging.LogMessage log)
 {
     LogShowing?.Invoke(this, log);
 }
Example #10
0
        private void ScanLogWorker()
        {
            // Keep Thread alive while log buffer is not empty
            while (_logBuffer != null)
            {
                try
                {
                    var duration = DateTime.Now;
                    Logging.LogMessage[] buffer;
                    // Lock buffer and copy to local variable for scanning
                    lock (_logBuffer)
                    {
                        buffer = new Logging.LogMessage[_logBuffer.Length + 1]; // set log new local log buffer size
                        _logBuffer.CopyTo(buffer, 0);                           // copy to local
                        _logBuffer = null;                                      // clear buffer
                    }
                    var count     = 0;                                          // Scan counter
                    var breakloop = false;
                    // Scan log items
                    foreach (Logging.LogMessage lm in buffer.Where(x => x != null))
                    {
                        count++; // add to counter
                        string msg = lm.Message;
                        // Log level specific scanning to prevent uneeded cpu usage
                        switch (lm.Level)
                        {
                        case LogLevel.Diagnostic:
                            if (!_allPluginsCompiled && FindPluginsCompiled(msg))
                            {
                                continue;                                                       // Find all plugins compiled line
                            }
                            // Find Start stop button click
                            if (msg.Equals("Start/Stop Button Clicked!") && !BotMain.IsRunning)
                            {
                                Send("UserStop");
                            }
                            break;     // case end

                        default:
                            //if (msg.Contains(d3Exit))
                            //{
                            //    Send("D3Exit");
                            //    Log("Attempting to safely close Demonbuddy");
                            //    SafeCloseProcess();
                            //    breakloop = true;
                            //    break;
                            //}

                            try
                            {
                                if (!ZetaDia.IsInGame && FindStartDelay(msg))
                                {
                                    continue;                                               // Find new start delay
                                }
                            }
                            catch (AccessViolationException)
                            {
                                if (ZetaDia.Memory.Process.HasExited)
                                {
                                    Send("D3Exit");     // Proces has exited
                                    breakloop = true;   // break out of loop
                                    break;
                                }
                            }
                            // Crash Tender check
                            if (ReCrashTender.Any(re => re.IsMatch(msg)))
                            {
                                Send("CrashTender " + ProfileManager.CurrentProfile.Path); // tell relogger to "crash tender" :)
                                breakloop = true;                                          // break out of loop
                                break;
                            }
                            // YAR compatibility with other plugins
                            if (ReCompatibility.Any(re => re.IsMatch(msg)))
                            {
                                Send("ThirdpartyStop");
                            }
                            break;     // case end
                        }
                        if (breakloop)
                        {
                            break;            // Check if we need to break out of loop
                        }
                    }

                    if (count > 1)
                    {
                        Logging.WriteDiagnostic("[YetAnotherRelogger] Scanned {0} log items in {1}ms", count, DateTime.Now.Subtract(duration).TotalMilliseconds);
                    }
                }
                catch (Exception ex)
                {
                    LogException(ex);
                }
            }
        }