예제 #1
0
        public static bool UpdateLisence(string key)
        {
            try
            {
                var sn       = SnProvider.CalculateSN();
                var password = Encryption.MakePassword(sn, AppConfiguration.ApplicationIdentifier);
                var coreKey  = key.Replace("-", string.Empty);
                if (password.Substring(3, 22) != coreKey.Substring(3, 22))
                {
                    throw new Exception("invalid lisence key!");
                }

                var    expiredDatetime = GetExpiredDateTime(coreKey);
                string HideInfo        = string.Format("{0};{1};{2}", expiredDatetime.ToString(), coreKey, LisenceType.Full.GetHashCode());
                if (File.Exists(GetLisencePath()))
                {
                    File.Delete(GetLisencePath());
                }
                FileReadWrite.WriteFile(GetLisencePath(), HideInfo);
                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(false);
            }
        }
예제 #2
0
        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            Log.Info("Provider GetLicense...");
            try
            {
                var _HideFilePath = LisenceService.GetLisencePath();
                var readfile      = FileReadWrite.ReadFile(_HideFilePath);
                if (string.IsNullOrWhiteSpace(readfile))
                {
                    Log.Warn("No license is found.");
                    return(null);
                }

                var info = readfile.Split(';');
                return(new SimpleLicense(info[1], DateTime.Parse(info[0]), int.Parse(info[2])));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw new LicenseException(type, instance, "License is invalid");
            }
        }
예제 #3
0
        public static bool ApplyTrialLisence()
        {
            try
            {
                if (GetLicense() != null)
                {
                    throw new Exception("Already has lisence key!");
                }

                var    sn              = SnProvider.CalculateSN(softwareName);
                var    password        = "******" + sn.Substring(3, 22); // trial version..
                var    expiredDatetime = GetExpiredDateTime(password);
                string HideInfo        = string.Format("{0};{1};{2}", expiredDatetime.ToString(), password, LisenceType.Trial.GetHashCode());
                FileReadWrite.WriteFile(GetLisencePath(), HideInfo);
                return(true);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(false);
            }
        }