ValidateInternalRecursive() private static method

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...
private static ValidateInternalRecursive ( System.ComponentModel.LicenseContext context, Type type, object instance, bool allowExceptions, System.ComponentModel.License &license, string &licenseKey ) : bool
context System.ComponentModel.LicenseContext
type Type
instance object
allowExceptions bool
license System.ComponentModel.License
licenseKey string
return bool
Beispiel #1
0
            // The CLR invokes this whenever a COM client invokes
            // IClassFactory2::GetLicInfo on a managed class.
            //
            // COM normally doesn't expect this function to fail so this method
            // should only throw in the case of a catastrophic error (stack, memory, etc.)
            private void GetLicInfo(RuntimeTypeHandle rth, ref int pRuntimeKeyAvail, ref int pLicVerified)
            {
                pRuntimeKeyAvail = 0;
                pLicVerified     = 0;

                Type    type = Type.GetTypeFromHandle(rth);
                License license;
                string  licenseKey;

                if (helperContext == null)
                {
                    helperContext = new DesigntimeLicenseContext();
                }
                else
                {
                    helperContext.savedLicenseKeys.Clear();
                }

                if (LicenseManager.ValidateInternalRecursive(helperContext, type, null, false, out license, out licenseKey))
                {
                    if (helperContext.savedLicenseKeys.Contains(type.AssemblyQualifiedName))
                    {
                        pRuntimeKeyAvail = 1;
                    }

                    if (license != null)
                    {
                        license.Dispose();
                        license = null;

                        pLicVerified = 1;
                    }
                }
            }
            // The CLR invokes this whenever a COM client invokes
            // IClassFactory2::RequestLicKey on a managed class.
            //
            // This method should return the appropriate HRESULT and set pbstrKey
            // to the licensing key.
            private static int RequestLicKey(RuntimeTypeHandle rth, ref IntPtr pbstrKey)
            {
                Type    type = Type.GetTypeFromHandle(rth);
                License license;
                string  licenseKey;

                // license will be null, since we passed no instance,
                // however we can still retrieve the "first" license
                // key from the file. This really will only
                // work for simple COM-compatible license providers
                // like LicFileLicenseProvider that don't require the
                // instance to grant a key.
                //
                if (!LicenseManager.ValidateInternalRecursive(LicenseManager.CurrentContext,
                                                              type,
                                                              null,
                                                              false,
                                                              out license,
                                                              out licenseKey))
                {
                    return(E_FAIL);
                }
                if (licenseKey == null)
                {
                    return(E_FAIL);
                }
                pbstrKey = Marshal.StringToBSTR(licenseKey);
                if (license != null)
                {
                    license.Dispose();
                    license = null;
                }
                return(S_OK);
            }
Beispiel #3
0
            // Used to validate a type and retrieve license details
            // when activating a managed COM server from an IClassFactory2 instance.
            public static bool ValidateAndRetrieveLicenseDetails(
                LicenseContext context,
                Type type,
                out License?license,
                out string?licenseKey)
            {
                context ??= LicenseManager.CurrentContext;

                return(LicenseManager.ValidateInternalRecursive(
                           context,
                           type,
                           instance: null,
                           allowExceptions: false,
                           out license,
                           out licenseKey));
            }
            private static int RequestLicKey(RuntimeTypeHandle rth, ref IntPtr pbstrKey)
            {
                License license;
                string  str;
                Type    typeFromHandle = Type.GetTypeFromHandle(rth);

                if (!LicenseManager.ValidateInternalRecursive(LicenseManager.CurrentContext, typeFromHandle, null, false, out license, out str))
                {
                    return(-2147483640);
                }
                if (str == null)
                {
                    return(-2147483640);
                }
                pbstrKey = Marshal.StringToBSTR(str);
                if (license != null)
                {
                    license.Dispose();
                    license = null;
                }
                return(0);
            }