示例#1
0
        /// <summary>
        /// Creaates a `Commands` instance from a combination of an external .commands file and the built-in commands.
        /// </summary>
        /// <param name="userCommandsFile">Path to MCEControl.commands file.</param>
        /// <param name="disableInternalCommands">If true, internal commands will not be added to created instance.</param>
        /// <returns></returns>
        public static CommandInvoker Create(string userCommandsFile, string currentVersion, bool disableInternalCommands)
        {
            CommandInvoker     commands = null;
            SerializedCommands serializedCmds;

            commands = CreateBuiltIns(disableInternalCommands);
            var nBuiltIn = commands.Count;

            // Load external .commands file.
            serializedCmds = SerializedCommands.LoadCommands(userCommandsFile, currentVersion);
            if (serializedCmds != null && serializedCmds.commandArray != null)
            {
                foreach (var cmd in serializedCmds.commandArray)
                {
                    // TELEMETRY: Mark user defined commands as such so they don't get collected
                    if (!commands.ContainsKey(cmd.Cmd))
                    {
                        cmd.UserDefined = true;
                    }

                    commands.Add(cmd);
                }
                Logger.Instance.Log4.Info($"{commands.GetType().Name}: {serializedCmds.Count} commands loaded");
            }

            // TELEMETRY:
            // what: Collect number of user defined commands created.
            // why: To determine how often users actaully create user commands, if at all.
            TelemetryService.Instance.TrackEvent("User Commands Created",
                                                 properties: new Dictionary <string, string> {
                { "userCommands", $"{commands.Values.Cast<Command>().GroupBy(o => o.UserDefined)}" }
            });

            return(commands);
        }
示例#2
0
        /// <summary>
        /// Creaates a `Commands` instance from a combination of an external .commands file and the built-in commands.
        /// </summary>
        /// <param name="userCommandsFile">Path to MCEControl.commands file.</param>
        /// <param name="disableInternalCommands">If true, internal commands will not be added to created instance.</param>
        /// <returns></returns>
        public static Commands Create(string userCommandsFile, bool disableInternalCommands)
        {
            Commands           commands = new Commands();
            SerializedCommands serializedCmds;

            // Add the built-ins that are defiend in the `Command`-derived classes
            // SECURITY: `Enabled` is set to `false` for all of these.
            if (!disableInternalCommands)
            {
                foreach (var cmd in CreateBuiltIns().Values.Cast <Command>())
                {
                    commands.Add(cmd);
                }
            }

            int nBuiltIn = commands.Count;

            // Load external .commands file.
            serializedCmds = SerializedCommands.LoadCommands(userCommandsFile);
            if (serializedCmds != null && serializedCmds.commandArray != null)
            {
                foreach (Command cmd in serializedCmds.commandArray)
                {
                    // TELEMETRY: Mark user defined commands as such so they don't get collected
                    if (!commands.ContainsKey(cmd.Cmd))
                    {
                        cmd.UserDefined = true;
                    }
                    commands.Add(cmd);
                }
                Logger.Instance.Log4.Info($"{commands.GetType().Name}: {serializedCmds.Count} commands loaded");
            }

            // TELEMETRY:
            // what: Collect number of user defined commands created.
            // why: To determine how often users actaully create user commands, if at all.
            TelemetryService.Instance.TrackEvent("User Commands Created",
                                                 properties: new Dictionary <string, string> {
                { "userCommands", $"{commands.Values.Cast<Command>().GroupBy(o => o.UserDefined)}" }
            });

            return(commands);
        }