From 6162904c5968f6308b49eacd12dbd2e26408034b Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sun, 4 Jan 2015 23:08:26 +0800 Subject: [PATCH] Refactoring --- Plugins/Wox.Plugin.Caculator/plugin.json | 2 +- .../PluginIndicator.cs | 3 ++- .../Wox.Plugin.PluginIndicator.csproj | 4 ++++ Plugins/Wox.Plugin.Program/Programs.cs | 7 +++++- Wox.Core/Plugin/CSharpPluginLoader.cs | 7 ------ Wox.Core/Plugin/PluginManager.cs | 23 +++++++++++++++---- .../SystemPluginQueryDispatcher.cs | 4 ++-- Wox.Infrastructure/Timeit.cs | 2 +- Wox.Infrastructure/Wox.Infrastructure.csproj | 7 +++++- Wox.Infrastructure/packages.config | 2 ++ 10 files changed, 42 insertions(+), 19 deletions(-) diff --git a/Plugins/Wox.Plugin.Caculator/plugin.json b/Plugins/Wox.Plugin.Caculator/plugin.json index 29ed5d15cc..f0371803f2 100644 --- a/Plugins/Wox.Plugin.Caculator/plugin.json +++ b/Plugins/Wox.Plugin.Caculator/plugin.json @@ -3,7 +3,7 @@ "ActionKeyword":"*", "Name":"Calculator", "Description":"Provide mathematical calculations.(Try 5*3-2 in Wox)", - "Author":"qianlifeng", + "Author":"cxfksword", "Version":"1.0.0", "Language":"csharp", "Website":"http://www.getwox.com/plugin", diff --git a/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs b/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs index 4198993be9..030d7e957a 100644 --- a/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs +++ b/Plugins/Wox.Plugin.PluginIndicator/PluginIndicator.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using Wox.Core.Plugin; using Wox.Infrastructure.Storage.UserSettings; namespace Wox.Plugin.PluginIndicator @@ -16,7 +17,7 @@ namespace Wox.Plugin.PluginIndicator if (allPlugins.Count == 0) { - allPlugins = context.API.GetAllPlugins().Where(o => o.Metadata.ActionKeyword != "*").ToList(); + allPlugins = context.API.GetAllPlugins().Where(o => !PluginManager.IsSystemPlugin(o.Metadata)).ToList(); } foreach (PluginMetadata metadata in allPlugins.Select(o => o.Metadata)) diff --git a/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj b/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj index 1c7a356bf6..82e530becb 100644 --- a/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj +++ b/Plugins/Wox.Plugin.PluginIndicator/Wox.Plugin.PluginIndicator.csproj @@ -47,6 +47,10 @@ + + {b749f0db-8e75-47db-9e5e-265d16d0c0d2} + Wox.Core + {4fd29318-a8ab-4d8f-aa47-60bc241b8da3} Wox.Infrastructure diff --git a/Plugins/Wox.Plugin.Program/Programs.cs b/Plugins/Wox.Plugin.Program/Programs.cs index 9e1c9c514f..7b6e90dcf9 100644 --- a/Plugins/Wox.Plugin.Program/Programs.cs +++ b/Plugins/Wox.Plugin.Program/Programs.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Reflection; using Wox.Infrastructure; @@ -72,7 +73,11 @@ namespace Wox.Plugin.Program public void Init(PluginInitContext context) { this.context = context; - programs = ProgramCacheStorage.Instance.Programs; + using (new Timeit("Preload programs")) + { + programs = ProgramCacheStorage.Instance.Programs; + } + Debug.WriteLine(string.Format("Preload {0} programs from cache",programs.Count),"Wox"); using (new Timeit("Program Index")) { IndexPrograms(); diff --git a/Wox.Core/Plugin/CSharpPluginLoader.cs b/Wox.Core/Plugin/CSharpPluginLoader.cs index 9ca8c9dfbc..7041d26c21 100644 --- a/Wox.Core/Plugin/CSharpPluginLoader.cs +++ b/Wox.Core/Plugin/CSharpPluginLoader.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Reflection; using Wox.Infrastructure.Logger; using Wox.Plugin; -//using Wox.Plugin.SystemPlugins; namespace Wox.Core.Plugin { @@ -35,12 +34,6 @@ namespace Wox.Core.Plugin Metadata = metadata }; - //var sys = pair.Plugin as BaseSystemPlugin; - //if (sys != null) - //{ - // sys.PluginDirectory = metadata.PluginDirectory; - //} - plugins.Add(pair); } } diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index 0d86afe233..ce988cd334 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using System.Threading; using Wox.Core.Exception; +using Wox.Infrastructure; using Wox.Infrastructure.Http; using Wox.Infrastructure.Logger; using Wox.Plugin; @@ -92,12 +93,19 @@ namespace Wox.Core.Plugin foreach (PluginPair pluginPair in plugins) { PluginPair pair = pluginPair; - ThreadPool.QueueUserWorkItem(o => pair.Plugin.Init(new PluginInitContext() + ThreadPool.QueueUserWorkItem(o => { - CurrentPluginMetadata = pair.Metadata, - Proxy = HttpProxy.Instance, - API = API - })); + using (new Timeit("Init Plugin: " + pair.Metadata.Name)) + { + pair.Plugin.Init(new PluginInitContext() + { + CurrentPluginMetadata = pair.Metadata, + Proxy = HttpProxy.Instance, + API = API + }); + } + }) + ; } } @@ -126,6 +134,11 @@ namespace Wox.Core.Plugin return plugins.Any(o => o.Metadata.PluginType == PluginType.User && o.Metadata.ActionKeyword == query.ActionName); } + public static bool IsSystemPlugin(PluginMetadata metadata) + { + return metadata.ActionKeyword == "*"; + } + public static void ActivatePluginDebugger(string path) { DebuggerMode = path; diff --git a/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs b/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs index b02d2d13d0..e8bcb896a5 100644 --- a/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs +++ b/Wox.Core/Plugin/QueryDispatcher/SystemPluginQueryDispatcher.cs @@ -9,7 +9,7 @@ namespace Wox.Core.Plugin.QueryDispatcher { public class SystemPluginQueryDispatcher : IQueryDispatcher { - private IEnumerable allSytemPlugins = PluginManager.AllPlugins.Where(o => o.Metadata.ActionKeyword == "*"); + private IEnumerable allSytemPlugins = PluginManager.AllPlugins.Where(o => PluginManager.IsSystemPlugin(o.Metadata)); public void Dispatch(Query query) { @@ -36,4 +36,4 @@ namespace Wox.Core.Plugin.QueryDispatcher } } } -} +} \ No newline at end of file diff --git a/Wox.Infrastructure/Timeit.cs b/Wox.Infrastructure/Timeit.cs index 5b020ac8c0..a29ea53ed8 100644 --- a/Wox.Infrastructure/Timeit.cs +++ b/Wox.Infrastructure/Timeit.cs @@ -20,7 +20,7 @@ namespace Wox.Infrastructure public void Dispose() { stopwatch.Stop(); - Debug.WriteLine(name + ":" + stopwatch.ElapsedMilliseconds + "ms"); + Debug.WriteLine(name + ":" + stopwatch.ElapsedMilliseconds + "ms","Wox"); } } } diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index d862f7774a..aff1b89b88 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -45,6 +45,9 @@ + + ..\packages\ServiceStack.Text.3.9.71\lib\net35\ServiceStack.Text.dll + @@ -88,7 +91,9 @@ Wox.Plugin - + + +