/// <summary> /// Dispose of resources /// </summary> public void Dispose() { if (_License != null) { _License.Dispose(); _License = null; } }
private const int CHECKKEYSRANDOMMAX = 50; //To randomly check keys on velodoc.com. The higher, the less often it is checked /// <summary> /// Gets the license from wherever it is stored /// </summary> /// <param name="context"></param> /// <param name="type"></param> /// <param name="instance"></param> /// <param name="allowExceptions"></param> /// <returns></returns> public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions) { const string CACHEDLIC = "VelodocLicense"; //Try to get the VelodocLicense from the http cache VelodocLicense objLicenseRet = HttpRuntime.Cache[CACHEDLIC] as VelodocLicense; //No need to check for context.UsageMode because users get at least a GPL License if (objLicenseRet == null) { string sLicenseKey; string sActivationKey; RegistryKey objRegistryKey = null; try { //All instances on the same machine share the same license key: should not be an issue. //Should match keys and names in WebInstaller. objRegistryKey = Registry.LocalMachine.OpenSubKey(APPROOTKEY); sLicenseKey = (string)objRegistryKey.GetValue(LICENSEKEY); sActivationKey = (string)objRegistryKey.GetValue(ACTIVATIONKEY); //Validate the license key (the following lines will raise an exception //if the license key is not a Guid) Guid gLicenseKey = new Guid(sLicenseKey); Guid gActivationKey = new Guid(sActivationKey); } catch { //Should anything occur, user at least gets a GPL license sLicenseKey = null; sActivationKey = null; } finally { if (objRegistryKey != null) { objRegistryKey.Close(); } } //Randomly check the activation key if (!String.IsNullOrEmpty(sLicenseKey)) { Random objRandom = new Random(); if (objRandom.Next(0, CHECKKEYSRANDOMMAX).Equals(0)) { LicensingServiceClient objLicensingServiceClient = null; try { //Then configure the service BasicHttpBinding objHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None); objHttpBinding.ProxyAddress = null; objHttpBinding.UseDefaultWebProxy = true; EndpointAddress objRemoteAddress = new EndpointAddress(LICENSINGSVC); //Finally call the service objLicensingServiceClient = new LicensingServiceClient(objHttpBinding, objRemoteAddress); int iResult = objLicensingServiceClient.Check(sLicenseKey, sActivationKey); if (iResult == 1) //Activation not found { this.Clear(); sLicenseKey = null; sActivationKey = null; } } catch { //If there is an exception (for example if there is no Internet connection), //do nothing. Note that our servers may also not be available for any reason. } finally { if (objLicensingServiceClient != null) { objLicensingServiceClient.Dispose(); //We can call Dispose thanks to LicensingServiceFix objLicensingServiceClient = null; } } } } //Create Velodoc License and add to cache objLicenseRet = new VelodocLicense(sLicenseKey, sActivationKey); HttpRuntime.Cache.Add( CACHEDLIC, objLicenseRet, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, Constants.SlidingExpiration, 0), CacheItemPriority.Default, null); } return(objLicenseRet); }
/// <summary> /// Constructor /// </summary> public UploadHttpModule() { _License = (Licensing.VelodocLicense)LicenseManager.Validate(typeof(UploadHttpModule), this); }