diff --git a/build.cake b/build.cake index c5d3f58..196093d 100644 --- a/build.cake +++ b/build.cake @@ -159,7 +159,7 @@ Task("Inno-Setup") .Does(() => { var path = MakeAbsolute(Directory(binDirectory)).FullPath + "\\"; var pluginDir = MakeAbsolute(Directory(binPluginDir)).FullPath + "\\"; - var plugins = new string[] { "spotify", "calculator", "clipboard" }; + var plugins = new string[] { "spotify", "calculator", "clipboard", "evernote" }; Information("Bin path : {0}: ", path); Information("Plugin path: {0}: ", pluginDir); @@ -171,7 +171,8 @@ Task("Inno-Setup") { "BinDirectory", path }, { "SpotifyPluginDir", String.Format(pluginDir, plugins[0]) }, { "CalculatorPluginDir", String.Format(pluginDir, plugins[1]) }, - { "ClipboardPluginDir", String.Format(pluginDir, plugins[2]) }, + { "ClipboardPluginDir", String.Format(pluginDir, plugins[2]) }, + { "EvernotePluginDir", String.Format(pluginDir, plugins[3]) } } }); }); @@ -191,7 +192,8 @@ Task("Release-GitHub") + publishDir + "/lanceur." + gitVersion.SemVer + ".setup.exe," + publishDir + "/plugin-calculator-" + gitVersion.SemVer + ".bin.zip," + publishDir + "/plugin-spotify-" + gitVersion.SemVer + ".bin.zip," - + publishDir + "/plugin-clipboard-" + gitVersion.SemVer + ".bin.zip" + + publishDir + "/plugin-clipboard-" + gitVersion.SemVer + ".bin.zip," + + publishDir + "/plugin-evernote-" + gitVersion.SemVer + ".bin.zip" }; GitReleaseManagerCreate(token, owner, "Lanceur", stg); diff --git a/setup.iss b/setup.iss index f8e1b5e..fb3637a 100644 --- a/setup.iss +++ b/setup.iss @@ -50,6 +50,7 @@ Source: "{#BinDirectory}*"; DestDir: "{app}"; Flags: ignoreversion recursesubdir Source: "{#SpotifyPluginDir}*"; DestDir: "{userappdata}\probel\lanceur\plugins\spotify\"; Flags: ignoreversion Source: "{#CalculatorPluginDir}*"; DestDir: "{userappdata}\probel\lanceur\plugins\calculator\"; Flags: ignoreversion Source: "{#ClipboardPluginDir}*"; DestDir: "{userappdata}\probel\lanceur\plugins\clipboard\"; Flags: ignoreversion +Source: "{#EvernotePluginDir}*"; DestDir: "{userappdata}\probel\lanceur\plugins\evernote\"; Flags: ignoreversion [Icons] Name: "{commonprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" diff --git a/src/Plugins/Probel.Lanceur.Plugin.Calculator/Probel.Lanceur.Plugin.Calculator.csproj b/src/Plugins/Probel.Lanceur.Plugin.Calculator/Probel.Lanceur.Plugin.Calculator.csproj index ecaf443..ca28514 100644 --- a/src/Plugins/Probel.Lanceur.Plugin.Calculator/Probel.Lanceur.Plugin.Calculator.csproj +++ b/src/Plugins/Probel.Lanceur.Plugin.Calculator/Probel.Lanceur.Plugin.Calculator.csproj @@ -112,10 +112,12 @@ {63FCDE3F-3D03-4075-90A4-4BF92996A32A} Probel.Lanceur.Infrastructure + False {f4db7268-da54-4141-9567-afbd6c5fe1ac} Probel.Lanceur.Plugin + False diff --git a/src/Plugins/Probel.Lanceur.Plugin.Clipboard/Probel.Lanceur.Plugin.Clipboard.csproj b/src/Plugins/Probel.Lanceur.Plugin.Clipboard/Probel.Lanceur.Plugin.Clipboard.csproj index fe2443d..b21b262 100644 --- a/src/Plugins/Probel.Lanceur.Plugin.Clipboard/Probel.Lanceur.Plugin.Clipboard.csproj +++ b/src/Plugins/Probel.Lanceur.Plugin.Clipboard/Probel.Lanceur.Plugin.Clipboard.csproj @@ -34,18 +34,23 @@ ..\..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll + False ..\..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.dll + False ..\..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.Core.dll + False ..\..\packages\ControlzEx.3.0.2.4\lib\net462\ControlzEx.dll + False ..\..\packages\MahApps.Metro.IconPacks.2.3.0\lib\net46\MahApps.Metro.IconPacks.dll + False ..\..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll @@ -107,6 +112,7 @@ {f4db7268-da54-4141-9567-afbd6c5fe1ac} Probel.Lanceur.Plugin + False diff --git a/src/Plugins/Probel.Lanceur.Plugin.Evernote/Models/Settings.cs b/src/Plugins/Probel.Lanceur.Plugin.Evernote/Models/Settings.cs index bbd190c..43dc99a 100644 --- a/src/Plugins/Probel.Lanceur.Plugin.Evernote/Models/Settings.cs +++ b/src/Plugins/Probel.Lanceur.Plugin.Evernote/Models/Settings.cs @@ -7,6 +7,12 @@ namespace Probel.Lanceur.Plugin.Evernote.Models { internal class Settings { + #region Fields + + private const string DefaultServer = "www.evernote.com"; + + #endregion Fields + #region Properties [JsonProperty("host")] @@ -16,7 +22,7 @@ internal class Settings public string Key { get; set; } [JsonProperty("server")] - public string Server { get; set; } = "sandbox.evernote.com"; + public string Server { get; set; } #endregion Properties @@ -33,6 +39,15 @@ internal static Settings Load() return s; } + internal static void Save(Settings src) + { + src.Normalise(); + + var json = JsonConvert.SerializeObject(src); + var p = GetPath(); + File.WriteAllText(p, json); + } + private static string GetPath() { var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); @@ -40,6 +55,14 @@ private static string GetPath() return path; } + private void Normalise() + { + if (string.IsNullOrEmpty(Server)) + { + Server = DefaultServer; + } + } + #endregion Methods } } \ No newline at end of file diff --git a/src/Plugins/Probel.Lanceur.Plugin.Evernote/Plugin.cs b/src/Plugins/Probel.Lanceur.Plugin.Evernote/Plugin.cs index 3cf90b3..02dabdd 100644 --- a/src/Plugins/Probel.Lanceur.Plugin.Evernote/Plugin.cs +++ b/src/Plugins/Probel.Lanceur.Plugin.Evernote/Plugin.cs @@ -10,9 +10,12 @@ public class Plugin : PluginBase public override void Execute(Cmdline cmd) { try - { + { var exec = new CmdExecutor(); - + if (exec.IsConfiguration(cmd.Parameters)) + { + exec.Configure(cmd.Parameters); + } if (exec.IsList(cmd.Parameters)) { var resul = exec.List(); diff --git a/src/Plugins/Probel.Lanceur.Plugin.Evernote/Probel.Lanceur.Plugin.Evernote.csproj b/src/Plugins/Probel.Lanceur.Plugin.Evernote/Probel.Lanceur.Plugin.Evernote.csproj index 649c1ba..0843ba8 100644 --- a/src/Plugins/Probel.Lanceur.Plugin.Evernote/Probel.Lanceur.Plugin.Evernote.csproj +++ b/src/Plugins/Probel.Lanceur.Plugin.Evernote/Probel.Lanceur.Plugin.Evernote.csproj @@ -92,6 +92,7 @@ + ResXFileCodeGenerator @@ -110,10 +111,12 @@ {63fcde3f-3d03-4075-90a4-4bf92996a32a} Probel.Lanceur.Infrastructure + False {f4db7268-da54-4141-9567-afbd6c5fe1ac} Probel.Lanceur.Plugin + False diff --git a/src/Plugins/Probel.Lanceur.Plugin.Evernote/Services/CmdExecutor.cs b/src/Plugins/Probel.Lanceur.Plugin.Evernote/Services/CmdExecutor.cs index 84e4c51..5400889 100644 --- a/src/Plugins/Probel.Lanceur.Plugin.Evernote/Services/CmdExecutor.cs +++ b/src/Plugins/Probel.Lanceur.Plugin.Evernote/Services/CmdExecutor.cs @@ -12,12 +12,24 @@ internal class CmdExecutor #endregion Fields - #region Constructors + #region Methods + public void Configure(string parameters) + { + var configurator = new Configurator(parameters); - #endregion Constructors + if (configurator.IsValid()) + { + var s = new Settings + { + Key = configurator.Key, + Server = configurator.Server, + Host = configurator.Host + }; - #region Methods + Settings.Save(s); + } + } public void Execute(Cmdline cmd) { @@ -25,6 +37,12 @@ public void Execute(Cmdline cmd) else if (IsNote(cmd.Parameters)) { CreateNote(cmd.Parameters); } } + public bool IsConfiguration(string parameters) + { + var regex = new Regex(@"(-c|config).*"); + return regex.IsMatch(parameters); + } + internal bool IsList(string parameters) { var regex = new Regex(@"(-l|list).*"); diff --git a/src/Plugins/Probel.Lanceur.Plugin.Evernote/Services/Configurator.cs b/src/Plugins/Probel.Lanceur.Plugin.Evernote/Services/Configurator.cs new file mode 100644 index 0000000..117c47e --- /dev/null +++ b/src/Plugins/Probel.Lanceur.Plugin.Evernote/Services/Configurator.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace Probel.Lanceur.Plugin.Evernote.Services +{ + internal class Configurator + { + #region Fields + + private readonly string _parameters; + private Dictionary _configuration = null; + private Regex _regex = new Regex(@"^(?(key|host|server)):(?.*)"); + + #endregion Fields + + #region Constructors + + public Configurator(string parameters) + { + this._parameters = parameters; + } + + #endregion Constructors + + #region Properties + + public string Host => Get("host"); + + public string Key => Get("key"); + + public string Server => Get("server"); + + #endregion Properties + + #region Methods + + public bool IsValid() => _parameters.StartsWith("-c") || _parameters.StartsWith("config"); + + private string Get(string key) + { + LoadConfiguration(); + return _configuration.ContainsKey(key) + ? _configuration[key] + : string.Empty; + } + + private string[] GetSplits() => _parameters.Split(' '); + + private void LoadConfiguration() + { + if (_configuration == null) + { + _configuration = new Dictionary(); + var splits = GetSplits(); + + foreach (var split in splits) + { + var groups = _regex.Match(split)?.Groups; + var key = groups["key"].Value; + var value = groups["value"].Value; + + if (_configuration.ContainsKey(key)) { throw new ArgumentException($"Evernote configuration is not valid. Configuration key '{key}' is already set."); } + else { _configuration.Add(key, value); } + } + } + } + + #endregion Methods + } +} \ No newline at end of file diff --git a/src/Plugins/Probel.Lanceur.Plugin.Spotify/Probel.Lanceur.Plugin.Spotify.csproj b/src/Plugins/Probel.Lanceur.Plugin.Spotify/Probel.Lanceur.Plugin.Spotify.csproj index 076ec02..b73b7ed 100644 --- a/src/Plugins/Probel.Lanceur.Plugin.Spotify/Probel.Lanceur.Plugin.Spotify.csproj +++ b/src/Plugins/Probel.Lanceur.Plugin.Spotify/Probel.Lanceur.Plugin.Spotify.csproj @@ -118,10 +118,12 @@ {63FCDE3F-3D03-4075-90A4-4BF92996A32A} Probel.Lanceur.Infrastructure + False {f4db7268-da54-4141-9567-afbd6c5fe1ac} Probel.Lanceur.Plugin + False diff --git a/src/Probel.Lanceur.Core/PluginsImpl/PluginLoader.cs b/src/Probel.Lanceur.Core/PluginsImpl/PluginLoader.cs index 91b8628..27ee395 100644 --- a/src/Probel.Lanceur.Core/PluginsImpl/PluginLoader.cs +++ b/src/Probel.Lanceur.Core/PluginsImpl/PluginLoader.cs @@ -69,7 +69,11 @@ where t.IsClass && t.GetInterfaces().Contains(typeof(IPlugin)) select t).FirstOrDefault(); - if (type != null) { pluginTypes.Add(dll, type); } + if (type != null) + { + _logger.Trace($"Loading plugin '{type}' from dll '{dll}'"); + pluginTypes.Add(dll, type); + } else { _logger.Warning($"Didn't find any plugins."); } } catch (ReflectionTypeLoadException ex) diff --git a/src/Probel.Lanceur.Core/ServicesImpl/CommandRunner.cs b/src/Probel.Lanceur.Core/ServicesImpl/CommandRunner.cs index a193da3..a2eccff 100644 --- a/src/Probel.Lanceur.Core/ServicesImpl/CommandRunner.cs +++ b/src/Probel.Lanceur.Core/ServicesImpl/CommandRunner.cs @@ -49,7 +49,9 @@ public ExecutionResult Execute(Alias alias) { return _keywordService.ExecuteActionFor(alias.Name, alias.Arguments); } - else { return ExecutionResult.Failure; } + else { + _log.Warning($"Alias '{alias.Name}' does not exist in the database."); + return ExecutionResult.Failure; } } private ProcessStartInfo GetProcessStartInfo(Alias alias) diff --git a/src/Probel.Lanceur/Controls/ResultList.xaml.cs b/src/Probel.Lanceur/Controls/ResultList.xaml.cs index 2966a18..84b951d 100644 --- a/src/Probel.Lanceur/Controls/ResultList.xaml.cs +++ b/src/Probel.Lanceur/Controls/ResultList.xaml.cs @@ -203,7 +203,7 @@ private void OnAliasClicked() if (si is SwitchSessionResult s) { alias = (AliasText)s; } else if (si is AliasText at) { alias = at; } - else { throw new NotSupportedException($"The selected item of the result of type '{si.GetType()}' is not supported."); } + else { throw new NotSupportedException($"The selected item of the result of type '{si?.GetType().ToString() ?? "NULL"}' is not supported."); } AliasClicked?.Invoke(this, new AliasTextEventArgs(alias)); } diff --git a/src/Version.cs b/src/Version.cs index 4e90b90..61709e4 100644 --- a/src/Version.cs +++ b/src/Version.cs @@ -1,6 +1,6 @@ using System.Reflection; -[assembly: AssemblyVersion("0.7.0.31")] +[assembly: AssemblyVersion("0.7.0.33")] [assembly: AssemblyFileVersion("0.7.0.0")] -[assembly: AssemblyInformationalVersion("0.7.0-beta.31+Branch.develop.Sha.38aa982a498a90e6c3b9b09fe0bbd3b7396061eb")] +[assembly: AssemblyInformationalVersion("0.7.0-beta.33+Branch.develop.Sha.96c0c8a18271dba2eb2832c80947f729c65f048f")]