/// <summary> /// Attaches the license. /// </summary> /// <param name="assembly">The assembly.</param> /// <param name="licenseAttribute">The license attribute.</param> public static void AttachLicense(Assembly assembly, BeyovaLicenseAttribute licenseAttribute) { if (assembly != null && licenseAttribute != null) { string assemblyName = assembly.GetName().Name; if (licenses.ContainsKey(assemblyName)) { return; } var license = licenseAttribute.ReadBeyovaLicense(); if (license != null) { licenses.Add(assemblyName, license); } else { if (licenseAttribute.IsRequired) { throw new InvalidLicenseException(assemblyName); } } } }
/// <summary> /// Reads the specified license attribute. /// </summary> /// <param name="licenseAttribute">The license attribute.</param> /// <returns>BeyovaLicense.</returns> public BeyovaLicenseInfo Read(BeyovaLicenseAttribute licenseAttribute) { if (licenseAttribute != null) { try { if (!string.IsNullOrWhiteSpace(licenseAttribute.LicensePath) && File.Exists(licenseAttribute.LicensePath)) { var json = Encoding.UTF8.GetString(Convert.FromBase64String(File.ReadAllText(licenseAttribute.LicensePath))); var result = JsonConvert.DeserializeObject<BeyovaLicenseInfo>(json); result.LicensePath = licenseAttribute.LicensePath; result.Entry = licenseAttribute.Entry; return result; } } catch (Exception ex) { Framework.ApiTracking?.LogException(ex.Handle(new { licenseAttribute.LicensePath, Uri = licenseAttribute.Entry?.GravityServiceUri, licenseAttribute.IsRequired }).ToExceptionInfo()); } } return null; }