Exemplo n.º 1
0
        public async Task <LicenseRegisterResult> RegisterLicenseAsync(string licenseKey)
        {
            LicensingClient client = new LicensingClient(
                LicensingClient.EndpointConfiguration.BasicHttpBinding_ILicensing,
                ServiceEndpoint)
            {
                Password     = Password,
                RsaPublicKey = RsaPublicKey,
            };

            var response = await client.RegisterLicenseAsync(
                new RegisterRequest { Hardware = hardware, Key = licenseKey, Product = Product });

            if (response.State == RegisterResponse.RegisterState.OK ||
                response.State == RegisterResponse.RegisterState.OKExisted)
            {
                LicenseInfo lic = GetStoredLicenseInfo() ??
                                  new LicenseInfo
                {
                    Counter  = this.MaxCheckPostponeCount,
                    Hardware = hardware,
                    License  = new License[] { },
                };

                var lickey = new License
                {
                    Key        = licenseKey,
                    Retired    = false,
                    Type       = 1, // dummy
                    Amount     = response.Amount,
                    IssueDate  = response.IssueDate.Value,
                    ExpireDate = response.ExpireDate.Value,
                };
                log.Debug(string.Format("RegisterLicenseAsync;IssueDate:{0},ExpireDate:{1}", response.IssueDate.Value, response.ExpireDate.Value));
                lic.License =
                    new[] { lickey }.Concat(
                    lic.License.Where(k => string.Compare(k.Key, licenseKey, StringComparison.OrdinalIgnoreCase) != 0)
                    ).ToArray();

                lic.Counter = this.MaxCheckPostponeCount;

                StoreLicenseInfo(lic);
                return(new LicenseRegisterResult
                {
                    State = response.State == RegisterResponse.RegisterState.OK ?
                            LicenseRegisterState.OK : LicenseRegisterState.AlreadyLicensed,
                    Amount = response.TotalAmount,
                    Message = response.Message,
                });
            }

            return(new LicenseRegisterResult
            {
                State =
                    response.State == RegisterResponse.RegisterState.AlreadyUsed ? LicenseRegisterState.AlreadyUsed :
                    response.State == RegisterResponse.RegisterState.Invalid ? LicenseRegisterState.InvalidKey :
                    response.State == RegisterResponse.RegisterState.Expired ? LicenseRegisterState.Expired :
                    LicenseRegisterState.StateError,
                Message = response.Message,
            });
        }
Exemplo n.º 2
0
 public bool IsExpired(DateTime check)
 {
     return(License.Where(l => !l.Retired).All(l => l.IsExpired(check)));
 }