Пример #1
0
        protected bool ValidateLicenseKey(LicenseHandler licenseHandler, string appName)
        {
            try
            {
                //LicenseHandler licenseHandler = new LicenseHandler(licenseKey);
                if (licenseHandler == null || appName == string.Empty)
                {
                    throw new NullReferenceException("The licensehandler reference may not be null.");
                }

                return(!licenseHandler.Expired && licenseHandler.CheckAppName(appName));
            }
            catch { }

            return(false);
        }
Пример #2
0
        internal RuntimeApplicationLicense(Type type, LicenseHandler licHandler)
        {
            InitializeFields();

            if (type == null)
            {
                throw new NullReferenceException("The licensed type reference may not be null.");
            }
            _type = type;

            if (licHandler == null)
            {
                throw new NullReferenceException("The licensehandler reference may not be null.");
            }

            _clientName = licHandler.ClientName;
            _customAtts = licHandler.CustomAtts;
            _expireDate = licHandler.ExpireDate;
            _serverList = licHandler.ServerList;
            _licenses   = licHandler.Licenses;
        }
Пример #3
0
        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            ////todo: these lines are only for test purpose. delete it later
            //if (!EventLog.SourceExists("LicenseManager"))
            //    EventLog.CreateEventSource("LicenseManager", "Application");
            //EventLog eventlog = new EventLog();
            //eventlog.Source = "LicenseManager";
            //eventlog.WriteEntry("Testing!!");

            if (context.UsageMode == LicenseUsageMode.Runtime)
            {
                string licenseKey = GetLicenseKey(instance);
                string appName    = string.Empty;

                try
                {
                    // using reflection
                    //appName = instance.GetType().GetField("appName",
                    //    BindingFlags.NonPublic | BindingFlags.Instance).GetValue(instance).ToString();

                    appName = instance.ToString().Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[0];
                }
                catch
                {
                    throw new LicenseException(type);
                }

                LicenseHandler licenseHandler = new LicenseHandler(licenseKey);

                if (!ValidateLicenseKey(licenseHandler, appName))
                {
                    throw new LicenseException(type);
                }

                return(new RuntimeApplicationLicense(type, licenseHandler));
            }

            return(null);
        }