private bool IsKeyExpired(SerialCodeResponse response) { if (response.IsTemporary && response.ValidUntil < DateTime.UtcNow) { return(true); } return(false); }
public async Task <bool> EnterCode(string key) { _locker.WaitOne(); if (!_fileDownloader.CheckInternetConnection()) { await _userInteraction.InformationMessage( _resourcesProvider.GetResource("NoInternetConnectionMessage")); return(false); } SerialCodeResponse response = await SerialCodeHandler.HandleCode(key); if (response.IsValid && !IsKeyExpired(response) && !string.IsNullOrEmpty(response.BaseId)) { Product product = GetProductByBaseId(response.BaseId); if (product != null) { if (!response.IsTemporary) { _productsDatabase.AddProduct(product.Id); string message = string.Format("{0}\n{1}", _resourcesProvider.GetResource("EnterCodeOk"), product.Name); await _userInteraction.InformationMessage(message); } else { _productsDatabase.AddProduct(product.Id, response.ValidUntil); string expiryDate = response.ValidUntil.ToString("dd MMMM yyyy"); string message = string.Format(_resourcesProvider.GetResource("EnterTempCodeOk"), expiryDate); await _userInteraction.InformationMessage(string.Format("{0}\n\n{1}", message, product.Name)); } Common.Delegate.Call(ProductPurchased, product.Id); } } else { await _userInteraction.ErrorMessage(_resourcesProvider.GetResource("EnterCodeError")); } return(response.IsValid); }
public static async Task <SerialCodeResponse> HandleCode(string rawKey) { SerialCodeResponse response = new SerialCodeResponse(); response.IsValid = false; response.BaseId = string.Empty; if (string.IsNullOrEmpty(rawKey)) { return(response); } string key = FormatKey(rawKey); if (string.IsNullOrEmpty(key)) { return(response); } if (!ValidatePlatform(key)) { return(response); } ValidateKeyResult validateResult = await ValidateCode(key); if (!validateResult.IsValid) { return(response); } response.IsValid = true; response.IsTemporary = validateResult.IsTemporary; response.ValidUntil = validateResult.ValidUntil; response.BaseId = GetBaseId(key); return(response); }