From 890397bae7061cdd8d05acefa4d1bd58c46eeb9e Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sun, 28 Dec 2014 15:17:58 +0800 Subject: [PATCH] Refactoring. Move plugin related work to Wox.Core --- Wox.Core/Exception/WoxCritialException.cs | 17 +++++++++++++++++ Wox.Core/Exception/WoxException.cs | 14 ++++++++++++++ .../Exception}/WoxHttpException.cs | 7 +------ .../Exception}/WoxJsonRPCException.cs | 2 +- Wox.Core/Plugin/CSharpPluginLoader.cs | 2 +- Wox.Core/Plugin/JsonRPCPlugin.cs | 5 ++--- Wox.Core/Plugin/JsonRPCPluginLoader.cs | 2 +- Wox.Core/Plugin/PluginConfig.cs | 4 ++-- Wox.Core/Plugin/PluginInstaller.cs | 8 ++++---- .../UserPluginQueryDispatcher.cs | 2 +- Wox.Core/Wox.Core.csproj | 4 ++++ Wox.Infrastructure/Exceptions/WoxException.cs | 13 ------------- Wox.Infrastructure/Wox.Infrastructure.csproj | 3 --- .../ControlPanel/ControlPanelItem.cs | 2 +- 14 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 Wox.Core/Exception/WoxCritialException.cs create mode 100644 Wox.Core/Exception/WoxException.cs rename {Wox.Infrastructure/Exceptions => Wox.Core/Exception}/WoxHttpException.cs (51%) rename {Wox.Infrastructure/Exceptions => Wox.Core/Exception}/WoxJsonRPCException.cs (78%) delete mode 100644 Wox.Infrastructure/Exceptions/WoxException.cs diff --git a/Wox.Core/Exception/WoxCritialException.cs b/Wox.Core/Exception/WoxCritialException.cs new file mode 100644 index 0000000000..76aea3dea6 --- /dev/null +++ b/Wox.Core/Exception/WoxCritialException.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Wox.Core.Exception +{ + /// + /// Represent exceptions that wox can't handle and MUST close running Wox. + /// + public class WoxCritialException : WoxException + { + public WoxCritialException(string msg) : base(msg) + { + } + } +} diff --git a/Wox.Core/Exception/WoxException.cs b/Wox.Core/Exception/WoxException.cs new file mode 100644 index 0000000000..a5df7a3d34 --- /dev/null +++ b/Wox.Core/Exception/WoxException.cs @@ -0,0 +1,14 @@ +namespace Wox.Core.Exception +{ + /// + /// Base Wox Exceptions + /// + public class WoxException : System.Exception + { + public WoxException(string msg) + : base(msg) + { + + } + } +} diff --git a/Wox.Infrastructure/Exceptions/WoxHttpException.cs b/Wox.Core/Exception/WoxHttpException.cs similarity index 51% rename from Wox.Infrastructure/Exceptions/WoxHttpException.cs rename to Wox.Core/Exception/WoxHttpException.cs index 026d1d8ab9..55e3431a0e 100644 --- a/Wox.Infrastructure/Exceptions/WoxHttpException.cs +++ b/Wox.Core/Exception/WoxHttpException.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Wox.Infrastructure.Exceptions +namespace Wox.Core.Exception { public class WoxHttpException :WoxException { diff --git a/Wox.Infrastructure/Exceptions/WoxJsonRPCException.cs b/Wox.Core/Exception/WoxJsonRPCException.cs similarity index 78% rename from Wox.Infrastructure/Exceptions/WoxJsonRPCException.cs rename to Wox.Core/Exception/WoxJsonRPCException.cs index 0e984a3e6f..d3c0bfb0da 100644 --- a/Wox.Infrastructure/Exceptions/WoxJsonRPCException.cs +++ b/Wox.Core/Exception/WoxJsonRPCException.cs @@ -1,4 +1,4 @@ -namespace Wox.Infrastructure.Exceptions +namespace Wox.Core.Exception { public class WoxJsonRPCException : WoxException { diff --git a/Wox.Core/Plugin/CSharpPluginLoader.cs b/Wox.Core/Plugin/CSharpPluginLoader.cs index 9cfdc56734..5910a6bebf 100644 --- a/Wox.Core/Plugin/CSharpPluginLoader.cs +++ b/Wox.Core/Plugin/CSharpPluginLoader.cs @@ -44,7 +44,7 @@ namespace Wox.Core.Plugin plugins.Add(pair); } } - catch (Exception e) + catch (System.Exception e) { Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message)); #if (DEBUG) diff --git a/Wox.Core/Plugin/JsonRPCPlugin.cs b/Wox.Core/Plugin/JsonRPCPlugin.cs index 0809826300..fd0514af36 100644 --- a/Wox.Core/Plugin/JsonRPCPlugin.cs +++ b/Wox.Core/Plugin/JsonRPCPlugin.cs @@ -6,7 +6,6 @@ using System.Reflection; using System.Threading; using System.Windows.Forms; using Newtonsoft.Json; -using Wox.Infrastructure.Exceptions; using Wox.Infrastructure.Logger; using Wox.Plugin; @@ -73,7 +72,7 @@ namespace Wox.Core.Plugin } return results; } - catch (Exception e) + catch (System.Exception e) { Log.Error(e.Message); } @@ -90,7 +89,7 @@ namespace Wox.Core.Plugin { methodInfo.Invoke(PluginManager.API, parameters); } - catch (Exception) + catch (System.Exception) { #if (DEBUG) { diff --git a/Wox.Core/Plugin/JsonRPCPluginLoader.cs b/Wox.Core/Plugin/JsonRPCPluginLoader.cs index 234da6a25d..0bf35979c9 100644 --- a/Wox.Core/Plugin/JsonRPCPluginLoader.cs +++ b/Wox.Core/Plugin/JsonRPCPluginLoader.cs @@ -13,7 +13,7 @@ namespace Wox.Core.Plugin return jsonRPCPluginMetadatas.Select(metadata => new PluginPair() { - Plugin = jsonRPCPlugin, + Plugin = new T(), //every JsonRPC plugin should has its own plugin instance Metadata = metadata }).ToList(); } diff --git a/Wox.Core/Plugin/PluginConfig.cs b/Wox.Core/Plugin/PluginConfig.cs index 5d6c8137d4..6d2cba1488 100644 --- a/Wox.Core/Plugin/PluginConfig.cs +++ b/Wox.Core/Plugin/PluginConfig.cs @@ -4,7 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; using Newtonsoft.Json; -using Wox.Infrastructure.Exceptions; +using Wox.Core.Exception; using Wox.Infrastructure.Logger; using Wox.Infrastructure.Storage.UserSettings; using Wox.Plugin; @@ -91,7 +91,7 @@ namespace Wox.Core.Plugin metadata.PluginType = PluginType.User; metadata.PluginDirectory = pluginDirectory; } - catch (Exception) + catch (System.Exception) { string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath); Log.Warn(error); diff --git a/Wox.Core/Plugin/PluginInstaller.cs b/Wox.Core/Plugin/PluginInstaller.cs index 3388c8c621..25e7d3b3c1 100644 --- a/Wox.Core/Plugin/PluginInstaller.cs +++ b/Wox.Core/Plugin/PluginInstaller.cs @@ -114,12 +114,12 @@ namespace Wox.Core.Plugin metadata.PluginType = PluginType.User; metadata.PluginDirectory = pluginDirectory; } - catch (Exception) + catch (System.Exception) { string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath); #if (DEBUG) { - throw new Exception(error); + throw new System.Exception(error); } #endif return null; @@ -132,7 +132,7 @@ namespace Wox.Core.Plugin metadata.Language); #if (DEBUG) { - throw new Exception(error); + throw new System.Exception(error); } #endif return null; @@ -143,7 +143,7 @@ namespace Wox.Core.Plugin metadata.ExecuteFilePath); #if (DEBUG) { - throw new Exception(error); + throw new System.Exception(error); } #endif return null; diff --git a/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs b/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs index 6c709e5bdc..3b96d2c3a8 100644 --- a/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs +++ b/Wox.Core/Plugin/QueryDispatcher/UserPluginQueryDispatcher.cs @@ -30,7 +30,7 @@ namespace Wox.Core.Plugin.QueryDispatcher List results = userPlugin.Plugin.Query(query) ?? new List(); PluginManager.API.PushResults(query,userPlugin.Metadata,results); } - catch (Exception queryException) + catch (System.Exception queryException) { Log.Error(string.Format("Plugin {0} query failed: {1}", userPlugin.Metadata.Name, queryException.Message)); diff --git a/Wox.Core/Wox.Core.csproj b/Wox.Core/Wox.Core.csproj index 237c191560..1aacac6d10 100644 --- a/Wox.Core/Wox.Core.csproj +++ b/Wox.Core/Wox.Core.csproj @@ -49,6 +49,10 @@ + + + + diff --git a/Wox.Infrastructure/Exceptions/WoxException.cs b/Wox.Infrastructure/Exceptions/WoxException.cs deleted file mode 100644 index 581f36edb7..0000000000 --- a/Wox.Infrastructure/Exceptions/WoxException.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace Wox.Infrastructure.Exceptions -{ - public class WoxException : Exception - { - public WoxException(string msg) - : base(msg) - { - - } - } -} diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index e3cfa6398a..7c84bf829c 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -56,9 +56,6 @@ - - - diff --git a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs index 6d76e269a0..5781fa2910 100644 --- a/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs +++ b/Wox.Plugin.SystemPlugins/ControlPanel/ControlPanelItem.cs @@ -22,4 +22,4 @@ namespace Wox.Plugin.SystemPlugins.ControlPanel GUID = newGUID; } } -} +} \ No newline at end of file