public void ShowInfo(PadInfo info) { PadName.text = info.PadName; Line1.Setup(info.Attributes[0]); Line2.Setup(info.Attributes[1]); Line3.Setup(info.Attributes[2]); Description.text = info.Description; }
void InternalAsyncGetVersionFromPad(object state) { Uri padUri = ((CheckerState)state).PadUri; Version currentVersion = ((CheckerState)state).CurrentVersion; try { PadInfo padInfo = GetInfoFromPad(padUri); bool isNewVersionDetected = currentVersion.CompareTo(padInfo.Version) < 0; if (null != VersionDetected) { VersionDetected(this, new VersionDetectedEventArgs(isNewVersionDetected, padInfo.Version)); } string localMsiFileName = null; if (isNewVersionDetected && null != padInfo.DownloadUri && !string.IsNullOrEmpty(padInfo.VersionedFileName)) { localMsiFileName = DownloadMsi(padInfo.DownloadUri, GetPackageNameFromRegistry(productId, padInfo.VersionedFileName)); } if (null != VersionRetrieved) { VersionRetrieved(this, new VersionRetrievedEventArgs(isNewVersionDetected, padInfo.Version, localMsiFileName)); } } catch (WebException) { // silent failure in case of network failure. } catch (InvalidOperationException) { // silent failure in case of PAD parsing failure. } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } } }
/// <summary>Retrieve the version number contained in an online PAD file.</summary> internal static PadInfo GetInfoFromPad(Uri padUri) { // HACK: if network connection is down, this method must fail in a clean manner. // For ex, an 'null' value could be returned. // retrieving the latest version number from the published PAD file using (XmlTextReader reader = new XmlTextReader(padUri.ToString())) { try { XmlDocument document = new XmlDocument(); document.Load(reader); PadInfo padInfo = new PadInfo(); XmlNode node = document.SelectSingleNode(@"/XML_DIZ_INFO/Program_Info/Program_Version"); if (null != node) { Version version = null; if (TryParseVersion(node.InnerText, out version)) { padInfo.Version = version; } else { throw new InvalidOperationException("Version number cannot be parsed."); } } node = document.SelectSingleNode(@"/XML_DIZ_INFO/Program_Info/File_Info/Filename_Versioned"); if (null != node) { padInfo.VersionedFileName = node.InnerText; } else { node = document.SelectSingleNode(@"/XML_DIZ_INFO/Program_Info/Program_Name"); if (node != null) { string name = node.InnerText; node = document.SelectSingleNode(@"/XML_DIZ_INFO/Program_Info/Program_Version"); if (node != null) { string version = node.InnerText; padInfo.VersionedFileName = (name + version.Replace(".", "")).Replace(" ", "") + ".msi"; } } } node = document.SelectSingleNode(@"/XML_DIZ_INFO/Web_Info/Download_URLs/Primary_Download_URL"); if (null != node) { try { padInfo.DownloadUri = new Uri(node.InnerText); } catch (UriFormatException) { padInfo.DownloadUri = null; } } return padInfo; } catch (XmlException) { throw new InvalidOperationException("PAD file does not appear to be correct XML."); } } }
public static extern bool _GetPadInfo([MarshalAs(UnmanagedType.LPStruct)][Out] PadInfo lplf, int PadIndex);