Esempio n. 1
0
        //============================================================
        // Methods
        //============================================================

        /// <summary>
        /// Ignored
        /// </summary>
        public override System.ComponentModel.License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            System.ComponentModel.License controlLicense = null;

            try
            {
                var licenseControl = instance as Control;
                if (licenseControl != null)
                {
                    if ((HttpContext.Current == null) || (AllowLocalHost && IsLocalHost()) || (AllowLocal && IsLocal()) || (IsLicensed(GetRunningServer(), GetMachineName(), ProductName, ProductVersion)))
                    {
                        controlLicense = new ValidLicense();
                    }
                }
            }
            catch (Exception)
            {
                if (allowExceptions)
                {
#if DEBUG
                    throw;
#else
                    throw new LicenseException(type, instance, Globalisation.GetString("invalidLicenseData"));
#endif
                }
            }

            return(controlLicense);
        }
Esempio n. 2
0
        private static string GetMachineName()
        {
            string machineName = null;

            if (HttpContext.Current != null)
            {
                machineName = HttpContext.Current.Server.MachineName.ToLower(Globalisation.GetCultureInfo());
            }

            return(machineName);
        }
Esempio n. 3
0
        private static string GetRunningServer()
        {
            string runningServer = null;

            if (HttpContext.Current != null)
            {
                runningServer = HttpContext.Current.Request.Url.Host.ToLower(Globalisation.GetCultureInfo());
            }

            return(runningServer);
        }
Esempio n. 4
0
        private static string[] GetElementValue(string licenseElement)
        {
            string value       = null;
            int    separatorAt = licenseElement.IndexOf(TitleValueSeparator);

            if (separatorAt > -1)
            {
                value = licenseElement.Substring(separatorAt + 1).Trim().ToLower(Globalisation.GetCultureInfo());
            }

            return(value == null ? null : value.Split(MultivalueSeparator.ToCharArray()));
        }
Esempio n. 5
0
        private static string GetElementTitle(string licenseElement)
        {
            string comment     = null;
            int    separatorAt = licenseElement.IndexOf(TitleValueSeparator);

            if (separatorAt > -1)
            {
                comment = licenseElement.Substring(0, separatorAt).Trim().ToLower(Globalisation.GetCultureInfo());
            }

            return(comment);
        }
Esempio n. 6
0
        private static bool IsStringInArray(string stringToTest, string[] arrayToTest)
        {
            bool isStringInArray = false;

            string normalised = stringToTest.ToLower(Globalisation.GetCultureInfo());

            for (int indexCounter = 0; indexCounter < arrayToTest.Length; indexCounter++)
            {
                if (Normaliser.StringCompare(arrayToTest [indexCounter], AllHosts) ||
                    Normaliser.StringCompare(arrayToTest [indexCounter], normalised) ||
                    Normaliser.StringCompare("www." + arrayToTest [indexCounter], normalised))
                {
                    isStringInArray = true;
                    break;
                }
            }

            return(isStringInArray);
        }
        //============================================================
        // Constructors
        //============================================================

        //============================================================
        // Properties
        //============================================================

        //============================================================
        // Methods
        //============================================================

        public void SetValue(string newValue)
        {
            string normalisedNewValue = newValue.ToLower(Globalisation.GetCultureInfo());

            switch (normalisedNewValue)
            {
            case "none":
                _currentValue = "none";
                _empty        = false;
                break;

            case "underline":
                _currentValue = "underline";
                _empty        = false;
                break;

            case "overline":
                _currentValue = "overline";
                _empty        = false;
                break;

            case "linethrough":
            case "line-through":
                _currentValue = "line-through";
                _empty        = false;
                break;

            case "blink":
                _currentValue = "blink";
                _empty        = false;
                break;

            default:
                _currentValue = "";
                _empty        = true;
                break;
            }

            return;
        }
Esempio n. 8
0
        private void Decode(string license)
        {
            if (!String.IsNullOrEmpty(license))
            {
                string dataPart = license.Substring(0, license.IndexOf(DataSignatureSeparator));

                byte[]   data        = Convert.FromBase64String(dataPart);
                var      utf8        = new UTF8Encoding();
                string   dataString  = utf8.GetString(data);
                string[] licenseData = dataString.Split(FieldSeparator.ToCharArray());

                string elementTitle;
                foreach (string element in licenseData)
                {
                    elementTitle = GetElementTitle(element);
                    string[] elementValue = GetElementValue(element);
                    if (!String.IsNullOrEmpty(elementTitle))
                    {
                        string elementTitleNormalised = elementTitle.Trim().ToLower(Globalisation.GetCultureInfo());

                        switch (elementTitleNormalised)
                        {
                        case "product":
                            _products = elementValue;
                            break;

                        case "version":
                            _versions = elementValue;
                            break;

                        case "hosts":
                            _hosts = elementValue;
                            break;

                        case "servers":
                            _servers = elementValue;
                            break;

                        case "types":
                            _licenseTypes = elementValue;
                            break;

                        case "ids":
                        case "vendors":
                        case "purchasers":
                            break;
                            //case "ids":
                            //    _ids = aszElementValue;
                            //    break;

                            //case "vendors":
                            //    _vendors = aszElementValue;
                            //    break;

                            //case "purchasers":
                            //    _purchasers = aszElementValue;
                            //    break;
                        }
                    }
                }
            }

            return;
        }