コード例 #1
0
        private static void CheckStatus(object stateInfo)
        {
            RobotBumLibCore.Alert currentAlert = null; // Para tratatamento de erro.

            var alerts = PluginsManager.GetAlerts(isToForceUpdateAll);

            isToForceUpdateAll = false;

            for (int i = 0; i < alerts.Count; i++)
            {
                currentAlert = alerts[i];
                ConsoleColor color = ConsoleColor.Gray;

                switch (currentAlert.AlertType)
                {
                case RobotBumLibCore.PluginAlertType.Low:
                    color = ConsoleColor.Green;
                    break;

                case RobotBumLibCore.PluginAlertType.Medium:
                    color = ConsoleColor.Yellow;
                    break;

                case RobotBumLibCore.PluginAlertType.High:
                    color = ConsoleColor.Red;
                    break;
                }

                if (alerts[i].AlertType != RobotBumLibCore.PluginAlertType.NoAlert)
                {
                    using (StreamWriter w = File.AppendText(strPath + "\\logAlerts_" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt"))
                    {
                        Log(alerts[i].ToString() + ";" + alerts[i].Justify, w);
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write(alerts[i].Radar.Name);
                        Console.ForegroundColor = color;
                        Console.WriteLine(" " + DateTime.Now.ToString("HH:mm:ss") + " - " + (alerts[i].ToString().Length < 64 ? alerts[i].ToString() : alerts[i].ToString().Substring(0, 61) + "..."));
                    }
                }
                // If it's a "high" alert, it must be posted on twitter or server
                if (alerts[i].AlertType == RobotBumLibCore.PluginAlertType.High)
                {
                    using (StreamWriter w = File.AppendText(strPath + "\\logAlertsHigh_" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt"))
                    {
                        if (isTwitterActive && !isFirstTime)
                        {
                            twitterManager.PostMessage(alerts[i].Radar, alerts[i].Message);
                        }
                        ;

                        Log(alerts[i].ToString(), w);
                    }
                }
                if (alerts[i].AlertType == RobotBumLibCore.PluginAlertType.NoAlert)
                {
                    using (StreamWriter w = File.AppendText(strPath + "\\log_" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt"))
                    {
                        Log(alerts[i].ToString(), w);
                    }
                }
            }

            ServerWriter.UpdatePages(alerts);

            Console.ForegroundColor = ConsoleColor.Gray;

            Console.Title = "Robot Bum (Core) - " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");


            if (isFirstTime)
            {
                isTwitterActive = true;
            }

            isFirstTime = false;
        }