Refactoring

This commit is contained in:
qianlifeng
2015-01-04 23:08:26 +08:00
parent 4d65b4c7a5
commit 6162904c59
10 changed files with 42 additions and 19 deletions

View File

@@ -3,7 +3,7 @@
"ActionKeyword":"*", "ActionKeyword":"*",
"Name":"Calculator", "Name":"Calculator",
"Description":"Provide mathematical calculations.(Try 5*3-2 in Wox)", "Description":"Provide mathematical calculations.(Try 5*3-2 in Wox)",
"Author":"qianlifeng", "Author":"cxfksword",
"Version":"1.0.0", "Version":"1.0.0",
"Language":"csharp", "Language":"csharp",
"Website":"http://www.getwox.com/plugin", "Website":"http://www.getwox.com/plugin",

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Wox.Core.Plugin;
using Wox.Infrastructure.Storage.UserSettings; using Wox.Infrastructure.Storage.UserSettings;
namespace Wox.Plugin.PluginIndicator namespace Wox.Plugin.PluginIndicator
@@ -16,7 +17,7 @@ namespace Wox.Plugin.PluginIndicator
if (allPlugins.Count == 0) 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)) foreach (PluginMetadata metadata in allPlugins.Select(o => o.Metadata))

View File

@@ -47,6 +47,10 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\Wox.Core\Wox.Core.csproj">
<Project>{b749f0db-8e75-47db-9e5e-265d16d0c0d2}</Project>
<Name>Wox.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj"> <ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project> <Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
<Name>Wox.Infrastructure</Name> <Name>Wox.Infrastructure</Name>

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Wox.Infrastructure; using Wox.Infrastructure;
@@ -72,7 +73,11 @@ namespace Wox.Plugin.Program
public void Init(PluginInitContext context) public void Init(PluginInitContext context)
{ {
this.context = 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")) using (new Timeit("Program Index"))
{ {
IndexPrograms(); IndexPrograms();

View File

@@ -4,7 +4,6 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using Wox.Infrastructure.Logger; using Wox.Infrastructure.Logger;
using Wox.Plugin; using Wox.Plugin;
//using Wox.Plugin.SystemPlugins;
namespace Wox.Core.Plugin namespace Wox.Core.Plugin
{ {
@@ -35,12 +34,6 @@ namespace Wox.Core.Plugin
Metadata = metadata Metadata = metadata
}; };
//var sys = pair.Plugin as BaseSystemPlugin;
//if (sys != null)
//{
// sys.PluginDirectory = metadata.PluginDirectory;
//}
plugins.Add(pair); plugins.Add(pair);
} }
} }

View File

@@ -5,6 +5,7 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using Wox.Core.Exception; using Wox.Core.Exception;
using Wox.Infrastructure;
using Wox.Infrastructure.Http; using Wox.Infrastructure.Http;
using Wox.Infrastructure.Logger; using Wox.Infrastructure.Logger;
using Wox.Plugin; using Wox.Plugin;
@@ -92,12 +93,19 @@ namespace Wox.Core.Plugin
foreach (PluginPair pluginPair in plugins) foreach (PluginPair pluginPair in plugins)
{ {
PluginPair pair = pluginPair; PluginPair pair = pluginPair;
ThreadPool.QueueUserWorkItem(o => pair.Plugin.Init(new PluginInitContext() ThreadPool.QueueUserWorkItem(o =>
{ {
CurrentPluginMetadata = pair.Metadata, using (new Timeit("Init Plugin: " + pair.Metadata.Name))
Proxy = HttpProxy.Instance, {
API = API 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); 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) public static void ActivatePluginDebugger(string path)
{ {
DebuggerMode = path; DebuggerMode = path;

View File

@@ -9,7 +9,7 @@ namespace Wox.Core.Plugin.QueryDispatcher
{ {
public class SystemPluginQueryDispatcher : IQueryDispatcher public class SystemPluginQueryDispatcher : IQueryDispatcher
{ {
private IEnumerable<PluginPair> allSytemPlugins = PluginManager.AllPlugins.Where(o => o.Metadata.ActionKeyword == "*"); private IEnumerable<PluginPair> allSytemPlugins = PluginManager.AllPlugins.Where(o => PluginManager.IsSystemPlugin(o.Metadata));
public void Dispatch(Query query) public void Dispatch(Query query)
{ {
@@ -36,4 +36,4 @@ namespace Wox.Core.Plugin.QueryDispatcher
} }
} }
} }
} }

View File

@@ -20,7 +20,7 @@ namespace Wox.Infrastructure
public void Dispose() public void Dispose()
{ {
stopwatch.Stop(); stopwatch.Stop();
Debug.WriteLine(name + ":" + stopwatch.ElapsedMilliseconds + "ms"); Debug.WriteLine(name + ":" + stopwatch.ElapsedMilliseconds + "ms","Wox");
} }
} }
} }

View File

@@ -45,6 +45,9 @@
</Reference> </Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
<Reference Include="ServiceStack.Text">
<HintPath>..\packages\ServiceStack.Text.3.9.71\lib\net35\ServiceStack.Text.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
@@ -88,7 +91,9 @@
<Name>Wox.Plugin</Name> <Name>Wox.Plugin</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -2,4 +2,6 @@
<packages> <packages>
<package id="log4net" version="2.0.3" targetFramework="net35" /> <package id="log4net" version="2.0.3" targetFramework="net35" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net35" /> <package id="Newtonsoft.Json" version="6.0.5" targetFramework="net35" />
<package id="protobuf-net" version="2.0.0.668" targetFramework="net35" />
<package id="ServiceStack.Text" version="3.9.71" targetFramework="net35" />
</packages> </packages>