private string GetSavedLicenseKey(LicenseContext context, System.Type type) { string savedLicenseKey1 = context.GetSavedLicenseKey(type, (Assembly)null); int num; if ((num & 0) == 0) { goto label_7; } label_1: int index; ++index; label_2: Assembly[] assemblies; if (index >= assemblies.Length) { return((string)null); } Assembly resourceAssembly = assemblies[index]; if (!(resourceAssembly is AssemblyBuilder)) { string savedLicenseKey2 = context.GetSavedLicenseKey(type, resourceAssembly); if (savedLicenseKey2 != null) { return(savedLicenseKey2); } goto label_1; } else { goto label_1; } label_7: if (savedLicenseKey1 != null) { return(savedLicenseKey1); } assemblies = AppDomain.CurrentDomain.GetAssemblies(); index = 0; if (false) { goto label_2; } else { goto label_2; } }
public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { switch (context.UsageMode) { case LicenseUsageMode.Runtime: { System.Diagnostics.Trace.TraceWarning("在运行时执行License检查"); } break; case LicenseUsageMode.Designtime: { System.Diagnostics.Trace.TraceWarning("在设计时或编译时执行License检查"); } break; default: break; } var savedKey = context.GetSavedLicenseKey(type, null); System.Diagnostics.Trace.TraceWarning("LicenseSavedKey::" + savedKey); if (string.IsNullOrEmpty(savedKey)) { var key = "MyKey"; context.SetSavedLicenseKey(type, key); savedKey = key; } return(new MyLicense(savedKey)); }
public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { MyLicense license = null; string cpuid = GetCpuID(); cpuid = DESLicense.Encrypt(cpuid);//加密 if (context != null) { if (context.UsageMode == LicenseUsageMode.Runtime) { String savedLicenseKey = context.GetSavedLicenseKey(type, null); if (cpuid.Equals(savedLicenseKey)) { return(new MyLicense(this, cpuid)); } } if (license != null) { return(license); } // 打开License文件 'MyLicense.dat' if (Validation(cpuid)) { license = new MyLicense(this, cpuid); } if (license != null) { context.SetSavedLicenseKey(type, cpuid); } } if (license == null) { //System.Windows.Forms.MessageBox.Show("!!!尚未注册!!!"); throw new LicenseException(type, instance, "Your license is invalid");; //return new MyLicense(this,"no"); } return(license); }
public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { // Step 1: locate the license key string licenseKey = null; switch (context.UsageMode) { case LicenseUsageMode.Designtime: licenseKey = GetDesignTimeLicenseKey(type); context.SetSavedLicenseKey(type, licenseKey); break; case LicenseUsageMode.Runtime: licenseKey = context.GetSavedLicenseKey(type, null); break; } if (licenseKey == null) { if (allowExceptions) { throw new LicenseException(type, instance, "No appropriate license key was located."); } else { return(null); } } // Step 2: validate the license key bool isValid = IsLicenseKeyValid(type, licenseKey); if (!isValid) { if (allowExceptions) { throw new LicenseException(type, instance, "License key is not valid."); } else { return(null); } } // Step 3: grant a license License license = CreateLicense(type, licenseKey); if (license == null) { if (allowExceptions) { throw new LicenseException(type, instance, "license could not be created."); } else { return(null); } } return(license); }
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 void GetSavedLicenseKey_Invoke_ReturnsNull() { var context = new LicenseContext(); Assert.Null(context.GetSavedLicenseKey(null, null)); }
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 override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { int num2; string[] textArray1; string text1 = "\nEnvironment info:\n"; text1 = text1 + "version: " + DiagramView.VersionName + "\n"; if (Assembly.GetEntryAssembly() != null) { text1 = text1 + "entry: "; try { text1 = text1 + Assembly.GetEntryAssembly().FullName; } catch (SecurityException) { text1 = text1 + "?fn?"; } object obj1 = null; try { obj1 = Assembly.GetEntryAssembly().EntryPoint; } catch (SecurityException) { text1 = text1 + "?ep?"; } if (obj1 != null) { text1 = text1 + ", has entry point\n"; } else { text1 = text1 + ", no entry point\n"; } } else { text1 = text1 + "null entry\n"; } int num1 = 0; string text2 = ""; try { try { text2 = context.GetSavedLicenseKey(type, null); } catch (SecurityException exception1) { text2 = null; text1 = text1 + "\n" + exception1.ToString(); } if (text2 != null) { text1 = text1 + "key: " + text2 + "\n"; } else { text1 = text1 + "null key\n"; } if ((text2 != null) && (text2.Length != 0)) { goto Label_01AF; } try { Assembly[] assemblyArray1 = AppDomain.CurrentDomain.GetAssemblies(); Assembly[] assemblyArray2 = assemblyArray1; for (num2 = 0; num2 < assemblyArray2.Length; num2++) { Assembly assembly1 = assemblyArray2[num2]; text1 = text1 + assembly1.FullName + "\n"; try { text2 = context.GetSavedLicenseKey(type, assembly1); } catch (SecurityException) { text2 = null; } if ((text2 != null) && (text2.Length > 0)) { goto Label_015A; } } } catch (SecurityException) { } Label_015A: text1 = text1 + DiagramView.myVersionName + "\n"; if (DiagramView.myVersionAssembly != null) { text1 = text1 + DiagramView.myVersionAssembly.GetName().Name + "\n"; } else { text1 = text1 + "null licensed assembly\n"; } if (DiagramView.myVersionName.Length > 0x18) { text2 = DiagramView.myVersionName; } Label_01AF: if ((text2 != null) && (text2.Length > 0)) { num1 = this.Dispose(text2, true); if (num1 == 4) { return(new DiagramViewLicense(text2, num1)); } } else { text2 = ""; RegistryKey key1 = null; try { key1 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Northwoods Software\Go.NET"); } catch (SecurityException exception2) { text1 = text1 + "\n" + exception2.ToString(); } if (key1 == null) { try { key1 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Northwoods Software\GoDiagram"); } catch (SecurityException) { } } if (key1 != null) { string text3 = type.Assembly.GetName().Name; object obj2 = null; try { obj2 = key1.GetValue(text3); } catch (SecurityException) { } if ((obj2 != null) && (obj2 is byte[])) { text2 = Convert.ToBase64String((byte[])obj2); } } num1 = this.Dispose(text2, false); if ((num1 == 0) && (key1 != null)) { text2 = ""; string text4 = type.Assembly.GetName().Name + " eval"; object obj3 = null; try { obj3 = key1.GetValue(text4); } catch (SecurityException) { } if ((obj3 != null) && (obj3 is byte[])) { text2 = Convert.ToBase64String((byte[])obj3); } num1 = this.Dispose(text2, false); } if ((num1 >= 4) && (context.UsageMode == LicenseUsageMode.Designtime)) { context.SetSavedLicenseKey(type, text2); } if ((num1 == 4) || (context.UsageMode == LicenseUsageMode.Designtime)) { return(new DiagramViewLicense(text2, num1)); } } } catch (Exception exception3) { text1 = text1 + "\n" + exception3.ToString(); } num2 = num1 & 3; switch (num2) { case 1: { string text7 = (num1 > 4) ? "beta" : "evaluation"; textArray1 = new string[0x10] { "Built using ", DiagramViewLicenseProvider.GONAME, " for .NET Windows Forms ", this.StringFloat(DiagramView.Version), Environment.NewLine, "Copyright \x00a9 Northwoods Software, 1998-2004. All Rights Reserved.", Environment.NewLine, "This ", text7, " copy of ", DiagramViewLicenseProvider.GONAME, " is about to expire.", Environment.NewLine, Environment.NewLine, "DO NOT DISTRIBUTE OR DEPLOY THIS SOFTWARE.", Environment.NewLine }; string text8 = string.Concat(textArray1); if (num1 < 4) { text8 = text8 + Environment.NewLine + "Please purchase a license at www.nwoods.com" + Environment.NewLine; } if (SystemInformation.UserInteractive) { MessageBox.Show(text8, type.Name + " License Check", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { Console.WriteLine(type.Name + " License Check"); Console.WriteLine(text8); } return(new DiagramViewLicense(text8, num1)); } case 2: { string text5 = (num1 > 4) ? "beta" : "evaluation"; textArray1 = new string[14] { "Built using ", DiagramViewLicenseProvider.GONAME, " for .NET Windows Forms ", this.StringFloat(DiagramView.Version), Environment.NewLine, "Copyright \x00a9 Northwoods Software, 1998-2004. All Rights Reserved.", Environment.NewLine, "This software is licensed for a limited ", text5, " period.", Environment.NewLine, Environment.NewLine, "DO NOT DISTRIBUTE OR DEPLOY THIS SOFTWARE.", Environment.NewLine }; string text6 = string.Concat(textArray1); if (num1 < 4) { text6 = text6 + Environment.NewLine + "Please purchase a license at www.nwoods.com" + Environment.NewLine; } if (SystemInformation.UserInteractive) { if (!DiagramViewLicenseProvider.err) { DiagramViewLicenseProvider.err = true; MessageBox.Show(text6, type.Name + " License Check", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { Console.WriteLine(type.Name + " License Check"); Console.WriteLine(text6); } return(new DiagramViewLicense(text6, num1)); } } textArray1 = new string[0x1c] { "Built using ", DiagramViewLicenseProvider.GONAME, " for .NET Windows Forms ", this.StringFloat(DiagramView.Version), Environment.NewLine, "Copyright \x00a9 Northwoods Software, 1998-2004. All Rights Reserved.", Environment.NewLine, "The license for this copy of ", DiagramViewLicenseProvider.GONAME, " is invalid or has expired.", Environment.NewLine, Environment.NewLine, "Please purchase a license at www.nwoods.com", Environment.NewLine, "If you have already purchased a ", DiagramViewLicenseProvider.GONAME, " development license,", Environment.NewLine, " have you requested an Unlock Code for your development machine by running the GoDiagram LicenseManager?", Environment.NewLine, "If you have already entered an Unlock Code in the LicenseManager,", Environment.NewLine, " did you link license objects into your application via the Microsoft license compiler?", Environment.NewLine, " (Make sure the needed components and correct VERSION are listed in the LICENSES.LICX file,", Environment.NewLine, " and that the LICENSES.LICX file is part of your EXECUTABLE's project, not in a DLL.)", Environment.NewLine }; string text9 = string.Concat(textArray1); text9 = text9 + text1; if (SystemInformation.UserInteractive) { MessageBox.Show(text9, type.Name + " License Check", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { Console.WriteLine(type.Name + " License Check"); Console.WriteLine(text9); } if (allowExceptions) { throw new LicenseException(type, instance, text9); } return(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); }