GetLicense() public abstract method

When overridden in a derived class, gets a license for an instance or type of component.
public abstract GetLicense ( System.ComponentModel.LicenseContext context, Type type, object? instance, bool allowExceptions ) : License?
context System.ComponentModel.LicenseContext
type Type
instance object?
allowExceptions bool
return License?
Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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);
        }
        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);
        }
Ejemplo n.º 4
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);
        }