public override License GetLicense(LicenseContext licenseContext_0, Type type_0, object object_0, bool bool_0) { License aELicense; if (licenseContext_0 == null) { throw new LicenseException(type_0, object_0, "License context is null."); } string savedLicenseKey = licenseContext_0.GetSavedLicenseKey(type_0, null); if ((savedLicenseKey == null ? true : !this.IsKeyValid(type_0, savedLicenseKey))) { switch (licenseContext_0.UsageMode) { case LicenseUsageMode.Runtime: { savedLicenseKey = this.GetLicenseFromFile(string.Concat(Application.StartupPath, "\\licences.lic"), type_0.FullName); if (savedLicenseKey == null || !this.IsKeyValid(type_0, savedLicenseKey)) { aELicense = null; break; } else { licenseContext_0.SetSavedLicenseKey(type_0, savedLicenseKey); aELicense = new AELicense("Runtime"); break; } } case LicenseUsageMode.Designtime: { ITypeResolutionService service = (ITypeResolutionService)licenseContext_0.GetService(typeof(ITypeResolutionService)); if (service != null) { if (service.GetPathOfAssembly(type_0.Assembly.GetName()) == null) { string fullyQualifiedName = type_0.Module.FullyQualifiedName; } savedLicenseKey = "受限许可"; } aELicense = new AELicense(savedLicenseKey); break; } default: { aELicense = null; break; } } } else { aELicense = new AELicense(savedLicenseKey); } return(aELicense); }
public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { ChartLicense chartLicense = null; if (context != null) { if (context.UsageMode == LicenseUsageMode.Designtime) { chartLicense = new ChartLicense(this, "Dundas Chart. Design-Time License"); } if (chartLicense == null) { string savedLicenseKey = context.GetSavedLicenseKey(type, null); if (savedLicenseKey != null && this.IsKeyValid(savedLicenseKey, type)) { chartLicense = new ChartLicense(this, savedLicenseKey); } } if (chartLicense == null) { string text = null; if (context != null) { ITypeResolutionService typeResolutionService = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService)); if (typeResolutionService != null) { text = typeResolutionService.GetPathOfAssembly(type.Assembly.GetName()); } } if (text == null) { text = type.Module.FullyQualifiedName; } string directoryName = Path.GetDirectoryName(text); string path = directoryName + "\\" + type.FullName + ".lic"; bool flag = File.Exists(path); if (!flag) { string path2 = directoryName + "\\__AssemblyInfo__.ini"; if (File.Exists(path2)) { string text2 = null; Stream stream = new FileStream(path2, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader streamReader = new StreamReader(stream); do { text2 = streamReader.ReadLine(); text2 = text2.ToUpper(CultureInfo.InvariantCulture); if (text2 != null && text2.StartsWith("URL=", StringComparison.Ordinal)) { directoryName = text2.Substring(4); if (directoryName.StartsWith("FILE:///", StringComparison.Ordinal)) { directoryName = directoryName.Substring(8); } directoryName = directoryName.Replace('/', '\\'); int num = directoryName.LastIndexOf('\\'); if (num >= 0) { directoryName = directoryName.Substring(0, num); } path = directoryName + "\\" + type.FullName + ".lic"; flag = File.Exists(path); text2 = null; } }while (text2 != null); streamReader.Close(); } } if (flag) { Stream stream2 = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader streamReader2 = new StreamReader(stream2); string key = streamReader2.ReadLine(); streamReader2.Close(); if (this.IsKeyValid(key, type)) { chartLicense = new ChartLicense(this, key); } } if (chartLicense != null) { context.SetSavedLicenseKey(type, chartLicense.LicenseKey); } } } return(chartLicense); }
public void GetService_Invoke_ReturnsNull() { var context = new LicenseContext(); Assert.Null(context.GetService(null)); }
/// <include file='doc\LicFileLicenseProvider.uex' path='docs/doc[@for="LicFileLicenseProvider.GetLicense"]/*' /> /// <devdoc> /// <para>Gets a license for the instance of the component and determines if it is valid.</para> /// </devdoc> public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { ProcCountLicense lic = null; Debug.Assert(context != null, "No context provided!"); //if no context is provided, do nothing if (context != null) { //if this control is in runtime mode if (context.UsageMode == LicenseUsageMode.Runtime) { //retreive the stored license key string key = context.GetSavedLicenseKey(type, null); //check if the stored license key is null // and call IsKeyValid to make sure its valid if (key != null && IsKeyValid(key, type)) { //if the key is valid create a new license lic = new ProcCountLicense(this, key); } } //if we're in design mode or //a suitable license key wasn't found in //the runtime context. //attempt to look for a .LIC file if (lic == null) { //build up the path where the .LIC file //should be string modulePath = null; // try and locate the file for the assembly if (context != null) { ITypeResolutionService resolver = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService)); if (resolver != null) { modulePath = resolver.GetPathOfAssembly(type.Assembly.GetName()); } } if (modulePath == null) { modulePath = type.Module.FullyQualifiedName; } //get the path from the file location string moduleDir = Path.GetDirectoryName(modulePath); //build the path of the .LIC file string licenseFile = moduleDir + "\\" + type.FullName + ".lic"; Debug.WriteLine("Path of license file: " + licenseFile); //if the .LIC file exists, dig into it if (File.Exists(licenseFile)) { //crack the file and get the first line Stream licStream = new FileStream(licenseFile, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader sr = new StreamReader(licStream); string s = sr.ReadLine(); sr.Close(); Debug.WriteLine("Contents of license file: " + s); //check if the key is valid if (IsKeyValid(s, type)) { //valid key so create a new License lic = new ProcCountLicense(this, s); } } //if we managed to create a license, stuff it into the context if (lic != null) { context.SetSavedLicenseKey(type, lic.LicenseKey); } } } return(lic); }