示例#1
0
        private async Task HandleUpdater()
        {
            try {
                string updateSiteString = "https://onedrive.live.com/download?resid=D332F531B200D073%218103";

                Uri updateSite = new Uri(updateSiteString);
                Uri remotePackageStorageDirectory = new Uri(updateSite, "Packages/");

                if (Directory.Exists(baseDirectory) == false)
                {
                    Directory.CreateDirectory(baseDirectory);
                }

                IStorageProvider storageProvider = new StorageProvider(baseDirectory);
                using (ICacheStorageProvider cacheStorageProvider = new CacheStorageProvider(System.IO.Path.Combine(baseDirectory, "Cache"))) {
                    IPackageAcquisitionFactory packageAcquisitionFactory = new PackageAcquisitionFactory();
                    IUpdaterCache updaterCache = UpdaterCache.InitializeCache(cacheStorageProvider);

                    IPackageMetadataCollection packageMetadataCollection = null;

                    IUpdater updater = new Updater.Updater();
                    using (XmlReader xmlReader = XmlReader.Create(updateSite.AbsoluteUri)) {
                        packageMetadataCollection = updater.ParseMetadataCollectionXml(xmlReader);
                    }

                    IUpdateState      updateState      = updater.DetermineUpdateState(updaterCache.InstalledPackages, packageMetadataCollection);
                    IPackageInstaller packageInstaller = updater.CreateInstaller();
                    foreach (IPackageMetadata packageMetadata in updateState.Packages)
                    {
                        IPackageAcquisition packageAcquisition = packageAcquisitionFactory.BuildPackageAcquisition(remotePackageStorageDirectory, cacheStorageProvider);
                        using (ZipArchive packageArchive = await packageAcquisition.AcquirePackageArchive(packageMetadata)) {
                            using (IPackage package = Package.OpenPackage(packageMetadata, packageArchive)) {
                                packageInstaller.Install(storageProvider, package);
                                updaterCache.MarkPackageAsInstalled(package.Metadata);
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                string baseDirectory = System.IO.Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "Updater");

                File.WriteAllText(System.IO.Path.Combine(baseDirectory, "error.txt"), ex.ToString());
            }
        }
示例#2
0
        static async Task MainAsync(string[] args)
        {
            Uri updateSite = new Uri(ConfigurationManager.AppSettings["updateSite"]);
            Uri remotePackageStorageDirectory = new Uri(updateSite, "Packages/");

            string baseDirectory = Path.GetFullPath("Testing");

            // Clean the old test environment if it already exist
            if (Directory.Exists(baseDirectory))
            {
                Directory.Delete(baseDirectory, true);
            }
            // Setup the test environment
            Directory.CreateDirectory(baseDirectory);

            IStorageProvider storageProvider = new StorageProvider(baseDirectory);

            using (ICacheStorageProvider cacheStorageProvider = new CacheStorageProvider(Path.Combine(baseDirectory, "Cache"))) {
                IPackageAcquisitionFactory packageAcquisitionFactory = new PackageAcquisitionFactory();
                IUpdaterCache updaterCache = UpdaterCache.InitializeCache(cacheStorageProvider);

                IPackageMetadataCollection packageMetadataCollection = null;

                IUpdater updater = new Updater();
                using (XmlReader xmlReader = XmlReader.Create(updateSite.AbsoluteUri)) {
                    packageMetadataCollection = updater.ParseMetadataCollectionXml(xmlReader);
                }

                IUpdateState      updateState      = updater.DetermineUpdateState(updaterCache.InstalledPackages, packageMetadataCollection);
                IPackageInstaller packageInstaller = updater.CreateInstaller();
                foreach (IPackageMetadata packageMetadata in updateState.Packages)
                {
                    IPackageAcquisition packageAcquisition = packageAcquisitionFactory.BuildPackageAcquisition(remotePackageStorageDirectory, cacheStorageProvider);
                    using (ZipArchive packageArchive = await packageAcquisition.AcquirePackageArchive(packageMetadata)) {
                        using (IPackage package = Package.OpenPackage(packageMetadata, packageArchive)) {
                            packageInstaller.Install(storageProvider, package);
                            updaterCache.MarkPackageAsInstalled(package.Metadata);
                        }
                    }
                }
            }
        }
示例#3
0
        private async void PerformUpdateCommandCallback()
        {
            Status = "Downloading update...";
            Uri updateSite = new Uri(@"https://onedrive.live.com/download?resid=D332F531B200D073%218103");
            Uri remotePackageStorageDirectory = new Uri(updateSite, "Packages/");

            string baseDirectory = Path.GetFullPath("Data");

            IStorageProvider storageProvider = new StorageProvider(baseDirectory);

            using (ICacheStorageProvider cacheStorageProvider = new CacheStorageProvider(Path.Combine(baseDirectory, "Cache"))) {
                IPackageAcquisitionFactory packageAcquisitionFactory = new PackageAcquisitionFactory();
                IUpdaterCache updaterCache = UpdaterCache.InitializeCache(cacheStorageProvider);

                IPackageMetadataCollection packageMetadataCollection = null;

                IUpdater updater = new Updater.Updater();
                using (XmlReader xmlReader = XmlReader.Create(updateSite.AbsoluteUri)) {
                    packageMetadataCollection = updater.ParseMetadataCollectionXml(xmlReader);
                }

                IUpdateState      updateState      = updater.DetermineUpdateState(updaterCache.InstalledPackages, packageMetadataCollection);
                IPackageInstaller packageInstaller = updater.CreateInstaller();
                foreach (IPackageMetadata packageMetadata in updateState.Packages)
                {
                    IPackageAcquisition packageAcquisition = packageAcquisitionFactory.BuildPackageAcquisition(remotePackageStorageDirectory, cacheStorageProvider);
                    using (ZipArchive packageArchive = await packageAcquisition.AcquirePackageArchive(packageMetadata)) {
                        using (IPackage package = Package.OpenPackage(packageMetadata, packageArchive)) {
                            packageInstaller.Install(storageProvider, package);
                            updaterCache.MarkPackageAsInstalled(package.Metadata);
                        }
                    }
                }
            }

            RefreshImage();
            Status = "Image updated!";
        }