mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 06:29:44 +08:00
Rearrange code
Fields -> Properties -> Init method -> Query methods -> Is methods -> Get Methods
This commit is contained in:
parent
8c7bac7dbb
commit
79461d52c2
@ -26,8 +26,6 @@ namespace Wox.Core.Plugin
|
||||
private static IEnumerable<PluginPair> exclusiveSearchPlugins;
|
||||
private static List<KeyValuePair<PluginPair, IContextMenu>> contextMenuPlugins;
|
||||
|
||||
public static IPublicAPI API { get; private set; }
|
||||
|
||||
private static List<PluginPair> plugins = new List<PluginPair>();
|
||||
|
||||
/// <summary>
|
||||
@ -35,17 +33,27 @@ namespace Wox.Core.Plugin
|
||||
/// </summary>
|
||||
private static List<string> pluginDirectories = new List<string>();
|
||||
|
||||
private static void SetupPluginDirectories()
|
||||
public static List<PluginPair> AllPlugins
|
||||
{
|
||||
pluginDirectories.Add(PluginDirectory);
|
||||
MakesurePluginDirectoriesExist();
|
||||
get
|
||||
{
|
||||
return plugins.OrderBy(o => o.Metadata.Name).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public static IPublicAPI API { private set; get; }
|
||||
|
||||
public static string PluginDirectory
|
||||
{
|
||||
get { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Plugins"); }
|
||||
}
|
||||
|
||||
private static void SetupPluginDirectories()
|
||||
{
|
||||
pluginDirectories.Add(PluginDirectory);
|
||||
MakesurePluginDirectoriesExist();
|
||||
}
|
||||
|
||||
private static void MakesurePluginDirectoriesExist()
|
||||
{
|
||||
foreach (string pluginDirectory in pluginDirectories)
|
||||
@ -159,11 +167,33 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
}
|
||||
|
||||
public static List<PluginPair> AllPlugins
|
||||
private static void QueryForPlugin(PluginPair pair, Query query)
|
||||
{
|
||||
get
|
||||
try
|
||||
{
|
||||
return plugins.OrderBy(o => o.Metadata.Name).ToList();
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<Result> results = pair.Plugin.Query(query) ?? new List<Result>();
|
||||
results.ForEach(o =>
|
||||
{
|
||||
o.PluginID = pair.Metadata.ID;
|
||||
});
|
||||
sw.Stop();
|
||||
Debug.WriteLine(string.Format("Plugin query: {0} - {1}", pair.Metadata.Name, sw.ElapsedMilliseconds));
|
||||
pair.QueryCount += 1;
|
||||
if (pair.QueryCount == 1)
|
||||
{
|
||||
pair.AvgQueryTime = sw.ElapsedMilliseconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
pair.AvgQueryTime = (pair.AvgQueryTime + sw.ElapsedMilliseconds) / 2;
|
||||
}
|
||||
API.PushResults(query, pair.Metadata, results);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
throw new WoxPluginException(pair.Metadata.Name, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,36 +228,6 @@ namespace Wox.Core.Plugin
|
||||
LoadInstantSearches().Any(o => o.Key.Metadata.ID == pluginMetadata.ID);
|
||||
}
|
||||
|
||||
private static void QueryForPlugin(PluginPair pair, Query query)
|
||||
{
|
||||
try
|
||||
{
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
List<Result> results = pair.Plugin.Query(query) ?? new List<Result>();
|
||||
results.ForEach(o =>
|
||||
{
|
||||
o.PluginID = pair.Metadata.ID;
|
||||
});
|
||||
sw.Stop();
|
||||
Debug.WriteLine(string.Format("Plugin query: {0} - {1}", pair.Metadata.Name, sw.ElapsedMilliseconds));
|
||||
pair.QueryCount += 1;
|
||||
if (pair.QueryCount == 1)
|
||||
{
|
||||
pair.AvgQueryTime = sw.ElapsedMilliseconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
pair.AvgQueryTime = (pair.AvgQueryTime + sw.ElapsedMilliseconds) / 2;
|
||||
}
|
||||
API.PushResults(query, pair.Metadata, results);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
throw new WoxPluginException(pair.Metadata.Name, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<KeyValuePair<PluginPair, IInstantQuery>> LoadInstantSearches()
|
||||
{
|
||||
if (instantSearches != null) return instantSearches;
|
||||
|
Loading…
Reference in New Issue
Block a user