Beispiel #1
0
        /// <summary>
        ///     Processes the input text and returns the processed value.
        /// </summary>
        /// <returns>The processed output</returns>
        protected override string ProcessChange()
        {
            var result = new AlfredCommandResult();

            var recipient = ChatEngine.Owner as IAlfredCommandRecipient;

            // Check to make sure we have a recipient to talk to
            if (recipient == null)
            {
                Log(Resources.AlfredTagHandlerProcessChangeNoRecipient, LogLevel.Warning);

                return result.Output.NonNull();
            }

            // Build a command
            var name = GetAttribute("command");
            var subsystem = GetAttribute("subsystem");
            var data = GetAttribute("data");

            var command = new ChatCommand(subsystem, name, data);

            // Send the command on to the owner. This may modify result or carry out other actions.
            recipient.ProcessAlfredCommand(command, result);

            // Get the output value from the result in case it was set externally
            return result.Output.NonNull();
        }
        /// <summary>
        ///     Processes an Alfred Command. If the command is handled, result should be modified accordingly
        ///     and the method should return true. Returning false will not stop the message from being
        ///     propagated.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="result">The result. If the command was handled, this should be updated.</param>
        /// <returns><c>True</c> if the command was handled; otherwise false.</returns>
        public bool ProcessAlfredCommand(ChatCommand command, AlfredCommandResult result)
        {
            var alfred = Alfred;
            if (alfred == null)
            {
                return false;
            }

            // Extract our target for loop readability
            var target = command.Subsystem;

            // Commands are very, very important and need to be logged.
            alfred.Console?.Log(Resources.AlfredCommandRouterProcessAlfredCommandLogHeader,
                                string.Format(CultureInfo.CurrentCulture,
                                              Resources.AlfredCommandRouterProcessAlfredCommandLogMessage,
                                              command.Name,
                                              target,
                                              command.Data),
                                LogLevel.Info);

            // Send the command to each subsystem. These will in turn send it on to their pages and modules.
            foreach (var subsystem in alfred.Subsystems)
            {
                // If the command isn't for the subsystem, move on.
                if (target.HasText() && !target.Matches(subsystem.Id))
                {
                    continue;
                }

                // Send the command to the subsystem for routing. If it's handled, the subsystem will return true.
                if (subsystem.ProcessAlfredCommand(command, result))
                {
                    return true;
                }
            }

            return false;
        }
Beispiel #3
0
        /// <summary>
        ///     Processes an Alfred Command. If the <paramref name="command"/> is handled,
        ///     <paramref name="result"/> should be modified accordingly and the method should
        ///     return true. Returning <see langword="false"/> will not stop the message from being
        ///     propagated.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="result">
        /// The result. If the <paramref name="command"/> was handled, this should be updated.
        /// </param>
        /// <returns>
        ///     <c>True</c> if the <paramref name="command"/> was handled; otherwise false.
        /// </returns>
        public override bool ProcessAlfredCommand(ChatCommand command, AlfredCommandResult result)
        {
            var al = AlfredInstance as TestAlfred;
            if (al != null)
            {
                al.LastCommand = command;
            }

            return base.ProcessAlfredCommand(command, result);
        }