Exemplo n.º 1
0
 public static void AddAsyncActions(this IQuickContext context, IEnumerable <AsyncActionUpdate> asyncActions)
 {
     foreach (AsyncActionUpdate asyncAction in asyncActions)
     {
         context.AddAsyncAction(asyncAction);
     }
 }
Exemplo n.º 2
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());
        }
Exemplo n.º 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());
            }
        }
        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());
        }
Exemplo n.º 5
0
        public IEnumerable <PluginMatchedMethodRecord> MatchInputs(IQuickContext context)
        {
            ICommand command = context.Command;

            if (command.ContainsError)
            {
                return(new PluginMatchedMethodRecord[0]);
            }

            List <PluginMatchedMethodRecord>        results      = new List <PluginMatchedMethodRecord>();
            Dictionary <object, List <MethodInfo> > temp_results = new Dictionary <object, List <MethodInfo> >();
            string          action   = command.Action;
            string          identity = command.Identity;
            object          instance;
            SortedSet <int> methodMap = new SortedSet <int>();

            if (identity.Length <= 0)
            {
                // empty
                foreach (var pair in ignoreIdentityEntry)
                {
                    foreach (IgnoreIdentityRecords rec in pair.Value)
                    {
                        List <MethodInfo> methods;
                        if (temp_results.TryGetValue(rec.Instance, out methods) == false)
                        {
                            methods = new List <MethodInfo>();
                            temp_results.Add(rec.Instance, methods);
                        }
                        foreach (MethodInfo method in rec.Methods)
                        {
                            if (methodMap.Contains(method.GetHashCode()))
                            {
                                continue;
                            }
                            methods.Add(method);
                            methodMap.Add(method.GetHashCode());
                        }
                    }
                }
            }
            else
            {
                if (action.Length > 0)
                {
                    List <PluginMethodRecord> records;
                    if (pluginEntry.TryGetValue(command.Identity, out records))
                    {
                        foreach (PluginMethodRecord record in records)
                        {
                            foreach (var pair in record.ActionEntry)
                            {
                                if (pair.Key.Length >= action.Length && pair.Key.StartsWith(action))
                                {
                                    List <MethodInfo> methods;
                                    if (temp_results.TryGetValue(record.Instance, out methods) == false)
                                    {
                                        methods = new List <MethodInfo>();
                                        temp_results.Add(record.Instance, methods);
                                    }
                                    foreach (MethodInfo method in pair.Value)
                                    {
                                        if (methodMap.Contains(method.GetHashCode()))
                                        {
                                            continue;
                                        }
                                        methods.Add(method);
                                        methodMap.Add(method.GetHashCode());
                                    }
                                }
                            }
                        }
                    }
                    List <IgnoreIdentityRecords> ignoreIdentityRecords;
                    if (ignoreIdentityEntry.TryGetValue(command.Identity, out ignoreIdentityRecords))
                    {
                        foreach (IgnoreIdentityRecords record in ignoreIdentityRecords)
                        {
                            List <MethodInfo> methods;
                            if (temp_results.TryGetValue(record.Instance, out methods) == false)
                            {
                                methods = new List <MethodInfo>();
                                temp_results.Add(record.Instance, methods);
                            }
                            foreach (MethodInfo method in record.Methods)
                            {
                                if (methodMap.Contains(method.GetHashCode()))
                                {
                                    continue;
                                }
                                methods.Add(method);
                                methodMap.Add(method.GetHashCode());
                            }
                        }
                    }
                }
                else
                {
                    // 只有identity
                    foreach (var pair in pluginEntry)
                    {
                        if (pair.Key.Length >= identity.Length && pair.Key.StartsWith(identity))
                        {
                            foreach (PluginMethodRecord rec in pair.Value)
                            {
                                List <MethodInfo> methods;
                                if (temp_results.TryGetValue(rec.Instance, out methods) == false)
                                {
                                    methods = new List <MethodInfo>();
                                    temp_results.Add(rec.Instance, methods);
                                }
                                foreach (List <MethodInfo> methodswithaction in rec.ActionEntry.Values)
                                {
                                    foreach (MethodInfo method in methodswithaction)
                                    {
                                        if (methodMap.Contains(method.GetHashCode()))
                                        {
                                            continue;
                                        }
                                        methods.Add(method);
                                        methodMap.Add(method.GetHashCode());
                                    }
                                }
                            }
                        }
                    }
                    foreach (var pair in ignoreIdentityEntry)
                    {
                        if (pair.Key.Length >= identity.Length && pair.Key.StartsWith(identity))
                        {
                            foreach (IgnoreIdentityRecords rec in pair.Value)
                            {
                                List <MethodInfo> methods;
                                if (temp_results.TryGetValue(rec.Instance, out methods) == false)
                                {
                                    methods = new List <MethodInfo>();
                                    temp_results.Add(rec.Instance, methods);
                                }
                                foreach (MethodInfo method in rec.Methods)
                                {
                                    if (methodMap.Contains(method.GetHashCode()))
                                    {
                                        continue;
                                    }
                                    methods.Add(method);
                                    methodMap.Add(method.GetHashCode());
                                }
                            }
                        }
                    }
                }
            }

            // explicts
            foreach (ExplictMethodRecord explict in explictEntry)
            {
                instance = explict.Instance;
                IReadOnlyList <MethodInfo> methods = explict.Methods;
                List <MethodInfo>          result_methods;
                if (temp_results.TryGetValue(instance, out result_methods) == false)
                {
                    result_methods = new List <MethodInfo>();
                    temp_results.Add(instance, result_methods);
                }
                foreach (MethodInfo method in methods)
                {
                    if (methodMap.Contains(method.GetHashCode()))
                    {
                        continue;
                    }
                    result_methods.Add(method);
                    methodMap.Add(method.GetHashCode());
                }
            }

            foreach (var pair in temp_results)
            {
                results.Add(new PluginMatchedMethodRecord(pair.Key, pair.Value));
            }
            return(results);
        }
Exemplo n.º 6
0
 public Repository(IQuickContext context)
 {
     _context = context as QuickContext;
     _dbSet   = _context.Set <T>();
     _connStr = _context.Database.GetDbConnection().ConnectionString;
 }
 /// <summary>
 /// Initializes a new instance of the QuickRoutesHttpHandler class.
 /// </summary>
 /// <param name="contextWrapper"></param>
 public QuickRoutesHttpHandler(IQuickContext context)
 {
     this.context = context;
 }
Exemplo n.º 8
0
 private void index(IQuickContext context)
 {
     context.Write("Hey Skipper");
 }
Exemplo n.º 9
0
 public HelloRepository(IQuickContext quickContext) : base(quickContext)
 {
 }