/// <summary> /// <para>Gets a license for the instance of the component and determines if it is valid.</para> /// </summary> public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { LicFileLicense lic = null; Debug.Assert(context != null, "No context provided!"); if (context != null) { if (context.UsageMode == LicenseUsageMode.Runtime) { string key = context.GetSavedLicenseKey(type, null); if (key != null && IsKeyValid(key, type)) { lic = new LicFileLicense(this, key); } } if (lic == null) { string modulePath = null; 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; } string moduleDir = Path.GetDirectoryName(modulePath); string licenseFile = moduleDir + "\\" + type.FullName + ".lic"; Debug.WriteLine($"Looking for license in: {licenseFile}"); if (File.Exists(licenseFile)) { Stream licStream = new FileStream(licenseFile, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader sr = new StreamReader(licStream); string s = sr.ReadLine(); sr.Close(); if (IsKeyValid(s, type)) { lic = new LicFileLicense(this, GetKey(type)); } } if (lic != null) { context.SetSavedLicenseKey(type, lic.LicenseKey); } } } return(lic); }
/// <summary> /// <para>Gets a license for the instance of the component and determines if it is valid.</para> /// </summary> public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { LicFileLicense lic = null; Debug.Assert(context != null, "No context provided!"); if (context != null) { if (context.UsageMode == LicenseUsageMode.Runtime) { string key = context.GetSavedLicenseKey(type, null); if (key != null && IsKeyValid(key, type)) { lic = new LicFileLicense(this, key); } } if (lic == null) { string modulePath = null; 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; } string moduleDir = Path.GetDirectoryName(modulePath); string licenseFile = moduleDir + "\\" + type.FullName + ".lic"; Debug.WriteLine($"Looking for license in: {licenseFile}"); if (File.Exists(licenseFile)) { Stream licStream = new FileStream(licenseFile, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader sr = new StreamReader(licStream); string s = sr.ReadLine(); sr.Close(); if (IsKeyValid(s, type)) { lic = new LicFileLicense(this, GetKey(type)); } } if (lic != null) { context.SetSavedLicenseKey(type, lic.LicenseKey); } } } return lic; }
// The CLR invokes this when instantiating an unmanaged COM // object. The purpose is to decide which IClassFactory method to // use. public static LicenseContext GetCurrentContextInfo(Type type, out bool isDesignTime, out string key) { LicenseContext licContext = LicenseManager.CurrentContext; isDesignTime = licContext.UsageMode == LicenseUsageMode.Designtime; key = null; if (!isDesignTime) { key = licContext.GetSavedLicenseKey(type, resourceAssembly: null); } return(licContext); }
public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { LicFileLicense license = null; if (context != null) { if (context.UsageMode == LicenseUsageMode.Runtime) { string savedLicenseKey = context.GetSavedLicenseKey(type, null); if ((savedLicenseKey != null) && this.IsKeyValid(savedLicenseKey, type)) { license = new LicFileLicense(this, savedLicenseKey); } } if (license != null) { return(license); } string path = null; if (context != null) { ITypeResolutionService service = (ITypeResolutionService)context.GetService(typeof(ITypeResolutionService)); if (service != null) { path = service.GetPathOfAssembly(type.Assembly.GetName()); } } if (path == null) { path = type.Module.FullyQualifiedName; } string str4 = Path.GetDirectoryName(path) + @"\" + type.FullName + ".lic"; if (File.Exists(str4)) { Stream stream = new FileStream(str4, FileMode.Open, FileAccess.Read, FileShare.Read); StreamReader reader = new StreamReader(stream); string key = reader.ReadLine(); reader.Close(); if (this.IsKeyValid(key, type)) { license = new LicFileLicense(this, this.GetKey(type)); } } if (license != null) { context.SetSavedLicenseKey(type, license.LicenseKey); } } return(license); }
// The CLR invokes this when instantiating an unmanaged COM // object. The purpose is to decide which classfactory method to // use. // // If the current context is design time, the CLR will // use ICF::CreateInstance(). // // If the current context is runtime and the current context // exposes a non-null license key and the COM object supports // IClassFactory2, the CLR will use ICF2::CreateInstanceLic(). // Otherwise, the CLR will use ICF::CreateInstance. // // Arguments: // ref int fDesignTime: on exit, this will be set to indicate // the nature of the current license context. // ref int bstrKey: on exit, this will point to the // licensekey saved inside the license context. // (only if the license context is runtime) // RuntimeTypeHandle rth: the managed type of the wrapper private void GetCurrentContextInfo(ref int fDesignTime, ref IntPtr bstrKey, RuntimeTypeHandle rth) { _savedLicenseContext = LicenseManager.CurrentContext; _savedType = Type.GetTypeFromHandle(rth); if (_savedLicenseContext.UsageMode == LicenseUsageMode.Designtime) { fDesignTime = 1; bstrKey = (IntPtr)0; } else { fDesignTime = 0; String key = _savedLicenseContext.GetSavedLicenseKey(_savedType, null); bstrKey = Marshal.StringToBSTR(key); } }
// Get the license for a type. public override License GetLicense (LicenseContext context, Type type, object instance, bool allowExceptions) { String key, path; StreamReader reader; // Bail out if we don't have a license context. if(context == null) { return null; } // Use the saved key if we saw this type previously. if(context.UsageMode == LicenseUsageMode.Runtime) { key = context.GetSavedLicenseKey(type, null); if(key != null && IsKeyValid(key, type)) { return new FileLicense(key); } } // Find the pathname of the assembly containing the type. #if CONFIG_COMPONENT_MODEL_DESIGN ITypeResolutionService trs; trs = (ITypeResolutionService) context.GetService(typeof(ITypeResolutionService)); if(trs != null) { path = trs.GetPathOfAssembly(type.Assembly.GetName()); if(path == null) { path = type.Assembly.Location; } } else #endif { path = type.Assembly.Location; } // Look for a "*.lic" file for the type. path = Path.Combine(Path.GetDirectoryName(path), type.FullName + ".lic"); try { reader = new StreamReader(path); } catch(Exception) { // Could not open the file, so assume unlicensed. return null; } // Read the key from the first line of the license file. key = reader.ReadLine(); reader.Close(); // Bail out if the key is invalid. if(key == null || !IsKeyValid(key, type)) { return null; } // Cache the key within the context. context.SetSavedLicenseKey(type, key); // Return a new file license to the caller. return new FileLicense(key); }
/// <summary> /// Return the license key for the given context and type /// </summary> /// <remarks> /// This can be overridden to change where the license key is stored by the provider. For /// instance a derived class could override this method to store the key in the Registry. /// </remarks> /// <param name="context">The license context</param> /// <param name="type">The type to get the key for</param> /// <returns>The license key</returns> protected virtual string GetLicenseKey(LicenseContext context, Type type) { string key = null; if (context.UsageMode == LicenseUsageMode.Runtime) { key = context.GetSavedLicenseKey(type, null); } // Try and loaded license from registry if (key == null) { key = ReadKeyFromRegistry(); } // if we're in design mode or a suitable license key wasn't found in // the runtime context look for a .LIC file // if (key == null) { key = ReadKeyFromFile(GetLicenseFilePath(context, type)); } return key; }
// Get the license for a type. public override License GetLicense (LicenseContext context, Type type, object instance, bool allowExceptions) { String key, path; StreamReader reader; // Bail out if we don't have a license context. if (context == null) { return(null); } // Use the saved key if we saw this type previously. if (context.UsageMode == LicenseUsageMode.Runtime) { key = context.GetSavedLicenseKey(type, null); if (key != null && IsKeyValid(key, type)) { return(new FileLicense(key)); } } // Find the pathname of the assembly containing the type. #if CONFIG_COMPONENT_MODEL_DESIGN ITypeResolutionService trs; trs = (ITypeResolutionService) context.GetService(typeof(ITypeResolutionService)); if (trs != null) { path = trs.GetPathOfAssembly(type.Assembly.GetName()); if (path == null) { path = type.Assembly.Location; } } else #endif { path = type.Assembly.Location; } // Look for a "*.lic" file for the type. path = Path.Combine(Path.GetDirectoryName(path), type.FullName + ".lic"); try { reader = new StreamReader(path); } catch (Exception) { // Could not open the file, so assume unlicensed. return(null); } // Read the key from the first line of the license file. key = reader.ReadLine(); reader.Close(); // Bail out if the key is invalid. if (key == null || !IsKeyValid(key, type)) { return(null); } // Cache the key within the context. context.SetSavedLicenseKey(type, key); // Return a new file license to the caller. return(new FileLicense(key)); }
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; }
/// <summary> /// Return the license key for the given context and type /// </summary> /// <remarks> /// This can be overridden to change where the license key is stored by the provider. For /// instance a derived class could override this method to store the key in the Registry. /// </remarks> /// <param name="context">The license context</param> /// <param name="type">The type to get the key for</param> /// <returns>The license key</returns> protected virtual string GetLicenseKey(LicenseContext context, Type type) { string key = null; if (context.UsageMode == LicenseUsageMode.Runtime) { try { key = context.GetSavedLicenseKey(type, null); } catch { // if something goes wrong retrieving the saved license key then just ignore it // and try reading from file } } // if we're in design mode or a suitable license key wasn't found in // the runtime context look for a .LIC file // if (key == null) { key = ReadKeyFromFile(GetLicenseFilePath(context, type)); } return key; }
public override License GetLicense(LicenseContext context,Type type,object instance,bool allowExceptions) { DevCoLicense lic = null; Debug.Assert(context!=null, "No context provided!"); #if !TRIAL //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 && IsKeyValid2(key, type)) { //if the key is valid create a new license lic = new DevCoLicense(key); } else { try { System.Reflection.Assembly[] assemblies=System.AppDomain.CurrentDomain.GetAssemblies(); foreach(System.Reflection.Assembly a in assemblies) { string codeBase = a.CodeBase; codeBase = codeBase.Substring(codeBase.LastIndexOf("/") + 1)+".licenses"; System.IO.Stream stream=this.GetManifestResourceStream(a,codeBase); if(stream==null) codeBase=codeBase.Replace(".DLL.",".dll."); stream=this.GetManifestResourceStream(a,codeBase); if(stream!=null) { key=DeserializeLicenseKey(stream); if (key != null && key!="") //IsKeyValid2(key, type)) { lic = new DevCoLicense(key); break; } } } } catch { lic=new DevCoLicense(""); } } } else { string sKey=""; Microsoft.Win32.RegistryKey regkey=Microsoft.Win32.Registry.LocalMachine; regkey=regkey.OpenSubKey("Software\\DevComponents\\Licenses",false); if(regkey!=null) { sKey=regkey.GetValue("DevComponents.DotNetBar.DotNetBarManager2").ToString(); } //check if the key is valid if (IsKeyValid(sKey, type)) { //valid key so create a new License lic = new DevCoLicense(Key(type)); } //if we managed to create a license, stuff it into the context if (lic != null) { context.SetSavedLicenseKey(type, lic.LicenseKey); } } } #else if (context != null) { lic=new DevCoLicense(""); //if this control is in runtime mode if (context.UsageMode == LicenseUsageMode.Runtime) { RemindForm frm=new RemindForm(); frm.ShowDialog(); } else { context.SetSavedLicenseKey(type, lic.LicenseKey); } } #endif if(lic==null && context!=null) { RemindForm frm=new RemindForm(); frm.ShowDialog(); lic=new DevCoLicense(""); } return lic; }