diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index d15b8ec8..1996d2b4 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,23 +1,28 @@ **What is this Pull-Request about** + What did get fixed. What was extended or implemented. What did you change. **What issue is this Pull-Request solving** + As example type `closes #` or `fixing #`. ** How hat this been tested? ** + Which tests did you run to verify your changes? * [x] Test A * [ ] Test B ** Checklist ** + * [ ] **IMPORTANT** I have checked that this pull request is targeting the develop branch -* [ ] I have reviewed my code -* [ ] I have added all the required summary tests +* [ ] I have reviewed my code +* [ ] I have added all the required summary blocks to my classes, methods and variables/fields **Special information required for reviewing or testing** + Write down any special information the reviewer could need for his or her review or any information to test this Pull-Request. Please write comments on the `changed files` tab to the code if you want to explain something more into detail to the reviewers. \ No newline at end of file diff --git a/.github/Screenshots/ActivateHotfolder.png b/.github/Screenshots/ActivateHotfolder.png new file mode 100644 index 00000000..040859d1 Binary files /dev/null and b/.github/Screenshots/ActivateHotfolder.png differ diff --git a/.github/Screenshots/AddPathToFile.png b/.github/Screenshots/AddPathToFile.png index f21caae4..935c8754 100644 Binary files a/.github/Screenshots/AddPathToFile.png and b/.github/Screenshots/AddPathToFile.png differ diff --git a/.github/Screenshots/ConverterSelection.png b/.github/Screenshots/ConverterSelection.png new file mode 100644 index 00000000..1b783760 Binary files /dev/null and b/.github/Screenshots/ConverterSelection.png differ diff --git a/.github/Screenshots/GeneralHotfolderSettings.png b/.github/Screenshots/GeneralHotfolderSettings.png new file mode 100644 index 00000000..616f0d12 Binary files /dev/null and b/.github/Screenshots/GeneralHotfolderSettings.png differ diff --git a/.github/Screenshots/InstallationFolder.png b/.github/Screenshots/InstallationFolder.png new file mode 100644 index 00000000..f7c642c2 Binary files /dev/null and b/.github/Screenshots/InstallationFolder.png differ diff --git a/.github/Screenshots/JsonExample.png b/.github/Screenshots/JsonExample.png new file mode 100644 index 00000000..0d6802e7 Binary files /dev/null and b/.github/Screenshots/JsonExample.png differ diff --git a/.github/Screenshots/ModeSelection.png b/.github/Screenshots/ModeSelection.png index f39923ad..847957db 100644 Binary files a/.github/Screenshots/ModeSelection.png and b/.github/Screenshots/ModeSelection.png differ diff --git a/.github/Screenshots/OpenPluginManager.png b/.github/Screenshots/OpenPluginManager.png new file mode 100644 index 00000000..f84cc2dd Binary files /dev/null and b/.github/Screenshots/OpenPluginManager.png differ diff --git a/.github/Screenshots/OpenSettings.png b/.github/Screenshots/OpenSettings.png new file mode 100644 index 00000000..aafe52ce Binary files /dev/null and b/.github/Screenshots/OpenSettings.png differ diff --git a/.github/Screenshots/PluginFolder.png b/.github/Screenshots/PluginFolder.png new file mode 100644 index 00000000..7cdbcdf2 Binary files /dev/null and b/.github/Screenshots/PluginFolder.png differ diff --git a/.github/Screenshots/PluginSelected.png b/.github/Screenshots/PluginSelected.png new file mode 100644 index 00000000..c221ab7f Binary files /dev/null and b/.github/Screenshots/PluginSelected.png differ diff --git a/.github/Screenshots/SelectButton.png b/.github/Screenshots/SelectButton.png index 1536aa72..cb2b14dc 100644 Binary files a/.github/Screenshots/SelectButton.png and b/.github/Screenshots/SelectButton.png differ diff --git a/.github/workflows/CheckPullRequest.yml b/.github/workflows/CheckPullRequest.yml new file mode 100644 index 00000000..d6a6688e --- /dev/null +++ b/.github/workflows/CheckPullRequest.yml @@ -0,0 +1,21 @@ +name: Check pull request + +on: [pull_request] + +jobs: + build: + name: Check pull request + runs-on: windows-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + - name: Install nuget + uses: nuget/setup-nuget@v1 + - name: Nuget restore + run: nuget restore + shell: powershell + - name: Setup msbuild + uses: microsoft/setup-msbuild@v1.0.0 + - name: Build project + run: msbuild /t:Build /p:Configuration=Release + shell: powershell \ No newline at end of file diff --git a/.github/workflows/CreateLiveBuild.yml b/.github/workflows/CreateLiveBuild.yml new file mode 100644 index 00000000..fa6080c2 --- /dev/null +++ b/.github/workflows/CreateLiveBuild.yml @@ -0,0 +1,75 @@ +name: Live build + +on: + push: + tags: + - '*' + +jobs: + build: + name: Create live versioned build artifact + runs-on: windows-latest + steps: + - name: Clone Repository + uses: actions/checkout@v2 + with: + ref: master + - name: Get Current Tag + run: echo "::set-env name=tag::$(($env:GITHUB_REF -split '/')[-1] -replace ' ','')" + - name: Install NuGet + uses: nuget/setup-nuget@v1 + - name: Install msbuild + uses: microsoft/setup-msbuild@v1.0.0 + - name: Build Project + run: | + nuget restore + echo $env:tag > .\XmlFormatter\Version.txt + msbuild /t:Build /p:Configuration=Release + shell: powershell + - name: Create Artifacts + run: | + $xmlFormatter = -join($env:tag, "_XmlFormatter.zip") + $jsonPlugin = -join($env:tag, "_JsonPlugin.zip") + echo "::set-env name=xmlFormatter::$($xmlFormatter)" + echo "::set-env name=jsonPlugin::$($JsonPlugin)" + mkdir ..\Artifacts + mkdir ..\Artifacts\XmlFormatter\ + mkdir ..\Artifacts\JsonPlugin\ + mv .\XmlFormatter\bin\Release\** ..\Artifacts\XmlFormatter\ + mv LICENSE ..\Artifacts\XmlFormatter\ + cd ..\Artifacts\ + mv .\XmlFormatter\Plugins\*Json*.dll .\JsonPlugin\ + 7z a $xmlFormatter .\XmlFormatter\** + 7z a $jsonPlugin .\JsonPlugin\** + shell: powershell + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release - ${{ env.tag }} + body: Body goes here! + draft: true + prerelease: false + - name: Upload XmlFormatter Release Asset + id: upload-application-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ..\Artifacts\${{ env.xmlFormatter }} + asset_name: ${{ env.xmlFormatter }} + asset_content_type: application/zip + - name: Upload JsonPlugin Release Asset + id: upload-plugin-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ..\Artifacts\${{ env.jsonPlugin }} + asset_name: ${{ env.jsonPlugin }} + asset_content_type: application/zip \ No newline at end of file diff --git a/.github/workflows/LatestBuild.yml b/.github/workflows/LatestBuild.yml new file mode 100644 index 00000000..ccdd5c33 --- /dev/null +++ b/.github/workflows/LatestBuild.yml @@ -0,0 +1,68 @@ +name: Latest unstable build + +on: + pull_request: + types: [closed] + +jobs: + build: + if: github.event.pull_request.merged == true + name: Create latest build artifact + runs-on: windows-latest + steps: + - name: Clone repository + uses: actions/checkout@v2 + with: + ref: develop + - name: Install nuget + uses: nuget/setup-nuget@v1 + - name: Setup msbuild + uses: microsoft/setup-msbuild@v1.0.0 + - name: Build project + run: | + nuget restore + msbuild /t:Build /p:Configuration=Release + shell: powershell + - name: Create artifacts + run: | + mkdir ..\Artifacts + mkdir ..\Artifacts\XmlFormatter\ + mkdir ..\Artifacts\JsonPlugin\ + mv .\XmlFormatter\bin\Release\** ..\Artifacts\XmlFormatter\ + mv LICENSE ..\Artifacts\XmlFormatter\ + cd ..\Artifacts\ + mv .\XmlFormatter\Plugins\*Json*.dll .\JsonPlugin\ + 7z a LatestDevelopment_XmlFormatter.zip .\XmlFormatter\** + 7z a LatestDevelopment_JsonPlugin.zip .\JsonPlugin\** + shell: powershell + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }}-${{ GITHUB.RUN_NUMBER }} + release_name: Latest unstable + body: You cannot update this version from within the application! + draft: false + prerelease: true + - name: Upload XmlFormatter Release Asset + id: upload-application-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ..\Artifacts\LatestDevelopment_XmlFormatter.zip + asset_name: LatestDevelopment_XmlFormatter.zip + asset_content_type: application/zip + - name: Upload Json Plugin Release Asset + id: upload-plugin-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ..\Artifacts\LatestDevelopment_JsonPlugin.zip + asset_name: LatestDevelopment_JsonPlugin.zip + asset_content_type: application/zip diff --git a/CorePlugin/CorePlugin.csproj b/CorePlugin/CorePlugin.csproj new file mode 100644 index 00000000..bf2c8c55 --- /dev/null +++ b/CorePlugin/CorePlugin.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {3E81CFB2-ADEE-4B81-BC13-F6CE8546F9C9} + Library + Properties + CorePlugin + CorePlugin + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Octokit.0.47.0\lib\net46\Octokit.dll + + + + + + + + + + + + + + + + + + + + + + + {9808f069-6dc1-4c26-a434-16630fc697e8} + PluginFramework + + + + \ No newline at end of file diff --git a/CorePlugin/Properties/AssemblyInfo.cs b/CorePlugin/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..c32bb472 --- /dev/null +++ b/CorePlugin/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +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("CorePlugin")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CorePlugin")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[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("3e81cfb2-adee-4b81-bc13-f6ce8546f9c9")] + +// 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/CorePlugin/packages.config b/CorePlugin/packages.config new file mode 100644 index 00000000..3866a875 --- /dev/null +++ b/CorePlugin/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/CorePlugin/src/Formatter/XmlFormatterProvider.cs b/CorePlugin/src/Formatter/XmlFormatterProvider.cs new file mode 100644 index 00000000..7efa3bcb --- /dev/null +++ b/CorePlugin/src/Formatter/XmlFormatterProvider.cs @@ -0,0 +1,91 @@ +using PluginFramework.src.DataContainer; +using PluginFramework.src.Formatter; +using System; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace CorePlugin.src.Formatter +{ + /// + /// A xml formatter class instance + /// + class XmlFormatterProvider : BaseFormatter + { + /// + /// Create a new instance of this class + /// + public XmlFormatterProvider() : base("xml", new PluginInformation("Xml Formatter", "Convert xml files", "XanatosX", new Version(1, 0))) + { + } + + /// + public override bool ConvertToFlat(string filePath, string outputName) + { + FormatFile(filePath, outputName, SaveOptions.DisableFormatting); + return true; + } + + /// + public override bool ConvertToFormatted(string filePath, string outputName) + { + FormatFile(filePath, outputName, SaveOptions.None); + return true; + } + + /// + /// This method will convert the file + /// + /// The input file to convert + /// The output file to generate + /// The save options to use + private async void FormatFile(string inputFilePath, string outputName, SaveOptions options) + { + if (!IsFileReadableWriteable(inputFilePath, outputName)) + { + FireEvent("Saving failed", "Files where locked!"); + return; + } + + FireEvent("Loading", "Loading ..."); + XElement fileToConvert = await Task.Run(() => + { + XElement returnElement; + try + { + returnElement = XElement.Load(inputFilePath); + } + catch (Exception) + { + FireEvent("Input file not valid", "The input file was not valid!"); + returnElement = null; + } + return returnElement; + }); + + if (fileToConvert == null) + { + return; + } + + FireEvent("Saving", "Saving ..."); + bool saveSuccess = await Task.Run(() => + { + try + { + fileToConvert.Save(outputName, options); + return true; + } + catch (Exception) + { + FireEvent("Saving did fail", "Saving went wrong, maybe the file was used?"); + return false; + } + }); + + if (saveSuccess) + { + FireEvent("Done", "Saving done!"); + } + } + } +} diff --git a/CorePlugin/src/Updating/DownloadGitHubReleaseStrategy.cs b/CorePlugin/src/Updating/DownloadGitHubReleaseStrategy.cs new file mode 100644 index 00000000..070f727a --- /dev/null +++ b/CorePlugin/src/Updating/DownloadGitHubReleaseStrategy.cs @@ -0,0 +1,68 @@ +using Octokit; +using PluginFramework.src.DataContainer; +using PluginFramework.src.Update; +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Net; + +namespace CorePlugin.src.Updating +{ + /// + /// This class descripes the download from GitHub strategy + /// + class DownloadGitHubReleaseStrategy : BaseUpdate + { + /// + /// Create a new instance of this strategy + /// + public DownloadGitHubReleaseStrategy() : base(new PluginInformation("Download GitHub releases", "Download the GitHub release", "XanatosX", new Version(1, 0))) + { + } + + /// + public override bool Update(VersionCompare versionInformation) + { + bool returnValue = true; + string tempFolder = Path.GetTempPath(); + using (WebClient client = new WebClient()) + { + foreach (ReleaseAsset release in versionInformation.Assets) + { + string localFile = tempFolder; + string[] splittet = release.BrowserDownloadUrl.Split('/'); + localFile += splittet.Last(); + if (File.Exists(localFile)) + { + try + { + using (FileStream fileStream = new FileStream(localFile, System.IO.FileMode.Open)) + { + if (!fileStream.CanWrite) + { + returnValue &= false; + continue; + } + } + } + catch (Exception) + { + returnValue &= false; + continue; + } + } + client.DownloadFile(release.BrowserDownloadUrl, localFile); + Process.Start(localFile); + } + } + + if (returnValue) + { + Process.Start(Environment.CurrentDirectory); + } + + return returnValue; + } + } +} diff --git a/CorePlugin/src/Updating/OpenGitHubReleasesStrategy.cs b/CorePlugin/src/Updating/OpenGitHubReleasesStrategy.cs new file mode 100644 index 00000000..ce973c42 --- /dev/null +++ b/CorePlugin/src/Updating/OpenGitHubReleasesStrategy.cs @@ -0,0 +1,27 @@ +using PluginFramework.src.DataContainer; +using PluginFramework.src.Update; +using System; +using System.Diagnostics; + +namespace CorePlugin.src.Updating +{ + /// + /// This class will open up the release GitHub page + /// + class OpenGitHubReleasesStrategy : BaseUpdate + { + /// + /// Create a new instance of this strategy + /// + public OpenGitHubReleasesStrategy() : base(new PluginInformation("Open GitHub releases", "Open the GitHub Release", "XanatosX", new Version(1, 0))) + { + } + + /// + public override bool Update(VersionCompare versionInformation) + { + Process.Start("https://github.com/XanatosX/XmlFormatter/releases/tag/" + versionInformation.LatestRelease.TagName); + return true; + } + } +} diff --git a/JsonPlugin/JsonPlugin.csproj b/JsonPlugin/JsonPlugin.csproj new file mode 100644 index 00000000..e0464e98 --- /dev/null +++ b/JsonPlugin/JsonPlugin.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {61B2922F-25C0-4F10-8DF0-FF91287C4452} + Library + Properties + JsonPlugin + JsonPlugin + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\Octokit.0.47.0\lib\net46\Octokit.dll + + + + + + + + + + + + + + + + + + + + {9808f069-6dc1-4c26-a434-16630fc697e8} + PluginFramework + + + + \ No newline at end of file diff --git a/JsonPlugin/Properties/AssemblyInfo.cs b/JsonPlugin/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..7503f11c --- /dev/null +++ b/JsonPlugin/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +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("JsonPlugin")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("JsonPlugin")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[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("61b2922f-25c0-4f10-8df0-ff91287c4452")] + +// 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/JsonPlugin/packages.config b/JsonPlugin/packages.config new file mode 100644 index 00000000..f0a4837d --- /dev/null +++ b/JsonPlugin/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/JsonPlugin/src/JsonFormatter.cs b/JsonPlugin/src/JsonFormatter.cs new file mode 100644 index 00000000..c4490461 --- /dev/null +++ b/JsonPlugin/src/JsonFormatter.cs @@ -0,0 +1,98 @@ +using Newtonsoft.Json; +using PluginFramework.src.DataContainer; +using PluginFramework.src.Formatter; +using System; +using System.IO; +using System.Threading.Tasks; + +namespace JsonPlugin +{ + /// + /// A foramtter to convert json files + /// + public class JsonFormatter : BaseFormatter + { + /// + /// Create a new instance of this formatter + /// + public JsonFormatter() + : base( + "json", + new PluginInformation("Json formatter", "This plugin will convert json files", "XanatosX", new Version(1, 0)) + ) + { + } + + /// + public override bool ConvertToFlat(string filePath, string outputName) + { + FormatFile(filePath, outputName, Formatting.None); + return true; + } + + /// + public override bool ConvertToFormatted(string filePath, string outputName) + { + FormatFile(filePath, outputName, Formatting.Indented); + return true; + } + + /// + /// This method will convert the file + /// + /// The input file to convert + /// The output file to generate + /// The save options to use + private async void FormatFile(string inputFilePath, string outputName, Formatting formatting) + { + if (!IsFileReadableWriteable(inputFilePath, outputName)) + { + FireEvent("Saving failed", "Files where locked!"); + return; + } + + FireEvent("Loading", "Loading ..."); + object data = await Task.Run(() => + { + object returnData = null; + try + { + + returnData = JsonConvert.DeserializeObject(File.ReadAllText(inputFilePath)); + } + catch (Exception) + { + FireEvent("Input file not valid", "The input file was not valid!"); + returnData = null; + } + return returnData; + }); + + if (data == null) + { + return; + } + + FireEvent("Saving", "Saving ..."); + bool saveSuccess = await Task.Run(() => + { + try + { + string writeableData = JsonConvert.SerializeObject(data, formatting); + File.WriteAllText(outputName, writeableData); + return true; + } + catch (Exception) + { + FireEvent("Saving did fail", "Saving went wrong, maybe the file was used?"); + return false; + } + }); + + if (saveSuccess) + { + FireEvent("Done", "Saving done!"); + } + } + } +} diff --git a/PluginFramework/PluginFramework.csproj b/PluginFramework/PluginFramework.csproj new file mode 100644 index 00000000..991a9135 --- /dev/null +++ b/PluginFramework/PluginFramework.csproj @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + {9808F069-6DC1-4C26-A434-16630FC697E8} + Library + Properties + PluginFramework + PluginFramework + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + none + true + bin\Release\ + TRACE + prompt + 3 + + + + ..\packages\Octokit.0.47.0\lib\net46\Octokit.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PluginFramework/Properties/AssemblyInfo.cs b/PluginFramework/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..ad29309e --- /dev/null +++ b/PluginFramework/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +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("PluginFramework")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PluginFramework")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[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("9808f069-6dc1-4c26-a434-16630fc697e8")] + +// 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/PluginFramework/packages.config b/PluginFramework/packages.config new file mode 100644 index 00000000..3866a875 --- /dev/null +++ b/PluginFramework/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/PluginFramework/src/DataContainer/PluginInformation.cs b/PluginFramework/src/DataContainer/PluginInformation.cs new file mode 100644 index 00000000..61cde932 --- /dev/null +++ b/PluginFramework/src/DataContainer/PluginInformation.cs @@ -0,0 +1,45 @@ +using System; + +namespace PluginFramework.src.DataContainer +{ + /// + /// This class represents all the information of the plugin + /// + public class PluginInformation + { + /// + /// The name of the plugin + /// + public string Name { get; } + + /// + /// The description of the plugin + /// + public string Description { get; } + + /// + /// The author name of the plugin + /// + public string Author { get; } + + /// + /// The version of the plugin + /// + public Version Version { get; } + + /// + /// Create a new plugin information instance + /// + /// Name of the plugin + /// Description of the plugin + /// Author name of the plugin + /// The version of the plugin + public PluginInformation(string name, string description, string author, Version version) + { + Name = name; + Description = description; + Author = author; + Version = version; + } + } +} diff --git a/PluginFramework/src/DataContainer/PluginMetaData.cs b/PluginFramework/src/DataContainer/PluginMetaData.cs new file mode 100644 index 00000000..5604fd82 --- /dev/null +++ b/PluginFramework/src/DataContainer/PluginMetaData.cs @@ -0,0 +1,40 @@ +using System; + +namespace PluginFramework.src.DataContainer +{ + /// + /// A class representing the meta data of the plugin + /// + public class PluginMetaData + { + /// + /// The plugin information provided by the author + /// + public PluginInformation Information { get; } + + /// + /// The unique id of the plugin + /// + public int Id { get; } + + /// + /// The type of the plugin + /// + public Type Type { get; } + + /// + /// Create a new instance of this meta dataset + /// + /// The id of the plugin + /// The author information of the plugin + /// The plugin type + public PluginMetaData(int id, PluginInformation information, Type type) + { + this.Id = id; + this.Information = information; + this.Type = type; + } + + + } +} diff --git a/PluginFramework/src/DataContainer/PluginSettings.cs b/PluginFramework/src/DataContainer/PluginSettings.cs new file mode 100644 index 00000000..b3bae09f --- /dev/null +++ b/PluginFramework/src/DataContainer/PluginSettings.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; + +namespace PluginFramework.src.DataContainer +{ + /// + /// The settings of the plugin + /// + public class PluginSettings + { + /// + /// Dictionary with all the settings + /// + public Dictionary Settings { get; } + + /// + /// Create a new instance of this class + /// + /// The initial settings + public PluginSettings(Dictionary settings) + { + this.Settings = settings; + } + + /// + /// Create a new instance of this class + /// + public PluginSettings() : this(new Dictionary()) + { + } + + /// + /// Add a new value to the settings + /// + /// The key of the setting + /// The value of the setting + public void AddValue(string key, object value) + { + AddValue(key, value, false); + } + + /// + /// Add a new value to the settings + /// + /// The key of the setting + /// The value of the setting + /// Should we override already existing settings + public void AddValue(string key, object value, bool allowOverride) + { + if (Settings.ContainsKey(key)) + { + if (allowOverride) + { + Settings[key] = value; + } + + return; + } + + Settings.Add(key, value); + } + + /// + /// The a value from the settings + /// + /// The type of the setting to get + /// The key to get + /// An instance of type T of the requested setting + public T GetValue(string key) + { + if (!Settings.ContainsKey(key)) + { + return default; + } + + try + { + object dataSet = Settings[key]; + return (T)dataSet; + } + catch (Exception) + { + //Cast did not work no error handling for now + } + + return default; + } + } +} \ No newline at end of file diff --git a/PluginFramework/src/DataContainer/VersionCompare.cs b/PluginFramework/src/DataContainer/VersionCompare.cs new file mode 100644 index 00000000..787f1099 --- /dev/null +++ b/PluginFramework/src/DataContainer/VersionCompare.cs @@ -0,0 +1,81 @@ +using Octokit; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace PluginFramework.src.DataContainer +{ + /// + /// This data container class which will combine different informations. + /// This class will tell you which version is newer and what versions are present + /// + public class VersionCompare + { + /// + /// Is the GitHub version newer + /// + private readonly bool gitHubIsNewer; + + /// + /// Readonly acces if the GitHub version is newer + /// + public bool GitHubIsNewer => gitHubIsNewer; + + /// + /// The version of the current client application + /// + private readonly Version clientVersion; + + /// + /// Readonly access to the current client version of this application + /// + public Version LocalVersion => clientVersion; + + /// + /// The version on GitHub + /// + private readonly Version gitHubVersion; + + /// + /// Readonly access to the GitHub version + /// + public Version GitHubVersion => gitHubVersion; + + /// + /// The newest release which can be found on GitHub + /// + private readonly Release lastestRelease; + + /// + /// Readonly access to the newest release on GitHub + /// + public Release LatestRelease => lastestRelease; + + /// + /// A readonly list of all the assets in the release build + /// + private readonly List assets; + + /// + /// Public access to the assets in the release build + /// + public List Assets => assets; + + /// + /// Create an new instance of this class + /// + /// Is the version on GitHub newer + /// The local version number + /// The GitHub version number + /// The latest release + public VersionCompare(bool gitHubIsNewer, Version localVersion, Version gitHubVersion, Release latestRelease) + { + this.gitHubIsNewer = gitHubIsNewer; + this.clientVersion = localVersion; + this.gitHubVersion = gitHubVersion; + this.lastestRelease = latestRelease; + this.assets = latestRelease.Assets.ToList(); + } + + } +} diff --git a/PluginFramework/src/Enums/ModesEnum.cs b/PluginFramework/src/Enums/ModesEnum.cs new file mode 100644 index 00000000..a76d2115 --- /dev/null +++ b/PluginFramework/src/Enums/ModesEnum.cs @@ -0,0 +1,11 @@ +namespace PluginFramework.src.Enums +{ + /// + /// Modes to convert files + /// + public enum ModesEnum + { + Formatted, + Flat + } +} diff --git a/PluginFramework/src/EventMessages/BaseEventArgs.cs b/PluginFramework/src/EventMessages/BaseEventArgs.cs new file mode 100644 index 00000000..9a9a84a4 --- /dev/null +++ b/PluginFramework/src/EventMessages/BaseEventArgs.cs @@ -0,0 +1,31 @@ +using System; + +namespace PluginFramework.src.EventMessages +{ + /// + /// This class is a simple event data container + /// + public class BaseEventArgs : EventArgs + { + /// + /// Readonly access to the event title + /// + public string Title { get; } + + /// + /// Readonly access to the event message + /// + public string Message { get; } + + /// + /// This will create a basic event data container + /// + /// The title of the event + /// The message of the event + public BaseEventArgs(string title, string message) + { + this.Title = title; + this.Message = message; + } + } +} diff --git a/PluginFramework/src/Formatter/BaseFormatter.cs b/PluginFramework/src/Formatter/BaseFormatter.cs new file mode 100644 index 00000000..0f1f3e44 --- /dev/null +++ b/PluginFramework/src/Formatter/BaseFormatter.cs @@ -0,0 +1,118 @@ +using PluginFramework.src.DataContainer; +using PluginFramework.src.Enums; +using PluginFramework.src.EventMessages; +using PluginFramework.src.Interfaces.PluginTypes; +using System; +using System.IO; +using System.Windows.Forms; + +namespace PluginFramework.src.Formatter +{ + /// + /// Base class for formatting + /// + public abstract class BaseFormatter : IFormatter + { + /// + public string Extension { get; } + + /// + public PluginInformation Information { get; } + + /// + public PluginSettings Settings { get; private set; } + + /// + public event EventHandler StatusChanged; + + /// + /// Create a new instance of this class + /// + /// The file extension this formatter is using + /// The information for this plugin + protected BaseFormatter(string fileExtension, PluginInformation pluginInformation) + { + Extension = fileExtension; + Information = pluginInformation; + Settings = new PluginSettings(); + } + + /// + public bool ConvertToFormat(string filePath, string outputName, ModesEnum mode) + { + return mode == ModesEnum.Flat ? ConvertToFlat(filePath, outputName) : ConvertToFormatted(filePath, outputName); + } + + /// + public void ChangeSettings(PluginSettings settings) + { + this.Settings = settings; + } + + /// + public virtual UserControl GetSettingsPage() + { + return null; + } + + /// + public abstract bool ConvertToFormatted(string filePath, string outputName); + + /// + public abstract bool ConvertToFlat(string filePath, string outputName); + + /// + /// Fire a new event + /// + /// The message bodyThe message caption + /// + protected void FireEvent(string caption, string message) + { + EventHandler handle = StatusChanged; + BaseEventArgs dataMessage = new BaseEventArgs(caption, message); + handle?.Invoke(this, dataMessage); + } + + /// + /// Check if the input file is readable and the output file is writeable + /// + /// The input file + /// The output file + /// If it is readable + protected bool IsFileReadableWriteable(string inputFilePath, string outputName) + { + bool readable; + try + { + using (FileStream fileStream = File.Open( + inputFilePath, + FileMode.Open, + FileAccess.ReadWrite, + FileShare.None + )) + { + fileStream.Close(); + } + if (File.Exists(outputName)) + { + using (FileStream fileStream = File.Open( + outputName, + FileMode.Open, + FileAccess.ReadWrite, + FileShare.None + )) + { + fileStream.Close(); + } + } + readable = true; + } + catch (Exception) + { + readable = false; + } + + return readable; + } + } +} diff --git a/PluginFramework/src/Interfaces/Manager/IPluginLoadStrategy.cs b/PluginFramework/src/Interfaces/Manager/IPluginLoadStrategy.cs new file mode 100644 index 00000000..8e347920 --- /dev/null +++ b/PluginFramework/src/Interfaces/Manager/IPluginLoadStrategy.cs @@ -0,0 +1,18 @@ +using PluginFramework.src.Interfaces.PluginTypes; +using System.Collections.Generic; + +namespace PluginFramework.src.Interfaces.Manager +{ + /// + /// Strategy to load a plugin + /// + public interface IPluginLoadStrategy + { + /// + /// Load all the plugins with this strategy + /// + /// Type of the plugin to load + /// A list with all the loaded plugins + List LoadPlugins() where T : IPluginOverhead; + } +} diff --git a/PluginFramework/src/Interfaces/Manager/IPluginManager.cs b/PluginFramework/src/Interfaces/Manager/IPluginManager.cs new file mode 100644 index 00000000..2a8621d8 --- /dev/null +++ b/PluginFramework/src/Interfaces/Manager/IPluginManager.cs @@ -0,0 +1,101 @@ +using PluginFramework.src.DataContainer; +using PluginFramework.src.Interfaces.PluginTypes; +using System.Collections.Generic; + +namespace PluginFramework.src.Interfaces.Manager +{ + /// + /// Plugin manager to list and load plugins + /// + public interface IPluginManager + { + /// + /// Set a default load stratedy which is getting used if you do not provide one + /// + /// The default load strategy to set + void SetDefaultLoadStrategy(IPluginLoadStrategy loadStrategy); + + /// + /// List all the plugins of a given type by using the default strategy + /// + /// The type of plugin to list + /// A list with the plugin meta data + List ListPlugins() where T : IPluginOverhead; + + /// + /// List all the plugins of a given type by using the default strategy + /// + /// The type of plugin to list + /// Reload all the plugins + /// A list with the plugin meta data + List ListPlugins(bool reload) where T : IPluginOverhead; + + /// + /// List all the plugins of a given type by + /// + /// The type of plugin to list + /// The strategy to use for loading + /// A list with the plugin meta data + List ListPlugins(IPluginLoadStrategy loadStrategy) where T : IPluginOverhead; + + /// + /// List all the plugins of a given type by + /// + /// The type of plugin to list + /// The strategy to use for loading + /// Reload all the plugins + /// A list with the plugin meta data + List ListPlugins(IPluginLoadStrategy loadStrategy, bool reload) where T : IPluginOverhead; + + /// + /// Load a plugin by the meta data + /// + /// The type of the plugin to load + /// The meta data + /// A instance of the plugin + T LoadPlugin(PluginMetaData metaData) where T : IPluginOverhead; + + /// + /// Load a plugin by the meta data + /// + /// The type of the plugin to load + /// The meta data + /// Settings for the plugin + /// A instance of the plugin + T LoadPlugin(PluginMetaData metaData, PluginSettings settings) where T : IPluginOverhead; + + /// + /// Load a plugin by the meta data + /// + /// The type of the plugin to load + /// The id of the plugin + /// A instance of the plugin + T LoadPlugin(int id) where T : IPluginOverhead; + + /// + /// Load a plugin by the meta data + /// + /// The type of the plugin to load + /// The id of the plugin + /// Settings for the plugin + /// A instance of the plugin + T LoadPlugin(int id, PluginSettings settings) where T : IPluginOverhead; + + /// + /// Load a plugin by the meta data + /// + /// The type of the plugin to load + /// The type of the plugin + /// A instance of the plugin + T LoadPlugin(string type) where T : IPluginOverhead; + + /// + /// Load a plugin by the meta data + /// + /// The type of the plugin to load + /// The type of the plugin + /// Settings for the plugin + /// A instance of the plugin + T LoadPlugin(string type, PluginSettings settings) where T : IPluginOverhead; + } +} \ No newline at end of file diff --git a/PluginFramework/src/Interfaces/PluginTypes/IFormatter.cs b/PluginFramework/src/Interfaces/PluginTypes/IFormatter.cs new file mode 100644 index 00000000..af5bad9a --- /dev/null +++ b/PluginFramework/src/Interfaces/PluginTypes/IFormatter.cs @@ -0,0 +1,47 @@ +using PluginFramework.src.Enums; +using PluginFramework.src.EventMessages; +using System; + +namespace PluginFramework.src.Interfaces.PluginTypes +{ + /// + /// This interface defines a formatter + /// + public interface IFormatter : IPluginOverhead + { + /// + /// Event if the status of the conversion has been changed + /// + event EventHandler StatusChanged; + + /// + /// The Extension to use + /// + string Extension { get; } + + /// + /// Convert the given file to the defined format + /// + /// The path to the file to convert + /// The path to the output file + /// The mode to use for converting + /// + bool ConvertToFormat(string filePath, string outputName, ModesEnum mode); + + /// + /// Convert the given file to a flat format + /// + /// The path to the file to convert + /// The path to the output file + /// + bool ConvertToFlat(string filePath, string outputName); + + /// + /// Convert the given file to a formattet format + /// + /// The path to the file to convert + /// The path to the output file + /// + bool ConvertToFormatted(string filePath, string outputName); + } +} diff --git a/PluginFramework/src/Interfaces/PluginTypes/IPluginOverhead.cs b/PluginFramework/src/Interfaces/PluginTypes/IPluginOverhead.cs new file mode 100644 index 00000000..eed85ffa --- /dev/null +++ b/PluginFramework/src/Interfaces/PluginTypes/IPluginOverhead.cs @@ -0,0 +1,30 @@ +using PluginFramework.src.DataContainer; +using System.Windows.Forms; + +namespace PluginFramework.src.Interfaces.PluginTypes +{ + /// + /// Represents the overhead of a plugin this interface needs to be extend for all managable plugins + /// + public interface IPluginOverhead + { + PluginSettings Settings { get; } + + /// + /// The information for the plugin + /// + PluginInformation Information { get; } + + /// + /// This method will allow the host application to change the plugin settings + /// + /// + void ChangeSettings(PluginSettings settings); + + /// + /// This method will return the settings view for the plugin + /// + /// A useable control to implement into the host application + UserControl GetSettingsPage(); + } +} diff --git a/PluginFramework/src/Interfaces/PluginTypes/IUpdateStrategy.cs b/PluginFramework/src/Interfaces/PluginTypes/IUpdateStrategy.cs new file mode 100644 index 00000000..d3501835 --- /dev/null +++ b/PluginFramework/src/Interfaces/PluginTypes/IUpdateStrategy.cs @@ -0,0 +1,17 @@ +using PluginFramework.src.DataContainer; + +namespace PluginFramework.src.Interfaces.PluginTypes +{ + /// + /// An strategy to update the version + /// + public interface IUpdateStrategy : IPluginOverhead + { + /// + /// Update the application with the current strategy + /// + /// The information about the new release + /// True if update was successful + bool Update(VersionCompare versionInformation); + } +} diff --git a/PluginFramework/src/LoadStrategies/PluginFolder.cs b/PluginFramework/src/LoadStrategies/PluginFolder.cs new file mode 100644 index 00000000..ebb0dea4 --- /dev/null +++ b/PluginFramework/src/LoadStrategies/PluginFolder.cs @@ -0,0 +1,66 @@ +using PluginFramework.src.Interfaces.Manager; +using PluginFramework.src.Interfaces.PluginTypes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace PluginFramework.src.LoadStrategies +{ + /// + /// Load strategy to load all plugins in a folder + /// + public class PluginFolder : IPluginLoadStrategy + { + /// + /// The folder to search the plugins ins + /// + private readonly string folder; + + /// + /// Create a new instance of this load strategy + /// + /// The folder to search for plugins + public PluginFolder(string folder) + { + this.folder = folder; + } + + /// + public List LoadPlugins() where T : IPluginOverhead + { + List returnList = new List(); + if (!Directory.Exists(folder)) + { + return returnList; + } + foreach (string file in Directory.GetFiles(folder)) + { + FileInfo fileInfo = new FileInfo(file); + if (fileInfo.Extension != ".dll") + { + continue; + } + + Assembly assembly = Assembly.LoadFrom(file); + try + { + foreach (Type type in assembly.GetTypes()) + { + if (type.GetInterfaces().Contains(typeof(T))) + { + T formatter = (T)Activator.CreateInstance(type); + returnList.Add(formatter); + } + } + } + catch (Exception) + { + //We just try to instanciate the plugin otherwise we ignore it and don't add it to the list + } + } + return returnList; + } + } +} diff --git a/PluginFramework/src/Manager/DefaultManager.cs b/PluginFramework/src/Manager/DefaultManager.cs new file mode 100644 index 00000000..38b01f7f --- /dev/null +++ b/PluginFramework/src/Manager/DefaultManager.cs @@ -0,0 +1,153 @@ +using PluginFramework.src.DataContainer; +using PluginFramework.src.Interfaces.Manager; +using PluginFramework.src.Interfaces.PluginTypes; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace PluginFramework.src.Manager +{ + /// + /// Default plugin manager + /// + public class DefaultManager : IPluginManager + { + /// + /// A list with all the plugins + /// + private readonly List plugins; + + /// + /// A list with all the plugin types which got loaded already + /// + private readonly List loadedTypes; + + /// + /// Default loading strategy to use + /// + private IPluginLoadStrategy defaultStrategy; + + /// + /// The next id of the plugin + /// + private int nextId; + + /// + /// Create a new instance of this plugin manager + /// + public DefaultManager() + { + plugins = new List(); + loadedTypes = new List(); + nextId = 0; + } + + /// + public void SetDefaultLoadStrategy(IPluginLoadStrategy loadStrategy) + { + defaultStrategy = loadStrategy ?? defaultStrategy; + } + + /// + public List ListPlugins() where T : IPluginOverhead + { + return ListPlugins(false); + } + + /// + public List ListPlugins(bool reload) where T : IPluginOverhead + { + return ListPlugins(defaultStrategy, false); + } + + /// + public List ListPlugins(IPluginLoadStrategy loadStrategy) where T : IPluginOverhead + { + return ListPlugins(loadStrategy, false); + } + + /// + public List ListPlugins(IPluginLoadStrategy loadStrategy, bool reload) where T : IPluginOverhead + { + if (loadStrategy == null) + { + return null; + } + + LoadPluginsOfType(loadStrategy, reload); + return plugins.FindAll(obj => obj.Type.GetInterfaces().Contains(typeof(T))); + } + + /// + /// Load all plugins of a given type + /// + /// The type to load the plugin for + /// The strategy to load the plugins + /// Should we delete all plugins with the given type + private void LoadPluginsOfType(IPluginLoadStrategy loadStrategy, bool reload) where T : IPluginOverhead + { + if (reload) + { + plugins.RemoveAll(plugin => plugin.Type.GetInterfaces().Contains(typeof(T))); + loadedTypes.Remove(typeof(T)); + } + + if (!loadedTypes.Contains(typeof(T))) + { + foreach (T plugin in loadStrategy.LoadPlugins()) + { + plugins.Add(new PluginMetaData(nextId, plugin.Information, plugin.GetType())); + nextId++; + } + loadedTypes.Add(typeof(T)); + } + } + + /// + public T LoadPlugin(PluginMetaData metaData) where T : IPluginOverhead + { + return LoadPlugin(metaData, null); + } + + /// + public T LoadPlugin(PluginMetaData metaData, PluginSettings settings) where T : IPluginOverhead + { + return LoadPlugin(metaData.Id, settings); + } + + /// + public T LoadPlugin(int id) where T : IPluginOverhead + { + return LoadPlugin(id, null); + } + + /// + public T LoadPlugin(int id, PluginSettings settings) where T : IPluginOverhead + { + PluginMetaData metaData = plugins.Find(plugin => plugin.Id == id); + T pluginInstance = metaData == null ? default : (T)Activator.CreateInstance(plugins[id].Type); + if (pluginInstance != null && settings != null) + { + pluginInstance.ChangeSettings(settings); + } + return pluginInstance; + } + + /// + public T LoadPlugin(string type) where T : IPluginOverhead + { + return LoadPlugin(type, null); + } + + /// + public T LoadPlugin(string type, PluginSettings settings) where T : IPluginOverhead + { + if (!loadedTypes.Contains(typeof(T))) + { + LoadPluginsOfType(defaultStrategy, false); + } + PluginMetaData metaData = plugins.Find(plugin => plugin.Type.ToString() == type); + return metaData != null ? LoadPlugin(metaData.Id) : default; + } + } +} diff --git a/PluginFramework/src/Update/BaseUpdate.cs b/PluginFramework/src/Update/BaseUpdate.cs new file mode 100644 index 00000000..8be2d0a7 --- /dev/null +++ b/PluginFramework/src/Update/BaseUpdate.cs @@ -0,0 +1,44 @@ +using PluginFramework.src.DataContainer; +using PluginFramework.src.Interfaces.PluginTypes; +using System.Windows.Forms; + +namespace PluginFramework.src.Update +{ + /// + /// Basic class for a new update plugin + /// + public abstract class BaseUpdate : IUpdateStrategy + { + /// + /// Settings of the update plugin + /// + public PluginSettings Settings { get; private set; } + + /// + public PluginInformation Information { get; } + + /// + /// Create a new intsance of this base plugin calss + /// + /// The plugin information to use + protected BaseUpdate(PluginInformation information) + { + Information = information; + } + + /// + public void ChangeSettings(PluginSettings settings) + { + this.Settings = settings; + } + + /// + public virtual UserControl GetSettingsPage() + { + return null; + } + + /// + public abstract bool Update(VersionCompare versionInformation); + } +} diff --git a/README.MD b/README.MD index 1da41bf2..717b8c5a 100644 --- a/README.MD +++ b/README.MD @@ -1,9 +1,9 @@ # XML Formatter -[![Build status](https://ci.appveyor.com/api/projects/status/od60o55s004tdjnn/branch/master?svg=true)](https://ci.appveyor.com/project/XanatosX/xmlformatter/branch/master) +![Live build](https://github.com/XanatosX/XmlFormatter/workflows/Live%20build/badge.svg) +![Latest unstable build](https://github.com/XanatosX/XmlFormatter/workflows/Latest%20unstable%20build/badge.svg) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d82f0208f13547ff890deff9207bb4c4)](https://www.codacy.com/manual/simonaberle/XmlFormatter?utm_source=github.com&utm_medium=referral&utm_content=XanatosX/XmlFormatter&utm_campaign=Badge_Grade) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FXanatosX%2FXmlFormatter.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FXanatosX%2FXmlFormatter?ref=badge_shield) - This project is a lightweight tool to convert xml files from a flat to a formatted format or the other way round. ## How to "install" this application @@ -15,10 +15,10 @@ You will need the .NET Framework 4.7 or newer installed on your machine. This is ### Installation 1. Download the newest zip file from the [Release](https://github.com/XanatosX/XmlFormatter/releases) tab. - 1. Click on the topmost entry in the list - 2. Click on the zip file in the `Assets` area + 1. Click on the topmost entry in the list + 2. Click on the zip file in the `Assets` area 2. Unzip the content of the file somewhere on your computer - * You do not need the `LICENSE` file. + * You do not need the `LICENSE` file. 3. Start the unzipped `XmlFormatter.exe` file. This application is portable, just copy the zip content to a portable disk. @@ -31,43 +31,40 @@ There are different ways to select the file you want to format #### 1. Use the select button -To "open" an xml file use the `Select XML` - - +To "open" an file use the `Select` button, keep in mind that the text of the button is related to the current converter you do use ![SelectButton.png](/.github/Screenshots/SelectButton.png) - - This will open up a file selector where you can choose the file for converting - - - - ![FileSelector.png](/.github/Screenshots/FileSelector.png) - - #### 2. Write the path to the into the Textbox You can write the path to the file into the textbox to select it for the formatting task +![AddPathToFile.png](/.github/Screenshots/AddPathToFile.png) +Please make sure that the file is a valid file and is located at the path you did provide in the textbox. -![AddPathToFile.png](/.github/Screenshots/AddPathToFile.png) +#### 3. Drag the file onto the window +The last option is to simple drag and drop the file into the window, please keep in mind that you can only drag one file for converting. +This will automatically fill the textbox with the correct file path. -Please make sure that the file is a valid xml file and is located at the path you did provide in the textbox +### Select the converter +You can select different converter if there are multiple plugins installed into the application. +**Important** If this selection is not visible for you there is only one converter available -#### 3. Drag the file onto the window +![ConverterSelection.png](/.github/Screenshots/ConverterSelection.png) -The last option is to simple drag and drop the file into the window, please keep in mind that you can only drag one file for converting. +Changing this setting will change different texts in the GUI. It will change some filters like which files you can select in the background as well. +Changing this selectbox will change the filetype you can convert. -This will automatically fill the textbox with the correct file path. +![JsonExample.png](/.github/Screenshots/JsonExample.png) ### Select the formatting mode @@ -75,8 +72,6 @@ There are two different modes to format one to flat out the file and one for pro ![ModeSelection.png](/.github/Screenshots/ModeSelection.png) - - * Formatted -> Format the file in a human readable format * Flat -> Flat the file so it will need less space on your disk @@ -84,6 +79,69 @@ There are two different modes to format one to flat out the file and one for pro To finally save the file just click on the `Save` button. This will load the file into your ram convert it and write it back to the disk. While this action is in progress the window will be locked for other interactions. +### Change the settings + +You can change the settings of this application by clicking on `File->Settings` + +![OpenSettings.png](/.github/Screenshots/OpenSettings.png) + +Do not forget to click on `Save and close` to apply your settings. + +### Hotfolder Support + +**Important** This functionality is not tested deeply so it is possible that the application will crash or bug out. + +The hotfolder support will, if activated, run in the background while the application is started and will try to watch all the configured folders and convert the files as configured. + +To use this functionality go to the settings and access the hotfolder tab, check the `Hotfolder active` flag first. + +![ActivateHotfolder.png](/.github/Screenshots/ActivateHotfolder.png) + +Click on the `Add` button to add a new hotfolder. This will bring up a new window, where you need to select the `provider` (Converter to use) and the `mode` if the files should be converted to flat or formatted. + +![GeneralHotfolderSettings.png](/.github/Screenshots/GeneralHotfolderSettings.png) + +After adding this information you should add the folder to watch. Keep in mind that the folder should be readable. Best practice is to set a Filter here in case of the xml formatter the filter should be `*.xml`. The output folder is filled automatically but can be changed if needed. It is not possible to select the same output folder as the input folder. + +The output file scheme will define how the file will be named after the conversion. At the moment there are the following variables + +* `{inputfile}` -> Name of the input file without extension and path. +* `{format}` -> The format (Formatted, Flat) the file was converted to. +* `{extension}` -> The extension of the converter. + +You can check the additional triggers if you want that the input file is deleted or if the process should be triggered on file rename as well. + +## Plugins + +**Important** Using plugins of any kind can cause harm to your computer be absolutely sure that the plugin author is trustworthy. + +### Install or Remove a Plugin + +To install or remove a plugin close the application first. After closing the application navigate to the installation folder. + +![InstallationFolder.png](/.github/Screenshots/InstallationFolder.png) + +The folder should look like this, you need to open the `Plugins` folder. You can add plugins for this application by dropping them into the folder, don't forget to put in the required dll's as well. To Remove a plugin just delete the dll file and there requirements. + +![PluginFolder.png](/.github/Screenshots/PluginFolder.png) + +Do not delete the `CorePlugin.dll` if you do not know what you are doing. The application will still start but if there is no replacement it will not function properly. + +### View Plugins and Manage there Settings + +If you want to take a look which plugins are loaded right now open the plugin manager by clicking on `Help->Plugins` + +![OpenPluginManager.png](/.github/Screenshots/OpenPluginManager.png) + +If you extend the tree view to the left you will see two root nodes + +* Formatter -> Entries listed under this node are converter for files +* Updater -> Entries listed under this node are updater, those are strategies you can use to update the application. + +You can select a plugin in this view to see the details of it, if there are settings available for the plugin there will be an additional tab to the right. + +![PluginSelected.png](/.github/Screenshots/PluginSelected.png) + ## Pre-requirements for creating a build To get started with the project you should check the following requirements @@ -99,14 +157,12 @@ You should fulfill the pre-requirements for these steps first. 2. Download the NuGet dependencies before compiling. If you IDE is not doing this on loading the project file use `nuget restore` in the root folder 3. Start the build in your IDE - ## Contributions If you have found a bug or a feature idea feel free to create an issue [here](https://github.com/XanatosX/XmlFormatter/issues). Before you open up a new issue, please search to see if it was already reported. In your issue try to be as detailed as possible. If you want to contribute fixes or features to this project, please read our [contributors guide](CONTRIBUTING.MD) first. - ## Using the Source Code The full source code and all the required assets are available here on GitHub. @@ -116,7 +172,3 @@ The full source code and all the required assets are available here on GitHub. This project is using the [MIT License](LICENSE). [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FXanatosX%2FXmlFormatter.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FXanatosX%2FXmlFormatter?ref=badge_large) - - - - diff --git a/XmlFormatter.sln b/XmlFormatter.sln index a3a8f445..969ee2cb 100644 --- a/XmlFormatter.sln +++ b/XmlFormatter.sln @@ -4,6 +4,16 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 16.0.29613.14 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlFormatter", "XmlFormatter\XmlFormatter.csproj", "{0EAED5C3-DAB2-4919-9C26-EAD4D8222BD0}" + ProjectSection(ProjectDependencies) = postProject + {61B2922F-25C0-4F10-8DF0-FF91287C4452} = {61B2922F-25C0-4F10-8DF0-FF91287C4452} + {3E81CFB2-ADEE-4B81-BC13-F6CE8546F9C9} = {3E81CFB2-ADEE-4B81-BC13-F6CE8546F9C9} + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonPlugin", "JsonPlugin\JsonPlugin.csproj", "{61B2922F-25C0-4F10-8DF0-FF91287C4452}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CorePlugin", "CorePlugin\CorePlugin.csproj", "{3E81CFB2-ADEE-4B81-BC13-F6CE8546F9C9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginFramework", "PluginFramework\PluginFramework.csproj", "{9808F069-6DC1-4C26-A434-16630FC697E8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +25,18 @@ Global {0EAED5C3-DAB2-4919-9C26-EAD4D8222BD0}.Debug|Any CPU.Build.0 = Debug|Any CPU {0EAED5C3-DAB2-4919-9C26-EAD4D8222BD0}.Release|Any CPU.ActiveCfg = Release|Any CPU {0EAED5C3-DAB2-4919-9C26-EAD4D8222BD0}.Release|Any CPU.Build.0 = Release|Any CPU + {61B2922F-25C0-4F10-8DF0-FF91287C4452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {61B2922F-25C0-4F10-8DF0-FF91287C4452}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61B2922F-25C0-4F10-8DF0-FF91287C4452}.Release|Any CPU.ActiveCfg = Release|Any CPU + {61B2922F-25C0-4F10-8DF0-FF91287C4452}.Release|Any CPU.Build.0 = Release|Any CPU + {3E81CFB2-ADEE-4B81-BC13-F6CE8546F9C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E81CFB2-ADEE-4B81-BC13-F6CE8546F9C9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E81CFB2-ADEE-4B81-BC13-F6CE8546F9C9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E81CFB2-ADEE-4B81-BC13-F6CE8546F9C9}.Release|Any CPU.Build.0 = Release|Any CPU + {9808F069-6DC1-4C26-A434-16630FC697E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9808F069-6DC1-4C26-A434-16630FC697E8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9808F069-6DC1-4C26-A434-16630FC697E8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9808F069-6DC1-4C26-A434-16630FC697E8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/XmlFormatter/App.config b/XmlFormatter/App.config index ea14522b..f5448674 100644 --- a/XmlFormatter/App.config +++ b/XmlFormatter/App.config @@ -11,6 +11,9 @@ + + + diff --git a/XmlFormatter/Program.cs b/XmlFormatter/Program.cs index 343aeed6..d2a90a9d 100644 --- a/XmlFormatter/Program.cs +++ b/XmlFormatter/Program.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; using XmlFormatter.src.Windows; @@ -15,9 +12,16 @@ static class Program [STAThread] static void Main() { + if (Environment.OSVersion.Version.Major >= 6) + { + SetProcessDPIAware(); + } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } + + [System.Runtime.InteropServices.DllImport("user32.dll")] + private static extern bool SetProcessDPIAware(); } } diff --git a/XmlFormatter/Properties/AssemblyInfo.cs b/XmlFormatter/Properties/AssemblyInfo.cs index 7b8dc8d4..c7702e82 100644 --- a/XmlFormatter/Properties/AssemblyInfo.cs +++ b/XmlFormatter/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/XmlFormatter/XmlFormatter.csproj b/XmlFormatter/XmlFormatter.csproj index 481b2fe1..9a574b4d 100644 --- a/XmlFormatter/XmlFormatter.csproj +++ b/XmlFormatter/XmlFormatter.csproj @@ -25,7 +25,7 @@ AnyCPU - pdbonly + none true bin\Release\ TRACE @@ -36,8 +36,8 @@ XmlFormatterIcon.ico - - ..\packages\Octokit.0.36.0\lib\net46\Octokit.dll + + ..\packages\Octokit.0.47.0\lib\net46\Octokit.dll @@ -53,6 +53,7 @@ + @@ -60,10 +61,8 @@ - - @@ -72,11 +71,9 @@ - - @@ -91,8 +88,6 @@ - - Form @@ -108,15 +103,26 @@ - + + Form + + + PluginManager.cs + Form Settings.cs + + Form + + + VersionInformation.cs + HotfolderEditor.cs @@ -148,14 +154,31 @@ + + PluginManager.cs + Settings.cs + + VersionInformation.cs + - + + + {9808f069-6dc1-4c26-a434-16630fc697e8} + PluginFramework + + + + mkdir "$(ProjectDir)\$(OutDir)\Plugins" +copy "$(ProjectDir)\..\CorePlugin\$(OutDir)\CorePlugin.dll" "$(ProjectDir)\$(OutDir)\Plugins" +copy "$(ProjectDir)\..\JsonPlugin\$(OutDir)\JsonPlugin.dll" "$(ProjectDir)\$(OutDir)\Plugins" +copy "$(ProjectDir)\..\JsonPlugin\$(OutDir)\Newtonsoft.Json.dll" "$(ProjectDir)\$(OutDir)\Plugins" + \ No newline at end of file diff --git a/XmlFormatter/packages.config b/XmlFormatter/packages.config index d1d9d70b..3866a875 100644 --- a/XmlFormatter/packages.config +++ b/XmlFormatter/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/XmlFormatter/src/DataContainer/ComboboxPluginItem.cs b/XmlFormatter/src/DataContainer/ComboboxPluginItem.cs new file mode 100644 index 00000000..db2ebcba --- /dev/null +++ b/XmlFormatter/src/DataContainer/ComboboxPluginItem.cs @@ -0,0 +1,49 @@ +using PluginFramework.src.DataContainer; +using System; + +namespace XmlFormatter.src.DataContainer +{ + /// + /// A class to use with the combobox + /// + public class ComboboxPluginItem + { + /// + /// The plugin information to display + /// + public PluginInformation Information => metaData.Information; + + /// + /// The id of the plugin + /// + public int Id => metaData.Id; + + /// + /// The type of the plugin + /// + public Type Type => metaData.Type; + + /// + /// The meta data of the plugin + /// + private readonly PluginMetaData metaData; + + /// + /// Create a new instance of this class + /// + /// The meta data to use + public ComboboxPluginItem(PluginMetaData metaData) + { + this.metaData = metaData; + } + + /// + /// Overriding the to string method + /// + /// The name of the plugin + public override string ToString() + { + return Information.Name; + } + } +} diff --git a/XmlFormatter/src/DataContainer/HotfolderTask.cs b/XmlFormatter/src/DataContainer/HotfolderTask.cs index e47ec6e6..800b516d 100644 --- a/XmlFormatter/src/DataContainer/HotfolderTask.cs +++ b/XmlFormatter/src/DataContainer/HotfolderTask.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using XmlFormatter.src.Interfaces.Hotfolder; +using XmlFormatter.src.Interfaces.Hotfolder; namespace XmlFormatter.src.DataContainer { diff --git a/XmlFormatter/src/DataContainer/Logging/LoggingMessage.cs b/XmlFormatter/src/DataContainer/Logging/LoggingMessage.cs index 565d64c3..d840395d 100644 --- a/XmlFormatter/src/DataContainer/Logging/LoggingMessage.cs +++ b/XmlFormatter/src/DataContainer/Logging/LoggingMessage.cs @@ -112,7 +112,7 @@ public LoggingMessage(LogScopesEnum scope, string sender, string message) /// The message itself /// A throwen exception public LoggingMessage(LogScopesEnum scope, object sender, string message, Exception exception) - : this (scope, sender.GetType().FullName, message, exception) + : this(scope, sender.GetType().FullName, message, exception) { } diff --git a/XmlFormatter/src/EventMessages/BaseEventArgs.cs b/XmlFormatter/src/EventMessages/BaseEventArgs.cs index b96010bd..1d67f1b7 100644 --- a/XmlFormatter/src/EventMessages/BaseEventArgs.cs +++ b/XmlFormatter/src/EventMessages/BaseEventArgs.cs @@ -37,6 +37,5 @@ public BaseEventArgs(string title, string message) this.title = title; this.message = message; } - } } diff --git a/XmlFormatter/src/Hotfolder/HotfolderContainer.cs b/XmlFormatter/src/Hotfolder/HotfolderContainer.cs index a45d4c82..bf942d15 100644 --- a/XmlFormatter/src/Hotfolder/HotfolderContainer.cs +++ b/XmlFormatter/src/Hotfolder/HotfolderContainer.cs @@ -1,5 +1,5 @@ -using XmlFormatter.src.Enums; -using XmlFormatter.src.Interfaces.Formatter; +using PluginFramework.src.Enums; +using PluginFramework.src.Interfaces.PluginTypes; using XmlFormatter.src.Interfaces.Hotfolder; namespace XmlFormatter.src.Hotfolder @@ -9,11 +9,6 @@ namespace XmlFormatter.src.Hotfolder /// class HotfolderContainer : IHotfolder { - /// - /// The mode to use for formatting - /// - private ModesEnum mode; - /// public ModesEnum Mode { @@ -22,14 +17,17 @@ public ModesEnum Mode } /// - /// The formatter to use + /// The mode to use for formatting /// - private readonly IFormatter formatterToUse; + private ModesEnum mode; /// public IFormatter FormatterToUse => formatterToUse; - private string watchedFolder; + /// + /// The formatter to use + /// + private readonly IFormatter formatterToUse; /// public string WatchedFolder @@ -39,21 +37,21 @@ public string WatchedFolder } /// - /// The filter to use in the watched folder + /// The folder which is getting watched /// - private string filter; + private string watchedFolder; /// public string Filter { get => filter; - set => filter = value; + set => filter = value; } /// - /// The output folder to save the new file in + /// The filter to use in the watched folder /// - private string outputFolder; + private string filter; /// public string OutputFolder @@ -63,9 +61,9 @@ public string OutputFolder } /// - /// The scheme of the output file + /// The output folder to save the new file in /// - private string outputFileScheme; + private string outputFolder; /// public string OutputFileScheme @@ -75,9 +73,9 @@ public string OutputFileScheme } /// - /// Should we trigger on rename as well + /// The scheme of the output file /// - private bool onRename; + private string outputFileScheme; /// public bool OnRename @@ -87,9 +85,9 @@ public bool OnRename } /// - /// Should we delete the old file + /// Should we trigger on rename as well /// - private bool removeOld; + private bool onRename; /// public bool RemoveOld @@ -98,6 +96,11 @@ public bool RemoveOld set => removeOld = value; } + /// + /// Should we delete the old file + /// + private bool removeOld; + /// /// Create a new instance of the hotfolder configuration /// diff --git a/XmlFormatter/src/Hotfolder/HotfolderManager.cs b/XmlFormatter/src/Hotfolder/HotfolderManager.cs index e3212e92..8c592dde 100644 --- a/XmlFormatter/src/Hotfolder/HotfolderManager.cs +++ b/XmlFormatter/src/Hotfolder/HotfolderManager.cs @@ -102,7 +102,7 @@ private void LogMessage(object sender, string message) /// public bool AddHotfolder(IHotfolder newHotfolder) { - if (GetHotfolderByWatchedFolder(newHotfolder.WatchedFolder) != null) + if (IsSameWatcherRegisterd(newHotfolder)) { return false; } @@ -126,10 +126,16 @@ public bool AddHotfolder(IHotfolder newHotfolder) LogMessage("Watched folder: " + newHotfolder.WatchedFolder); LogMessage("Output folder: " + newHotfolder.OutputFolder); LogMessage("Mode: " + newHotfolder.Mode); - LogMessage("Formatter " + newHotfolder.FormatterToUse.ToString()); - newHotfolder.FormatterToUse.StatusChanged += FormatterToUse_StatusChanged; - hotfolders.Add(newHotfolder, watcher); - return true; + if (newHotfolder.FormatterToUse != null) + { + LogMessage("Formatter " + newHotfolder.FormatterToUse.ToString()); + newHotfolder.FormatterToUse.StatusChanged += FormatterToUse_StatusChanged; + hotfolders.Add(newHotfolder, watcher); + return true; + } + + LogMessage("Formatter: Could not be found! Maybe the plugin was deleted?"); + return false; } /// @@ -137,7 +143,7 @@ public bool AddHotfolder(IHotfolder newHotfolder) /// /// Sender of the message /// The data of the event - private void FormatterToUse_StatusChanged(object sender, EventMessages.BaseEventArgs e) + private void FormatterToUse_StatusChanged(object sender, PluginFramework.src.EventMessages.BaseEventArgs e) { LogMessage(sender, "Convert status: " + e.Message); } @@ -146,15 +152,43 @@ private void FormatterToUse_StatusChanged(object sender, EventMessages.BaseEvent /// Get the hotfolder by the watched folder /// /// The watched folder to get the hotfolder for + /// The filter used by the watcher /// The hotfolder - private IHotfolder GetHotfolderByWatchedFolder(string watchedFolder) + /// // + private IHotfolder GetHotfolderByWatchedFolder(string watchedFolder, string filter) { return hotfolders.Keys.ToList().Find((currentHotfolder) => { - return currentHotfolder.WatchedFolder == watchedFolder; + return currentHotfolder.WatchedFolder == watchedFolder && currentHotfolder.Filter == filter; }); } + /// + /// Is there already an identical watcher registerec + /// + /// The new hotfolder config to check + /// True if there is already an identical active configuration + private bool IsSameWatcherRegisterd(IHotfolder hotfolder) + { + return hotfolders.Keys.ToList().Find(currentHotfolder => + { + bool isIdentical = false; + if (hotfolder.FormatterToUse == null) + { + return true; + } + if (currentHotfolder.FormatterToUse.GetType() == hotfolder.FormatterToUse.GetType()) + { + if (currentHotfolder.Mode == hotfolder.Mode && currentHotfolder.WatchedFolder == hotfolder.WatchedFolder) + { + isIdentical = true; + } + } + + return isIdentical; + }) != null; + } + /// /// Something in a hotfolder did change /// @@ -167,24 +201,27 @@ private void Watcher_Changed(object sender, FileSystemEventArgs e) return; } - FileInfo fileInfo = new FileInfo(e.FullPath); - IHotfolder hotfolder = GetHotfolderByWatchedFolder(fileInfo.DirectoryName); - if (hotfolder == null || lastInput == e.FullPath) - { - return; - } - if (tasks.Find((data) => { return data.InputFile == e.FullPath; }) == null) + if (sender is FileSystemWatcher watcher) { - LogMessage("Adding new convert task"); - LogMessage("Input " + e.FullPath); - LogMessage("Output folder " + hotfolder.OutputFolder); - LogMessage("Mode " + hotfolder.Mode); - LogMessage("Converter " + hotfolder.FormatterToUse.ToString()); - lastInput = e.FullPath; - tasks.Add(new HotfolderTask(e.FullPath, hotfolder)); - LogMessage("Current task stack " + tasks.Count); + FileInfo fileInfo = new FileInfo(e.FullPath); + IHotfolder hotfolder = GetHotfolderByWatchedFolder(fileInfo.DirectoryName, watcher.Filter); + if (hotfolder == null || lastInput == e.FullPath) + { + return; + } + if (tasks.Find((data) => { return data.InputFile == e.FullPath; }) == null) + { + LogMessage("Adding new convert task"); + LogMessage("Input " + e.FullPath); + LogMessage("Output folder " + hotfolder.OutputFolder); + LogMessage("Mode " + hotfolder.Mode); + LogMessage("Converter " + hotfolder.FormatterToUse.ToString()); + lastInput = e.FullPath; + tasks.Add(new HotfolderTask(e.FullPath, hotfolder)); + LogMessage("Current task stack " + tasks.Count); + } + PerformeTasks(); } - PerformeTasks(); } /// diff --git a/XmlFormatter/src/Interfaces/Hotfolder/IHotfolder.cs b/XmlFormatter/src/Interfaces/Hotfolder/IHotfolder.cs index 836c12e5..1ac6da8d 100644 --- a/XmlFormatter/src/Interfaces/Hotfolder/IHotfolder.cs +++ b/XmlFormatter/src/Interfaces/Hotfolder/IHotfolder.cs @@ -1,5 +1,5 @@ -using XmlFormatter.src.Enums; -using XmlFormatter.src.Interfaces.Formatter; +using PluginFramework.src.Enums; +using PluginFramework.src.Interfaces.PluginTypes; namespace XmlFormatter.src.Interfaces.Hotfolder { @@ -26,7 +26,7 @@ public interface IHotfolder /// /// The filter to use for the input files /// - string Filter { get; set;} + string Filter { get; set; } /// /// The folder to write the output to diff --git a/XmlFormatter/src/Interfaces/Hotfolder/IHotfolderManager.cs b/XmlFormatter/src/Interfaces/Hotfolder/IHotfolderManager.cs index 600d9fce..0eb74df4 100644 --- a/XmlFormatter/src/Interfaces/Hotfolder/IHotfolderManager.cs +++ b/XmlFormatter/src/Interfaces/Hotfolder/IHotfolderManager.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace XmlFormatter.src.Interfaces.Hotfolder { diff --git a/XmlFormatter/src/Interfaces/Updates/IUpdater.cs b/XmlFormatter/src/Interfaces/Updates/IUpdater.cs index ce494fc0..de6f34e8 100644 --- a/XmlFormatter/src/Interfaces/Updates/IUpdater.cs +++ b/XmlFormatter/src/Interfaces/Updates/IUpdater.cs @@ -1,4 +1,5 @@ -using XmlFormatter.src.DataContainer; +using PluginFramework.src.DataContainer; +using PluginFramework.src.Interfaces.PluginTypes; namespace XmlFormatter.src.Interfaces.Updates { @@ -7,6 +8,8 @@ namespace XmlFormatter.src.Interfaces.Updates /// interface IUpdater { + bool IsStrategySet { get; } + /// /// The strategy to use for the update /// diff --git a/XmlFormatter/src/Logging/FormatStrategies/SimpleFileFormatStrategy.cs b/XmlFormatter/src/Logging/FormatStrategies/SimpleFileFormatStrategy.cs index c2b970c5..9b3f7c01 100644 --- a/XmlFormatter/src/Logging/FormatStrategies/SimpleFileFormatStrategy.cs +++ b/XmlFormatter/src/Logging/FormatStrategies/SimpleFileFormatStrategy.cs @@ -20,7 +20,7 @@ class SimpleFileFormatStrategy : ILoggingFormatStrategy public SimpleFileFormatStrategy() : this(70) { - + } /// diff --git a/XmlFormatter/src/Manager/VersionManager.cs b/XmlFormatter/src/Manager/VersionManager.cs index 92cab6f1..750f92ff 100644 --- a/XmlFormatter/src/Manager/VersionManager.cs +++ b/XmlFormatter/src/Manager/VersionManager.cs @@ -1,13 +1,12 @@ using Octokit; +using PluginFramework.src.DataContainer; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; -using XmlFormatter.src.DataContainer; using XmlFormatter.src.EventMessages; namespace XmlFormatter.src.Manager @@ -81,13 +80,17 @@ public async Task GitHubVersionIsNewer() { ThrowError("No version found", "Could't not find a version on GitHub"); } - Release latestRelease = releases[0]; - string latest = latestRelease.Name; - Regex regex = new Regex(@"([0-9]{1,}.[0-9]{1,}.[0-9]{1,})"); + string gitHubString = ""; Version gitHubVersion = null; - foreach (Match match in regex.Matches(latest)) + Regex regex = new Regex(@"([0-9]{1,}.[0-9]{1,}.[0-9]{1,})"); + + List correctTags = releases.Where(release => regex.IsMatch(release.TagName)).ToList(); + Release latestRelease = correctTags.Count > 0 ? correctTags[0] : null; + + if (latestRelease != null) { - gitHubVersion = ConvertInnerFormatToProperVersion(match.Value); + string version = regex.Match(latestRelease.TagName).Value; + gitHubVersion = ConvertInnerFormatToProperVersion(version); } Version applicationVersion = GetApplicationVersion(); int compareResult = applicationVersion.CompareTo(gitHubVersion); diff --git a/XmlFormatter/src/Settings/Adapter/PropertyAdapter.cs b/XmlFormatter/src/Settings/Adapter/PropertyAdapter.cs index f27bdde3..369528cf 100644 --- a/XmlFormatter/src/Settings/Adapter/PropertyAdapter.cs +++ b/XmlFormatter/src/Settings/Adapter/PropertyAdapter.cs @@ -77,7 +77,7 @@ public ISettingPair GetSetting(string name) { //Not important since we can return an empty value } - + return returnValue; } diff --git a/XmlFormatter/src/Settings/Hotfolder/HotfolderExtension.cs b/XmlFormatter/src/Settings/Hotfolder/HotfolderExtension.cs index 175ebbfc..9b252bd7 100644 --- a/XmlFormatter/src/Settings/Hotfolder/HotfolderExtension.cs +++ b/XmlFormatter/src/Settings/Hotfolder/HotfolderExtension.cs @@ -1,10 +1,9 @@ -using System; +using PluginFramework.src.Enums; +using PluginFramework.src.Interfaces.Manager; +using PluginFramework.src.Interfaces.PluginTypes; +using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using XmlFormatter.src.Enums; using XmlFormatter.src.Hotfolder; -using XmlFormatter.src.Interfaces.Formatter; using XmlFormatter.src.Interfaces.Hotfolder; using XmlFormatter.src.Interfaces.Settings; using XmlFormatter.src.Interfaces.Settings.DataStructure; @@ -21,13 +20,19 @@ class HotfolderExtension /// private readonly ISettingsManager settingsManager; + /// + /// Plugin manager to use + /// + private readonly IPluginManager pluginManager; + /// /// Create a new instance of this extension class /// /// The settings manager to use - public HotfolderExtension(ISettingsManager settingsManager) + public HotfolderExtension(ISettingsManager settingsManager, IPluginManager pluginManager) { this.settingsManager = settingsManager; + this.pluginManager = pluginManager; } /// @@ -46,8 +51,7 @@ public List GetHotFoldersFromSettings() { string type = subSetting.GetSetting("Type").GetValue(); string watchFolder = subSetting.GetSetting("WatchedFolder").GetValue(); - Type realType = Type.GetType(type); - IFormatter formatter = (IFormatter)Activator.CreateInstance(realType); + IFormatter formatter = pluginManager.LoadPlugin(type); IHotfolder hotfolderToAdd = new HotfolderContainer(formatter, watchFolder); string mode = subSetting.GetSetting("Mode").GetValue(); hotfolderToAdd.Mode = (ModesEnum)Enum.Parse(typeof(ModesEnum), mode); diff --git a/XmlFormatter/src/Settings/Provider/XmlSaverProvider.cs b/XmlFormatter/src/Settings/Provider/XmlSaverProvider.cs index 4e2459d7..7fcbafea 100644 --- a/XmlFormatter/src/Settings/Provider/XmlSaverProvider.cs +++ b/XmlFormatter/src/Settings/Provider/XmlSaverProvider.cs @@ -33,7 +33,7 @@ public bool SaveSettings(ISettingsManager settingsManager, string filePath) { xmlSerializer.Serialize(writer, container); } - + return true; } diff --git a/XmlFormatter/src/Update/UpdateManager.cs b/XmlFormatter/src/Update/UpdateManager.cs index 83a90b07..c86079c0 100644 --- a/XmlFormatter/src/Update/UpdateManager.cs +++ b/XmlFormatter/src/Update/UpdateManager.cs @@ -1,4 +1,5 @@ -using XmlFormatter.src.DataContainer; +using PluginFramework.src.DataContainer; +using PluginFramework.src.Interfaces.PluginTypes; using XmlFormatter.src.Interfaces.Updates; namespace XmlFormatter.src.Update @@ -8,8 +9,16 @@ namespace XmlFormatter.src.Update /// class UpdateManager : IUpdater { + /// + /// The strategy to use + /// private IUpdateStrategy strategy; + /// + /// Is there a update strategy set + /// + public bool IsStrategySet => strategy != null; + /// public void SetStrategy(IUpdateStrategy updateStrategy) { diff --git a/XmlFormatter/src/Windows/HotfolderEditor.Designer.cs b/XmlFormatter/src/Windows/HotfolderEditor.Designer.cs index d11d77bb..5607e160 100644 --- a/XmlFormatter/src/Windows/HotfolderEditor.Designer.cs +++ b/XmlFormatter/src/Windows/HotfolderEditor.Designer.cs @@ -61,9 +61,11 @@ private void InitializeComponent() this.GB_General.Controls.Add(this.L_Mode); this.GB_General.Controls.Add(this.L_Provider); this.GB_General.Controls.Add(this.CB_Formatter); - this.GB_General.Location = new System.Drawing.Point(12, 12); + this.GB_General.Location = new System.Drawing.Point(18, 18); + this.GB_General.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.GB_General.Name = "GB_General"; - this.GB_General.Size = new System.Drawing.Size(346, 115); + this.GB_General.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.GB_General.Size = new System.Drawing.Size(519, 177); this.GB_General.TabIndex = 0; this.GB_General.TabStop = false; this.GB_General.Text = "General"; @@ -72,26 +74,29 @@ private void InitializeComponent() // this.CB_Mode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_Mode.FormattingEnabled = true; - this.CB_Mode.Location = new System.Drawing.Point(6, 75); + this.CB_Mode.Location = new System.Drawing.Point(9, 115); + this.CB_Mode.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.CB_Mode.Name = "CB_Mode"; - this.CB_Mode.Size = new System.Drawing.Size(334, 21); + this.CB_Mode.Size = new System.Drawing.Size(499, 28); this.CB_Mode.TabIndex = 3; // // L_Mode // this.L_Mode.AutoSize = true; - this.L_Mode.Location = new System.Drawing.Point(3, 59); + this.L_Mode.Location = new System.Drawing.Point(4, 91); + this.L_Mode.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.L_Mode.Name = "L_Mode"; - this.L_Mode.Size = new System.Drawing.Size(34, 13); + this.L_Mode.Size = new System.Drawing.Size(49, 20); this.L_Mode.TabIndex = 2; this.L_Mode.Text = "Mode"; // // L_Provider // this.L_Provider.AutoSize = true; - this.L_Provider.Location = new System.Drawing.Point(3, 16); + this.L_Provider.Location = new System.Drawing.Point(4, 25); + this.L_Provider.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.L_Provider.Name = "L_Provider"; - this.L_Provider.Size = new System.Drawing.Size(46, 13); + this.L_Provider.Size = new System.Drawing.Size(66, 20); this.L_Provider.TabIndex = 1; this.L_Provider.Text = "Provider"; // @@ -99,9 +104,10 @@ private void InitializeComponent() // this.CB_Formatter.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_Formatter.FormattingEnabled = true; - this.CB_Formatter.Location = new System.Drawing.Point(6, 35); + this.CB_Formatter.Location = new System.Drawing.Point(9, 54); + this.CB_Formatter.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.CB_Formatter.Name = "CB_Formatter"; - this.CB_Formatter.Size = new System.Drawing.Size(334, 21); + this.CB_Formatter.Size = new System.Drawing.Size(499, 28); this.CB_Formatter.TabIndex = 0; // // GB_Folders @@ -116,50 +122,57 @@ private void InitializeComponent() this.GB_Folders.Controls.Add(this.B_OpenWatchFolder); this.GB_Folders.Controls.Add(this.TB_WatchedFolder); this.GB_Folders.Controls.Add(this.L_WatchedFolder); - this.GB_Folders.Location = new System.Drawing.Point(12, 133); + this.GB_Folders.Location = new System.Drawing.Point(18, 205); + this.GB_Folders.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.GB_Folders.Name = "GB_Folders"; - this.GB_Folders.Size = new System.Drawing.Size(346, 181); + this.GB_Folders.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.GB_Folders.Size = new System.Drawing.Size(519, 278); this.GB_Folders.TabIndex = 1; this.GB_Folders.TabStop = false; this.GB_Folders.Text = "Folders"; // // TB_OutputFileScheme // - this.TB_OutputFileScheme.Location = new System.Drawing.Point(6, 149); + this.TB_OutputFileScheme.Location = new System.Drawing.Point(9, 229); + this.TB_OutputFileScheme.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.TB_OutputFileScheme.Name = "TB_OutputFileScheme"; - this.TB_OutputFileScheme.Size = new System.Drawing.Size(304, 20); + this.TB_OutputFileScheme.Size = new System.Drawing.Size(454, 26); this.TB_OutputFileScheme.TabIndex = 11; // // L_OutputScheme // this.L_OutputScheme.AutoSize = true; - this.L_OutputScheme.Location = new System.Drawing.Point(3, 133); + this.L_OutputScheme.Location = new System.Drawing.Point(4, 205); + this.L_OutputScheme.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.L_OutputScheme.Name = "L_OutputScheme"; - this.L_OutputScheme.Size = new System.Drawing.Size(95, 13); + this.L_OutputScheme.Size = new System.Drawing.Size(142, 20); this.L_OutputScheme.TabIndex = 10; this.L_OutputScheme.Text = "Output file scheme"; // // L_Filter // this.L_Filter.AutoSize = true; - this.L_Filter.Location = new System.Drawing.Point(3, 55); + this.L_Filter.Location = new System.Drawing.Point(4, 85); + this.L_Filter.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.L_Filter.Name = "L_Filter"; - this.L_Filter.Size = new System.Drawing.Size(29, 13); + this.L_Filter.Size = new System.Drawing.Size(44, 20); this.L_Filter.TabIndex = 9; this.L_Filter.Text = "Filter"; // // TB_Filter // - this.TB_Filter.Location = new System.Drawing.Point(6, 71); + this.TB_Filter.Location = new System.Drawing.Point(9, 109); + this.TB_Filter.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.TB_Filter.Name = "TB_Filter"; - this.TB_Filter.Size = new System.Drawing.Size(304, 20); + this.TB_Filter.Size = new System.Drawing.Size(454, 26); this.TB_Filter.TabIndex = 8; // // B_OutputFolder // - this.B_OutputFolder.Location = new System.Drawing.Point(316, 110); + this.B_OutputFolder.Location = new System.Drawing.Point(474, 169); + this.B_OutputFolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_OutputFolder.Name = "B_OutputFolder"; - this.B_OutputFolder.Size = new System.Drawing.Size(24, 20); + this.B_OutputFolder.Size = new System.Drawing.Size(36, 31); this.B_OutputFolder.TabIndex = 5; this.B_OutputFolder.Text = "..."; this.B_OutputFolder.UseVisualStyleBackColor = true; @@ -167,25 +180,28 @@ private void InitializeComponent() // // TB_OutputFolder // - this.TB_OutputFolder.Location = new System.Drawing.Point(6, 110); + this.TB_OutputFolder.Location = new System.Drawing.Point(9, 169); + this.TB_OutputFolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.TB_OutputFolder.Name = "TB_OutputFolder"; - this.TB_OutputFolder.Size = new System.Drawing.Size(304, 20); + this.TB_OutputFolder.Size = new System.Drawing.Size(454, 26); this.TB_OutputFolder.TabIndex = 4; // // L_OutputFolder // this.L_OutputFolder.AutoSize = true; - this.L_OutputFolder.Location = new System.Drawing.Point(3, 94); + this.L_OutputFolder.Location = new System.Drawing.Point(4, 145); + this.L_OutputFolder.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.L_OutputFolder.Name = "L_OutputFolder"; - this.L_OutputFolder.Size = new System.Drawing.Size(68, 13); + this.L_OutputFolder.Size = new System.Drawing.Size(102, 20); this.L_OutputFolder.TabIndex = 3; this.L_OutputFolder.Text = "Output folder"; // // B_OpenWatchFolder // - this.B_OpenWatchFolder.Location = new System.Drawing.Point(316, 32); + this.B_OpenWatchFolder.Location = new System.Drawing.Point(474, 49); + this.B_OpenWatchFolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_OpenWatchFolder.Name = "B_OpenWatchFolder"; - this.B_OpenWatchFolder.Size = new System.Drawing.Size(24, 20); + this.B_OpenWatchFolder.Size = new System.Drawing.Size(36, 31); this.B_OpenWatchFolder.TabIndex = 2; this.B_OpenWatchFolder.Text = "..."; this.B_OpenWatchFolder.UseVisualStyleBackColor = true; @@ -193,17 +209,19 @@ private void InitializeComponent() // // TB_WatchedFolder // - this.TB_WatchedFolder.Location = new System.Drawing.Point(6, 32); + this.TB_WatchedFolder.Location = new System.Drawing.Point(9, 49); + this.TB_WatchedFolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.TB_WatchedFolder.Name = "TB_WatchedFolder"; - this.TB_WatchedFolder.Size = new System.Drawing.Size(304, 20); + this.TB_WatchedFolder.Size = new System.Drawing.Size(454, 26); this.TB_WatchedFolder.TabIndex = 1; // // L_WatchedFolder // this.L_WatchedFolder.AutoSize = true; - this.L_WatchedFolder.Location = new System.Drawing.Point(3, 16); + this.L_WatchedFolder.Location = new System.Drawing.Point(4, 25); + this.L_WatchedFolder.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.L_WatchedFolder.Name = "L_WatchedFolder"; - this.L_WatchedFolder.Size = new System.Drawing.Size(80, 13); + this.L_WatchedFolder.Size = new System.Drawing.Size(118, 20); this.L_WatchedFolder.TabIndex = 0; this.L_WatchedFolder.Text = "Folder to watch"; // @@ -211,9 +229,11 @@ private void InitializeComponent() // this.GB_Triggers.Controls.Add(this.CB_RemoveOld); this.GB_Triggers.Controls.Add(this.CB_OnRename); - this.GB_Triggers.Location = new System.Drawing.Point(12, 320); + this.GB_Triggers.Location = new System.Drawing.Point(18, 492); + this.GB_Triggers.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.GB_Triggers.Name = "GB_Triggers"; - this.GB_Triggers.Size = new System.Drawing.Size(346, 46); + this.GB_Triggers.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.GB_Triggers.Size = new System.Drawing.Size(519, 71); this.GB_Triggers.TabIndex = 2; this.GB_Triggers.TabStop = false; this.GB_Triggers.Text = "Trigger"; @@ -221,9 +241,10 @@ private void InitializeComponent() // CB_RemoveOld // this.CB_RemoveOld.AutoSize = true; - this.CB_RemoveOld.Location = new System.Drawing.Point(232, 19); + this.CB_RemoveOld.Location = new System.Drawing.Point(348, 29); + this.CB_RemoveOld.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.CB_RemoveOld.Name = "CB_RemoveOld"; - this.CB_RemoveOld.Size = new System.Drawing.Size(108, 17); + this.CB_RemoveOld.Size = new System.Drawing.Size(157, 24); this.CB_RemoveOld.TabIndex = 1; this.CB_RemoveOld.Text = "Remove input file"; this.CB_RemoveOld.UseVisualStyleBackColor = true; @@ -231,18 +252,20 @@ private void InitializeComponent() // CB_OnRename // this.CB_OnRename.AutoSize = true; - this.CB_OnRename.Location = new System.Drawing.Point(6, 19); + this.CB_OnRename.Location = new System.Drawing.Point(9, 29); + this.CB_OnRename.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.CB_OnRename.Name = "CB_OnRename"; - this.CB_OnRename.Size = new System.Drawing.Size(72, 17); + this.CB_OnRename.Size = new System.Drawing.Size(105, 24); this.CB_OnRename.TabIndex = 0; this.CB_OnRename.Text = "Renamed"; this.CB_OnRename.UseVisualStyleBackColor = true; // // B_Save // - this.B_Save.Location = new System.Drawing.Point(12, 372); + this.B_Save.Location = new System.Drawing.Point(18, 572); + this.B_Save.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_Save.Name = "B_Save"; - this.B_Save.Size = new System.Drawing.Size(75, 23); + this.B_Save.Size = new System.Drawing.Size(112, 35); this.B_Save.TabIndex = 3; this.B_Save.Text = "Save"; this.B_Save.UseVisualStyleBackColor = true; @@ -250,9 +273,10 @@ private void InitializeComponent() // // B_Cancel // - this.B_Cancel.Location = new System.Drawing.Point(283, 372); + this.B_Cancel.Location = new System.Drawing.Point(424, 572); + this.B_Cancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_Cancel.Name = "B_Cancel"; - this.B_Cancel.Size = new System.Drawing.Size(75, 23); + this.B_Cancel.Size = new System.Drawing.Size(112, 35); this.B_Cancel.TabIndex = 4; this.B_Cancel.Text = "Cancel"; this.B_Cancel.UseVisualStyleBackColor = true; @@ -260,9 +284,9 @@ private void InitializeComponent() // // HotfolderEditor // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(370, 402); + this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(555, 618); this.Controls.Add(this.B_Cancel); this.Controls.Add(this.B_Save); this.Controls.Add(this.GB_Triggers); @@ -270,6 +294,7 @@ private void InitializeComponent() this.Controls.Add(this.GB_General); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.Name = "HotfolderEditor"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Hotfolder Editor"; diff --git a/XmlFormatter/src/Windows/HotfolderEditor.cs b/XmlFormatter/src/Windows/HotfolderEditor.cs index 6d64e7fb..483e64b5 100644 --- a/XmlFormatter/src/Windows/HotfolderEditor.cs +++ b/XmlFormatter/src/Windows/HotfolderEditor.cs @@ -1,13 +1,13 @@ -using System; +using PluginFramework.src.DataContainer; +using PluginFramework.src.Enums; +using PluginFramework.src.Interfaces.Manager; +using PluginFramework.src.Interfaces.PluginTypes; +using System; using System.Collections.Generic; -using System.Data; using System.IO; -using System.Linq; -using System.Reflection; using System.Windows.Forms; -using XmlFormatter.src.Enums; +using XmlFormatter.src.DataContainer; using XmlFormatter.src.Hotfolder; -using XmlFormatter.src.Interfaces.Formatter; using XmlFormatter.src.Interfaces.Hotfolder; namespace XmlFormatter.src.Windows @@ -22,44 +22,43 @@ public partial class HotfolderEditor : Form /// private readonly bool editMode; - /// - /// Was something saved - /// - private bool saved; - /// /// Readonly access if something was saved /// - public bool Saved => saved; + public bool Saved { get; private set; } /// - /// A lookup for the formatters + /// Readonly access to the hotfolder configuration /// - private readonly Dictionary formatters; + public IHotfolder Hotfolder { get; private set; } /// - /// The current hotfolder configuration + /// The plugin manager to use /// - private IHotfolder hotfolder; + private readonly IPluginManager PluginManager; /// - /// Readonly access to the hotfolder configuration + /// Create a new instance of the editor /// - public IHotfolder Hotfolder => hotfolder; + /// The hotfolder configuration to use for editing + public HotfolderEditor(IPluginManager pluginManager) : this(null, pluginManager) + { + + } /// /// Create a new instance of the editor /// /// The hotfolder configuration to use for editing - public HotfolderEditor(IHotfolder hotfolder) + public HotfolderEditor(IHotfolder hotfolder, IPluginManager pluginManager) { editMode = hotfolder != null; - formatters = new Dictionary(); - + InitializeComponent(); CB_Formatter.Enabled = !editMode; - this.hotfolder = hotfolder; + Hotfolder = hotfolder; + PluginManager = pluginManager; } @@ -70,14 +69,11 @@ public HotfolderEditor(IHotfolder hotfolder) /// Event arguments private void HotfolderEditor_Load(object sender, EventArgs e) { - Type type = typeof(IFormatter); - Type[] types = Assembly.GetExecutingAssembly().GetTypes(); - var formatterTypes = types.Where(currentType => currentType.GetInterfaces().Contains(type)); + List pluginsMetaData = PluginManager.ListPlugins(); - foreach (Type currentType in formatterTypes) + foreach (PluginMetaData metaData in pluginsMetaData) { - formatters.Add(currentType.Name, currentType); - CB_Formatter.Items.Add(currentType.Name); + CB_Formatter.Items.Add(new ComboboxPluginItem(metaData)); } foreach (ModesEnum mode in Enum.GetValues(typeof(ModesEnum))) @@ -101,34 +97,50 @@ private void FillSettingWindow() CB_Mode.SelectedIndex = 0; if (editMode) { + bool foundEntry = false; for (int i = 0; i < CB_Formatter.Items.Count; i++) { - string item = CB_Formatter.Items[i].ToString(); - if (item == hotfolder.FormatterToUse.GetType().Name) + if (CB_Formatter.Items[i] is ComboboxPluginItem item) { - CB_Formatter.SelectedIndex = i; - break; + if (item.Type.FullName == Hotfolder.FormatterToUse.GetType().FullName) + { + CB_Formatter.SelectedIndex = i; + foundEntry = true; + break; + } } + } for (int i = 0; i < CB_Mode.Items.Count; i++) { string item = CB_Mode.Items[i].ToString(); - if (item == hotfolder.Mode.ToString()) + if (item == Hotfolder.Mode.ToString()) { CB_Mode.SelectedIndex = i; break; } } - TB_WatchedFolder.Text = hotfolder.WatchedFolder; - TB_Filter.Text = hotfolder.Filter; - TB_OutputFolder.Text = hotfolder.OutputFolder; - TB_OutputFileScheme.Text = hotfolder.OutputFileScheme; + TB_WatchedFolder.Text = Hotfolder.WatchedFolder; + TB_Filter.Text = Hotfolder.Filter; + TB_OutputFolder.Text = Hotfolder.OutputFolder; + TB_OutputFileScheme.Text = Hotfolder.OutputFileScheme; - CB_OnRename.Checked = hotfolder.OnRename; - CB_RemoveOld.Checked = hotfolder.RemoveOld; + CB_OnRename.Checked = Hotfolder.OnRename; + CB_RemoveOld.Checked = Hotfolder.RemoveOld; + + if (!foundEntry) + { + CB_Formatter.Enabled = true; + MessageBox.Show( + "Missing type " + Hotfolder.FormatterToUse.GetType().FullName + " did you delete the plugin?", + "Missing formatter", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); } + } } /// @@ -200,18 +212,20 @@ private void B_Save_Click(object sender, EventArgs e) ); return; } - Type formatterType = formatters[CB_Formatter.SelectedItem.ToString()]; - IFormatter formatter = (IFormatter)Activator.CreateInstance(formatterType); - hotfolder = new HotfolderContainer(formatter, TB_WatchedFolder.Text) + if (CB_Formatter.SelectedItem is ComboboxPluginItem selectedItem) { - Mode = (ModesEnum)Enum.Parse(typeof(ModesEnum), CB_Mode.SelectedItem.ToString()), - Filter = TB_Filter.Text, - OutputFolder = TB_OutputFolder.Text, - OnRename = CB_OnRename.Checked, - RemoveOld = CB_RemoveOld.Checked - }; - - saved = true; + IFormatter plugin = PluginManager.LoadPlugin(selectedItem.Id); + Hotfolder = new HotfolderContainer(plugin, TB_WatchedFolder.Text) + { + Mode = (ModesEnum)Enum.Parse(typeof(ModesEnum), CB_Mode.SelectedItem.ToString()), + Filter = TB_Filter.Text, + OutputFolder = TB_OutputFolder.Text, + OnRename = CB_OnRename.Checked, + RemoveOld = CB_RemoveOld.Checked + }; + } + + Saved = true; B_Cancel.PerformClick(); } diff --git a/XmlFormatter/src/Windows/MainForm.Designer.cs b/XmlFormatter/src/Windows/MainForm.Designer.cs index abe5d128..3a09e84a 100644 --- a/XmlFormatter/src/Windows/MainForm.Designer.cs +++ b/XmlFormatter/src/Windows/MainForm.Designer.cs @@ -41,35 +41,38 @@ private void InitializeComponent() this.MI_Settings = new System.Windows.Forms.ToolStripMenuItem(); this.MI_Help = new System.Windows.Forms.ToolStripMenuItem(); this.MI_CheckForUpdate = new System.Windows.Forms.ToolStripMenuItem(); + this.pluginsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.MI_About = new System.Windows.Forms.ToolStripMenuItem(); this.MI_ReportIssue = new System.Windows.Forms.ToolStripMenuItem(); this.L_Status = new System.Windows.Forms.Label(); this.NI_Notification = new System.Windows.Forms.NotifyIcon(this.components); + this.CB_Formatter = new System.Windows.Forms.ComboBox(); this.MI_MainMenu.SuspendLayout(); this.SuspendLayout(); // // B_Select // - this.B_Select.Location = new System.Drawing.Point(15, 67); + this.B_Select.Location = new System.Drawing.Point(15, 69); this.B_Select.Name = "B_Select"; - this.B_Select.Size = new System.Drawing.Size(75, 23); + this.B_Select.Size = new System.Drawing.Size(96, 23); this.B_Select.TabIndex = 0; - this.B_Select.Text = "Select XML"; + this.B_Select.Text = "B_Select"; this.B_Select.UseVisualStyleBackColor = true; this.B_Select.Click += new System.EventHandler(this.B_Select_Click); // // TB_SelectedXml // - this.TB_SelectedXml.Location = new System.Drawing.Point(15, 41); + this.TB_SelectedXml.Location = new System.Drawing.Point(15, 42); this.TB_SelectedXml.Name = "TB_SelectedXml"; this.TB_SelectedXml.Size = new System.Drawing.Size(773, 20); this.TB_SelectedXml.TabIndex = 1; // // B_Save // - this.B_Save.Location = new System.Drawing.Point(713, 66); + this.B_Save.Location = new System.Drawing.Point(713, 69); this.B_Save.Name = "B_Save"; - this.B_Save.Size = new System.Drawing.Size(75, 23); + this.B_Save.Size = new System.Drawing.Size(75, 21); this.B_Save.TabIndex = 2; this.B_Save.Text = "Save formatted"; this.B_Save.UseVisualStyleBackColor = true; @@ -78,11 +81,11 @@ private void InitializeComponent() // L_SelectedPath // this.L_SelectedPath.AutoSize = true; - this.L_SelectedPath.Location = new System.Drawing.Point(12, 24); + this.L_SelectedPath.Location = new System.Drawing.Point(12, 25); this.L_SelectedPath.Name = "L_SelectedPath"; - this.L_SelectedPath.Size = new System.Drawing.Size(114, 13); + this.L_SelectedPath.Size = new System.Drawing.Size(83, 13); this.L_SelectedPath.TabIndex = 3; - this.L_SelectedPath.Text = "Selected XML file path"; + this.L_SelectedPath.Text = "L_SelectedPath"; // // CB_Mode // @@ -91,19 +94,21 @@ private void InitializeComponent() this.CB_Mode.Items.AddRange(new object[] { "Formatted", "Flat"}); - this.CB_Mode.Location = new System.Drawing.Point(586, 67); + this.CB_Mode.Location = new System.Drawing.Point(586, 70); this.CB_Mode.Name = "CB_Mode"; this.CB_Mode.Size = new System.Drawing.Size(121, 21); this.CB_Mode.TabIndex = 4; // // MI_MainMenu // + this.MI_MainMenu.ImageScalingSize = new System.Drawing.Size(24, 24); this.MI_MainMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.MI_Help, this.MI_ReportIssue}); this.MI_MainMenu.Location = new System.Drawing.Point(0, 0); this.MI_MainMenu.Name = "MI_MainMenu"; + this.MI_MainMenu.Padding = new System.Windows.Forms.Padding(4, 1, 0, 1); this.MI_MainMenu.Size = new System.Drawing.Size(800, 24); this.MI_MainMenu.TabIndex = 5; this.MI_MainMenu.Text = "menuStrip1"; @@ -114,7 +119,7 @@ private void InitializeComponent() this.MI_HideToTray, this.MI_Settings}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); + this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 22); this.fileToolStripMenuItem.Text = "File"; // // MI_HideToTray @@ -135,9 +140,11 @@ private void InitializeComponent() // this.MI_Help.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.MI_CheckForUpdate, + this.pluginsToolStripMenuItem, + this.toolStripSeparator1, this.MI_About}); this.MI_Help.Name = "MI_Help"; - this.MI_Help.Size = new System.Drawing.Size(44, 20); + this.MI_Help.Size = new System.Drawing.Size(44, 22); this.MI_Help.Text = "Help"; // // MI_CheckForUpdate @@ -147,6 +154,18 @@ private void InitializeComponent() this.MI_CheckForUpdate.Text = "Check for update"; this.MI_CheckForUpdate.Click += new System.EventHandler(this.MI_CheckForUpdate_Click); // + // pluginsToolStripMenuItem + // + this.pluginsToolStripMenuItem.Name = "pluginsToolStripMenuItem"; + this.pluginsToolStripMenuItem.Size = new System.Drawing.Size(165, 22); + this.pluginsToolStripMenuItem.Text = "Plugins"; + this.pluginsToolStripMenuItem.Click += new System.EventHandler(this.pluginsToolStripMenuItem_Click); + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(162, 6); + // // MI_About // this.MI_About.Name = "MI_About"; @@ -157,14 +176,14 @@ private void InitializeComponent() // MI_ReportIssue // this.MI_ReportIssue.Name = "MI_ReportIssue"; - this.MI_ReportIssue.Size = new System.Drawing.Size(83, 20); + this.MI_ReportIssue.Size = new System.Drawing.Size(83, 22); this.MI_ReportIssue.Text = "Report Issue"; this.MI_ReportIssue.Click += new System.EventHandler(this.MI_ReportIssue_Click); // // L_Status // this.L_Status.AutoSize = true; - this.L_Status.Location = new System.Drawing.Point(92, 72); + this.L_Status.Location = new System.Drawing.Point(117, 74); this.L_Status.Name = "L_Status"; this.L_Status.Size = new System.Drawing.Size(49, 13); this.L_Status.TabIndex = 7; @@ -176,11 +195,22 @@ private void InitializeComponent() this.NI_Notification.Text = "notifyIcon1"; this.NI_Notification.Click += new System.EventHandler(this.NI_Notification_Click); // + // CB_Formatter + // + this.CB_Formatter.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_Formatter.FormattingEnabled = true; + this.CB_Formatter.Location = new System.Drawing.Point(436, 70); + this.CB_Formatter.Name = "CB_Formatter"; + this.CB_Formatter.Size = new System.Drawing.Size(144, 21); + this.CB_Formatter.TabIndex = 8; + this.CB_Formatter.SelectedIndexChanged += new System.EventHandler(this.CB_Formatter_SelectedIndexChanged); + // // MainForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 99); + this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(800, 101); + this.Controls.Add(this.CB_Formatter); this.Controls.Add(this.L_Status); this.Controls.Add(this.CB_Mode); this.Controls.Add(this.L_SelectedPath); @@ -222,6 +252,9 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem MI_HideToTray; private System.Windows.Forms.ToolStripMenuItem MI_Settings; private System.Windows.Forms.ToolStripMenuItem MI_ReportIssue; + private System.Windows.Forms.ComboBox CB_Formatter; + private System.Windows.Forms.ToolStripMenuItem pluginsToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; } } diff --git a/XmlFormatter/src/Windows/MainForm.cs b/XmlFormatter/src/Windows/MainForm.cs index 90b3dada..444fab0a 100644 --- a/XmlFormatter/src/Windows/MainForm.cs +++ b/XmlFormatter/src/Windows/MainForm.cs @@ -1,30 +1,33 @@ -using System; -using System.IO; -using System.Windows.Forms; +using PluginFramework.src.DataContainer; +using PluginFramework.src.Enums; +using PluginFramework.src.Interfaces.Manager; +using PluginFramework.src.Interfaces.PluginTypes; +using PluginFramework.src.LoadStrategies; +using PluginFramework.src.Manager; +using System; +using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Threading.Tasks; -using XmlFormatter.src.Manager; +using System.Windows.Forms; using XmlFormatter.src.DataContainer; -using XmlFormatter.src.Settings; -using XmlFormatter.src.Settings.DataStructure; -using XmlFormatter.src.Settings.Adapter; -using XmlFormatter.src.Settings.Provider.Factories; -using XmlFormatter.src.Interfaces.Settings; -using XmlFormatter.src.Interfaces.Settings.DataStructure; -using XmlFormatter.src.Formatter; using XmlFormatter.src.Enums; -using XmlFormatter.src.Interfaces.Formatter; -using XmlFormatter.src.EventMessages; using XmlFormatter.src.Hotfolder; using XmlFormatter.src.Interfaces.Hotfolder; -using XmlFormatter.src.Settings.Hotfolder; -using XmlFormatter.src.Update; +using XmlFormatter.src.Interfaces.Logging; +using XmlFormatter.src.Interfaces.Settings; +using XmlFormatter.src.Interfaces.Settings.DataStructure; using XmlFormatter.src.Interfaces.Updates; -using XmlFormatter.src.Update.Strategies; using XmlFormatter.src.Logging; -using XmlFormatter.src.Interfaces.Logging; -using XmlFormatter.src.Logging.Strategies; using XmlFormatter.src.Logging.FormatStrategies; +using XmlFormatter.src.Logging.Strategies; +using XmlFormatter.src.Manager; +using XmlFormatter.src.Settings; +using XmlFormatter.src.Settings.Adapter; +using XmlFormatter.src.Settings.DataStructure; +using XmlFormatter.src.Settings.Hotfolder; +using XmlFormatter.src.Settings.Provider.Factories; +using XmlFormatter.src.Update; namespace XmlFormatter.src.Windows { @@ -58,6 +61,11 @@ public partial class MainForm : Form /// private readonly IUpdater updateManager; + /// + /// Instance to manage plugins + /// + private readonly IPluginManager pluginManager; + /// /// The formatter to use /// @@ -121,6 +129,9 @@ public MainForm() Properties.Settings.Default[settingPair.Name] = settingPair.Value; } + pluginManager = new DefaultManager(); + pluginManager.SetDefaultLoadStrategy(new PluginFolder(AppDomain.CurrentDomain.BaseDirectory + "\\Plugins")); + settingManager.Save(settingFile); updateManager = new UpdateManager(); SetUpdateStrategy(); @@ -155,16 +166,14 @@ private void SetupLogging() /// private void SetUpdateStrategy() { - IUpdateStrategy updateStrategy; + IUpdateStrategy updateStrategy = null; try { - Type type = Type.GetType(Properties.Settings.Default.UpdateStrategy); - updateStrategy = (IUpdateStrategy)Activator.CreateInstance(type); + string type = Properties.Settings.Default.UpdateStrategy; + updateStrategy = pluginManager.LoadPlugin(type); } catch (Exception) { - updateStrategy = new OpenGitHubReleasesStrategy(); - Properties.Settings.Default.UpdateStrategy = updateStrategy.GetType().FullName; } updateManager.SetStrategy(updateStrategy); } @@ -186,9 +195,31 @@ private void MainForm_Load(object sender, EventArgs e) CheckForUpdatedVersion(true); } - SetFormatter(new XmlFormatterProvider()); SetupHotFolder(); - + SetupFormatterSelection(); + } + + /// + /// Setup the formatter selection combobox + /// + private void SetupFormatterSelection() + { + CB_Formatter.Items.Clear(); + List formatters = pluginManager.ListPlugins(); + foreach (PluginMetaData metaData in formatters) + { + CB_Formatter.Items.Add(new ComboboxPluginItem(metaData)); + } + if (CB_Formatter.Items.Count > 0) + { + CB_Formatter.SelectedIndex = 0; + ComboboxPluginItem item = CB_Formatter.SelectedItem as ComboboxPluginItem; + SetFormatter(pluginManager.LoadPlugin(item.Id)); + } + if (CB_Formatter.Items.Count == 1) + { + CB_Formatter.Visible = false; + } } /// @@ -203,19 +234,19 @@ private void SetupHotFolder() hotfolderManager.ResetManager(); hotfolderManager = null; } - + return; } hotfolderManager = hotfolderManager ?? new HotfolderManager(); - if (hotfolderManager is ILoggable) + if (hotfolderManager is ILoggable loggable) { - ((ILoggable)hotfolderManager).SetLoggingManager(loggingManager); + loggable.SetLoggingManager(loggingManager); } hotfolderManager.ResetManager(); - HotfolderExtension hotfolderExtension = new HotfolderExtension(settingManager); + HotfolderExtension hotfolderExtension = new HotfolderExtension(settingManager, pluginManager); foreach (IHotfolder hotfolder in hotfolderExtension.GetHotFoldersFromSettings()) - { + { hotfolderManager.AddHotfolder(hotfolder); } } @@ -228,10 +259,12 @@ private void SetFormatter(IFormatter formatter) { if (formatterToUse != null) { - formatterToUse.StatusChanged -= FormatterToUse_StatusChanged; + formatterToUse.StatusChanged -= FormatterToUse_StatusChanged; } formatterToUse = formatter; formatterToUse.StatusChanged += FormatterToUse_StatusChanged; + L_SelectedPath.Text = "Selected " + formatterToUse.Extension.ToUpper() + "-file path"; + B_Select.Text = "Select " + formatterToUse.Extension.ToUpper(); } /// @@ -239,7 +272,7 @@ private void SetFormatter(IFormatter formatter) /// /// The sender of the message /// The new status - private void FormatterToUse_StatusChanged(object sender, BaseEventArgs e) + private void FormatterToUse_StatusChanged(object sender, PluginFramework.src.EventMessages.BaseEventArgs e) { UpdateLabelTextThreadSafe(L_Status, e.Message); } @@ -261,7 +294,6 @@ public void UpdateLabelTextThreadSafe(Label label, string newText) label.Text = textToUse; } - /// /// This method will allow you to select the xml file you want to convert /// @@ -271,7 +303,7 @@ private void B_Select_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog { - Filter = "XML files (*.xml)|*.xml" + Filter = formatterToUse.Extension.ToUpper() + " files (*." + formatterToUse.Extension + ")|*." + formatterToUse.Extension }; DialogResult result = dialog.ShowDialog(); @@ -310,7 +342,8 @@ private void B_Save_Click(object sender, EventArgs e) FileInfo fi = new FileInfo(TB_SelectedXml.Text); string name = fi.Name.Replace(fi.Extension, ""); saveFile.FileName = name + "_" + CB_Mode.SelectedItem.ToString() + fi.Extension; - saveFile.Filter = "XML files (*.xml)|*.xml"; + + saveFile.Filter = formatterToUse.Extension.ToUpper() + " files (*." + formatterToUse.Extension + ")|*." + formatterToUse.Extension; DialogResult result = saveFile.ShowDialog(); if (result != DialogResult.OK) @@ -337,7 +370,7 @@ private async Task SaveFormattedFile(string inputFilePath, string outputFi ModesEnum currentEnum = formatted ? ModesEnum.Formatted : ModesEnum.Flat; bool success = formatterToUse.ConvertToFormat(inputFilePath, outputFilePath, currentEnum); - + SwitchFormMode(true); return success; } @@ -368,7 +401,7 @@ private void MainForm_DragEnter(object sender, DragEventArgs e) } string fileName = files[0]; FileInfo fi = new FileInfo(fileName); - if (e.Data.GetDataPresent(DataFormats.FileDrop) && fi.Extension.ToLower() == ".xml") + if (e.Data.GetDataPresent(DataFormats.FileDrop) && fi.Extension.ToLower() == "." + formatterToUse.Extension) { e.Effect = DragDropEffects.Copy; } @@ -396,9 +429,8 @@ private void MainForm_DragDrop(object sender, DragEventArgs e) /// The event arguments private void MI_About_Click(object sender, EventArgs e) { - VersionManager manager = new VersionManager(); - Version version = manager.GetApplicationVersion(); - MessageBox.Show(manager.GetStringVersion(version), "Version", MessageBoxButtons.OK, MessageBoxIcon.Information); + VersionInformation versionInformation = new VersionInformation(); + versionInformation.ShowDialog(); } /// @@ -440,9 +472,12 @@ private async void CheckForUpdatedVersion(bool onlyShowNewBox) text += "\n\nYour version: " + manager.GetStringVersion(versionCompare.LocalVersion); text += "\nGitHub version: " + manager.GetStringVersion(versionCompare.GitHubVersion); - text += "\n\nDo you want to upgrade now?"; - buttons = MessageBoxButtons.YesNo; - forceShow = true; + if (updateManager.IsStrategySet) + { + text += "\n\nDo you want to upgrade now?"; + buttons = MessageBoxButtons.YesNo; + forceShow = true; + } } if (forceShow || !onlyShowNewBox) @@ -567,11 +602,38 @@ private void MI_HideToTray_Click(object sender, EventArgs e) /// The arguments provided by the sender private void MI_Settings_Click(object sender, EventArgs e) { - Settings settings = new Settings(settingManager, settingFile); + Settings settings = new Settings(settingManager, settingFile, pluginManager); settings.ShowDialog(); SetupLogging(); SetupHotFolder(); SetUpdateStrategy(); } + + /// + /// Selected formatter did change + /// + /// + /// + private void CB_Formatter_SelectedIndexChanged(object sender, EventArgs e) + { + if (sender is ComboBox box && box.SelectedItem is ComboboxPluginItem item) + { + IFormatter formatter = pluginManager.LoadPlugin(item.Id); + SetFormatter(formatter); + TB_SelectedXml.Text = string.Empty; + } + } + + /// + /// Event if plugin dialog is clicked + /// + /// The sender of the event + /// The event arguments + private void pluginsToolStripMenuItem_Click(object sender, EventArgs e) + { + PluginManager pluginManagerWindow = new PluginManager(pluginManager, settingManager, settingFile); + pluginManagerWindow.ShowDialog(); + + } } } diff --git a/XmlFormatter/src/Windows/PluginManager.Designer.cs b/XmlFormatter/src/Windows/PluginManager.Designer.cs new file mode 100644 index 00000000..8fd419e0 --- /dev/null +++ b/XmlFormatter/src/Windows/PluginManager.Designer.cs @@ -0,0 +1,173 @@ +namespace XmlFormatter.src.Windows +{ + partial class PluginManager + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PluginManager)); + this.TV_Plugins = new System.Windows.Forms.TreeView(); + this.panel1 = new System.Windows.Forms.Panel(); + this.TC_PluginData = new System.Windows.Forms.TabControl(); + this.TP_GeneralInformation = new System.Windows.Forms.TabPage(); + this.TB_Description = new System.Windows.Forms.TextBox(); + this.L_Description = new System.Windows.Forms.Label(); + this.L_Version = new System.Windows.Forms.Label(); + this.L_Author = new System.Windows.Forms.Label(); + this.L_Name = new System.Windows.Forms.Label(); + this.panel1.SuspendLayout(); + this.TC_PluginData.SuspendLayout(); + this.TP_GeneralInformation.SuspendLayout(); + this.SuspendLayout(); + // + // TV_Plugins + // + this.TV_Plugins.Location = new System.Drawing.Point(18, 18); + this.TV_Plugins.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TV_Plugins.Name = "TV_Plugins"; + this.TV_Plugins.Size = new System.Drawing.Size(214, 653); + this.TV_Plugins.TabIndex = 0; + this.TV_Plugins.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.TV_Plugins_AfterSelect); + // + // panel1 + // + this.panel1.Controls.Add(this.TC_PluginData); + this.panel1.Location = new System.Drawing.Point(243, 18); + this.panel1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(939, 655); + this.panel1.TabIndex = 1; + // + // TC_PluginData + // + this.TC_PluginData.Controls.Add(this.TP_GeneralInformation); + this.TC_PluginData.Location = new System.Drawing.Point(4, 5); + this.TC_PluginData.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TC_PluginData.Name = "TC_PluginData"; + this.TC_PluginData.SelectedIndex = 0; + this.TC_PluginData.Size = new System.Drawing.Size(930, 646); + this.TC_PluginData.TabIndex = 0; + // + // TP_GeneralInformation + // + this.TP_GeneralInformation.Controls.Add(this.TB_Description); + this.TP_GeneralInformation.Controls.Add(this.L_Description); + this.TP_GeneralInformation.Controls.Add(this.L_Version); + this.TP_GeneralInformation.Controls.Add(this.L_Author); + this.TP_GeneralInformation.Controls.Add(this.L_Name); + this.TP_GeneralInformation.Location = new System.Drawing.Point(4, 29); + this.TP_GeneralInformation.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TP_GeneralInformation.Name = "TP_GeneralInformation"; + this.TP_GeneralInformation.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TP_GeneralInformation.Size = new System.Drawing.Size(922, 613); + this.TP_GeneralInformation.TabIndex = 0; + this.TP_GeneralInformation.Text = "General Information"; + this.TP_GeneralInformation.UseVisualStyleBackColor = true; + // + // TB_Description + // + this.TB_Description.Location = new System.Drawing.Point(14, 108); + this.TB_Description.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TB_Description.Multiline = true; + this.TB_Description.Name = "TB_Description"; + this.TB_Description.Size = new System.Drawing.Size(894, 487); + this.TB_Description.TabIndex = 4; + // + // L_Description + // + this.L_Description.AutoSize = true; + this.L_Description.Location = new System.Drawing.Point(9, 83); + this.L_Description.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.L_Description.Name = "L_Description"; + this.L_Description.Size = new System.Drawing.Size(89, 20); + this.L_Description.TabIndex = 3; + this.L_Description.Text = "Description"; + // + // L_Version + // + this.L_Version.AutoSize = true; + this.L_Version.Location = new System.Drawing.Point(9, 58); + this.L_Version.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.L_Version.Name = "L_Version"; + this.L_Version.Size = new System.Drawing.Size(67, 20); + this.L_Version.TabIndex = 2; + this.L_Version.Text = "Version:"; + // + // L_Author + // + this.L_Author.AutoSize = true; + this.L_Author.Location = new System.Drawing.Point(9, 9); + this.L_Author.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.L_Author.Name = "L_Author"; + this.L_Author.Size = new System.Drawing.Size(61, 20); + this.L_Author.TabIndex = 1; + this.L_Author.Text = "Author:"; + // + // L_Name + // + this.L_Name.AutoSize = true; + this.L_Name.Location = new System.Drawing.Point(9, 34); + this.L_Name.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.L_Name.Name = "L_Name"; + this.L_Name.Size = new System.Drawing.Size(55, 20); + this.L_Name.TabIndex = 0; + this.L_Name.Text = "Name:"; + // + // PluginManager + // + this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(1200, 692); + this.Controls.Add(this.panel1); + this.Controls.Add(this.TV_Plugins); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "PluginManager"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "PluginManager"; + this.Load += new System.EventHandler(this.PluginManager_Load); + this.panel1.ResumeLayout(false); + this.TC_PluginData.ResumeLayout(false); + this.TP_GeneralInformation.ResumeLayout(false); + this.TP_GeneralInformation.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TreeView TV_Plugins; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.TabControl TC_PluginData; + private System.Windows.Forms.TabPage TP_GeneralInformation; + private System.Windows.Forms.TextBox TB_Description; + private System.Windows.Forms.Label L_Description; + private System.Windows.Forms.Label L_Version; + private System.Windows.Forms.Label L_Author; + private System.Windows.Forms.Label L_Name; + } +} \ No newline at end of file diff --git a/XmlFormatter/src/Windows/PluginManager.cs b/XmlFormatter/src/Windows/PluginManager.cs new file mode 100644 index 00000000..1d89c495 --- /dev/null +++ b/XmlFormatter/src/Windows/PluginManager.cs @@ -0,0 +1,245 @@ +using PluginFramework.src.DataContainer; +using PluginFramework.src.Interfaces.Manager; +using PluginFramework.src.Interfaces.PluginTypes; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; +using XmlFormatter.src.Interfaces.Settings; +using XmlFormatter.src.Interfaces.Settings.DataStructure; +using XmlFormatter.src.Settings.DataStructure; + +namespace XmlFormatter.src.Windows +{ + /// + /// Window to manage the plugins + /// + public partial class PluginManager : Form + { + /// + /// Instance of the plugin manager to use + /// + private readonly IPluginManager pluginManager; + + /// + /// Instance of the settings manager to use + /// + private readonly ISettingsManager settingsManager; + + /// + /// Path where the settings file is stored + /// + private readonly string settingFile; + + /// + /// Current plugin which was selected + /// + private IPluginOverhead currentPlugin; + + /// + /// Current panel to put the plugin settings into + /// + private Panel currentSettingsPanel; + + /// + /// Create a new instance of the plugin manager window + /// + /// The plugin manager to use + /// The settings manager to use + /// The file to save the settings in + public PluginManager(IPluginManager pluginManager, ISettingsManager settingsManager, string settingsFileName) + { + InitializeComponent(); + this.pluginManager = pluginManager; + this.settingsManager = settingsManager; + this.settingFile = settingsFileName; + + currentSettingsPanel = null; + + TC_PluginData.Enabled = false; + L_Name.Tag = L_Name.Text; + L_Version.Tag = L_Version.Text; + L_Author.Tag = L_Author.Text; + TB_Description.ReadOnly = true; + } + + /// + /// Load event of the plugin window + /// + /// Sender of the event + /// The event arguments + private void PluginManager_Load(object sender, EventArgs e) + { + TreeNode root = new TreeNode("Plugins"); + TreeNode formatter = new TreeNode("Formatter"); + AddPluginsOfType(formatter); + root.Nodes.Add(formatter); + + TreeNode updater = new TreeNode("Updater"); + AddPluginsOfType(updater); + root.Nodes.Add(updater); + + TV_Plugins.Nodes.Add(root); + } + + /// + /// Add new plugins to the tree view of a given type + /// + /// The plugin type + /// The root node to create the plugins in + private void AddPluginsOfType(TreeNode node) where T : IPluginOverhead + { + List pluginMetas = pluginManager.ListPlugins(); + foreach (PluginMetaData metaData in pluginMetas) + { + TreeNode selectedPlugin = new TreeNode(metaData.Information.Name) + { + Tag = metaData + }; + node.Nodes.Add(selectedPlugin); + } + } + + /// + /// After item was selected in the tree view + /// + /// The sender of the event + /// The arguments of the evend + private void TV_Plugins_AfterSelect(object sender, TreeViewEventArgs e) + { + currentPlugin = null; + RemoveSettingsTab(); + if (sender is TreeView treeView) + { + if (treeView.SelectedNode is TreeNode node && node.Tag is PluginMetaData metaData) + { + L_Name.Text = L_Name.Tag.ToString() + " " + metaData.Information.Name; + L_Author.Text = L_Author.Tag.ToString() + " " + metaData.Information.Author; + L_Version.Text = L_Version.Tag.ToString() + " " + metaData.Information.Version; + TB_Description.Text = metaData.Information.Description; + TC_PluginData.Enabled = true; + + currentPlugin = pluginManager.LoadPlugin(metaData.Id); + ISettingScope settings = settingsManager.GetScope(GetScopeName()); + if (settings != null) + { + currentPlugin.ChangeSettings(ConvertToPluginSettings(settings)); + } + + + if (currentPlugin.GetSettingsPage() == null) + { + return; + } + + AddSettingsTab(); + UserControl control = currentPlugin.GetSettingsPage(); + control.Width = currentSettingsPanel.Width; + control.Height = currentSettingsPanel.Height; + currentSettingsPanel.Controls.Add(control); + } + } + } + + /// + /// Convert ISettingScope to plugin settings + /// + /// The settings scope to convert + /// The plugin settings ready to use + private PluginSettings ConvertToPluginSettings(ISettingScope settingScope) + { + PluginSettings returnSettings = new PluginSettings(); + foreach (SettingPair settingPair in settingScope.GetSettings()) + { + returnSettings.AddValue(settingPair.Name, settingPair.Value); + } + + return returnSettings; + } + + /// + /// Save the plugin settings + /// + /// Sender of the event + /// Arguments of the event + private void B_Save_Click(object sender, EventArgs e) + { + if (currentPlugin != null) + { + PluginSettings settings = currentPlugin.Settings; + string scopeName = GetScopeName(); + ISettingScope scope = new SettingScope(scopeName); + foreach (KeyValuePair settingPair in settings.Settings) + { + ISettingPair pair = new SettingPair(settingPair.Key); + pair.SetValue(settingPair.Value); + scope.AddSetting(pair); + } + + settingsManager.AddScope(scope); + settingsManager.Save(settingFile); + } + } + + /// + /// Add the settings tab to the tab control + /// + private void AddSettingsTab() + { + if (TC_PluginData.TabPages.Count < 2) + { + TabPage settings = new TabPage("Settings"); + TC_PluginData.TabPages.Add(settings); + + currentSettingsPanel = new Panel + { + Width = settings.Width, + Height = settings.Height - 31 + }; + + Button button = new Button + { + Text = "Save settings", + Location = new Point(5, settings.Height - 27), + Height = 23, + Width = 87 + }; + button.Click += B_Save_Click; + + settings.Controls.Add(button); + settings.Controls.Add(currentSettingsPanel); + } + } + + /// + /// Remove the settings tab from the tab control + /// + private void RemoveSettingsTab() + { + if (TC_PluginData.TabPages.Count == 2) + { + TC_PluginData.TabPages.RemoveAt(1); + currentSettingsPanel = null; + } + } + + /// + /// Get the name of the scope to save the settings to + /// + /// Name of the scope to use + private string GetScopeName() + { + string returnString = string.Empty; + if (currentPlugin != null) + { + returnString = "plugin_"; + returnString += currentPlugin.Information.Author; + returnString += "_"; + returnString += currentPlugin.Information.Name; + returnString = returnString.Replace(" ", ""); + } + + return returnString; + } + } +} \ No newline at end of file diff --git a/XmlFormatter/src/Windows/PluginManager.resx b/XmlFormatter/src/Windows/PluginManager.resx new file mode 100644 index 00000000..8bb5947a --- /dev/null +++ b/XmlFormatter/src/Windows/PluginManager.resx @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + AAABAAEAICAAAAEAGACoDAAAFgAAACgAAAAgAAAAQAAAAAEAGAAAAAAAqAwAAAAAAAAAAAAAAAAAAAAA + AACHfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD6HfoRAPD4AAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAABAPD6HfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD6H + foRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD6HfoRAPD4AAAAAAABAPD4AAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAABAPD5pYmZAPD5APD6HfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD5APD6H + foSHfoSHfoRAPD4AAAAAAAAAAABAPD5APD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD6HfoSHfoSHfoSHfoR4cXVAPD4AAABAPD5pYmZp + YmZAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AABAPD6HfoSHfoSHfoSHfoR4cXVpYmZpYmZAPD54cXWHfoSHfoSHfoRAPD4AAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD6HfoSHfoSHfoR4cXVpYmZA + PD6HfoSHfoSHfoSHfoSHfoSHfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAABAPD6HfoSHfoRpYmZAPD6HfoSHfoSHfoRAPD5APD6HfoSHfoSHfoRA + PD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA + PD5pYmZAPD6HfoSHfoSHfoRAPD4AAAAAAABAPD6HfoSHfoSHfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD6HfoSHfoSHfoRAPD4AAAAAAABA + PD4AAABAPD6HfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAABAPD6HfoSHfoSHfoRAPD4AAAAAAABAPD6HfoRAPD4AAABAPD4AAAAAAAAAAABAPD4A + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD6HfoSHfoSHfoRAPD4A + AAAAAABAPD6HfoSHfoSHfoRAPD4AAAAAAAAAAABAPD5pYmZAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAABAPD6HfoSHfoSHfoRAPD4AAABAPD6HfoSHfoSHfoSHfoSHfoRAPD4A + AABAPD54cXVpYmZpYmZAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABA + PD6HfoSHfoSHfoRAPD4AAABAPD6HfoSHfoSHfoSHfoSHfoRAPD6HfoSHfoSHfoSHfoSHfoRAPD4AAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD6clJmclJmclJlAPD4AAABAPD6H + foSHfoSHfoSHfoSHfoSHfoSHfoSHfoSHfoSHfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAABAPD64rbS4rbS4rbRAPD4AAABAPD6HfoSHfoSHfoSHfoSHfoSHfoSHfoSH + foRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD64 + rbRAPD4AAAAAAAAAAABAPD6HfoSHfoSHfoSHfoSHfoSHfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD4AAAAAAAAAAABAPD6HfoSHfoSHfoSH + foSHfoSHfoRAPD6clJlAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAABAPD6clJmclJmclJmclJmclJmclJlAPD6clJmHfoSHfoRAPD4AAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD64rbSc + lJmclJm4rbS4rbS4rbRAPD6clJmHfoSHfoSHfoSHfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD64rbS4rbS4rbS4rbRAPD6clJmclJmHfoSH + foSHfoSHfoSHfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAABAPD7Rx83Rx81APD4AAABAPD64rbSclJmclJmclJmclJlAPD4AAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD7Rx80AAAAA + AAAAAABAPD64rbS4rbS4rbRAPD5APD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD7Rx81APD5APD6HfoRA + PD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD4AAAAAAABAPD6HfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAABAPD6HfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD6HfoRAPD4A + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAPD6HfoRAPD4AAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAABAPD6HfoQ/////H////4/////H////43////A////4HP//+Ah///AAP//4AB///AAP//4D + B///Bo///gxd//wYOP/8EBB//ggAP/8EAD//ggB//8cA///uAH///AA///gAH//8AA///hAf//84H/// + /A////7H////4/////H////4/////A== + + + \ No newline at end of file diff --git a/XmlFormatter/src/Windows/Settings.Designer.cs b/XmlFormatter/src/Windows/Settings.Designer.cs index eb69be91..c6dc1e3c 100644 --- a/XmlFormatter/src/Windows/Settings.Designer.cs +++ b/XmlFormatter/src/Windows/Settings.Designer.cs @@ -81,9 +81,11 @@ private void InitializeComponent() // this.groupBox1.Controls.Add(this.CB_AskBeforeClose); this.groupBox1.Controls.Add(this.CB_MinimizeToTray); - this.groupBox1.Location = new System.Drawing.Point(8, 6); + this.groupBox1.Location = new System.Drawing.Point(12, 9); + this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(700, 68); + this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.groupBox1.Size = new System.Drawing.Size(1050, 105); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Application settings"; @@ -91,9 +93,10 @@ private void InitializeComponent() // CB_AskBeforeClose // this.CB_AskBeforeClose.AutoSize = true; - this.CB_AskBeforeClose.Location = new System.Drawing.Point(6, 42); + this.CB_AskBeforeClose.Location = new System.Drawing.Point(9, 65); + this.CB_AskBeforeClose.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.CB_AskBeforeClose.Name = "CB_AskBeforeClose"; - this.CB_AskBeforeClose.Size = new System.Drawing.Size(113, 17); + this.CB_AskBeforeClose.Size = new System.Drawing.Size(165, 24); this.CB_AskBeforeClose.TabIndex = 1; this.CB_AskBeforeClose.Text = "Ask before closing"; this.CB_AskBeforeClose.UseVisualStyleBackColor = true; @@ -101,9 +104,10 @@ private void InitializeComponent() // CB_MinimizeToTray // this.CB_MinimizeToTray.AutoSize = true; - this.CB_MinimizeToTray.Location = new System.Drawing.Point(6, 19); + this.CB_MinimizeToTray.Location = new System.Drawing.Point(9, 29); + this.CB_MinimizeToTray.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.CB_MinimizeToTray.Name = "CB_MinimizeToTray"; - this.CB_MinimizeToTray.Size = new System.Drawing.Size(98, 17); + this.CB_MinimizeToTray.Size = new System.Drawing.Size(144, 24); this.CB_MinimizeToTray.TabIndex = 0; this.CB_MinimizeToTray.Text = "Minimize to tray"; this.CB_MinimizeToTray.UseVisualStyleBackColor = true; @@ -111,18 +115,20 @@ private void InitializeComponent() // CB_CheckUpdatesOnStartup // this.CB_CheckUpdatesOnStartup.AutoSize = true; - this.CB_CheckUpdatesOnStartup.Location = new System.Drawing.Point(6, 14); + this.CB_CheckUpdatesOnStartup.Location = new System.Drawing.Point(9, 22); + this.CB_CheckUpdatesOnStartup.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.CB_CheckUpdatesOnStartup.Name = "CB_CheckUpdatesOnStartup"; - this.CB_CheckUpdatesOnStartup.Size = new System.Drawing.Size(163, 17); + this.CB_CheckUpdatesOnStartup.Size = new System.Drawing.Size(241, 24); this.CB_CheckUpdatesOnStartup.TabIndex = 2; this.CB_CheckUpdatesOnStartup.Text = "Check for updates on startup"; this.CB_CheckUpdatesOnStartup.UseVisualStyleBackColor = true; // // B_SaveAndClose // - this.B_SaveAndClose.Location = new System.Drawing.Point(12, 274); + this.B_SaveAndClose.Location = new System.Drawing.Point(18, 422); + this.B_SaveAndClose.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_SaveAndClose.Name = "B_SaveAndClose"; - this.B_SaveAndClose.Size = new System.Drawing.Size(104, 23); + this.B_SaveAndClose.Size = new System.Drawing.Size(156, 35); this.B_SaveAndClose.TabIndex = 1; this.B_SaveAndClose.Text = "Save and close"; this.B_SaveAndClose.UseVisualStyleBackColor = true; @@ -130,9 +136,10 @@ private void InitializeComponent() // // B_Cancel // - this.B_Cancel.Location = new System.Drawing.Point(637, 274); + this.B_Cancel.Location = new System.Drawing.Point(956, 422); + this.B_Cancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_Cancel.Name = "B_Cancel"; - this.B_Cancel.Size = new System.Drawing.Size(75, 23); + this.B_Cancel.Size = new System.Drawing.Size(112, 35); this.B_Cancel.TabIndex = 2; this.B_Cancel.Text = "Cancel"; this.B_Cancel.UseVisualStyleBackColor = true; @@ -140,26 +147,28 @@ private void InitializeComponent() // // MI_SettingsMenu // + this.MI_SettingsMenu.GripMargin = new System.Windows.Forms.Padding(2, 2, 0, 2); + this.MI_SettingsMenu.ImageScalingSize = new System.Drawing.Size(24, 24); this.MI_SettingsMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.exportSettingsToolStripMenuItem, this.importSettingsToolStripMenuItem}); this.MI_SettingsMenu.Location = new System.Drawing.Point(0, 0); this.MI_SettingsMenu.Name = "MI_SettingsMenu"; - this.MI_SettingsMenu.Size = new System.Drawing.Size(734, 24); + this.MI_SettingsMenu.Size = new System.Drawing.Size(1101, 36); this.MI_SettingsMenu.TabIndex = 3; this.MI_SettingsMenu.Text = "menuStrip1"; // // exportSettingsToolStripMenuItem // this.exportSettingsToolStripMenuItem.Name = "exportSettingsToolStripMenuItem"; - this.exportSettingsToolStripMenuItem.Size = new System.Drawing.Size(97, 20); + this.exportSettingsToolStripMenuItem.Size = new System.Drawing.Size(146, 30); this.exportSettingsToolStripMenuItem.Text = "Export settings"; this.exportSettingsToolStripMenuItem.Click += new System.EventHandler(this.ExportSettingsToolStripMenuItem_Click); // // importSettingsToolStripMenuItem // this.importSettingsToolStripMenuItem.Name = "importSettingsToolStripMenuItem"; - this.importSettingsToolStripMenuItem.Size = new System.Drawing.Size(99, 20); + this.importSettingsToolStripMenuItem.Size = new System.Drawing.Size(150, 30); this.importSettingsToolStripMenuItem.Text = "Import settings"; this.importSettingsToolStripMenuItem.Click += new System.EventHandler(this.ImportSettingsToolStripMenuItem_Click); // @@ -168,20 +177,22 @@ private void InitializeComponent() this.TC_SettingTabs.Controls.Add(this.TP_Application); this.TC_SettingTabs.Controls.Add(this.TP_Logging); this.TC_SettingTabs.Controls.Add(this.TP_Hotfolder); - this.TC_SettingTabs.Location = new System.Drawing.Point(0, 27); + this.TC_SettingTabs.Location = new System.Drawing.Point(0, 42); + this.TC_SettingTabs.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.TC_SettingTabs.Name = "TC_SettingTabs"; this.TC_SettingTabs.SelectedIndex = 0; - this.TC_SettingTabs.Size = new System.Drawing.Size(722, 245); + this.TC_SettingTabs.Size = new System.Drawing.Size(1083, 377); this.TC_SettingTabs.TabIndex = 3; // // TP_Application // this.TP_Application.Controls.Add(this.GB_Update); this.TP_Application.Controls.Add(this.groupBox1); - this.TP_Application.Location = new System.Drawing.Point(4, 22); + this.TP_Application.Location = new System.Drawing.Point(4, 29); + this.TP_Application.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.TP_Application.Name = "TP_Application"; - this.TP_Application.Padding = new System.Windows.Forms.Padding(3); - this.TP_Application.Size = new System.Drawing.Size(714, 219); + this.TP_Application.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TP_Application.Size = new System.Drawing.Size(1075, 344); this.TP_Application.TabIndex = 0; this.TP_Application.Text = "Application"; this.TP_Application.UseVisualStyleBackColor = true; @@ -191,9 +202,11 @@ private void InitializeComponent() this.GB_Update.Controls.Add(this.CB_CheckUpdatesOnStartup); this.GB_Update.Controls.Add(this.L_UpdateStrategy); this.GB_Update.Controls.Add(this.CB_UpdateStrategy); - this.GB_Update.Location = new System.Drawing.Point(8, 80); + this.GB_Update.Location = new System.Drawing.Point(12, 123); + this.GB_Update.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.GB_Update.Name = "GB_Update"; - this.GB_Update.Size = new System.Drawing.Size(700, 69); + this.GB_Update.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.GB_Update.Size = new System.Drawing.Size(1050, 106); this.GB_Update.TabIndex = 1; this.GB_Update.TabStop = false; this.GB_Update.Text = "Updating"; @@ -201,9 +214,10 @@ private void InitializeComponent() // L_UpdateStrategy // this.L_UpdateStrategy.AutoSize = true; - this.L_UpdateStrategy.Location = new System.Drawing.Point(3, 40); + this.L_UpdateStrategy.Location = new System.Drawing.Point(4, 62); + this.L_UpdateStrategy.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.L_UpdateStrategy.Name = "L_UpdateStrategy"; - this.L_UpdateStrategy.Size = new System.Drawing.Size(82, 13); + this.L_UpdateStrategy.Size = new System.Drawing.Size(123, 20); this.L_UpdateStrategy.TabIndex = 4; this.L_UpdateStrategy.Text = "Update strategy"; // @@ -211,9 +225,10 @@ private void InitializeComponent() // this.CB_UpdateStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_UpdateStrategy.FormattingEnabled = true; - this.CB_UpdateStrategy.Location = new System.Drawing.Point(91, 37); + this.CB_UpdateStrategy.Location = new System.Drawing.Point(136, 57); + this.CB_UpdateStrategy.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.CB_UpdateStrategy.Name = "CB_UpdateStrategy"; - this.CB_UpdateStrategy.Size = new System.Drawing.Size(163, 21); + this.CB_UpdateStrategy.Size = new System.Drawing.Size(242, 28); this.CB_UpdateStrategy.TabIndex = 3; // // TP_Logging @@ -223,18 +238,20 @@ private void InitializeComponent() this.TP_Logging.Controls.Add(this.LV_logFiles); this.TP_Logging.Controls.Add(this.RTB_loggingText); this.TP_Logging.Controls.Add(this.CB_LoggingActive); - this.TP_Logging.Location = new System.Drawing.Point(4, 22); + this.TP_Logging.Location = new System.Drawing.Point(4, 29); + this.TP_Logging.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.TP_Logging.Name = "TP_Logging"; - this.TP_Logging.Size = new System.Drawing.Size(714, 219); + this.TP_Logging.Size = new System.Drawing.Size(1075, 344); this.TP_Logging.TabIndex = 2; this.TP_Logging.Text = "Logging"; this.TP_Logging.UseVisualStyleBackColor = true; // // B_OpenFolder // - this.B_OpenFolder.Location = new System.Drawing.Point(65, 191); + this.B_OpenFolder.Location = new System.Drawing.Point(98, 294); + this.B_OpenFolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_OpenFolder.Name = "B_OpenFolder"; - this.B_OpenFolder.Size = new System.Drawing.Size(92, 23); + this.B_OpenFolder.Size = new System.Drawing.Size(138, 35); this.B_OpenFolder.TabIndex = 6; this.B_OpenFolder.Text = "Open folder"; this.B_OpenFolder.UseVisualStyleBackColor = true; @@ -242,9 +259,10 @@ private void InitializeComponent() // // B_DeleteLog // - this.B_DeleteLog.Location = new System.Drawing.Point(8, 191); + this.B_DeleteLog.Location = new System.Drawing.Point(12, 294); + this.B_DeleteLog.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_DeleteLog.Name = "B_DeleteLog"; - this.B_DeleteLog.Size = new System.Drawing.Size(51, 23); + this.B_DeleteLog.Size = new System.Drawing.Size(76, 35); this.B_DeleteLog.TabIndex = 5; this.B_DeleteLog.Text = "Delete"; this.B_DeleteLog.UseVisualStyleBackColor = true; @@ -255,9 +273,10 @@ private void InitializeComponent() this.LV_logFiles.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.CH_logFiles}); this.LV_logFiles.HideSelection = false; - this.LV_logFiles.Location = new System.Drawing.Point(3, 26); + this.LV_logFiles.Location = new System.Drawing.Point(4, 40); + this.LV_logFiles.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.LV_logFiles.Name = "LV_logFiles"; - this.LV_logFiles.Size = new System.Drawing.Size(149, 159); + this.LV_logFiles.Size = new System.Drawing.Size(222, 242); this.LV_logFiles.TabIndex = 4; this.LV_logFiles.UseCompatibleStateImageBehavior = false; this.LV_logFiles.View = System.Windows.Forms.View.Details; @@ -269,19 +288,21 @@ private void InitializeComponent() // // RTB_loggingText // - this.RTB_loggingText.Location = new System.Drawing.Point(158, 26); + this.RTB_loggingText.Location = new System.Drawing.Point(237, 40); + this.RTB_loggingText.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.RTB_loggingText.Name = "RTB_loggingText"; this.RTB_loggingText.ReadOnly = true; - this.RTB_loggingText.Size = new System.Drawing.Size(553, 159); + this.RTB_loggingText.Size = new System.Drawing.Size(828, 242); this.RTB_loggingText.TabIndex = 3; this.RTB_loggingText.Text = ""; // // CB_LoggingActive // this.CB_LoggingActive.AutoSize = true; - this.CB_LoggingActive.Location = new System.Drawing.Point(8, 3); + this.CB_LoggingActive.Location = new System.Drawing.Point(12, 5); + this.CB_LoggingActive.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.CB_LoggingActive.Name = "CB_LoggingActive"; - this.CB_LoggingActive.Size = new System.Drawing.Size(96, 17); + this.CB_LoggingActive.Size = new System.Drawing.Size(137, 24); this.CB_LoggingActive.TabIndex = 0; this.CB_LoggingActive.Text = "Logging active"; this.CB_LoggingActive.UseVisualStyleBackColor = true; @@ -290,10 +311,11 @@ private void InitializeComponent() // this.TP_Hotfolder.Controls.Add(this.GB_Hotfolder); this.TP_Hotfolder.Controls.Add(this.CB_Hotfolder); - this.TP_Hotfolder.Location = new System.Drawing.Point(4, 22); + this.TP_Hotfolder.Location = new System.Drawing.Point(4, 29); + this.TP_Hotfolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.TP_Hotfolder.Name = "TP_Hotfolder"; - this.TP_Hotfolder.Padding = new System.Windows.Forms.Padding(3); - this.TP_Hotfolder.Size = new System.Drawing.Size(714, 219); + this.TP_Hotfolder.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TP_Hotfolder.Size = new System.Drawing.Size(1075, 344); this.TP_Hotfolder.TabIndex = 1; this.TP_Hotfolder.Text = "Hotfolder"; this.TP_Hotfolder.UseVisualStyleBackColor = true; @@ -304,18 +326,21 @@ private void InitializeComponent() this.GB_Hotfolder.Controls.Add(this.B_EditHotfolder); this.GB_Hotfolder.Controls.Add(this.B_AddHotfolder); this.GB_Hotfolder.Controls.Add(this.LV_Hotfolders); - this.GB_Hotfolder.Location = new System.Drawing.Point(8, 29); + this.GB_Hotfolder.Location = new System.Drawing.Point(12, 45); + this.GB_Hotfolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.GB_Hotfolder.Name = "GB_Hotfolder"; - this.GB_Hotfolder.Size = new System.Drawing.Size(700, 184); + this.GB_Hotfolder.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.GB_Hotfolder.Size = new System.Drawing.Size(1050, 283); this.GB_Hotfolder.TabIndex = 1; this.GB_Hotfolder.TabStop = false; this.GB_Hotfolder.Text = "Hotfolder"; // // B_RemoveHotfolder // - this.B_RemoveHotfolder.Location = new System.Drawing.Point(619, 156); + this.B_RemoveHotfolder.Location = new System.Drawing.Point(928, 240); + this.B_RemoveHotfolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_RemoveHotfolder.Name = "B_RemoveHotfolder"; - this.B_RemoveHotfolder.Size = new System.Drawing.Size(75, 23); + this.B_RemoveHotfolder.Size = new System.Drawing.Size(112, 35); this.B_RemoveHotfolder.TabIndex = 3; this.B_RemoveHotfolder.Text = "Remove"; this.B_RemoveHotfolder.UseVisualStyleBackColor = true; @@ -323,9 +348,10 @@ private void InitializeComponent() // // B_EditHotfolder // - this.B_EditHotfolder.Location = new System.Drawing.Point(87, 156); + this.B_EditHotfolder.Location = new System.Drawing.Point(130, 240); + this.B_EditHotfolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_EditHotfolder.Name = "B_EditHotfolder"; - this.B_EditHotfolder.Size = new System.Drawing.Size(75, 23); + this.B_EditHotfolder.Size = new System.Drawing.Size(112, 35); this.B_EditHotfolder.TabIndex = 2; this.B_EditHotfolder.Text = "Edit"; this.B_EditHotfolder.UseVisualStyleBackColor = true; @@ -333,9 +359,10 @@ private void InitializeComponent() // // B_AddHotfolder // - this.B_AddHotfolder.Location = new System.Drawing.Point(6, 156); + this.B_AddHotfolder.Location = new System.Drawing.Point(9, 240); + this.B_AddHotfolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.B_AddHotfolder.Name = "B_AddHotfolder"; - this.B_AddHotfolder.Size = new System.Drawing.Size(75, 23); + this.B_AddHotfolder.Size = new System.Drawing.Size(112, 35); this.B_AddHotfolder.TabIndex = 1; this.B_AddHotfolder.Text = "Add"; this.B_AddHotfolder.UseVisualStyleBackColor = true; @@ -356,9 +383,10 @@ private void InitializeComponent() this.LV_Hotfolders.GridLines = true; this.LV_Hotfolders.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; this.LV_Hotfolders.HideSelection = false; - this.LV_Hotfolders.Location = new System.Drawing.Point(6, 19); + this.LV_Hotfolders.Location = new System.Drawing.Point(9, 29); + this.LV_Hotfolders.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.LV_Hotfolders.Name = "LV_Hotfolders"; - this.LV_Hotfolders.Size = new System.Drawing.Size(688, 131); + this.LV_Hotfolders.Size = new System.Drawing.Size(1030, 199); this.LV_Hotfolders.TabIndex = 0; this.LV_Hotfolders.UseCompatibleStateImageBehavior = false; this.LV_Hotfolders.View = System.Windows.Forms.View.Details; @@ -399,9 +427,10 @@ private void InitializeComponent() // CB_Hotfolder // this.CB_Hotfolder.AutoSize = true; - this.CB_Hotfolder.Location = new System.Drawing.Point(8, 6); + this.CB_Hotfolder.Location = new System.Drawing.Point(12, 9); + this.CB_Hotfolder.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.CB_Hotfolder.Name = "CB_Hotfolder"; - this.CB_Hotfolder.Size = new System.Drawing.Size(101, 17); + this.CB_Hotfolder.Size = new System.Drawing.Size(146, 24); this.CB_Hotfolder.TabIndex = 0; this.CB_Hotfolder.Text = "Hotfolder active"; this.CB_Hotfolder.UseVisualStyleBackColor = true; @@ -409,9 +438,9 @@ private void InitializeComponent() // // Settings // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(734, 305); + this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(1101, 469); this.Controls.Add(this.TC_SettingTabs); this.Controls.Add(this.B_Cancel); this.Controls.Add(this.B_SaveAndClose); @@ -419,6 +448,7 @@ private void InitializeComponent() this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MainMenuStrip = this.MI_SettingsMenu; + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "Settings"; diff --git a/XmlFormatter/src/Windows/Settings.cs b/XmlFormatter/src/Windows/Settings.cs index 0c6a28d9..6f0243f1 100644 --- a/XmlFormatter/src/Windows/Settings.cs +++ b/XmlFormatter/src/Windows/Settings.cs @@ -1,20 +1,24 @@ -using System; +using PluginFramework.src.DataContainer; +using PluginFramework.src.Interfaces.Manager; +using PluginFramework.src.Interfaces.PluginTypes; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Reflection; using System.Windows.Forms; +using XmlFormatter.src.DataContainer; using XmlFormatter.src.Interfaces.Hotfolder; using XmlFormatter.src.Interfaces.Settings; using XmlFormatter.src.Interfaces.Settings.DataStructure; -using XmlFormatter.src.Interfaces.Updates; using XmlFormatter.src.Manager; using XmlFormatter.src.Settings.DataStructure; using XmlFormatter.src.Settings.Hotfolder; namespace XmlFormatter.src.Windows { + /// + /// Settings window + /// public partial class Settings : Form { /// @@ -28,20 +32,20 @@ public partial class Settings : Form private readonly string settingFile; /// - /// A dictionary with all the update strategies + /// The plugin manager to use /// - private readonly Dictionary updateStrategies; + private readonly IPluginManager pluginManager; /// /// Create a new settings window /// - public Settings(ISettingsManager settingManager, string settingFile) + public Settings(ISettingsManager settingManager, string settingFile, IPluginManager pluginManager) { InitializeComponent(); this.settingManager = settingManager; this.settingFile = settingFile; - updateStrategies = new Dictionary(); + this.pluginManager = pluginManager; SetupToolTip(CB_MinimizeToTray); SetupToolTip(CB_AskBeforeClose); @@ -54,6 +58,7 @@ public Settings(ISettingsManager settingManager, string settingFile) B_RemoveHotfolder.Enabled = false; LV_Hotfolders.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); + settingManager.Load(settingFile); SetupControls(); } @@ -97,27 +102,21 @@ private void SetupControls() CB_LoggingActive.Checked = Properties.Settings.Default.LoggingEnabled; LV_Hotfolders.Items.Clear(); - HotfolderExtension hotfolderExtension = new HotfolderExtension(settingManager); + HotfolderExtension hotfolderExtension = new HotfolderExtension(settingManager, pluginManager); foreach (IHotfolder hotfolder in hotfolderExtension.GetHotFoldersFromSettings()) { ListViewItem item = HotfolderToListView(hotfolder); LV_Hotfolders.Items.Add(item); } - Type type = typeof(IUpdateStrategy); - Type[] types = Assembly.GetExecutingAssembly().GetTypes(); - var possibleStrategies = types.Where(currentType => currentType.GetInterfaces().Contains(type)); + List updatePlugins = pluginManager.ListPlugins(); - foreach (Type currentStrategy in possibleStrategies) + foreach (PluginMetaData metaData in updatePlugins) { try { - IUpdateStrategy updateStrategy = (IUpdateStrategy)Activator.CreateInstance(currentStrategy); - updateStrategies.Add(updateStrategy.DisplayName, updateStrategy); - CB_UpdateStrategy.Items.Add(updateStrategy.DisplayName); - var test = currentStrategy.ToString(); - var test2 = Properties.Settings.Default.UpdateStrategy; - if (currentStrategy.ToString() == Properties.Settings.Default.UpdateStrategy) + CB_UpdateStrategy.Items.Add(new ComboboxPluginItem(metaData)); + if (metaData.Type.ToString() == Properties.Settings.Default.UpdateStrategy) { CB_UpdateStrategy.SelectedIndex = CB_UpdateStrategy.Items.Count - 1; } @@ -130,6 +129,10 @@ private void SetupControls() FillLogFolderView(); LV_logFiles.Columns[0].Width = LV_logFiles.Width; + if (CB_UpdateStrategy.SelectedIndex == -1 && CB_UpdateStrategy.Items.Count > 0) + { + CB_UpdateStrategy.SelectedIndex = 0; + } } /// @@ -145,8 +148,10 @@ private void FillLogFolderView() { continue; } - ListViewItem listViewItem = new ListViewItem(fileInfo.Name); - listViewItem.Tag = file; + ListViewItem listViewItem = new ListViewItem(fileInfo.Name) + { + Tag = file + }; LV_logFiles.Items.Add(listViewItem); } } @@ -174,11 +179,9 @@ private void WriteSettings() Properties.Settings.Default.HotfolderActive = CB_Hotfolder.Checked; Properties.Settings.Default.LoggingEnabled = CB_LoggingActive.Checked; - string strategyName = CB_UpdateStrategy.SelectedItem.ToString(); - if (updateStrategies.ContainsKey(strategyName)) + if (CB_UpdateStrategy.SelectedItem is ComboboxPluginItem updateItem) { - IUpdateStrategy updateStrategy = updateStrategies[strategyName]; - Properties.Settings.Default.UpdateStrategy = updateStrategy.GetType().ToString(); + Properties.Settings.Default.UpdateStrategy = updateItem.Type.ToString(); } ISettingScope hotfolderScope = settingManager.GetScope("Hotfolder"); @@ -328,7 +331,7 @@ private void LV_Hotfolders_SelectedIndexChanged(object sender, EventArgs e) /// Event arguments private void B_AddHotfolder_Click(object sender, EventArgs e) { - HotfolderEditor hotfolderEditor = new HotfolderEditor(null); + HotfolderEditor hotfolderEditor = new HotfolderEditor(pluginManager); hotfolderEditor.ShowDialog(); if (hotfolderEditor.Saved) { @@ -350,10 +353,15 @@ private void B_AddHotfolder_Click(object sender, EventArgs e) /// A valid ListViewItem private ListViewItem HotfolderToListView(IHotfolder hotfolder) { - ListViewItem listViewItem = new ListViewItem(hotfolder.FormatterToUse.ToString()) + ListViewItem listViewItem = new ListViewItem("Plugin not found!"); + if (hotfolder.FormatterToUse != null) { - Tag = hotfolder - }; + listViewItem = new ListViewItem(hotfolder.FormatterToUse.Information.Name) + { + Tag = hotfolder + }; + } + listViewItem.SubItems.Add(hotfolder.Mode.ToString()); listViewItem.SubItems.Add(hotfolder.WatchedFolder); listViewItem.SubItems.Add(hotfolder.Filter); @@ -435,7 +443,7 @@ private void B_EditHotfolder_Click(object sender, EventArgs e) ListViewItem selectedItem = LV_Hotfolders.SelectedItems[0]; if (selectedItem.Tag is IHotfolder) { - HotfolderEditor hotfolderEditor = new HotfolderEditor((IHotfolder)selectedItem.Tag); + HotfolderEditor hotfolderEditor = new HotfolderEditor((IHotfolder)selectedItem.Tag, pluginManager); hotfolderEditor.ShowDialog(); if (hotfolderEditor.Saved) { diff --git a/XmlFormatter/src/Windows/VersionInformation.Designer.cs b/XmlFormatter/src/Windows/VersionInformation.Designer.cs new file mode 100644 index 00000000..03d743ee --- /dev/null +++ b/XmlFormatter/src/Windows/VersionInformation.Designer.cs @@ -0,0 +1,236 @@ +namespace XmlFormatter.src.Windows +{ + partial class VersionInformation + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("Octokit"); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.TP_General = new System.Windows.Forms.TabPage(); + this.LL_MIT = new System.Windows.Forms.LinkLabel(); + this.L_VersionNumber = new System.Windows.Forms.Label(); + this.L_MaintainerName = new System.Windows.Forms.Label(); + this.L_Project = new System.Windows.Forms.Label(); + this.LL_Project = new System.Windows.Forms.LinkLabel(); + this.L_License = new System.Windows.Forms.Label(); + this.L_Maintainer = new System.Windows.Forms.Label(); + this.L_Version = new System.Windows.Forms.Label(); + this.TP_ThirdParty = new System.Windows.Forms.TabPage(); + this.LV_ThirdPartyLibraries = new System.Windows.Forms.ListView(); + this.CH_ThirdParty = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.tabControl1.SuspendLayout(); + this.TP_General.SuspendLayout(); + this.TP_ThirdParty.SuspendLayout(); + this.SuspendLayout(); + // + // tabControl1 + // + this.tabControl1.Controls.Add(this.TP_General); + this.tabControl1.Controls.Add(this.TP_ThirdParty); + this.tabControl1.Location = new System.Drawing.Point(18, 18); + this.tabControl1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(608, 166); + this.tabControl1.TabIndex = 1; + // + // TP_General + // + this.TP_General.Controls.Add(this.LL_MIT); + this.TP_General.Controls.Add(this.L_VersionNumber); + this.TP_General.Controls.Add(this.L_MaintainerName); + this.TP_General.Controls.Add(this.L_Project); + this.TP_General.Controls.Add(this.LL_Project); + this.TP_General.Controls.Add(this.L_License); + this.TP_General.Controls.Add(this.L_Maintainer); + this.TP_General.Controls.Add(this.L_Version); + this.TP_General.Location = new System.Drawing.Point(4, 29); + this.TP_General.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TP_General.Name = "TP_General"; + this.TP_General.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TP_General.Size = new System.Drawing.Size(600, 133); + this.TP_General.TabIndex = 0; + this.TP_General.Text = "General"; + this.TP_General.UseVisualStyleBackColor = true; + // + // LL_MIT + // + this.LL_MIT.AutoSize = true; + this.LL_MIT.Location = new System.Drawing.Point(106, 65); + this.LL_MIT.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.LL_MIT.Name = "LL_MIT"; + this.LL_MIT.Size = new System.Drawing.Size(36, 20); + this.LL_MIT.TabIndex = 8; + this.LL_MIT.TabStop = true; + this.LL_MIT.Tag = "https://github.com/XanatosX/XmlFormatter/blob/master/LICENSE"; + this.LL_MIT.Text = "MIT"; + this.LL_MIT.Click += new System.EventHandler(this.OpenLinkLabel_Click); + // + // L_VersionNumber + // + this.L_VersionNumber.AutoSize = true; + this.L_VersionNumber.Location = new System.Drawing.Point(106, 15); + this.L_VersionNumber.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.L_VersionNumber.Name = "L_VersionNumber"; + this.L_VersionNumber.Size = new System.Drawing.Size(44, 20); + this.L_VersionNumber.TabIndex = 7; + this.L_VersionNumber.Text = "0.0.0"; + // + // L_MaintainerName + // + this.L_MaintainerName.AutoSize = true; + this.L_MaintainerName.Location = new System.Drawing.Point(106, 40); + this.L_MaintainerName.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.L_MaintainerName.Name = "L_MaintainerName"; + this.L_MaintainerName.Size = new System.Drawing.Size(80, 20); + this.L_MaintainerName.TabIndex = 6; + this.L_MaintainerName.Text = "XanatosX"; + // + // L_Project + // + this.L_Project.AutoSize = true; + this.L_Project.Location = new System.Drawing.Point(9, 89); + this.L_Project.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.L_Project.Name = "L_Project"; + this.L_Project.Size = new System.Drawing.Size(62, 20); + this.L_Project.TabIndex = 4; + this.L_Project.Text = "Project:"; + // + // LL_Project + // + this.LL_Project.AutoSize = true; + this.LL_Project.Location = new System.Drawing.Point(106, 89); + this.LL_Project.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.LL_Project.Name = "LL_Project"; + this.LL_Project.Size = new System.Drawing.Size(311, 20); + this.LL_Project.TabIndex = 3; + this.LL_Project.TabStop = true; + this.LL_Project.Tag = "https://github.com/XanatosX/XmlFormatter"; + this.LL_Project.Text = "https://github.com/XanatosX/XmlFormatter"; + this.LL_Project.Click += new System.EventHandler(this.OpenLinkLabel_Click); + // + // L_License + // + this.L_License.AutoSize = true; + this.L_License.Location = new System.Drawing.Point(9, 65); + this.L_License.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.L_License.Name = "L_License"; + this.L_License.Size = new System.Drawing.Size(68, 20); + this.L_License.TabIndex = 2; + this.L_License.Text = "License:"; + // + // L_Maintainer + // + this.L_Maintainer.AutoSize = true; + this.L_Maintainer.Location = new System.Drawing.Point(9, 40); + this.L_Maintainer.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.L_Maintainer.Name = "L_Maintainer"; + this.L_Maintainer.Size = new System.Drawing.Size(87, 20); + this.L_Maintainer.TabIndex = 1; + this.L_Maintainer.Text = "Maintainer:"; + // + // L_Version + // + this.L_Version.AutoSize = true; + this.L_Version.Location = new System.Drawing.Point(9, 15); + this.L_Version.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.L_Version.Name = "L_Version"; + this.L_Version.Size = new System.Drawing.Size(67, 20); + this.L_Version.TabIndex = 0; + this.L_Version.Text = "Version:"; + // + // TP_ThirdParty + // + this.TP_ThirdParty.Controls.Add(this.LV_ThirdPartyLibraries); + this.TP_ThirdParty.Location = new System.Drawing.Point(4, 29); + this.TP_ThirdParty.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TP_ThirdParty.Name = "TP_ThirdParty"; + this.TP_ThirdParty.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.TP_ThirdParty.Size = new System.Drawing.Size(600, 133); + this.TP_ThirdParty.TabIndex = 1; + this.TP_ThirdParty.Text = "Third Party"; + this.TP_ThirdParty.UseVisualStyleBackColor = true; + // + // LV_ThirdPartyLibraries + // + this.LV_ThirdPartyLibraries.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.CH_ThirdParty}); + this.LV_ThirdPartyLibraries.FullRowSelect = true; + this.LV_ThirdPartyLibraries.HideSelection = false; + listViewItem1.Tag = "https://github.com/octokit/octokit.net"; + this.LV_ThirdPartyLibraries.Items.AddRange(new System.Windows.Forms.ListViewItem[] { + listViewItem1}); + this.LV_ThirdPartyLibraries.Location = new System.Drawing.Point(9, 9); + this.LV_ThirdPartyLibraries.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.LV_ThirdPartyLibraries.Name = "LV_ThirdPartyLibraries"; + this.LV_ThirdPartyLibraries.Size = new System.Drawing.Size(576, 106); + this.LV_ThirdPartyLibraries.TabIndex = 0; + this.LV_ThirdPartyLibraries.UseCompatibleStateImageBehavior = false; + this.LV_ThirdPartyLibraries.View = System.Windows.Forms.View.Details; + this.LV_ThirdPartyLibraries.SelectedIndexChanged += new System.EventHandler(this.LV_ThirdPartyLibraries_SelectedIndexChanged); + // + // CH_ThirdParty + // + this.CH_ThirdParty.Text = "Third Party Libraries"; + // + // VersionInformation + // + this.AutoScaleDimensions = new System.Drawing.SizeF(144F, 144F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(644, 194); + this.Controls.Add(this.tabControl1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D; + this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.Name = "VersionInformation"; + this.ShowIcon = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "VersionInformation"; + this.Load += new System.EventHandler(this.VersionInformation_Load); + this.tabControl1.ResumeLayout(false); + this.TP_General.ResumeLayout(false); + this.TP_General.PerformLayout(); + this.TP_ThirdParty.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage TP_General; + private System.Windows.Forms.TabPage TP_ThirdParty; + private System.Windows.Forms.ListView LV_ThirdPartyLibraries; + private System.Windows.Forms.ColumnHeader CH_ThirdParty; + private System.Windows.Forms.Label L_Project; + private System.Windows.Forms.LinkLabel LL_Project; + private System.Windows.Forms.Label L_License; + private System.Windows.Forms.Label L_Maintainer; + private System.Windows.Forms.Label L_Version; + private System.Windows.Forms.Label L_VersionNumber; + private System.Windows.Forms.Label L_MaintainerName; + private System.Windows.Forms.LinkLabel LL_MIT; + } +} \ No newline at end of file diff --git a/XmlFormatter/src/Windows/VersionInformation.cs b/XmlFormatter/src/Windows/VersionInformation.cs new file mode 100644 index 00000000..7c29bc54 --- /dev/null +++ b/XmlFormatter/src/Windows/VersionInformation.cs @@ -0,0 +1,77 @@ +using System; +using System.Diagnostics; +using System.Windows.Forms; +using XmlFormatter.src.Manager; + +namespace XmlFormatter.src.Windows +{ + /// + /// Version information windows + /// + public partial class VersionInformation : Form + { + /// + /// Index of the last selected third party + /// + private int lastSelectedThirdParty; + + /// + /// Creating a new instance of this window + /// + public VersionInformation() + { + InitializeComponent(); + lastSelectedThirdParty = -1; + MinimizeBox = false; + MaximizeBox = false; + Text = "Version Information"; + } + + /// + /// Load event + /// + /// Event sender + /// Event arguments + private void VersionInformation_Load(object sender, EventArgs e) + { + VersionManager manager = new VersionManager(); + Version version = manager.GetApplicationVersion(); + L_VersionNumber.Text = manager.GetStringVersion(version); + + LV_ThirdPartyLibraries.Columns[0].Width = LV_ThirdPartyLibraries.Width - 4; + } + + /// + /// List view selection changed + /// + /// Event sender + /// Event arguments + private void LV_ThirdPartyLibraries_SelectedIndexChanged(object sender, EventArgs e) + { + if (sender is ListView listView) + { + if (listView.SelectedItems.Count > 0 + && listView.SelectedItems[0] is ListViewItem listViewItem + && lastSelectedThirdParty != listView.SelectedIndices[0]) + { + Process.Start(listViewItem.Tag.ToString()); + lastSelectedThirdParty = listView.SelectedIndices[0]; + } + } + + } + + /// + /// Event if link was pressed + /// + /// The event sender + /// The event parameter + private void OpenLinkLabel_Click(object sender, EventArgs e) + { + if (sender is LinkLabel linkLabel) + { + Process.Start(linkLabel.Tag.ToString()); + } + } + } +} diff --git a/XmlFormatter/src/Windows/VersionInformation.resx b/XmlFormatter/src/Windows/VersionInformation.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/XmlFormatter/src/Windows/VersionInformation.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file