Add source
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#if NET5_0_OR_NETFRAMEWORK
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.ComponentModel
|
||||
{
|
||||
// These compatibility classes are needed because we don't have a reference to System.ComponentModel
|
||||
// in modern .NET or need to ensure consistent behavior across frameworks
|
||||
|
||||
#if !NET5_0_OR_GREATER
|
||||
public abstract class License : IDisposable
|
||||
{
|
||||
protected License() { }
|
||||
public abstract string LicenseKey { get; }
|
||||
public abstract void Dispose();
|
||||
}
|
||||
|
||||
// License provider abstract class
|
||||
public abstract class LicenseProvider
|
||||
{
|
||||
protected LicenseProvider() { }
|
||||
public abstract License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions);
|
||||
}
|
||||
|
||||
// License context
|
||||
public class LicenseContext : IServiceProvider
|
||||
{
|
||||
public LicenseContext() { }
|
||||
|
||||
public virtual object GetService(Type serviceType)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual string GetSavedLicenseKey(Type type, string key)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual void SetSavedLicenseKey(Type type, string key)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// License usage mode enum
|
||||
public enum LicenseUsageMode
|
||||
{
|
||||
Designtime,
|
||||
Runtime
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
#if NET5_0_OR_NETFRAMEWORK
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
// A minimal DefaultInterpolatedStringHandler implementation for .NET 5.0 and .NET Framework
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
internal struct DefaultInterpolatedStringHandler
|
||||
{
|
||||
private StringBuilder _builder;
|
||||
|
||||
public DefaultInterpolatedStringHandler(int literalLength, int formattedCount)
|
||||
{
|
||||
_builder = new StringBuilder(literalLength + formattedCount * 11);
|
||||
}
|
||||
|
||||
public void AppendLiteral(string value)
|
||||
{
|
||||
_builder.Append(value);
|
||||
}
|
||||
|
||||
public void AppendFormatted<T>(T value)
|
||||
{
|
||||
_builder.Append(value?.ToString() ?? string.Empty);
|
||||
}
|
||||
|
||||
public void AppendFormatted<T>(T value, string format)
|
||||
{
|
||||
if (value is IFormattable formattable)
|
||||
{
|
||||
_builder.Append(formattable.ToString(format, null));
|
||||
}
|
||||
else
|
||||
{
|
||||
_builder.Append(value?.ToString() ?? string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public void AppendFormatted(string value)
|
||||
{
|
||||
_builder.Append(value ?? string.Empty);
|
||||
}
|
||||
|
||||
public void AppendFormatted(int value)
|
||||
{
|
||||
_builder.Append(value);
|
||||
}
|
||||
|
||||
public void AppendFormatted<T>(T value, int alignment)
|
||||
{
|
||||
string str = value?.ToString() ?? string.Empty;
|
||||
if (alignment != 0)
|
||||
{
|
||||
if (alignment < 0)
|
||||
{
|
||||
_builder.Append(str.PadRight(-alignment));
|
||||
}
|
||||
else
|
||||
{
|
||||
_builder.Append(str.PadLeft(alignment));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_builder.Append(str);
|
||||
}
|
||||
}
|
||||
|
||||
public void AppendFormatted<T>(T value, int alignment, string format)
|
||||
{
|
||||
string str;
|
||||
if (value is IFormattable formattable)
|
||||
{
|
||||
str = formattable.ToString(format, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
str = value?.ToString() ?? string.Empty;
|
||||
}
|
||||
|
||||
if (alignment != 0)
|
||||
{
|
||||
if (alignment < 0)
|
||||
{
|
||||
_builder.Append(str.PadRight(-alignment));
|
||||
}
|
||||
else
|
||||
{
|
||||
_builder.Append(str.PadLeft(alignment));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_builder.Append(str);
|
||||
}
|
||||
}
|
||||
|
||||
public string ToStringAndClear()
|
||||
{
|
||||
string result = _builder.ToString();
|
||||
_builder.Clear();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Bunifu.Licensing.Compatibility
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods for delegate compatibility across different .NET versions
|
||||
/// </summary>
|
||||
internal static class DelegateExtensions
|
||||
{
|
||||
// Helper method to create a ThreadStart delegate
|
||||
public static ThreadStart CreateThreadStart(Action action)
|
||||
{
|
||||
return new ThreadStart(action);
|
||||
}
|
||||
|
||||
// Helper method to create a MethodInvoker delegate
|
||||
public static MethodInvoker CreateMethodInvoker(Action action)
|
||||
{
|
||||
return new MethodInvoker(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#if NET40_OR_GREATER && !NET5_0_OR_GREATER
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bunifu.Licensing.Compatibility
|
||||
{
|
||||
internal static class HttpClientCompat
|
||||
{
|
||||
public static string PostJson(string url, string jsonContent)
|
||||
{
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
client.Headers[HttpRequestHeader.ContentType] = "application/json";
|
||||
return client.UploadString(url, jsonContent);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetString(string url)
|
||||
{
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
return client.DownloadString(url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,164 @@
|
||||
#if !NET5_0_OR_GREATER
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace System.Net.Http
|
||||
{
|
||||
// Basic HttpClient implementation for .NET Framework
|
||||
public class HttpClient : IDisposable
|
||||
{
|
||||
private readonly WebClient _webClient;
|
||||
|
||||
public HttpClient()
|
||||
{
|
||||
_webClient = new WebClient();
|
||||
DefaultRequestHeaders = new HttpRequestHeaders();
|
||||
}
|
||||
|
||||
public Uri BaseAddress { get; set; }
|
||||
public HttpRequestHeaders DefaultRequestHeaders { get; private set; }
|
||||
|
||||
public Task<HttpResponseMessage> PostAsync(string requestUri, StringContent content)
|
||||
{
|
||||
try
|
||||
{
|
||||
string fullUri = BaseAddress != null ? new Uri(BaseAddress, requestUri).ToString() : requestUri;
|
||||
|
||||
foreach (var header in DefaultRequestHeaders.AcceptHeaders)
|
||||
{
|
||||
_webClient.Headers.Add("Accept", header);
|
||||
}
|
||||
|
||||
_webClient.Headers.Add("Content-Type", content.MediaType);
|
||||
byte[] responseBytes = _webClient.UploadData(fullUri, "POST", content.GetBytes());
|
||||
|
||||
var response = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = HttpStatusCode.Created,
|
||||
Content = new ByteArrayContent(responseBytes)
|
||||
};
|
||||
|
||||
return Task.FromResult(response);
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
HttpStatusCode statusCode = HttpStatusCode.InternalServerError;
|
||||
if (ex.Response is HttpWebResponse webResponse)
|
||||
{
|
||||
statusCode = webResponse.StatusCode;
|
||||
}
|
||||
|
||||
var response = new HttpResponseMessage
|
||||
{
|
||||
StatusCode = statusCode,
|
||||
Content = new StringContent(ex.Message)
|
||||
};
|
||||
|
||||
return Task.FromResult(response);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_webClient.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public class HttpRequestHeaders
|
||||
{
|
||||
private readonly List<string> _acceptHeaders = new List<string>();
|
||||
|
||||
public List<string> AcceptHeaders => _acceptHeaders;
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_acceptHeaders.Clear();
|
||||
}
|
||||
|
||||
public void Add(MediaTypeWithQualityHeaderValue header)
|
||||
{
|
||||
_acceptHeaders.Add(header.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public class HttpResponseMessage
|
||||
{
|
||||
public HttpStatusCode StatusCode { get; set; }
|
||||
public HttpContent Content { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return StatusCode.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class HttpContent
|
||||
{
|
||||
public abstract string ToString();
|
||||
}
|
||||
|
||||
public class StringContent : HttpContent
|
||||
{
|
||||
private readonly string _content;
|
||||
private readonly byte[] _contentBytes;
|
||||
|
||||
public string MediaType { get; }
|
||||
|
||||
public StringContent(string content, Encoding encoding, string mediaType)
|
||||
{
|
||||
_content = content;
|
||||
_contentBytes = encoding.GetBytes(content);
|
||||
MediaType = mediaType;
|
||||
}
|
||||
|
||||
// Add parameterless constructor for .NET Framework compatibility
|
||||
public StringContent(string content) : this(content, Encoding.UTF8, "text/plain")
|
||||
{
|
||||
}
|
||||
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
return _contentBytes;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _content;
|
||||
}
|
||||
}
|
||||
|
||||
public class ByteArrayContent : HttpContent
|
||||
{
|
||||
private readonly byte[] _content;
|
||||
|
||||
public ByteArrayContent(byte[] content)
|
||||
{
|
||||
_content = content;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Encoding.UTF8.GetString(_content);
|
||||
}
|
||||
}
|
||||
|
||||
public class MediaTypeWithQualityHeaderValue
|
||||
{
|
||||
private readonly string _mediaType;
|
||||
|
||||
public MediaTypeWithQualityHeaderValue(string mediaType)
|
||||
{
|
||||
_mediaType = mediaType;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _mediaType;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
#if NET5_0_OR_GREATER || NET6_0_OR_GREATER
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
#endif
|
||||
|
||||
namespace Bunifu.Licensing.Compatibility
|
||||
{
|
||||
// This class ensures that HTTP types are properly imported
|
||||
internal static class HttpImports
|
||||
{
|
||||
// Method to reference the types so they are included in compilation
|
||||
internal static void ReferenceHttpTypes()
|
||||
{
|
||||
#if NET5_0_OR_GREATER || NET6_0_OR_GREATER
|
||||
var client = new HttpClient();
|
||||
var mediaType = new MediaTypeWithQualityHeaderValue("application/json");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
// Define compatibility types for .NET Framework only
|
||||
#if NETFRAMEWORK && NET40_OR_GREATER
|
||||
namespace System.ComponentModel
|
||||
{
|
||||
// Create a custom License implementation if needed
|
||||
// This will only be used if the System.ComponentModel.License cannot be found
|
||||
public class License : IDisposable
|
||||
{
|
||||
public virtual string LicenseKey { get; set; }
|
||||
|
||||
public virtual void Dispose()
|
||||
{
|
||||
// Cleanup
|
||||
}
|
||||
}
|
||||
|
||||
// Define LicenseContext for compatibility
|
||||
public class LicenseContext
|
||||
{
|
||||
private Hashtable _savedLicenseKeys;
|
||||
|
||||
public LicenseContext()
|
||||
{
|
||||
_savedLicenseKeys = new Hashtable();
|
||||
}
|
||||
|
||||
public string GetSavedLicenseKey(Type type)
|
||||
{
|
||||
if (_savedLicenseKeys == null)
|
||||
return null;
|
||||
|
||||
return (string)_savedLicenseKeys[type];
|
||||
}
|
||||
|
||||
public string GetSavedLicenseKey(Type type, object instance)
|
||||
{
|
||||
return GetSavedLicenseKey(type);
|
||||
}
|
||||
|
||||
public void SetSavedLicenseKey(Type type, string key)
|
||||
{
|
||||
if (_savedLicenseKeys == null)
|
||||
_savedLicenseKeys = new Hashtable();
|
||||
|
||||
_savedLicenseKeys[type] = key;
|
||||
}
|
||||
}
|
||||
|
||||
// Define LicenseUsageMode enum
|
||||
public enum LicenseUsageMode
|
||||
{
|
||||
Runtime,
|
||||
Designtime
|
||||
}
|
||||
|
||||
// Define LicenseManager for compatibility
|
||||
public static class LicenseManager
|
||||
{
|
||||
private static LicenseUsageMode _usageMode = LicenseUsageMode.Runtime;
|
||||
|
||||
public static LicenseUsageMode UsageMode
|
||||
{
|
||||
get { return _usageMode; }
|
||||
set { _usageMode = value; }
|
||||
}
|
||||
|
||||
public static License Validate(Type type, object instance)
|
||||
{
|
||||
return new License();
|
||||
}
|
||||
}
|
||||
|
||||
// LicenseProvider class
|
||||
public abstract class LicenseProvider
|
||||
{
|
||||
public abstract License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#if NET5_0_OR_NETFRAMEWORK
|
||||
namespace System.Runtime.Versioning
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
|
||||
internal sealed class TargetPlatformAttribute : Attribute
|
||||
{
|
||||
public TargetPlatformAttribute(string platformName)
|
||||
{
|
||||
PlatformName = platformName;
|
||||
}
|
||||
|
||||
public string PlatformName { get; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
|
||||
internal sealed class SupportedOSPlatformAttribute : Attribute
|
||||
{
|
||||
public SupportedOSPlatformAttribute(string platformName)
|
||||
{
|
||||
PlatformName = platformName;
|
||||
}
|
||||
|
||||
public string PlatformName { get; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#if NETFRAMEWORK && !NET5_0_OR_GREATER
|
||||
using System;
|
||||
|
||||
namespace System.Runtime.Versioning
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
|
||||
public sealed class TargetPlatformAttribute : Attribute
|
||||
{
|
||||
public TargetPlatformAttribute(string targetPlatformName)
|
||||
{
|
||||
PlatformName = targetPlatformName;
|
||||
}
|
||||
|
||||
public string PlatformName { get; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
|
||||
public sealed class SupportedOSPlatformAttribute : Attribute
|
||||
{
|
||||
public SupportedOSPlatformAttribute(string platformName)
|
||||
{
|
||||
PlatformName = platformName;
|
||||
}
|
||||
|
||||
public string PlatformName { get; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
#if NETFRAMEWORK && NET40_OR_GREATER
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bunifu.Licensing.Compatibility
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for string operations to support compatibility across frameworks
|
||||
/// </summary>
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Split a string with StringSplitOptions
|
||||
/// </summary>
|
||||
public static string[] Split(this string str, char[] separator, StringSplitOptions options)
|
||||
{
|
||||
return str.Split(separator, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Split a string with a single character and StringSplitOptions
|
||||
/// </summary>
|
||||
public static string[] Split(this string str, char separator, StringSplitOptions options)
|
||||
{
|
||||
return str.Split(new[] { separator }, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
#if NETFRAMEWORK || NET5_0 || NET5_0_OR_NETFRAMEWORK
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public struct DefaultInterpolatedStringHandler
|
||||
{
|
||||
private StringBuilder _builder;
|
||||
|
||||
public DefaultInterpolatedStringHandler(int literalLength, int formattedCount)
|
||||
{
|
||||
_builder = new StringBuilder(literalLength + formattedCount * 11);
|
||||
}
|
||||
|
||||
public string ToStringAndClear()
|
||||
{
|
||||
string result = _builder.ToString();
|
||||
_builder.Clear();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void AppendLiteral(string value)
|
||||
{
|
||||
_builder.Append(value);
|
||||
}
|
||||
|
||||
public void AppendFormatted<T>(T value)
|
||||
{
|
||||
_builder.Append(value?.ToString() ?? string.Empty);
|
||||
}
|
||||
|
||||
public void AppendFormatted<T>(T value, string format)
|
||||
{
|
||||
if (value is IFormattable formattable)
|
||||
{
|
||||
_builder.Append(formattable.ToString(format, null));
|
||||
}
|
||||
else
|
||||
{
|
||||
_builder.Append(value?.ToString() ?? string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Bunifu.Licensing.Compatibility
|
||||
{
|
||||
// This class ensures that all compatibility types are properly imported
|
||||
internal static class StringImports
|
||||
{
|
||||
// Method to reference the types so they are included in compilation
|
||||
internal static void ReferenceStringHandlerTypes()
|
||||
{
|
||||
#if NETFRAMEWORK || NET5_0 || NET5_0_OR_NETFRAMEWORK
|
||||
var handler = new DefaultInterpolatedStringHandler(10, 2);
|
||||
handler.AppendLiteral("Test");
|
||||
handler.AppendFormatted("value");
|
||||
var result = handler.ToStringAndClear();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user