private static ILicenser _LoadLicenseComponent(out Assembly licAssembly) { licAssembly = null; ICollection <string> assemblyFiles = CommonHelpers.GetAssembliesFiles( AppDomain.CurrentDomain.BaseDirectory); string interfaceName = typeof(ILicenser).ToString(); ILicenser licenser = null; foreach (string path in assemblyFiles) { Assembly assembly = Assembly.LoadFrom(path); licenser = _LoadLicenserFromAssembly(assembly, interfaceName); if (licenser != null) { licAssembly = assembly; break; } } return(licenser); }
private static ILicenser _LoadLicenserFromAssembly(Assembly assembly, string interfaceName) { ILicenser licenser = null; try { foreach (Type type in assembly.GetTypes()) { if (type.IsPublic && !type.IsAbstract) { Type interfaceType = type.GetInterface(interfaceName); if (interfaceType != null) { try { licenser = (ILicenser)Activator.CreateInstance(type); break; } catch { } } } } } catch (Exception e) { Logger.Error(e); } return(licenser); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes licenser instance. /// </summary> /// <param name="licenseCacheStorage">The reference to the license cache /// storage object.</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="licenseCacheStorage"/> is a null reference.</exception> public static void Initialize(ILicenseCacheStorage licenseCacheStorage) { if (licenseCacheStorage == null) { throw new ArgumentNullException("licenseCacheStorage"); } // load license component Assembly licAssembly = null; ILicenser licenser = _LoadLicenseComponent(out licAssembly); if (licenser == null) { throw new LicenseException(LicenseError.LicenseComponentNotFound, Properties.Messages.Error_LicenseComponentNotFound); } // verify if assembly correctly signed _VerifySignature(licAssembly); _innerLicenser = licenser; _licenseCacheStorage = licenseCacheStorage; Licenser.LicenseExpirationChecker = new LicenseExpirationChecker( _licenseCacheStorage); }