예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GlobalCommand"/> class.
        /// </summary>
        /// <param name="name">The name of the command, as it should appear in the processor console. Limited to 23 characters.</param>
        /// <param name="help">Help text shown when entering 'help user' on a processor command prompt. Limited to 79 characters.</param>
        /// <param name="access">The user access level the command should be given.</param>
        public GlobalCommand(string name, string help, Access access)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentOutOfRangeException("name", "The name must be non-empty and non-null.");
            }

            if (name.Length >= 23)
            {
                throw new ArgumentOutOfRangeException("name", "The name can be no longer than 23 characters.");
            }

            Name = name;
            Help = help.Substring(0, Math.Min(help.Length, 76));
            if (Help.Length == 76 && help.Length != 76)
            {
                Help = Help + "...";
            }

            CommandAccess           = access;
            WriteErrorMethod        = (msg) => ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.BrightRed, msg);
            WriteHelpMethod         = (msg) => ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.BrightYellow, msg);
            FormatHelpCommandMethod = (msg) => ConsoleBase.Colors.BrightGreen.FormatText(msg);
            FormatHelpVerbMethod    = (msg) => ConsoleBase.Colors.BrightMagenta.FormatText(msg);
            FormatHelpOperandMethod = (msg) => ConsoleBase.Colors.BrightCyan.FormatText(msg);
            FormatHelpFlagMethod    = (msg) => ConsoleBase.Colors.BrightBlue.FormatText(msg);
            FormatHelpSampleMethod  = (msg) => ConsoleBase.Colors.BrightGreen.FormatText(msg);
            FormatHelpTextMethod    = (msg) => ConsoleBase.Colors.BrightYellow.FormatText(msg);
        }
예제 #2
0
 public void EchoBlueMessage(
     [Operand("message", "The message to echo.")] string message,
     [Flag("caps", 'c', "When present prints the message in all caps.", true)] bool caps,
     [Flag("blue", 'b', "When present prints the message in blue.")] bool blue)
 {
     ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.BrightBlue, caps ? message.ToUpper() : message);
 }
        /// <summary>
        /// Prints the current logging configuration to the console.
        /// </summary>
        private void PrintCurrentConfiguration()
        {
            ConsoleBase.WriteCommandResponse(
                "Logging of {0} is {1}\r\n",
                ConsoleBase.Colors.Debug.FormatText("Debug Messages"),
                Options.Instance.LogLevels.Contains(LogLevels.Debug) ? ConsoleBase.Colors.BrightGreen.FormatText("Enabled") : ConsoleBase.Colors.BrightRed.FormatText("Disabled"));

            ConsoleBase.WriteCommandResponse(
                "Logging of {0} are {1}\r\n",
                ConsoleBase.Colors.Notice.FormatText("Notices"),
                Options.Instance.LogLevels.Contains(LogLevels.Notice) ? ConsoleBase.Colors.BrightGreen.FormatText("Enabled") : ConsoleBase.Colors.BrightRed.FormatText("Disabled"));

            ConsoleBase.WriteCommandResponse(
                "Logging of {0} are {1}\r\n",
                ConsoleBase.Colors.Warning.FormatText("Warnings"),
                Options.Instance.LogLevels.Contains(LogLevels.Warning) ? ConsoleBase.Colors.BrightGreen.FormatText("Enabled") : ConsoleBase.Colors.BrightRed.FormatText("Disabled"));

            ConsoleBase.WriteCommandResponse(
                "Logging of {0} are {1}\r\n",
                ConsoleBase.Colors.Error.FormatText("Errors"),
                Options.Instance.LogLevels.Contains(LogLevels.Error) ? ConsoleBase.Colors.BrightGreen.FormatText("Enabled") : ConsoleBase.Colors.BrightRed.FormatText("Disabled"));

            ConsoleBase.WriteCommandResponse(
                "Logging of {0} are {1}\r\n",
                ConsoleBase.Colors.Exception.FormatText("Exceptions"),
                Options.Instance.LogLevels.Contains(LogLevels.Exception) ? ConsoleBase.Colors.BrightGreen.FormatText("Enabled") : ConsoleBase.Colors.BrightRed.FormatText("Disabled"));
        }
        public ResetScreenCommand(ConsoleBase consoleBase)
            : base("reset", "Resets current and stored settings back to default.")
        {
            AddName("r");

            _consoleBase = consoleBase;
        }
예제 #5
0
 public override void Initialize()
 {
     base.Initialize();
     base.ConsoleInterface        = new WorldConsole();
     this.VirtualConsoleInterface = new WorldVirtualConsole();
     ConsoleBase.SetTitle("#Stump World Server : " + WorldServer.ServerInformation.Name);
     this.logger.Info("Initializing Database...");
     base.DBAccessor = new DatabaseAccessor(WorldServer.DatabaseConfiguration);
     base.DBAccessor.RegisterMappingAssembly(System.Reflection.Assembly.GetExecutingAssembly());
     base.InitializationManager.Initialize(InitializationPass.Database);
     base.DBAccessor.Initialize();
     this.logger.Info("Opening Database...");
     base.DBAccessor.OpenConnection();
     DataManager.DefaultDatabase   = base.DBAccessor.Database;
     DataManagerAllocator.Assembly = System.Reflection.Assembly.GetExecutingAssembly();
     this.logger.Info("Register Messages...");
     MessageReceiver.Initialize();
     ProtocolTypeManager.Initialize();
     this.logger.Info("Register Packet Handlers...");
     this.HandlerManager = Singleton <WorldPacketHandler> .Instance;
     this.HandlerManager.RegisterAll(System.Reflection.Assembly.GetExecutingAssembly());
     this.logger.Info("Register Commands...");
     base.CommandManager.RegisterAll(System.Reflection.Assembly.GetExecutingAssembly());
     base.InitializationManager.InitializeAll();
     base.IsInitialized = true;
 }
예제 #6
0
 public void EchoRedMessage(
     [Operand("message", "The message to echo.")] string message,
     [Flag("caps", 'c', "When present prints the message in all caps.", true)] bool caps,
     [Flag("red", 'r', "When present prints the message in red.")] bool red)
 {
     ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.BrightRed, caps ? message.ToUpper() : message);
 }
예제 #7
0
 public void MyTestInitialize()
 {
     underTest = new GlobalCommand("app", "app", Access.Administrator);
     underTest.AddToConsole();
     testWriter = new TestConsoleWriter();
     ConsoleBase.RegisterConsoleWriter(testWriter);
 }
 public void TestCleanup()
 {
     writer.Messages.Clear();
     ConsoleBase.UnregisterConsoleWriter(writer);
     ConsoleBase.OptionalHeader             = string.Empty;
     Options.Instance.ColorizeConsoleOutput = true;
 }
예제 #9
0
 public void TestInitialize()
 {
     ConsoleBase.RegisterConsoleWriter(writer);
     Logger.RegisterLogWriter(logger);
     Options.Instance.ColorizeConsoleOutput = true;
     Options.Instance.LogLevels             = LogLevels.All;
 }
예제 #10
0
        /// <summary>
        /// Writes an exception to the console.
        /// </summary>
        /// <param name="obj">The object the exception originated from. Can be null.</param>
        /// <param name="ex">The exception being written.</param>
        /// <param name="message">The message to write before the exception.</param>
        /// <param name="args">Optional arguments to use when formatting the message.</param>
        public static void WriteException(object obj, Exception ex, string message, params object[] args)
        {
            if (Options.Instance.DebugLevels.Contains(DebugLevels.Exception) && IsValid(obj))
            {
                var sb = new StringBuilder();
                if (!isLastWriteALine)
                {
                    isLastWriteALine = true;
                    ConsoleBase.WriteLine();
                }

                var header = GetMessageHeader(obj, true, true);

                message = Formatters.GetColorFormattedString(ConsoleBase.Colors.Exception, message, args);

                sb.AppendFormat("{0}{1}", header, message);

                int exceptionIndex = 0;

                var exceptionFormat = ConsoleBase.Colors.Exception;

                while (ex != null)
                {
                    exceptionIndex++;
                    sb.Append(exceptionFormat.FormatText(false, "{1}--------Exception {0}--------{1}", exceptionIndex, ConsoleBase.NewLine));
                    sb.AppendFormat("{0}", ex.ToString().Replace(Environment.NewLine, ConsoleBase.NewLine));
                    sb.Append(exceptionFormat.FormatText(true, "{0}-----------------------------", ConsoleBase.NewLine));
                    ex = ex.InnerException;
                }

                ForceWriteLine(
                    Formatters.GetColorFormattedString(ConsoleBase.Colors.Exception, sb.ToString()));
            }
        }
예제 #11
0
 public void Optional(
     [Flag("opt", "help", true)] bool optional)
 {
     if (!optional)
     {
         ConsoleBase.WriteLineNoHeader("OPTIONAL");
     }
 }
 public void TestCleanup()
 {
     writer.Messages.Clear();
     ConsoleBase.UnregisterConsoleWriter(writer);
     ConsoleBase.OptionalHeader = string.Empty;
     Options.Instance.Suppressed.Clear();
     Options.Instance.Allowed.Clear();
 }
예제 #13
0
 /// <summary>Creates service definition that can be registered with a server</summary>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static grpc::ServerServiceDefinition BindService(ConsoleBase serviceImpl)
 {
     return(grpc::ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_LogDebug, serviceImpl.LogDebug)
            .AddMethod(__Method_LogInfo, serviceImpl.LogInfo)
            .AddMethod(__Method_LogWarn, serviceImpl.LogWarn)
            .AddMethod(__Method_LogError, serviceImpl.LogError).Build());
 }
예제 #14
0
 /// <summary>
 /// Writes a debug message to the console, with no additional color formatting applied.
 /// </summary>
 /// <param name="message">The message to write.</param>
 /// <param name="args">Optional arguments to use when formatting the message.</param>
 public static void Write(string message, params object[] args)
 {
     if (Options.Instance.DebugLevels.Contains(DebugLevels.Uncategorized))
     {
         ConsoleBase.Write(message, args);
         isLastWriteALine = false;
     }
 }
예제 #15
0
 /// <summary>
 /// Writes a debug message to the console, with no additional color formatting applied.
 /// </summary>
 /// <param name="message">The message to write.</param>
 /// <param name="args">Optional arguments to use when formatting the message.</param>
 public static void WriteLine(string message, params object[] args)
 {
     if (Options.Instance.DebugLevels.Contains(DebugLevels.Uncategorized))
     {
         isLastWriteALine = true;
         ConsoleBase.WriteLineNoHeader(message, args);
     }
 }
예제 #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ControlSystem"/> class.
        /// </summary>
        public ControlSystem()
            : base()
        {
            try
            {
                Thread.MaxNumberOfUserThreads = 20;

                // Setup the static instance reference for the control system.
                Instance = this;

                // Setup the path the options are saved to and loaded from.
                Options.FilePath = "/USER/pellucid.console-options.toml";

                // Setup the global command(s).
                var appCommand = new GlobalCommand("app", "Application commands.", Access.Programmer);
                var regResult  = appCommand.AddToConsole();

                // Add a console writer to the console.
                // This could be done with the ProConsole class as well, or your own
                // implementation extending the ConsoleBase class.
                // Technically if no writer is registered then the CrestronConsoleWriter
                // gets registered by default, precluding the need for this, but it shows
                // how to hook your own console writers into the system.
                ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Terminal.CrestronConsoleWriter());

                if (!regResult)
                {
                    Debug.WriteErrorLine(this, "Unable to add global app to the Crestron Console.");
                }

                // Initialize specific global commands.
                ProConsole.InitializeConsole("app");

                var csc = new ControlSystemCommands();
                csc.RegisterCommand("app");

                var exc = new ExampleCommands();
                exc.RegisterCommand("app");

                // Register log writers.
                Logger.RegisterLogWriter(new CrestronLogWriter());

                // In addition to the CrestronLogWriter we're registering an additional writer that targets another file.
                var path = Path.Combine(Directory.GetApplicationRootDirectory(), "/user");
                path = Path.Combine(path, "logs");
                path = Path.Combine(path, string.Format("App{0}SimpleLog.log", InitialParametersClass.ApplicationNumber));
                Logger.RegisterLogWriter(new Evands.Pellucid.Diagnostics.SimpleFileLogger(path));

                // Subscribe to the controller events (System, Program, and Ethernet)
                CrestronEnvironment.SystemEventHandler        += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler);
                CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler);
                CrestronEnvironment.EthernetEventHandler      += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler);
            }
            catch (Exception e)
            {
                this.LogException(e, "Exception in the constructor.");
            }
        }
예제 #17
0
 public void TestCleanup()
 {
     writer.Messages.Clear();
     logger.Messages.Clear();
     ConsoleBase.UnregisterConsoleWriter(writer);
     Logger.UnregisterLogWriter(logger);
     ConsoleBase.OptionalHeader = string.Empty;
     Options.Instance.LogLevels = LogLevels.None;
 }
예제 #18
0
        /// <summary>
        /// Dumps the specified object to the console.
        /// </summary>
        /// <param name="obj">The object to dump to the console.</param>
        public static void Dump(this object obj)
        {
            if (Crestron.SimplSharp.CrestronEnvironment.ProgramCompatibility == Crestron.SimplSharp.eCrestronSeries.Series3)
            {
                ConsoleBase.WriteLine();
            }

            ConsoleBase.WriteNoHeader(Terminal.Formatting.Formatters.FormatObjectForConsole(obj));
        }
예제 #19
0
        /// <summary>
        /// Dumps the specified object to the console.
        /// </summary>
        /// <param name="obj">The object to format details about.</param>
        /// <param name="maxDepth">The maximum number of times to recurse on complex objects.
        /// <para>A value of 1 would indicate dumping the top-level properties on the object provided,
        /// while ignoring properties that are complex objects with additional properties of their own.</para>
        /// <para>A value of 0 indicates no max depth.</para>
        /// </param>
        /// <param name="useFullTypeNames"><see langword="true"/> to use an object's fully qualified
        /// name, otherwise just the short name.</param>
        /// <typeparam name="T">The type of the object being dumped.</typeparam>
        /// <returns>The object being dumped.</returns>
        public static T Dump <T>(this T obj, int maxDepth, bool useFullTypeNames)
        {
            if (Crestron.SimplSharp.CrestronEnvironment.ProgramCompatibility == Crestron.SimplSharp.eCrestronSeries.Series3)
            {
                ConsoleBase.WriteLine();
            }

            ConsoleBase.WriteNoHeader(Terminal.Formatting.Formatters.FormatObjectForConsole(obj, maxDepth, useFullTypeNames));
            return(obj);
        }
예제 #20
0
        public void CurrentStatus()
        {
            ConsoleBase.WriteCommandResponse(
                ConsoleBase.Colors.Progress,
                "Timestamps are {0}.\r\n24 Hour Timestamps are {0}.\r\n",
                Options.Instance.UseTimestamps ? "enabled" : "disabled",
                Options.Instance.Use24HourTime ? "enabled" : "disabled");

            ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.Progress, "Debug Levels = '{0}'\r\n", Options.Instance.DebugLevels);
        }
예제 #21
0
 public void MyTestCleanup()
 {
     underTest.RemoveFromConsole();
     underTest.Dispose();
     underTest = null;
     Crestron.SimplSharp.CrestronConsole.AddNewConsoleCommandResult = true;
     Crestron.SimplSharp.CrestronEnvironment.DevicePlatform         = Crestron.SimplSharp.eDevicePlatform.Appliance;
     ConsoleBase.UnregisterConsoleWriter(testWriter);
     testWriter = null;
 }
예제 #22
0
        public void ValidateWriter_DoesNothing_When_NewValidator_IsNull()
        {
            underTest.WriteErrorMethod = (s) => { ConsoleBase.Write(s); };
            underTest.WriteErrorMethod("temp");
            Assert.IsTrue(testWriter.Contains("temp") && !testWriter.Contains("temp" + ConsoleBase.NewLine));

            underTest.WriteErrorMethod = null;
            underTest.WriteErrorMethod("Error");
            Assert.IsTrue(testWriter.Contains("Error"));
        }
예제 #23
0
 public void MyTestCleanup()
 {
     global.RemoveCommand(command);
     global  = null;
     command = null;
     CrestronConsole.Messages.Length = 0;
     if (writer != null)
     {
         ConsoleBase.UnregisterConsoleWriter(writer);
     }
 }
예제 #24
0
        public OpenSimMain(bool sandBoxMode, bool startLoginServer, string physicsEngine, bool useConfigFile, bool verbose, string configFile)
        {
            this.configFileSetup = useConfigFile;
            m_sandbox            = sandBoxMode;
            m_loginserver        = startLoginServer;
            m_physicsEngine      = physicsEngine;
            m_config             = configFile;

            m_console = new ConsoleBase("region-console-" + Guid.NewGuid().ToString() + ".log", "Region", this, verbose);
            OpenSim.Framework.Console.MainConsole.Instance = m_console;
        }
예제 #25
0
        private static void Main()
        {
            var person = new PersonVM {
                Name = "Bart", Length = 1.80, Weight = 83.2
            };
            var console = new ConsoleBase {
                DataContext = person
            };

            console.AskQuestion();
        }
예제 #26
0
        public void CommandAlias_Shows_InTopLevelHelp()
        {
            var expected = "(test)";

            Options.Instance.ColorizeConsoleOutput = false;
            writer = new TestConsoleWriter();
            ConsoleBase.RegisterConsoleWriter(writer);
            global.ExecuteCommand("-h");
            Assert.IsTrue(writer.Contains(expected));
            Options.Instance.ColorizeConsoleOutput = true;
        }
예제 #27
0
        public override void Initialize()
        {
            try
            {
                base.Initialize();
                ConsoleInterface = new AuthConsole();
                ConsoleBase.SetTitle($"#Stump Authentification Server - {Version}");

                logger.Info("Initializing Database...");
                DBAccessor = new DatabaseAccessor(DatabaseConfiguration);
                DBAccessor.RegisterMappingAssembly(Assembly.GetExecutingAssembly());
                InitializationManager.Initialize(InitializationPass.Database);
                DBAccessor.Initialize();

                logger.Info("Opening Database...");
                DBAccessor.OpenConnection();
                DataManager.DefaultDatabase   = DBAccessor.Database;
                DataManagerAllocator.Assembly = Assembly.GetExecutingAssembly();

                logger.Info("Register Messages...");
                MessageReceiver.Initialize();
                ProtocolTypeManager.Initialize();

                logger.Info("Register Packets Handlers...");
                HandlerManager = AuthPacketHandler.Instance;
                HandlerManager.RegisterAll(Assembly.GetExecutingAssembly());

                logger.Info("Register Commands...");
                CommandManager.RegisterAll(Assembly.GetExecutingAssembly());

                logger.Info("Start World Servers Manager");
                WorldServerManager.Instance.Initialize();

                logger.Info("Initialize Account Manager");
                AccountManager.Instance.Initialize();

                logger.Info("Initialize IPC Server..");
                IpcHost = new IPCHost(IpcAddress, IpcPort);

                InitializationManager.InitializeAll();
                IsInitialized = true;

                if (Environment.GetCommandLineArgs().Contains("-maintenance"))
                {
                    m_maintenanceMode = true;
                }
            }
            catch (Exception ex)
            {
                HandleCrashException(ex);
                Shutdown();
            }
        }
예제 #28
0
 public void AddAllowed(
     [Operand("Add", "Adds the name that follows to the allowed list.")] string valueToAdd)
 {
     if (Debug.AddAllowed(valueToAdd))
     {
         ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.Success, "Added the value '{0}' to the allowed list.\r\n", valueToAdd);
     }
     else
     {
         ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.Error, "The value '{0}' was already in the allowed list.\r\n", valueToAdd);
     }
 }
예제 #29
0
 public void SampleTable(
     [Operand("min", "Sets the minimum width the cells can be.")] int minWidth)
 {
     ConsoleBase.WriteLine();
     ConsoleBase.WriteLineNoHeader(Table.Create()
                                   .SetMinimumColumnWidth(minWidth)
                                   .AddColumnWithHeader("Device", "Touchpanel", "DSP", "Codec", "Display 1", "Display 2")
                                   .AddColumnWithHeader("Status", "Online", "Online", "Offline", "Offline", "Online")
                                   .FormatHeaders(ConsoleBase.Colors.BrightYellow, HorizontalAlignment.Center)
                                   .FormatColumn(0, ConsoleBase.Colors.BrightCyan, HorizontalAlignment.Right)
                                   .ForEachCellInColumn(1, c => c.Color = c.Contents == "Offline" ? ConsoleBase.Colors.BrightRed : ConsoleBase.Colors.BrightGreen).ToString());
 }
예제 #30
0
 public void RemoveAllowed(
     [Operand("Remove", "Removes the name that follows from the suppression list.")] string valueToRemove)
 {
     if (Debug.RemoveAllowed(valueToRemove))
     {
         ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.Success, "Removed the value '{0}' from the allowed list.\r\n", valueToRemove);
     }
     else
     {
         ConsoleBase.WriteCommandResponse(ConsoleBase.Colors.Error, "The value '{0}' was not in the allowed list.\r\n", valueToRemove);
     }
 }