private void OnlineRequest_Finished(string responce) { _appLicenseJwt = JsonConvert.DeserializeObject <AppLicenseJwt>(responce); var payload = JwtUtilities.GetPayload(_appLicenseJwt.Token); _appLicense = CreateAndSaveLicenses(payload); }
/// <summary> /// License check finished, check response and either load locally or validate. /// </summary> /// <param name="request">The http request.</param> /// <param name="response">The http response for the request.</param> private void OnlineRequest_Finished(WebRequest /*HTTPRequest*/ request, WebResponse /*HTTPResponse*/ response) { var res = (HttpWebResponse)response; try { if (res.StatusCode == HttpStatusCode.GatewayTimeout || response == null) //if (request.State == HTTPRequestStates.ConnectionTimedOut || response == null) { //Debug.LogWarning("LicenseManager: No response."); //_errorMessage = string.Format(TimeOutMessage, response?.StatusCode); _errorMessage = string.Format(TimeOutMessage, res?.StatusCode); } else { if (res.StatusCode != HttpStatusCode.OK) //if (response.StatusCode != ValidResponseCode) { //Debug.LogWarning("LicenseManager: Invalid status code returned - " + response.StatusCode); //_errorMessage = string.Format(InvalidResponseMessage, response?.StatusCode); _errorMessage = string.Format(InvalidResponseMessage, res?.StatusCode); } else { //_appLicenseJwt = JsonConvert.DeserializeObject<AppLicenseJwt>(response.DataAsText); var stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); string data = reader.ReadToEnd(); _appLicenseJwt = JsonConvert.DeserializeObject <AppLicenseJwt>(data); var payload = JwtUtilities.GetPayload(_appLicenseJwt.Token); _appLicense = CreateAndSaveLicenses(payload); } } } catch (Exception e) { //Debug.LogWarning("Exception while processing license response: " + e); _errorMessage = string.Format(InvalidResponseMessage, "error while processing response"); } var validLicense = CheckLocalLicense(); }
/// <summary> /// Tries to deserialize the license from local storage and to convert it from jwt. /// </summary> private void LoadLocalLicense() { _licenseFileUri = Path.Combine(PathHelper.GetApplicationWorkingDirectory(), FileName); if (!File.Exists(_licenseFileUri /*.OriginalUri*/)) { return; } using (var stream = new FileStream(_licenseFileUri, FileMode.OpenOrCreate) /*_resourceManager.GetStream(_licenseFileUri)*/) { if (stream != null) { var reader = new StreamReader(stream); var localFileText = reader.ReadToEnd(); _appLicenseJwt = JsonConvert.DeserializeObject <AppLicenseJwt>(localFileText); var payload = JwtUtilities.GetPayload(_appLicenseJwt.Token); _appLicense = JsonConvert.DeserializeObject <AppLicense>(payload); } } }