private static async Task <IParseInfo> ParseJson(Uri location, string appId) { try { // Get json object var doc = await GetInfoDoc(location.AbsoluteUri); ParseInfoObject parseInfo = null; await Task.Run(() => { var updateJson = JsonConvert.DeserializeObject <RootObject>(doc); var appUpdate = updateJson.eUpdate.update.FirstOrDefault(x => x.appID == appId); if (appUpdate == null) { return; } // Parse data // If Version is null, then we can't compare assembly versions for update var versionString = appUpdate.version; if (string.IsNullOrWhiteSpace(versionString)) { return; } var version = Version.Parse(versionString); var fileList = new List <IParsedFile>(); foreach (var file in appUpdate.files.file) { var parsedFile = new ParsedFile { FileName = file.fileName, Md5 = file.md5, Url = new Uri(file.url) }; fileList.Add(parsedFile); } var description = appUpdate.description; parseInfo = new ParseInfoObject(version, fileList, description, null); }); return(parseInfo); } catch (Exception) { return(null); } }
private static async Task <IParseInfo> ParseXml(Uri location, string appId) { try { ParseInfoObject parseInfo = null; await Task.Run(() => { // Load the document var doc = new XmlDocument(); doc.Load(location.AbsoluteUri); // Gets the appId's node with the update info // This allows you to store all program's update nodes in one file var updateNode = doc.DocumentElement?.SelectSingleNode("//update[@appID='" + appId + "']"); // If the node doesn't exist, there is no update if (updateNode == null) { return; } // Parse data // If Version is null, then we can't compare assembly versions for update var versionString = updateNode["version"]?.InnerText; if (string.IsNullOrWhiteSpace(versionString)) { return; } var version = Version.Parse(versionString); var files = updateNode["files"]?.ChildNodes; if (files == null) { return; } var fileList = new List <IParsedFile>(); foreach (XmlNode file in files) { Uri uri = null; var url = file["url"]?.InnerText; if (!string.IsNullOrEmpty(url)) { uri = new Uri(url); } var parsedFile = new ParsedFile { FileName = file["fileName"]?.InnerText, Md5 = file["md5"]?.InnerText, Url = uri }; fileList.Add(parsedFile); } var md5 = updateNode["md5"]?.InnerText; var description = updateNode["description"]?.InnerText; var launchArgs = updateNode["launchArgs"]?.InnerText; parseInfo = new ParseInfoObject(version, fileList, description, launchArgs); }); return(parseInfo); } catch (Exception ex) { // Log or display return(null); } }