Added library license validation check with a detailed description

This commit is contained in:
MarcinZiabek
2023-04-18 01:58:40 +02:00
parent ef89be9710
commit 76844dc8dd
5 changed files with 84 additions and 1 deletions
+15
View File
@@ -0,0 +1,15 @@
using NUnit.Framework;
using QuestPDF.Infrastructure;
namespace QuestPDF.Examples
{
[SetUpFixture]
public class LicenseSetup
{
[OneTimeSetUp]
public static void Setup()
{
QuestPDF.Settings.License = LicenseType.Community;
}
}
}
+2
View File
@@ -17,6 +17,8 @@ namespace QuestPDF.ReportSample
[SetUp]
public void SetUp()
{
QuestPDF.Settings.License = LicenseType.Community;
var model = DataSource.GetReport();
Report = new StandardReport(model);
}
@@ -17,6 +17,7 @@ namespace QuestPDF.Drawing
{
internal static void GeneratePdf(Stream stream, IDocument document)
{
ValidateLicense();
CheckIfStreamIsCompatible(stream);
var metadata = document.GetMetadata();
@@ -26,6 +27,7 @@ namespace QuestPDF.Drawing
internal static void GenerateXps(Stream stream, IDocument document)
{
ValidateLicense();
CheckIfStreamIsCompatible(stream);
var metadata = document.GetMetadata();
@@ -44,6 +46,8 @@ namespace QuestPDF.Drawing
internal static ICollection<byte[]> GenerateImages(IDocument document)
{
ValidateLicense();
var metadata = document.GetMetadata();
var canvas = new ImageCanvas(metadata);
RenderDocument(canvas, document);
@@ -51,6 +55,33 @@ namespace QuestPDF.Drawing
return canvas.Images;
}
private static void ValidateLicense()
{
if (Settings.License.HasValue)
return;
var newParagraph = Environment.NewLine + Environment.NewLine;
var exceptionMessage =
$"QuestPDF is a modern open-source library. " +
$"We identify the importance of the library in your projects, and therefore want to make sure you can safely and confidently continue the development. " +
$"Being a healthy and growing community is our primary goal that motivates us to pursue professionalism. {newParagraph}" +
$"The library is free for the commercial usage for the vast majority of users under the QuestPDF Community MIT license. {newParagraph}" +
$"However, if you are consuming the QuestPDF library as a Direct Package Dependency for usage in a Closed Source software in the capacity of a for-profit company/individual with more than 1M USD annual gross revenue, you must purchase the QuestPDF Professional or Enterprise License, depending on number of software developers. {newParagraph}" +
$"For evaluation purposes, feel free to use the QuestPDF Community License in a non-production environment. {newParagraph}" +
$"Please refer to the QuestPDF License and Pricing webpage for more details. (https://www.questpdf.com/pricing.html) {newParagraph}" +
$"If you are an existing QuestPDF user and for any reason cannot update, you can stay with the 2022.12.X release with the extended quality support but without any new features, improvements or optimizations. That release is and always will be available under the MIT license, free for commercial usage. {newParagraph}" +
$"The library does not require any license key. " +
$"We trust our users and therefore the process is simple. " +
$"To disable license validation and turn off this exception, please configure an eligible license by using the QuestPDF.Settings.License API, for example: {newParagraph}" +
$"\"QuestPDF.Settings.License = LicenseType.Community;\". {newParagraph}";
throw new Exception(exceptionMessage)
{
HelpLink = "https://www.questpdf.com/pricing.html"
};
}
internal static ICollection<PreviewerPicture> GeneratePreviewerPictures(IDocument document)
{
var canvas = new SkiaPictureCanvas();
@@ -0,0 +1,27 @@
namespace QuestPDF.Infrastructure
{
public enum LicenseType
{
/// <summary>
/// <para>The library is free for the commercial usage for the vast majority of users under the QuestPDF Community MIT license. Please kindly check if you are eligible to use this license.</para>
/// <para>License link: https://www.questpdf.com/license-community.html</para>
/// </summary>
Community,
/// <summary>
/// <para>You must purchase the QuestPDF Professional license, if you are consuming the QuestPDF library as a Direct Package Dependency for usage in a Closed Source software in the capacity of a for-profit company/individual with more than 1M USD annual gross revenue, <c>and there are up to 10 developers</c>.</para>
/// <para>If the number of developers is more than 10, you must purchase the QuestPDF Enterprise license.</para>
/// <para>Before making a license purchase, please evaluate the library in a non-production environment.</para>
/// <para>License link: https://www.questpdf.com/license-commercial.html</para>
/// </summary>
Professional,
/// <summary>
/// <para>You must purchase the QuestPDF Professional license, if you are consuming the QuestPDF library as a Direct Package Dependency for usage in a Closed Source software in the capacity of a for-profit company/individual with more than 1M USD annual gross revenue.</para>
/// <para>If the there are less than 10 developers, you are eligible to use the cheaper QuestPDF Professional License.</para>
/// <para>Before making a license purchase, please evaluate the library in a non-production environment.</para>
/// <para>License link: https://www.questpdf.com/license-commercial.html</para>
/// </summary>
Enterprise
}
}
+9 -1
View File
@@ -1,7 +1,15 @@
namespace QuestPDF
using QuestPDF.Infrastructure;
namespace QuestPDF
{
public static class Settings
{
/// <summary>
/// <para>Please kindly select license type that applies to your usage of the QuestPDF library.</para>
/// <para>For more details, please check the QuestPDF License and Pricing page: https://www.questpdf.com/pricing.html</para>
/// </summary>
public static LicenseType? License { get; set; }
/// <summary>
/// This value represents the maximum number of pages that the library produces.
/// This is useful when layout constraints are too strong, e.g. one element does not fit in another.