public async Task <License> CreateLicense(Entities.License license, string customerName, string contactEmail)
        {
            var additionalAttributes = new Dictionary <string, string>
            {
                { nameof(license.Name), license.Name },
                { nameof(license.CreatedBy), license.CreatedBy },
                { nameof(license.DateFrom), license.DateFrom.ToString() },
                { nameof(license.HardwareId), HardwareInfoHelper.EncryptHardwareId(license.HardwareId) },
                { nameof(license.Active), license.Active.ToString() },
                { LicenseConstants.LicenseDbIdAttributeName, license.Id.ToString() }
            };

            var productFeatures = new Dictionary <string, string>
            {
                { nameof(license.NumberOfConcurrentUserSessionsAllowed), license.NumberOfConcurrentUserSessionsAllowed.ToString() },
            };

            return(License.New()
                   .WithUniqueIdentifier(Guid.NewGuid())
                   .As(LicenseType.Trial)
                   .ExpiresAt(license.DateTo)
                   .WithMaximumUtilization(license.NumberOfConcurrentUserSessionsAllowed)
                   .WithProductFeatures(productFeatures)
                   .WithAdditionalAttributes(additionalAttributes)
                   .LicensedTo(customerName, contactEmail)
                   .CreateAndSignWithPrivateKey(await this.licenseKeyService.GetPrivateKey(), LicenseConstants.PassPhrase));
        }
        public async Task <License> LoadLicenseFromDisk(string licenseDocumentId)
        {
            var filePath = $"{LicenseConstants.LicensesDirectory}/{licenseDocumentId}{LicenseConstants.LicensFileExtension}";

            if (!File.Exists(filePath))
            {
                return(null);
            }

            return(License.Load(await File.ReadAllTextAsync(filePath)));
        }
 public async Task <IEnumerable <LicenseValidationFailure> > ValidateLicense(License license, string customerName, string contactEmail, DateTime validationDate)
 {
     return(license.Validate()
            .ExpirationDate()
            .When(lic => lic.Type == LicenseType.Trial)
            .And()
            .IsLicensedTo(customerName, contactEmail)
            .And()
            .HasValidHardwareId()
            .And()
            .HasValidValidationDate(validationDate)
            .And()
            .Signature(await this.licenseKeyService.GetPublicKey())
            .AssertValidLicense()
            .Select(i => new LicenseValidationFailure()
     {
         Message = i.Message,
         HowToResolve = i.HowToResolve
     }));
 }
        public async Task <bool> Init()
        {
            string pubKey = "";

            using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("Automatica.Core.Internals.pub.txt")))
            {
                pubKey = await reader.ReadToEndAsync();
            }

            if (File.Exists(LicensePath))
            {
                using (var file = File.OpenRead(LicensePath))
                {
                    var license = Standard.Licensing.License.Load(file);

                    var validationFailures = license.Validate().
                                             ExpirationDate().
                                             When(lic => lic.Type == LicenseType.Trial).
                                             And().
                                             Signature(pubKey).
                                             AssertValidLicense();
                    ValidationErrors = validationFailures.ToList();
                    _license         = license;
                }

                IsLicensed = ValidationErrors.Count == 0;
            }

            if (IsLicensed)
            {
                MaxDatapoints = Convert.ToInt32(_license.ProductFeatures.Get("MaxDatapoints"));
                MaxUsers      = Convert.ToInt32(_license.ProductFeatures.Get("MaxUsers"));
            }
            else
            {
                MaxDatapoints = int.MaxValue;
                MaxUsers      = int.MaxValue;
            }
            return(IsLicensed);
        }
 public async Task SaveLicense(License license)
 {
     Directory.CreateDirectory(LicenseConstants.LicensesDirectory);
     var fileName = license.Id.ToString();
     await File.WriteAllTextAsync($"{LicenseConstants.LicensesDirectory}/{fileName}{LicenseConstants.LicensFileExtension}", license.ToString(), Encoding.UTF8);
 }
 public License LoadLicense(Stream stream)
 {
     return(License.Load(stream));
 }
 public License LoadLicense(string xmlString)
 {
     return(License.Load(xmlString));
 }
        public void DeleteLicense(License license)
        {
            var fileName = license.Id.ToString();

            File.Delete($"{LicenseConstants.LicensesDirectory}/{fileName}{LicenseConstants.LicensFileExtension}");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="LicenseBuilder"/> class.
 /// </summary>
 public LicenseBuilder()
 {
     license = new License();
 }