diff --git a/WinAlfred.Plugin.System/CMD.cs b/WinAlfred.Plugin.System/CMD.cs new file mode 100644 index 0000000000..1175f58d7b --- /dev/null +++ b/WinAlfred.Plugin.System/CMD.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WinAlfred.Plugin.System +{ + public class CMD:IPlugin + { + public List Query(Query query) + { + throw new NotImplementedException(); + } + + public void Init() + { + throw new NotImplementedException(); + } + } +} diff --git a/WinAlfred.Plugin.System/ISystemPlugin.cs b/WinAlfred.Plugin.System/ISystemPlugin.cs new file mode 100644 index 0000000000..3eb6f9dbf6 --- /dev/null +++ b/WinAlfred.Plugin.System/ISystemPlugin.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WinAlfred.Plugin.System +{ + public interface ISystemPlugin : IPlugin + { + } +} diff --git a/WinAlfred.Plugin.System/Properties/AssemblyInfo.cs b/WinAlfred.Plugin.System/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..4e78f925c4 --- /dev/null +++ b/WinAlfred.Plugin.System/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WinAlfred.Plugin.System")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Oracle Corporation")] +[assembly: AssemblyProduct("WinAlfred.Plugin.System")] +[assembly: AssemblyCopyright("Copyright © Oracle Corporation 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("bab8d3dc-d6be-42b3-8aa4-24801d667528")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj b/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj new file mode 100644 index 0000000000..ae8c238f6c --- /dev/null +++ b/WinAlfred.Plugin.System/WinAlfred.Plugin.System.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8} + Library + Properties + WinAlfred.Plugin.System + WinAlfred.Plugin.System + v3.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80} + WinAlfred.Plugin + + + + + \ No newline at end of file diff --git a/WinAlfred.Plugin/PluginMetadata.cs b/WinAlfred.Plugin/PluginMetadata.cs index 23d54b8c24..167e299e51 100644 --- a/WinAlfred.Plugin/PluginMetadata.cs +++ b/WinAlfred.Plugin/PluginMetadata.cs @@ -16,5 +16,6 @@ namespace WinAlfred.Plugin public string ExecuteFileName { get; set; } public string PluginDirecotry { get; set; } public string ActionKeyword { get; set; } + public PluginType PluginType { get; set; } } } diff --git a/WinAlfred.Plugin/PluginType.cs b/WinAlfred.Plugin/PluginType.cs new file mode 100644 index 0000000000..1db293c16a --- /dev/null +++ b/WinAlfred.Plugin/PluginType.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace WinAlfred.Plugin +{ + public enum PluginType + { + System, + ThirdParty + } +} diff --git a/WinAlfred.Plugin/WinAlfred.Plugin.csproj b/WinAlfred.Plugin/WinAlfred.Plugin.csproj index e0b1b3869d..8d13730b5d 100644 --- a/WinAlfred.Plugin/WinAlfred.Plugin.csproj +++ b/WinAlfred.Plugin/WinAlfred.Plugin.csproj @@ -61,6 +61,7 @@ + diff --git a/WinAlfred.sln b/WinAlfred.sln index 1b27e33db8..a90d1236b2 100644 --- a/WinAlfred.sln +++ b/WinAlfred.sln @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred", "WinAlfred\WinA EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PyWinAlfred", "PyWinAlfred\PyWinAlfred.vcxproj", "{D03FD663-38A8-4C1A-8431-EB44F93E7EBA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinAlfred.Plugin.System", "WinAlfred.Plugin.System\WinAlfred.Plugin.System.csproj", "{69CE0206-CB41-453D-88AF-DF86092EF9B8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -104,6 +106,20 @@ Global {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x64.Build.0 = Release|x64 {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x86.ActiveCfg = Release|Win32 {D03FD663-38A8-4C1A-8431-EB44F93E7EBA}.Release|x86.Build.0 = Release|Win32 + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|Win32.ActiveCfg = Debug|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|x64.ActiveCfg = Debug|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Debug|x86.ActiveCfg = Debug|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|Any CPU.Build.0 = Release|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|Win32.ActiveCfg = Release|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|x64.ActiveCfg = Release|Any CPU + {69CE0206-CB41-453D-88AF-DF86092EF9B8}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WinAlfred/Commands/CommandDispatcher.cs b/WinAlfred/Commands/CommandDispatcher.cs new file mode 100644 index 0000000000..e6f0f691ce --- /dev/null +++ b/WinAlfred/Commands/CommandDispatcher.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using WinAlfred.Helper; +using WinAlfred.Plugin; + +namespace WinAlfred.Commands +{ + public class CommandDispatcher + { + private PluginCommand pluginCmd = new PluginCommand(); + private SystemCommand systemCmd = new SystemCommand(); + + //public delegate void resultUpdateDelegate(List results); + + //public event resultUpdateDelegate OnResultUpdateEvent; + + //protected virtual void OnOnResultUpdateEvent(List list) + //{ + // resultUpdateDelegate handler = OnResultUpdateEvent; + // if (handler != null) handler(list); + //} + + public void DispatchCommand(Query query) + { + systemCmd.Dispatch(query); + pluginCmd.Dispatch(query); + } + } +} diff --git a/WinAlfred/Commands/PluginCommand.cs b/WinAlfred/Commands/PluginCommand.cs new file mode 100644 index 0000000000..37e1de91d5 --- /dev/null +++ b/WinAlfred/Commands/PluginCommand.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using WinAlfred.Helper; +using WinAlfred.Plugin; +using WinAlfred.PluginLoader; + +namespace WinAlfred.Commands +{ + public class PluginCommand + { + public void Dispatch(Query q) + { + //ThreadPool.QueueUserWorkItem(state => + //{ + foreach (PluginPair pair in Plugins.AllPlugins) + { + if (pair.Metadata.ActionKeyword == q.ActionName) + { + try + { + pair.Plugin.Query(q).ForEach(o => o.PluginDirectory = pair.Metadata.PluginDirecotry); + } + catch (Exception queryException) + { + Log.Error(string.Format("Plugin {0} query failed: {1}", pair.Metadata.Name, + queryException.Message)); +#if (DEBUG) + { + throw; + } +#endif + } + } + } + resultCtrl.Dispatcher.Invoke(new Action(() => + { + resultCtrl.AddResults(results.OrderByDescending(o => o.Score).ToList()); + resultCtrl.SelectFirst(); + })); + //}); + } + } +} diff --git a/WinAlfred/Commands/SystemCommand.cs b/WinAlfred/Commands/SystemCommand.cs new file mode 100644 index 0000000000..4544150694 --- /dev/null +++ b/WinAlfred/Commands/SystemCommand.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using WinAlfred.Plugin; + +namespace WinAlfred.Commands +{ + public class SystemCommand + { + public void Dispatch(Query query) + { + + } + } +} diff --git a/WinAlfred/MainWindow.xaml.cs b/WinAlfred/MainWindow.xaml.cs index 0c3d2aa2c3..9b5dbf78ab 100644 --- a/WinAlfred/MainWindow.xaml.cs +++ b/WinAlfred/MainWindow.xaml.cs @@ -8,6 +8,7 @@ using System.Windows.Controls; using System.Windows.Forms; using System.Windows.Input; using System.Windows.Threading; +using WinAlfred.Commands; using WinAlfred.Helper; using WinAlfred.Plugin; using WinAlfred.PluginLoader; @@ -18,9 +19,9 @@ namespace WinAlfred public partial class MainWindow : Window { private KeyboardHook hook = new KeyboardHook(); - public List plugins = new List(); private List results = new List(); private NotifyIcon notifyIcon = null; + private CommandDispatcher cmdDispatcher = new CommandDispatcher(); public MainWindow() { @@ -67,38 +68,8 @@ namespace WinAlfred private void TextBoxBase_OnTextChanged(object sender, TextChangedEventArgs e) { - string query = tbQuery.Text; - //ThreadPool.QueueUserWorkItem(state => - //{ - results.Clear(); - foreach (PluginPair pair in plugins) - { - var q = new Query(query); - if (pair.Metadata.ActionKeyword == q.ActionName) - { - try - { - results.AddRange(pair.Plugin.Query(q)); - results.ForEach(o => o.PluginDirectory = pair.Metadata.PluginDirecotry); - } - catch (Exception queryException) - { - Log.Error(string.Format("Plugin {0} query failed: {1}", pair.Metadata.Name, - queryException.Message)); -#if (DEBUG) - { - throw; - } -#endif - } - } - } - resultCtrl.Dispatcher.Invoke(new Action(() => - { - resultCtrl.AddResults(results.OrderByDescending(o => o.Score).ToList()); - resultCtrl.SelectFirst(); - })); - //}); + var q = new Query(tbQuery.Text); + cmdDispatcher.DispatchCommand(q); } private void HideWinAlfred() @@ -116,9 +87,7 @@ namespace WinAlfred private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { - plugins.AddRange(new PythonPluginLoader().LoadPlugin()); - plugins.AddRange(new CSharpPluginLoader().LoadPlugin()); - + Plugins.Init(); ShowWinAlfred(); InitialTray(); } diff --git a/WinAlfred/PluginLoader/BasePluginLoader.cs b/WinAlfred/PluginLoader/BasePluginLoader.cs index d16042b494..7aeb83dd04 100644 --- a/WinAlfred/PluginLoader/BasePluginLoader.cs +++ b/WinAlfred/PluginLoader/BasePluginLoader.cs @@ -1,8 +1,11 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; +using System.Reflection; using WinAlfred.Helper; using WinAlfred.Plugin; +using WinAlfred.Plugin.System; namespace WinAlfred.PluginLoader { @@ -21,11 +24,34 @@ namespace WinAlfred.PluginLoader private static void ParsePlugins() { - ParseDirectories(); - ParsePackagedPlugin(); + ParseSystemPlugins(); + ParseThirdPartyPlugins(); } - private static void ParseDirectories() + private static void ParseSystemPlugins() + { + try + { + Assembly asm = Assembly.GetAssembly(typeof (CMD)); + List types = asm.GetTypes().Where(o => o.GetInterfaces().Contains(typeof(ISystemPlugin))).ToList(); + foreach (Type type in types) + { + ISystemPlugin sysPlugin = Activator.CreateInstance(types[0]) as ISystemPlugin; + PluginMetadata metadata = new PluginMetadata(); + } + } + catch (Exception e) + { + Log.Error(string.Format("Cound't load system plugin: {0}", e.Message)); +#if (DEBUG) + { + throw; + } +#endif + } + } + + private static void ParseThirdPartyPlugins() { string[] directories = Directory.GetDirectories(PluginPath); foreach (string directory in directories) @@ -35,11 +61,6 @@ namespace WinAlfred.PluginLoader } } - private static void ParsePackagedPlugin() - { - - } - private static PluginMetadata GetMetadataFromIni(string directory) { string iniPath = directory + "\\" + PluginConfigName; @@ -50,7 +71,6 @@ namespace WinAlfred.PluginLoader return null; } - try { PluginMetadata metadata = new PluginMetadata(); @@ -60,6 +80,7 @@ namespace WinAlfred.PluginLoader metadata.Description = ini.GetSetting("plugin", "Description"); metadata.Language = ini.GetSetting("plugin", "Language"); metadata.Version = ini.GetSetting("plugin", "Version"); + metadata.PluginType = PluginType.ThirdParty; metadata.ActionKeyword = ini.GetSetting("plugin", "ActionKeyword"); metadata.ExecuteFilePath = AppDomain.CurrentDomain.BaseDirectory + directory + "\\" + ini.GetSetting("plugin", "ExecuteFile"); metadata.PluginDirecotry = AppDomain.CurrentDomain.BaseDirectory + directory + "\\"; diff --git a/WinAlfred/PluginLoader/Plugins.cs b/WinAlfred/PluginLoader/Plugins.cs new file mode 100644 index 0000000000..b744b351a5 --- /dev/null +++ b/WinAlfred/PluginLoader/Plugins.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using WinAlfred.Plugin; + +namespace WinAlfred.PluginLoader +{ + public static class Plugins + { + private static List plugins = new List(); + + public static void Init() + { + plugins.Clear(); + plugins.AddRange(new PythonPluginLoader().LoadPlugin()); + plugins.AddRange(new CSharpPluginLoader().LoadPlugin()); + } + + public static List AllPlugins + { + get { return plugins; } + } + } +} diff --git a/WinAlfred/WinAlfred.csproj b/WinAlfred/WinAlfred.csproj index 02dcadb309..5806e4e447 100644 --- a/WinAlfred/WinAlfred.csproj +++ b/WinAlfred/WinAlfred.csproj @@ -64,12 +64,16 @@ MSBuild:Compile Designer + + + + @@ -128,6 +132,10 @@ + + {69ce0206-cb41-453d-88af-df86092ef9b8} + WinAlfred.Plugin.System + {8451ECDD-2EA4-4966-BB0A-7BBC40138E80} WinAlfred.Plugin