Пример #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
        internal void Save(string userCommandsFile)
        {
            Logger.Instance.Log4.Info($@"{GetType().Name}: Saving {Program.ConfigPath}MCEControl.commands...");
            var sc = new SerializedCommands();

            var values = Values.Cast <Command>().ToArray();

            // Sort
            sc.commandArray = values.OrderBy(c => c.Cmd).ToArray();

            SerializedCommands.SaveCommands(userCommandsFile, sc, System.Windows.Forms.Application.ProductVersion);
        }
Пример #3
0
        internal void Save(string userCommandsFile)
        {
            Logger.Instance.Log4.Info($@"Commands: Saving {Program.ConfigPath}MCEControl.commands...");
            var sc = new SerializedCommands();

            var values = Values.Cast <Command>().ToArray();

            // Sort
            sc.commandArray = values.OrderBy(c => c.Cmd).ToArray();

            SerializedCommands.SaveCommands(userCommandsFile, sc);
        }
Пример #4
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);
        }
Пример #5
0
        public static Commands Create(string userCommandsFile, bool disableInternalCommands)
        {
            Commands           commands = new Commands();
            SerializedCommands serializedCmds;

            // Start with the .commands file that's built in as an EXE resource
            if (!disableInternalCommands)
            {
                serializedCmds = SerializedCommands.LoadBuiltInCommands();
            }
            else
            {
                serializedCmds = new SerializedCommands();
            }

            foreach (Command cmd in serializedCmds.commandArray)
            {
                commands.Add(cmd);
            }
            Logger.Instance.Log4.Info($"{commands.GetType().Name}: {serializedCmds.Count} commands loaded from built-in .commands resource.");

            // Add the built-ins
            foreach (Command cmd in McecCommand.Commands)
            {
                commands.Add(cmd);
            }

            foreach (Command cmd in MouseCommand.Commands)
            {
                commands.Add(cmd);
            }

            foreach (Command cmd in ShutdownCommand.Commands)
            {
                commands.Add(cmd);
            }

            foreach (Command cmd in CharsCommand.Commands)
            {
                commands.Add(cmd);
            }

            foreach (Command cmd in SendInputCommand.Commands)
            {
                commands.Add(cmd);
            }

            foreach (Command cmd in PauseCommand.Commands)
            {
                commands.Add(cmd);
            }

            var nBuiltin = commands.Count;

            Logger.Instance.Log4.Info($"{commands.GetType().Name}: {commands.Count} built-in commands defined.");

            // Load external .commands file
            serializedCmds = SerializedCommands.LoadUserCommands(userCommandsFile);
            if (serializedCmds != null)
            {
                foreach (Command cmd in serializedCmds.commandArray)
                {
                    commands.Add(cmd, true);
                }
                Logger.Instance.Log4.Info($"{commands.GetType().Name}: {serializedCmds.Count} user-defined commands loaded.");
            }

            TelemetryService.Instance.TrackEvent("Commands Created",
                                                 properties: new Dictionary <string, string> {
                { "builtinCommands", $"{nBuiltin}" },
                { "userCommands", $"{(serializedCmds == null ? 0 : serializedCmds.Count)}" }
            });

            return(commands);
        }