public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { FileLicense license = null; StringBuilder listMsg = new StringBuilder(); if (context != null) { if (context.UsageMode == LicenseUsageMode.Designtime) { license = new FileLicense(this, ""); } if (license != null) { return(license); } //licenses string licenseFile = GetlicFilePath(); if (!string.IsNullOrWhiteSpace(licenseFile) && File.Exists(licenseFile)) { try { StreamReader sr = new StreamReader(licenseFile, Encoding.Default); String xmlStr = DESEncrypt.Decrypt(sr.ReadToEnd()); var entity = XmlFormatterSerializer.DeserializeFromXml <LicenseEntity>(xmlStr, typeof(LicenseEntity)); if (entity != null) { var pastDate = DateTime.Parse(entity.PastDate); if (DateTime.Now > pastDate) { listMsg.AppendLine(" 许可证已过期"); } } if (listMsg.Length > 5) { listMsg.Insert(0, " 许可证编号:" + entity.ID); listMsg.Insert(1, " 许可证名称:" + entity.Name); listMsg.Insert(2, " 程序集版本号:" + entity.AssemblyName); license = new FileLicense(this, listMsg.ToString()); } else { license = new FileLicense(this, ""); } } catch (IOException e) { license = new FileLicense(this, "检查许可证失败" + e.Message); } } else { license = new FileLicense(this, "lic文件不存在,请联系供应商"); } } return(license); }
public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { FileLicense license = null; StringBuilder listMsg = new StringBuilder(); if (context != null) { if (context.UsageMode == LicenseUsageMode.Designtime) { license = new FileLicense(this, ""); } if (license != null) { return license; } //licenses string licenseFile = GetlicFilePath(); if (!string.IsNullOrWhiteSpace(licenseFile) && File.Exists(licenseFile)) { try { StreamReader sr = new StreamReader(licenseFile, Encoding.Default); String xmlStr = DESEncrypt.Decrypt(sr.ReadToEnd()); var entity = XmlFormatterSerializer.DeserializeFromXml<LicenseEntity>(xmlStr, typeof(LicenseEntity)); if (entity != null) { var pastDate = DateTime.Parse(entity.PastDate); if (DateTime.Now > pastDate) { listMsg.AppendLine(" 许可证已过期"); } } if (listMsg.Length > 5) { listMsg.Insert(0, " 许可证编号:" + entity.ID); listMsg.Insert(1, " 许可证名称:" + entity.Name); listMsg.Insert(2, " 程序集版本号:" + entity.AssemblyName); license = new FileLicense(this, listMsg.ToString()); } else license = new FileLicense(this, ""); } catch (IOException e) { license = new FileLicense(this, "检查许可证失败" + e.Message); } } else { license = new FileLicense(this, "lic文件不存在,请联系供应商"); } } return license; }