Пример #1
0
        public static InstalledPackageMetadataCollection LoadFromXml(XmlReader xmlReader)
        {
            InstalledPackageMetadataCollection installedMetadataCollection = new InstalledPackageMetadataCollection();

            while (xmlReader.Read())
            {
                if (xmlReader.IsStartElement())
                {
                    switch (xmlReader.Name)
                    {
                    case "Package": {
                        // Package metadata is stored as attributes
                        int      id          = Convert.ToInt32(xmlReader.GetAttribute("Id"));
                        string   name        = xmlReader.GetAttribute("Name");
                        string   hash        = xmlReader.GetAttribute("Hash");
                        long     size        = Convert.ToInt64(xmlReader.GetAttribute("Size"));
                        DateTime publishDate = DateTime.FromBinary(Convert.ToInt64(xmlReader.GetAttribute("PublishDate")));
                        DateTime installDate = DateTime.FromBinary(Convert.ToInt64(xmlReader.GetAttribute("InstallDate")));
                        // Source is optional. If it is not specified, it will be auto-generated based on conventions
                        string source = xmlReader.GetAttribute("Source");

                        IInstalledPackageMetadata packageMetadata = new InstalledPackageMetadata(id, name, hash, size, publishDate, source, installDate);
                        installedMetadataCollection.Add(id, packageMetadata);
                    }
                    break;
                    }
                }
            }

            return(installedMetadataCollection);
        }
Пример #2
0
        public static UpdaterCache InitializeCache(ICacheStorageProvider cacheStorageProvider)
        {
            IInstalledPackageMetadataCollection installedPackages;

            using (XmlReader xmlReader = cacheStorageProvider.OpenInstalledPackageRepository()) {
                installedPackages = InstalledPackageMetadataCollection.LoadFromXml(xmlReader);
            }

            return(new UpdaterCache(cacheStorageProvider, installedPackages));
        }