コード例 #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 void MarkPackageAsInstalled(IPackageMetadata packageMetadata)
        {
            if (InstalledPackages.ContainsKey(packageMetadata.Id))
            {
                // The package has previously been intalled - remove the data from the collection
                // The entry will be recreated later on with the updated value
                InstalledPackages.Remove(packageMetadata.Id);
            }

            IInstalledPackageMetadata installedMetadata = new InstalledPackageMetadata(packageMetadata.Id, packageMetadata.Name, packageMetadata.Hash, packageMetadata.Size, packageMetadata.PublishDate, packageMetadata.Source, DateTime.UtcNow);

            InstalledPackages.Add(installedMetadata.Id, installedMetadata);

            using (XmlWriter xmlWriter = StorageProvider.CreateInstalledPackageRepository()) {
                InstalledPackages.Save(xmlWriter);
            }
        }