private static ValidateKeyResult GetValidateResult(string serverResponce) { try { ValidateKeyResult result = new ValidateKeyResult(); result.IsValid = false; XDocument xmlResponce = XDocument.Parse(serverResponce); XElement rootElement = xmlResponce.Root; if (rootElement.Name != "response") { return(result); } XElement serialElement = rootElement.Element("serial"); if (serialElement.Attribute("status").Value == "accepted") { result.IsValid = true; } else { return(result); } XAttribute validUntilAttribute = serialElement.Attribute("valid_until"); if (validUntilAttribute != null) { result.IsTemporary = true; result.ValidUntil = DateTime.Parse(validUntilAttribute.Value); } else { result.IsTemporary = false; } return(result); } catch (Exception ex) { Debug.WriteLine(ex.Message); ValidateKeyResult invalidResult = new ValidateKeyResult(); invalidResult.IsValid = false; return(invalidResult); } }
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); }