Skip to content

Commit

Permalink
Use System.Runtime.InteropServices.OSPlatform to detect platform
Browse files Browse the repository at this point in the history
  • Loading branch information
axunonb committed Oct 20, 2019
1 parent 2105be0 commit 1b08f36
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 186 deletions.
1 change: 1 addition & 0 deletions MailMergeLib.Tests/HtmlBodyBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using MailMergeLib.Tests.NUnit;
using NUnit.Framework;

namespace MailMergeLib.Tests
Expand Down
1 change: 1 addition & 0 deletions MailMergeLib.Tests/Message_Config.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using MailMergeLib.Tests.NUnit;
using NUnit.Framework;

namespace MailMergeLib.Tests
Expand Down
13 changes: 13 additions & 0 deletions MailMergeLib.Tests/NUnit/OpSys.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace MailMergeLib.Tests.NUnit
{
/// <summary>
/// Used enum names must be identical to
/// https://github.com/nunit/docs/wiki/Platform-Attribute
/// </summary>
public enum OpSys
{
Win,
Linux,
MacOsX
}
}
90 changes: 0 additions & 90 deletions MailMergeLib.Tests/Platform.cs

This file was deleted.

17 changes: 10 additions & 7 deletions MailMergeLib/MailMergeLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<Description>MailMergeLib is a mail message client library which provides comfortable mail merge capabilities for text, inline images and attachments, as well as good throughput and fault tolerance for sending mail messages.</Description>
<Copyright>© 2007-2019 by axuno gGmbH</Copyright>
<AssemblyTitle>MailMergeLib</AssemblyTitle>
<Version>5.6.1.0</Version>
<AssemblyVersion>5.6.1.0</AssemblyVersion>
<FileVersion>5.6.1.0</FileVersion>
<Version>5.6.2.0</Version>
<AssemblyVersion>5.6.2.0</AssemblyVersion>
<FileVersion>5.6.2.0</FileVersion>
<Authors>axuno gGmbH</Authors>
<TargetFrameworks>netstandard1.6;netstandard2.0;net45</TargetFrameworks>
<DefineConstants>TRACE;DEBUG;RELEASE</DefineConstants>
Expand All @@ -18,17 +18,20 @@
<PackageId>MailMergeLib</PackageId>
<PackageProjectUrl>https://github.com/axuno/MailMergeLib</PackageProjectUrl>
<PackageIconUrl>https://github.com/axuno/MailMergeLib/raw/master/MailMergeLib_64x64.png</PackageIconUrl>
<PackageLicenseUrl>https://github.com/axuno/MailMergeLib/blob/master/MailMergeLib/License.txt</PackageLicenseUrl>
<PackageLicenseUrl></PackageLicenseUrl>
<RepositoryUrl>https://github.com/axuno/MailMergeLib</RepositoryUrl>
<PackageReleaseNotes>* Reverted back to v5.5.0 behavior: MessageConfig.FileBaseDirectory must be a full path only before the MailMergeMessage is processed (not already, when the property is set).
* Classes in namespace 'MailMergLib.SmartFormatMail' are obsolete. Use namespace 'SmartFormat' from dependency 'SmartFormat.Net' instead.
* This is the last version which supports netstandard1.6
<PackageReleaseNotes>* Encryption of Credential in Settings can now be disabled. Breaking change: disabled is the default.
* SMTP settings can now be read from app.config/web.config
* Path checks (e.g. inline images, attachments) now respect Linux and MacOsX platform rules beside Windows
* Classes in namespace 'MailMergLib.SmartFormatMail' were obsolete and are now removed.
* Updated versions of dependencies</PackageReleaseNotes>
<PackageTags>smtp mime mail email merge template netcore netstandard net45 c#</PackageTags>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<RootNamespace>MailMergeLib</RootNamespace>
<LangVersion>latest</LangVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>GitHub</RepositoryType>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand Down
12 changes: 7 additions & 5 deletions MailMergeLib/MailMergeMessage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -10,6 +9,9 @@
using MailMergeLib.Templates;
using MimeKit;
using YAXLib;
#if NETFRAMEWORK || NETSTANDARD2_0
using System.Data;
#endif

namespace MailMergeLib
{
Expand Down Expand Up @@ -336,8 +338,8 @@ private MailSmartFormatter GetConfiguredMailSmartFormatter()
/// <param name="dataItem"></param>
/// <returns>Returns the text with all variables replaced.</returns>
/// <remarks>
/// In case <see cref="SmartFormatMail.Core.Settings.SmartSettings.FormatErrorAction"/> == ErrorAction.ThrowError
/// or <see cref="SmartFormatMail.Core.Settings.SmartSettings.ParseErrorAction"/> == ErrorAction.ThrowError
/// In case <see cref="SmartFormat.Core.Settings.SmartSettings.FormatErrorAction"/> == ErrorAction.ThrowError
/// or <see cref="SmartFormat.Core.Settings.SmartSettings.ParseErrorAction"/> == ErrorAction.ThrowError
/// we simple catch the exception and simulate setting ErrorAction.MaintainTokens.
/// Note: We track such errors by subscribing to Parser.OnParsingFailure and Formatter.OnFormattingFailure.
/// </remarks>
Expand Down Expand Up @@ -369,8 +371,8 @@ internal string SearchAndReplaceVars(string text, object dataItem)
/// <param name="dataItem"></param>
/// <returns>Returns the text with all variables replaced.</returns>
/// <remarks>
/// In case <see cref="SmartFormatMail.Core.Settings.SmartSettings.FormatErrorAction"/> == ErrorAction.ThrowError
/// or <see cref="SmartFormatMail.Core.Settings.SmartSettings.ParseErrorAction"/> == ErrorAction.ThrowError
/// In case <see cref="SmartFormat.Core.Settings.SmartSettings.FormatErrorAction"/> == ErrorAction.ThrowError
/// or <see cref="SmartFormat.Core.Settings.SmartSettings.ParseErrorAction"/> == ErrorAction.ThrowError
/// we simple catch the exception and simulate setting ErrorAction.MaintainTokens.
/// Note: We track such errors by subscribing to Parser.OnParsingFailure and Formatter.OnFormattingFailure.
/// </remarks>
Expand Down
78 changes: 0 additions & 78 deletions MailMergeLib/Platform.cs

This file was deleted.

4 changes: 2 additions & 2 deletions MailMergeLib/Templates/Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ internal set
}

/// <summary>
/// Gets the parts for the <see cref="key"/> argument.
/// Gets the parts for the key parameter.
/// If there is no part for the key, and the <see cref="DefaultKey"/> is not Null,
/// the parts for the default key are returned. If neither can be found, but there are only max.
/// 2 entries with 1 key, this one is returned. If all fail the returned array will be empty.
/// </summary>
/// <param name="key">The key to get the parts for. If null or omitted, the <see cref="Key"/> property of the <see cref="Template"/> will be used.</param>
/// <returns>If the <param name="key"/> parameter is found, it returns an array of <see cref="Part"/> for the <param name="key"/> parameter, else from the default key.</returns>
/// <returns>If the key parameter is found, it returns an array of <see cref="Part"/> for the <param name="key"/> parameter, else from the default key.</returns>
public Part[] GetParts(string key = null)
{
if (key == null) key = Key;
Expand Down
9 changes: 5 additions & 4 deletions MailMergeLib/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using MimeKit;

Expand All @@ -13,20 +14,20 @@ namespace MailMergeLib
public static class Tools
{
/// <summary>
/// Checks whether the given path is a full path, depending on the <see cref="OpSys"/>.
/// Checks whether the given path is a full path, depending on the platform.
/// </summary>
/// <param name="path"></param>
/// <returns>Returns true if the path is absolute, else false.</returns>
public static bool IsFullPath(string path)
{
if (string.IsNullOrWhiteSpace(path) || path.IndexOfAny(Path.GetInvalidPathChars()) != -1 || !Path.IsPathRooted(path))
return false;

if (Platform.OpSys != OpSys.Win)
#if NETSTANDARD
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return true;
}

#endif
var pathRoot = Path.GetPathRoot(path);
if (pathRoot.Length <= 2) // Accepts X:\ and \\UNC\PATH, rejects empty string, \ and X:
return false;
Expand Down

0 comments on commit 1b08f36

Please sign in to comment.