Skip to content

Commit

Permalink
Merge pull request #94 from XanatosX/feature/upgrade-plugin-view-mode…
Browse files Browse the repository at this point in the history
…l-to-mvvm-toolkit

[Feature] upgrade plugin view model to mvvm toolkit
  • Loading branch information
XanatosX authored Jun 14, 2023
2 parents 071763d + 59611d8 commit 937d080
Show file tree
Hide file tree
Showing 49 changed files with 592 additions and 464 deletions.
41 changes: 0 additions & 41 deletions src/CorePlugin/Assets/ResourceLoader.cs

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion src/CorePlugin/Assets/Updating/OpenGitHubDescription.txt

This file was deleted.

12 changes: 4 additions & 8 deletions src/CorePlugin/CorePlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Assets\Updating\DownloadGitHubDescription.txt" />
<None Remove="Assets\Updating\OpenGitHubDescription.txt" />
<None Remove="Resources\XmlFormatterDescription.md" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Assets\Updating\DownloadGitHubDescription.txt" />
<EmbeddedResource Include="Assets\Updating\OpenGitHubDescription.txt" />
<EmbeddedResource Include="Resources\DownloadGitHubDescription.md" />
<EmbeddedResource Include="Resources\OpenGitHubDescription.md" />
<EmbeddedResource Include="Resources\XmlFormatterDescription.md" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PluginFramework\PluginFramework.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Assets\Formatter\" />
</ItemGroup>

</Project>
11 changes: 10 additions & 1 deletion src/CorePlugin/Formatter/XmlFormatterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ class XmlFormatterProvider : BaseFormatter
/// <summary>
/// Create a new instance of this class
/// </summary>
public XmlFormatterProvider() : base("xml", new PluginInformation("Xml Formatter", "Convert xml files", "XanatosX", new Version(1, 0)))
public XmlFormatterProvider() : base(
"xml",
new PluginInformation(
"Xml Formatter",
"Convert xml files",
"XanatosX",
new Version(1, 1),
"https://github.com/XanatosX",
"https://github.com/XanatosX/XmlFormatter"))
{
Information.SetMarkdownDescription(LoadFromEmbeddedResource("CorePlugin.Resources.XmlFormatterDescription.md"));
}

/// <inheritdoc/>
Expand Down
5 changes: 5 additions & 0 deletions src/CorePlugin/Resources/DownloadGitHubDescription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Information

Download the newest release of this Software from GitHub.
It will open up the artifact zips so that you can copy it over to your installation
directory after completion.
4 changes: 4 additions & 0 deletions src/CorePlugin/Resources/OpenGitHubDescription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Information

This download plugin will open the GitHub release page and show you the newest update to download.
You have to download this on your own and update the application by hand.
4 changes: 4 additions & 0 deletions src/CorePlugin/Resources/XmlFormatterDescription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Information

This is the default plugin for the XML Formatter. It will allow you to convert XML files into a
Human readable format or convert it back to an efficient one.
15 changes: 8 additions & 7 deletions src/CorePlugin/Updating/DownloadGitHubReleaseStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using CorePlugin.Assets;
using Octokit;
using PluginFramework.DataContainer;
using PluginFramework.DataContainer;
using PluginFramework.Update;
using System;
using System.Diagnostics;
Expand All @@ -21,10 +19,13 @@ class DownloadGitHubReleaseStrategy : BaseUpdate
/// </summary>
public DownloadGitHubReleaseStrategy()
{
ResourceLoader loader = new ResourceLoader();

string description = loader.LoadResource("Updating.DownloadGitHubDescription.txt");
Information = new PluginInformation("Download GitHub releases", description, "XanatosX", new Version(1, 1, 1));
Information = new PluginInformation("Download GitHub releases",
"Download the github release as zip and open the file",
"XanatosX",
new Version(1, 1, 1),
"https://github.com/XanatosX",
"https://github.com/XanatosX/XmlFormatter");
Information.SetMarkdownDescription(LoadFromEmbeddedResource("CorePlugin.Resources.DownloadGitHubDescription.md"));
}

/// <inheritdoc/>
Expand Down
15 changes: 9 additions & 6 deletions src/CorePlugin/Updating/OpenGitHubReleasesStrategy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CorePlugin.Assets;
using PluginFramework.DataContainer;
using PluginFramework.DataContainer;
using PluginFramework.Update;
using PluginFramework.Utils;
using System;
Expand All @@ -22,10 +21,14 @@ class OpenGitHubReleasesStrategy : BaseUpdate
/// </summary>
public OpenGitHubReleasesStrategy()
{
ResourceLoader loader = new ResourceLoader();

string description = loader.LoadResource("Updating.OpenGitHubDescription.txt");
Information = new PluginInformation("Open GitHub releases", description, "XanatosX", new Version(1, 1, 2));
Information = new PluginInformation(
"Open GitHub releases",
"Open the latest github release in the browser",
"XanatosX",
new Version(1, 1, 3),
"https://github.com/XanatosX",
"https://github.com/XanatosX/XmlFormatter");
Information.SetMarkdownDescription(LoadFromEmbeddedResource("CorePlugin.Resources.OpenGitHubDescription.md"));
urlOpener = new UrlOpener();
}

Expand Down
10 changes: 9 additions & 1 deletion src/JsonPlugin/JsonFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ public class JsonFormatter : BaseFormatter
public JsonFormatter()
: base(
"json",
new PluginInformation("Json formatter", "This plugin will convert json files", "XanatosX", new Version(1, 0))
new PluginInformation(
"Json formatter",
"This plugin will convert json files",
"XanatosX",
new Version(1, 1),
"https://github.com/XanatosX",
"https://github.com/XanatosX/XmlFormatter"
)
)
{
Information.SetMarkdownDescription(LoadFromEmbeddedResource("JsonPlugin.Resources.Description.md"));
}

/// <inheritdoc/>
Expand Down
8 changes: 8 additions & 0 deletions src/JsonPlugin/JsonPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
<None Remove="Resources\Description.md" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\Description.md" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions src/JsonPlugin/Resources/Description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Information

This plugin will convert json files into a human readable format
or convert them back to a space saving one.

The plugin can only be used in connection with the Xml Formatter tool.

### Additional

This Plugin is delivered as an extension to the Xml Formatter by the Author itself.
50 changes: 49 additions & 1 deletion src/PluginFramework/DataContainer/PluginInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,31 @@ public class PluginInformation
/// </summary>
public string Name { get; }

/// <summary>
/// The url to the project
/// </summary>
public string ProjectUrl { get; }

/// <summary>
/// The description of the plugin
/// </summary>
public string Description { get; }

/// <summary>
/// THe Markdown description for this plugin information
/// </summary>
public string MarkdownDescription { get; private set; }

/// <summary>
/// The author name of the plugin
/// </summary>
public string Author { get; }

/// <summary>
/// The url to the author
/// </summary>
public string AuthorUrl { get; }

/// <summary>
/// The version of the plugin
/// </summary>
Expand All @@ -34,12 +49,45 @@ public class PluginInformation
/// <param name="description">Description of the plugin</param>
/// <param name="author">Author name of the plugin</param>
/// <param name="version">The version of the plugin</param>
public PluginInformation(string name, string description, string author, Version version)
public PluginInformation(string name, string description, string author, Version version) : this(name, description, author, version, null)
{
}

/// <summary>
/// Create a new plugin information instance
/// </summary>
/// <param name="name">Name of the plugin</param>
/// <param name="description">Description of the plugin</param>
/// <param name="author">Author name of the plugin</param>
/// <param name="version">The version of the plugin</param>
/// <param name="authorUrl">The url with information about the author</param>
public PluginInformation(string name, string description, string author, Version version, string authorUrl) : this(name, description, author, version, authorUrl, null)
{
}

/// <summary>
/// Create a new plugin information instance
/// </summary>
/// <param name="name">Name of the plugin</param>
/// <param name="description">Description of the plugin</param>
/// <param name="author">Author name of the plugin</param>
/// <param name="version">The version of the plugin</param>
/// <param name="authorUrl">The url with information about the author</param>
/// <param name="projectUrl">The url to the project</param>
public PluginInformation(string name, string description, string author, Version version, string authorUrl, string projectUrl)
{
Name = name;
Description = description;
Author = author;
Version = version;
AuthorUrl = authorUrl;
ProjectUrl = projectUrl;
SetMarkdownDescription(description);
}

public void SetMarkdownDescription(string description)
{
MarkdownDescription = description;
}
}
}
31 changes: 31 additions & 0 deletions src/PluginFramework/Formatter/BaseFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using PluginFramework.EventMessages;
using PluginFramework.Interfaces.PluginTypes;
using System;
using System.Data;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace PluginFramework.Formatter
{
Expand Down Expand Up @@ -107,5 +110,33 @@ protected bool IsFileReadableWriteable(string inputFilePath, string outputName)

return readable;
}

/// <summary>
/// Method to load information from an resource embeeded into the plugin
/// </summary>
/// <param name="resourcePath">The path to the embedded resource</param>
/// <returns>The content of the resource or an empty string if nothing was found</returns>
protected string LoadFromEmbeddedResource(string resourcePath)
{
string returnData = string.Empty;
Assembly assembly = Assembly.GetCallingAssembly();
if (assembly is null || string.IsNullOrEmpty(resourcePath))
{
return returnData;
}
using (Stream stream = assembly.GetManifestResourceStream(resourcePath))
{
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
returnData = reader.ReadToEnd();
}
}
}


return returnData;
}
}
}
32 changes: 31 additions & 1 deletion src/PluginFramework/Update/BaseUpdate.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using PluginFramework.DataContainer;
using PluginFramework.Interfaces.PluginTypes;
using System;
using System.IO;
using System.Reflection;
using XmlFormatterModel.Update;

namespace PluginFramework.Update
Expand All @@ -22,7 +24,7 @@ public abstract class BaseUpdate : IUpdateStrategy
/// Create a new instance of this class
/// </summary>
public BaseUpdate()
: this(new PluginInformation(string.Empty, string.Empty, string.Empty, new Version(0,0)))
: this(new PluginInformation(string.Empty, string.Empty, string.Empty, new Version(0, 0)))
{

}
Expand All @@ -44,5 +46,33 @@ public void ChangeSettings(PluginSettings settings)

/// <inheritdoc/>
public abstract bool Update(VersionCompare versionInformation, Predicate<IReleaseAsset> assetFilter);

/// <summary>
/// Method to load information from an resource embeeded into the plugin
/// </summary>
/// <param name="resourcePath">The path to the embedded resource</param>
/// <returns>The content of the resource or an empty string if nothing was found</returns>
protected string LoadFromEmbeddedResource(string resourcePath)
{
string returnData = string.Empty;
Assembly assembly = Assembly.GetCallingAssembly();
if (assembly is null || string.IsNullOrEmpty(resourcePath))
{
return returnData;
}
using (Stream stream = assembly.GetManifestResourceStream(resourcePath))
{
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
returnData = reader.ReadToEnd();
}
}
}


return returnData;
}
}
}
11 changes: 11 additions & 0 deletions src/XMLFormatterModel/Enums/ScopeEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace XmlFormatterModel.Enums
{
/// <summary>
/// Enum to show if a service scope is either local or remote
/// </summary>
public enum ScopeEnum
{
Local,
Remote
}
}
Loading

0 comments on commit 937d080

Please sign in to comment.