ZeroInstall.Publish.FeedBuilder.Build C# (CSharp) Method

Build() public method

Generates a feed as described by the properties.
is null.
public Build ( ) : SignedFeed
return SignedFeed
        public SignedFeed Build()
        {
            #region Sanity checks
            if (MainCandidate == null) throw new InvalidOperationException("MainCandidate is not set.");
            #endregion

            var implementation = new Implementation
            {
                ID = @"sha1new=" + ManifestDigest.Sha1New,
                ManifestDigest = ManifestDigest,
                Version = MainCandidate.Version,
                Architecture = MainCandidate.Architecture
            };
            implementation.Commands.AddRange(Commands);
            if (RetrievalMethod != null) implementation.RetrievalMethods.Add(RetrievalMethod);

            var feed = new Feed
            {
                Name = MainCandidate.Name,
                Uri = Uri,
                Summaries = {MainCandidate.Summary},
                NeedsTerminal = MainCandidate.NeedsTerminal,
                Elements = {implementation}
            };
            feed.Icons.AddRange(_icons);
            if (!string.IsNullOrEmpty(MainCandidate.Category)) feed.Categories.Add(new Category {Name = MainCandidate.Category});
            feed.EntryPoints.AddRange(EntryPoints);
            if (CapabilityList != null && CapabilityList.Entries.Count != 0) feed.CapabilityLists.Add(CapabilityList);

            return new SignedFeed(feed, SecretKey);
        }
        #endregion

Usage Example

Ejemplo n.º 1
0
        public void TestBuild()
        {
            TestCalculateDigest();
            TestDetectCandidates();
            TestGenerateCommands();

            _builder.RetrievalMethod = new Archive();
            _builder.Uri             = new FeedUri("http://0install.de/feeds/test/test1.xml");
            _builder.Icons.Add(new Icon {
                MimeType = Icon.MimeTypePng, Href = new Uri("http://0install.de/test.png")
            });
            _builder.Icons.Add(new Icon {
                MimeType = Icon.MimeTypeIco, Href = new Uri("http://0install.de/test.ico")
            });
            _builder.SecretKey = new OpenPgpSecretKey("fingerprint", "key", "user", new DateTime(2000, 1, 1), OpenPgpAlgorithm.Rsa, 1024);
            var signedFeed = _builder.Build();

            Assert.AreEqual(expected: _builder.MainCandidate.Name, actual: signedFeed.Feed.Name);
            Assert.AreEqual(expected: _builder.Uri, actual: signedFeed.Feed.Uri);
            CollectionAssert.AreEqual(
                expected: new LocalizableStringCollection {
                _builder.MainCandidate.Summary
            },
                actual: signedFeed.Feed.Summaries);
            Assert.AreEqual(expected: _builder.MainCandidate.NeedsTerminal, actual: signedFeed.Feed.NeedsTerminal);
            CollectionAssert.AreEqual(
                expected: new[]
            {
                new Implementation
                {
                    ID             = "sha1new=" + ManifestDigest.Empty.Sha1New,
                    ManifestDigest = ManifestDigest.Empty,
                    Version        = _builder.MainCandidate.Version,
                    Architecture   = _builder.MainCandidate.Architecture,
                    Commands       = { new Command {
                                           Name = Command.NameRun, Path = "test"
                                       } },
                    RetrievalMethods = { _builder.RetrievalMethod }
                }
            },
                actual: signedFeed.Feed.Elements);
            CollectionAssert.AreEqual(expected: _builder.Icons, actual: signedFeed.Feed.Icons);
            CollectionAssert.IsEmpty(signedFeed.Feed.EntryPoints, "Should not generate entry points if there is only a single command");
            Assert.AreEqual(expected: _builder.SecretKey, actual: signedFeed.SecretKey);
        }
All Usage Examples Of ZeroInstall.Publish.FeedBuilder::Build