Esempio n. 1
0
        public void AddLicense(Type objectType, ServerLicense license)
        {
            if (objectType == null)
            {
                throw new ArgumentNullException("objectType");
            }
            if (license == null)
            {
                throw new ArgumentNullException("objectType");
            }

            collectedLicenses[objectType] = license;
        }
        public override System.ComponentModel.License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            if (context.UsageMode == LicenseUsageMode.Designtime)
            {
                return(new ServerLicense(type));
            }

            ServerLicense license = LicenseCollector.GetLicense(type);

            if (license != null)
            {
                return(license);
            }

            if (HttpContext.Current != null)
            {
                if (HttpContext.Current.Request.Url.IsLoopback)
                {
                    return(new ServerLicense(type));
                }
            }

            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\.NETFramework\AssemblyFolders\ObjectServer");

            if (key == null)
            {
                throw new LicenseException(type, instance, @"Could not locate registry key Software\Microsoft\.NETFramework\AssemblyFolders\ObjectServer");
            }


            if (key.GetValue(String.Empty) == null)
            {
                throw new LicenseException(type, instance, @"Could not retrieve default value for key Software\Microsoft\.NETFramework\AssemblyFolders\ObjectServer");
            }

            string path = key.GetValue(String.Empty) + @"License.xml";

            if (!File.Exists(path))
            {
                throw new LicenseException(type, instance, "Could not locate file " + path);
            }

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(path);

            bool valid = ValidateSignature(xmldoc);

            valid = valid && ValidateLicense(xmldoc);

            if (valid)
            {
                license = new ServerLicense(type);
            }

            if (license != null)
            {
                LicenseCollector.AddLicense(type, license);
                return(license);
            }

            if (allowExceptions)
            {
                throw new LicenseException(type, instance, "Your license is invalid");
            }

            return(null);
        }