Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Close #123 - Release Evernote plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jibedoubleve committed May 18, 2020
1 parent c75df55 commit 851b039
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 14 deletions.
8 changes: 5 additions & 3 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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]) }
}
});
});
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@
<ProjectReference Include="..\..\Probel.Lanceur.Infrastructure\Probel.Lanceur.Infrastructure.csproj">
<Project>{63FCDE3F-3D03-4075-90A4-4BF92996A32A}</Project>
<Name>Probel.Lanceur.Infrastructure</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\Probel.Lanceur.Plugin\Probel.Lanceur.Plugin.csproj">
<Project>{f4db7268-da54-4141-9567-afbd6c5fe1ac}</Project>
<Name>Probel.Lanceur.Plugin</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,23 @@
<ItemGroup>
<Reference Include="Caliburn.Micro, Version=3.2.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\..\packages\Caliburn.Micro.Core.3.2.0\lib\net45\Caliburn.Micro.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Caliburn.Micro.Platform, Version=3.2.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Caliburn.Micro.Platform.Core, Version=3.2.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
<HintPath>..\..\packages\Caliburn.Micro.3.2.0\lib\net45\Caliburn.Micro.Platform.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="ControlzEx, Version=3.0.2.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\ControlzEx.3.0.2.4\lib\net462\ControlzEx.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MahApps.Metro.IconPacks, Version=2.3.0.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\MahApps.Metro.IconPacks.2.3.0\lib\net46\MahApps.Metro.IconPacks.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down Expand Up @@ -107,6 +112,7 @@
<ProjectReference Include="..\..\Probel.Lanceur.Plugin\Probel.Lanceur.Plugin.csproj">
<Project>{f4db7268-da54-4141-9567-afbd6c5fe1ac}</Project>
<Name>Probel.Lanceur.Plugin</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup />
Expand Down
25 changes: 24 additions & 1 deletion src/Plugins/Probel.Lanceur.Plugin.Evernote/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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

Expand All @@ -33,13 +39,30 @@ 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);
var path = Path.Combine(dir, "api.json");
return path;
}

private void Normalise()
{
if (string.IsNullOrEmpty(Server))
{
Server = DefaultServer;
}
}

#endregion Methods
}
}
7 changes: 5 additions & 2 deletions src/Plugins/Probel.Lanceur.Plugin.Evernote/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
</Compile>
<Compile Include="Models\Settings.cs" />
<Compile Include="Services\CmdExecutor.cs" />
<Compile Include="Services\Configurator.cs" />
<Compile Include="Services\EvernoteService.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand All @@ -110,10 +111,12 @@
<ProjectReference Include="..\..\Probel.Lanceur.Infrastructure\Probel.Lanceur.Infrastructure.csproj">
<Project>{63fcde3f-3d03-4075-90a4-4bf92996a32a}</Project>
<Name>Probel.Lanceur.Infrastructure</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\Probel.Lanceur.Plugin\Probel.Lanceur.Plugin.csproj">
<Project>{f4db7268-da54-4141-9567-afbd6c5fe1ac}</Project>
<Name>Probel.Lanceur.Plugin</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup />
Expand Down
24 changes: 21 additions & 3 deletions src/Plugins/Probel.Lanceur.Plugin.Evernote/Services/CmdExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,37 @@ 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)
{
if (IsReminder(cmd.Parameters)) { CreateReminder(cmd.Parameters); }
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).*");
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, string> _configuration = null;
private Regex _regex = new Regex(@"^(?<key>(key|host|server)):(?<value>.*)");

#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<string, string>();
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@
<ProjectReference Include="..\..\Probel.Lanceur.Infrastructure\Probel.Lanceur.Infrastructure.csproj">
<Project>{63FCDE3F-3D03-4075-90A4-4BF92996A32A}</Project>
<Name>Probel.Lanceur.Infrastructure</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\Probel.Lanceur.Plugin\Probel.Lanceur.Plugin.csproj">
<Project>{f4db7268-da54-4141-9567-afbd6c5fe1ac}</Project>
<Name>Probel.Lanceur.Plugin</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
6 changes: 5 additions & 1 deletion src/Probel.Lanceur.Core/PluginsImpl/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/Probel.Lanceur.Core/ServicesImpl/CommandRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Probel.Lanceur/Controls/ResultList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions src/Version.cs
Original file line number Diff line number Diff line change
@@ -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")]

0 comments on commit 851b039

Please sign in to comment.