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

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

Exports all feeds listed in a Selections document along with any OpenPGP public key files required for validation.
The file could not be read or written. Write access to the directory is not permitted. A feed or GnuPG could not be read from the cache.
public ExportFeeds ( [ feedCache, [ openPgp ) : void
feedCache [ Used to get local feed files.
openPgp [ Used to get export keys feeds were signed with.
Результат void
        public void ExportFeeds([NotNull] IFeedCache feedCache, [NotNull] IOpenPgp openPgp)
        {
            #region Sanity checks
            if (feedCache == null) throw new ArgumentNullException(nameof(feedCache));
            if (openPgp == null) throw new ArgumentNullException(nameof(openPgp));
            #endregion

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

            var feedUris = _selections.Implementations.Select(x => x.FromFeed ?? x.InterfaceUri).Distinct().ToList();

            foreach (var feedUri in feedUris)
            {
                string filePath = Path.Combine(contentDir, feedUri.PrettyEscape());
                if (!filePath.EndsWith(".xml")) filePath += ".xml";

                Log.Info("Exporting feed " + feedUri.ToStringRfc());
                File.Copy(feedCache.GetPath(feedUri), filePath, overwrite: true);
            }

            foreach (var signature in feedUris.SelectMany(feedCache.GetSignatures).OfType<ValidSignature>().Distinct())
            {
                Log.Info("Exporting GPG key " + signature.FormatKeyID());
                openPgp.DeployPublicKey(signature, contentDir);
            }
        }

Usage Example

Пример #1
0
        public void TestExportFeeds()
        {
            using (var feedFile1 = new TemporaryFile("0install-unit-tests"))
                using (var feedFile2 = new TemporaryFile("0install-unit-tests"))
                {
                    var feedCacheMock = CreateMock <IFeedCache>();

                    feedCacheMock.Setup(x => x.GetPath(FeedTest.Sub1Uri)).Returns(feedFile1);
                    feedCacheMock.Setup(x => x.GetPath(FeedTest.Sub2Uri)).Returns(feedFile2);

                    var signature = new ValidSignature(123, new byte[0], new DateTime(2000, 1, 1));
                    feedCacheMock.Setup(x => x.GetSignatures(FeedTest.Sub1Uri)).Returns(new OpenPgpSignature[] { signature });
                    feedCacheMock.Setup(x => x.GetSignatures(FeedTest.Sub2Uri)).Returns(new OpenPgpSignature[] { signature });

                    var openPgpMock = CreateMock <IOpenPgp>();
                    openPgpMock.Setup(x => x.ExportKey(signature)).Returns("abc");

                    _target.ExportFeeds(feedCacheMock.Object, openPgpMock.Object);

                    string contentDir = Path.Combine(_destination, "content");
                    FileAssert.AreEqual(
                        expected: new FileInfo(feedFile1),
                        actual: new FileInfo(Path.Combine(contentDir, FeedTest.Sub1Uri.PrettyEscape())),
                        message: "Feed should be exported.");
                    FileAssert.AreEqual(
                        expected: new FileInfo(feedFile2),
                        actual: new FileInfo(Path.Combine(contentDir, FeedTest.Sub2Uri.PrettyEscape())),
                        message: "Feed should be exported.");

                    File.ReadAllText(Path.Combine(contentDir, "000000000000007B.gpg")).Should()
                    .Be("abc", because: "GPG keys should be exported.");
                }
        }
All Usage Examples Of ZeroInstall.Commands.Utils.Exporter::ExportFeeds