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":"*",
"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",

View file

@ -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))

View file

@ -47,6 +47,10 @@
</None>
</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">
<Project>{4fd29318-a8ab-4d8f-aa47-60bc241b8da3}</Project>
<Name>Wox.Infrastructure</Name>

View file

@ -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();

View file

@ -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);
}
}

View file

@ -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;

View file

@ -9,7 +9,7 @@ namespace Wox.Core.Plugin.QueryDispatcher
{
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)
{
@ -36,4 +36,4 @@ namespace Wox.Core.Plugin.QueryDispatcher
}
}
}
}
}

View file

@ -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");
}
}
}

View file

@ -45,6 +45,9 @@
</Reference>
<Reference Include="PresentationCore" />
<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.Core" />
<Reference Include="System.Drawing" />
@ -88,7 +91,9 @@
<Name>Wox.Plugin</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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.

View file

@ -2,4 +2,6 @@
<packages>
<package id="log4net" version="2.0.3" 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>