ZeroInstall.Commands.Utils.Exporter.ExportImplementations C# (CSharp) Метод

ExportImplementations() публичный Метод

Exports all implementations listed in a Selections document as archives.
The user canceled the task. The file could not be read or written. Write access to the directory is not permitted. An implementation archive could not be creates.
public ExportImplementations ( [ store, [ handler ) : void
store [ Used to get cached implementations.
handler [ A callback object used when the the user needs to be asked questions or informed about download and IO tasks.
Результат void
        public void ExportImplementations([NotNull] IStore store, [NotNull] ITaskHandler handler)
        {
            #region Sanity checks
            if (store == null) throw new ArgumentNullException(nameof(store));
            if (handler == null) throw new ArgumentNullException(nameof(handler));
            #endregion

            string contentDir = Path.Combine(_destination, "content");
            Directory.CreateDirectory(contentDir);

            foreach (var digest in _selections.Implementations.Select(x => x.ManifestDigest).Where(x => x.Best != null).Distinct())
            {
                string sourcePath = store.GetPath(digest);
                if (sourcePath == null)
                {
                    Log.Warn("Implementation " + digest + " missing from cache");
                    continue;
                }

                using (var generator = ArchiveGenerator.Create(sourcePath, Path.Combine(contentDir, digest.Best + ".tbz2"), Archive.MimeTypeTarBzip))
                    handler.RunTask(generator);
            }
        }

Usage Example

Пример #1
0
        public void TestExportImplementations()
        {
            using (var implDir1 = new TemporaryDirectory("0install-unit-tests"))
                using (var implDir2 = new TemporaryDirectory("0install-unit-tests"))
                {
                    var storeMock = CreateMock <IStore>();
                    storeMock.Setup(x => x.GetPath(new ManifestDigest(null, null, "123", null))).Returns(implDir1);
                    storeMock.Setup(x => x.GetPath(new ManifestDigest(null, null, "abc", null))).Returns(implDir2);

                    _target.ExportImplementations(storeMock.Object, new SilentTaskHandler());
                }

            string contentDir = Path.Combine(_destination, "content");

            File.Exists(Path.Combine(contentDir, "sha256=123.tbz2")).Should()
            .BeTrue(because: "Implementation should be exported.");
            File.Exists(Path.Combine(contentDir, "sha256=abc.tbz2")).Should()
            .BeTrue(because: "Implementation should be exported.");
        }
All Usage Examples Of ZeroInstall.Commands.Utils.Exporter::ExportImplementations