Example #1
0
        private static bool privateGetLicense(Type type, object instance, bool allowExceptions, out License license)
        {
            bool    result   = false;
            License license2 = null;
            LicenseProviderAttribute licenseProviderAttribute = (LicenseProviderAttribute)Attribute.GetCustomAttribute(type, typeof(LicenseProviderAttribute), true);

            if (licenseProviderAttribute != null)
            {
                Type licenseProvider = licenseProviderAttribute.LicenseProvider;
                if (licenseProvider != null)
                {
                    LicenseProvider licenseProvider2 = (LicenseProvider)Activator.CreateInstance(licenseProvider);
                    if (licenseProvider2 != null)
                    {
                        license2 = licenseProvider2.GetLicense(LicenseManager.CurrentContext, type, instance, allowExceptions);
                        if (license2 != null)
                        {
                            result = true;
                        }
                    }
                }
            }
            else
            {
                result = true;
            }
            license = license2;
            return(result);
        }
Example #2
0
        /// <summary>
        /// Caches the provider, both in the instance cache, and the type
        /// cache.
        /// </summary>
        private static void CacheProvider(Type type, LicenseProvider provider)
        {
            if (s_providers == null)
            {
                Interlocked.CompareExchange(ref s_providers, new Hashtable(), null);
            }

            lock (s_providers)
            {
                s_providers[type] = provider;
            }

            if (provider != null)
            {
                if (s_providerInstances == null)
                {
                    Interlocked.CompareExchange(ref s_providerInstances, new Hashtable(), null);
                }

                Type providerType = provider.GetType();
                lock (s_providerInstances)
                {
                    s_providerInstances[providerType] = provider;
                }
            }
        }
Example #3
0
        // Perform license validation for a type.
        private static License PerformValidation(Type type, Object instance)
        {
            LicenseProvider provider = GetProvider(type);

            return(provider.GetLicense
                       (CurrentContext, type, instance, false));
        }
        private static bool ValidateInternalRecursive(LicenseContext context, Type type, object instance, bool allowExceptions, out License license, out string licenseKey)
        {
            LicenseProvider cachedProvider = GetCachedProvider(type);

            if ((cachedProvider == null) && !GetCachedNoLicenseProvider(type))
            {
                LicenseProviderAttribute attribute = (LicenseProviderAttribute)Attribute.GetCustomAttribute(type, typeof(LicenseProviderAttribute), false);
                if (attribute != null)
                {
                    Type licenseProvider = attribute.LicenseProvider;
                    cachedProvider = GetCachedProviderInstance(licenseProvider);
                    if (cachedProvider == null)
                    {
                        cachedProvider = (LicenseProvider)SecurityUtils.SecureCreateInstance(licenseProvider);
                    }
                }
                CacheProvider(type, cachedProvider);
            }
            license = null;
            bool flag = true;

            licenseKey = null;
            if (cachedProvider != null)
            {
                license = cachedProvider.GetLicense(context, type, instance, allowExceptions);
                if (license == null)
                {
                    flag = false;
                }
                else
                {
                    licenseKey = license.LicenseKey;
                }
            }
            if (flag && (instance == null))
            {
                string str;
                Type   baseType = type.BaseType;
                if (!(baseType != typeof(object)) || (baseType == null))
                {
                    return(flag);
                }
                if (license != null)
                {
                    license.Dispose();
                    license = null;
                }
                flag = ValidateInternalRecursive(context, baseType, null, allowExceptions, out license, out str);
                if (license != null)
                {
                    license.Dispose();
                    license = null;
                }
            }
            return(flag);
        }
 private static void CacheProvider(Type type, LicenseProvider provider)
 {
     if (providers == null)
     {
         providers = new Hashtable();
     }
     providers[type] = provider;
     if (provider != null)
     {
         if (providerInstances == null)
         {
             providerInstances = new Hashtable();
         }
         providerInstances[provider.GetType()] = provider;
     }
 }
 private static void CacheProvider(Type type, LicenseProvider provider)
 {
     if (providers == null)
     {
         providers = new Hashtable();
     }
     providers[type] = provider;
     if (provider != null)
     {
         if (providerInstances == null)
         {
             providerInstances = new Hashtable();
         }
         providerInstances[provider.GetType()] = provider;
     }
 }
Example #7
0
        /// <include file='doc\LicenseManager.uex' path='docs/doc[@for="LicenseManager.ValidateInternalRecursive"]/*' />
        /// <devdoc>
        ///     Since we want to walk up the entire inheritance change, when not
        ///     give an instance, we need another helper method to walk up
        ///     the chain...
        /// </devdoc>
        private static bool ValidateInternalRecursive(LicenseContext context, Type type, object instance, bool allowExceptions, out License license, out string licenseKey)
        {
            LicenseProvider provider = GetCachedProvider(type);

            if (provider == null && !GetCachedNoLicenseProvider(type))
            {
                // NOTE : Must look directly at the class, we want no inheritance.
                //
                LicenseProviderAttribute attr = (LicenseProviderAttribute)Attribute.GetCustomAttribute(type, typeof(LicenseProviderAttribute), false);
                if (attr != null)
                {
                    Type providerType = attr.LicenseProvider;
                    provider = GetCachedProviderInstance(providerType);

                    if (provider == null)
                    {
                        provider = (LicenseProvider)SecurityUtils.SecureCreateInstance(providerType);
                    }
                }

                CacheProvider(type, provider);
            }

            license = null;
            bool isValid = true;

            licenseKey = null;
            if (provider != null)
            {
                license = provider.GetLicense(context, type, instance, allowExceptions);
                if (license == null)
                {
                    isValid = false;
                }
                else
                {
                    // For the case where a COM client is calling "RequestLicKey",
                    // we try to squirrel away the first found license key
                    //
                    licenseKey = license.LicenseKey;
                }
            }

            // When looking only at a type, we need to recurse up the inheritence
            // chain, however, we can't give out the license, since this may be
            // from more than one provider.
            //
            if (isValid && instance == null)
            {
                Type baseType = type.BaseType;
                if (baseType != typeof(object) && baseType != null)
                {
                    if (license != null)
                    {
                        license.Dispose();
                        license = null;
                    }
                    string temp;
                    isValid = ValidateInternalRecursive(context, baseType, null, allowExceptions, out license, out temp);
                    if (license != null)
                    {
                        license.Dispose();
                        license = null;
                    }
                }
            }

            return(isValid);
        }