Example #1
0
        public Task Invoke(IQuickContext context, Func <Task> next, IServiceProvider services)
        {
            object[] args = new object[context.Command.UnnamedArguments.Count + 2];
            args[0] = context;
            args[1] = context.Command;
            if (context.Command.UnnamedArguments.Count > 0)
            {
                context.Command.UnnamedArguments.CopyTo(args, 2);
            }
            IEnumerable <PluginMatchedMethodRecord> records = plugins.MatchInputs(context);

            foreach (PluginMatchedMethodRecord record in records)
            {
                foreach (MethodInfo method in record.MatchedMethods)
                {
                    try
                    {
                        object returnvalue = ObjectFactory.InvokeMethod(record.Instance, method, services, context.Command.NamedArguments, args);
                        if (returnvalue == null)
                        {
                            continue;
                        }

                        if (returnvalue is ActionUpdateResult action)
                        {
                            context.AddAction(action.Action, action.Priority);
                        }
                        else if (returnvalue is AsyncActionUpdate asyncAction)
                        {
                            context.AddAsyncAction(asyncAction);
                        }
                        else if (returnvalue is IEnumerable <ActionUpdateResult> actions)
                        {
                            foreach (ActionUpdateResult act in actions)
                            {
                                context.AddAction(act.Action, act.Priority);
                            }
                        }
                        else if (returnvalue is IEnumerable <AsyncActionUpdate> asyncActions)
                        {
                            context.AddAsyncActions(asyncActions);
                        }
                    }
                    catch { }
                }
            }
            return(next());
        }
        public Task Invoke(IQuickContext context, IProgramContext program, Func <Task> next)
        {
            if (!Config.EnableSearch)
            {
                return(next());
            }

            bool isChrome = program.CurrentProcess.ProcessName == "chrome";

            if (isChrome)
            {
                string search = context.Command.Raw.Trim().ToLower();
                if (search.Length <= 0)
                {
                    return(next());
                }

                Regex searchReg = null;
                try
                {
                    searchReg = new Regex(search);
                }
                catch
                {
                    SearchPatternErrorAction.Update("搜索模式错误", search);
                    context.AddAction(SearchPatternErrorAction);
                }
                if (searchReg != null)
                {
                    List <Bookmark> bookmarks = new List <Bookmark>();
                    SearchFolder(Bookmarks.BookmarkBar, searchReg, bookmarks);
                    SearchFolder(Bookmarks.Others, searchReg, bookmarks);
                    foreach (Bookmark bookmark in bookmarks)
                    {
                        context.AddAction(new BookmarkAction(bookmark.Name, bookmark.Url));
                    }
                }
            }
            return(next());
        }
Example #3
0
        public Task Invoke(IQuickContext context, Func <Task> next)
        {
            ICommand command = context.Command;

            if (!command.ContainsError)
            {
                return(next());
            }

            errorAction.Set("ERORR", command.Raw);
            context.AddAction(errorAction, ActionPriority.Topmost);
            if (blockIfError)
            {
                return(completedTask);
            }
            else
            {
                return(next());
            }
        }