/// <summary> /// Verifica se il prodotto è sbloccato da codice di sblocco. /// </summary> /// <param name="productInfo">Informazioni sul prodotto</param> /// <returns>Restituire true se il prodotto è sbloccato, false altrimenti</returns> public bool IsProductUnlocked(ProductCache productInfo) { try { if (productInfo == null) { throw new Exception("Product object is null"); } if (productInfo.Purchased) { Debug.WriteLine("Do not invoke IsProductUnlocked for purchased product [{0}]", new[] { productInfo.Id }); return(true); } if (productInfo.Unlocked && !productInfo.UnlockCodeExpire) { Debug.WriteLine("Product {0} is unlocked without expiration terms", new [] { productInfo.Id }); return(true); } if (string.IsNullOrEmpty(App.PwdManager.Password)) { return(productInfo.Unlocked); } productInfo.Unlocked = CheckUnlockCode(productInfo.Id, productInfo.UnlockCode, App.PwdManager.Password, out bool expire); productInfo.UnlockCodeExpire = expire; return(productInfo.Unlocked); } catch (Exception ex) { Debug.WriteLine("IsProductUnlocked error: " + ex.Message); return(false); } }
/// <summary> /// Legge i dati presenti in cache /// </summary> /// <returns></returns> public async Task ReadCache() { ProductsList.Clear(); try { StreamReader streamReader = new StreamReader(AppCacheFileName); string content = await streamReader.ReadToEndAsync(); streamReader.Close(); if (string.IsNullOrEmpty(content)) { await WriteCache(); return; } EncDecHelper enc = new EncDecHelper { PasswordString = Password }; string json = enc.AESDecrypt(content, out bool warning); if (warning) { Debug.WriteLine("CacheManager read: warning in file reading"); } JObject jObject = JObject.Parse(json); if (Utility.SafeTryGetJSONString(jObject, "version", out string version)) { Debug.WriteLine("CacheManager file version " + version); } if (Utility.SafeTryGetJSON(jObject, "products", out JToken productsToken)) { JArray products = productsToken.ToObject <JArray>(); foreach (JObject item in products) { ProductCache product = new ProductCache { Id = item[nameof(ProductCache.Id)].ToString(), Purchased = item[nameof(ProductCache.Purchased)].ToObject <bool>() }; // Dalla versione 1.1.0 ho il codice di sblocco della versioen PLUS if (CompareVersions(version, "1.1.0") >= 0) { product.Unlocked = item[nameof(ProductCache.Unlocked)].ToObject <bool>(); product.UnlockCode = item[nameof(ProductCache.UnlockCode)].ToObject <string>(); product.UnlockCodeExpire = item[nameof(ProductCache.UnlockCodeExpire)].ToObject <bool>(); } ProductsList.Add(product); } } } catch (FileNotFoundException) { // Ok. Genera il file await WriteCache(); } catch (Exception ex) { Debug.WriteLine("CacheManager error on read: " + ex.Message); } }