Example #1
0
        /// <summary>
        /// Finds the commands specified in the config file and invokes them with the specified attributes.
        /// </summary>
        /// <param name="command"></param>
        /// <param name="config"></param>
        /// <param name="password">The password to decrypt encrypted config commands</param>
        protected void Execute(ICommand command, IConfig config, String password = null) {
            if (config != null && config.Root != null) {

                foreach (var loadedConfigCommand in config.RootOf(this.GetType()).Children<JObject>().Select(item => item.ToObject<ConfigCommand>(JsonSerialization.Minimal)).Where(item => item != null)) {
                    // only attempt a decrypt if we've been given a password. If we don't have a password, we won't bother
                    // and the command will have a null Command and be skipped anyway.
                    if (password != null) {
                        loadedConfigCommand.Decrypt(password);
                    }

                    var loadedCommand = loadedConfigCommand.Command;

                    if (loadedCommand != null && loadedCommand.Name != null) {
                        command.ParseCommandType(loadedCommand.Name);
                        command.Parameters = loadedCommand.Parameters;
                        command.Scope = loadedCommand.Scope;

                        this.Tunnel(command);
                    }
                }
            }
        }