ZeroInstall.Publish.SignedFeed.Save C# (CSharp) Method

Save() public method

Saves Feed to an XML file, adds the default stylesheet and sign it it with SecretKey (if specified).
Writing and signing the feed file are performed as an atomic operation (i.e. if signing fails an existing file remains unchanged).
A problem occurs while writing the file. Write access to the file is not permitted. The specified could not be found on the system. was incorrect.
public Save ( [ path, [ passphrase = null ) : void
path [ The file to save in.
passphrase [ The passphrase to use to unlock the secret key; can be null if is null.
return void
        public void Save([NotNull] string path, [CanBeNull] string passphrase = null)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path));
            #endregion

            if (SecretKey == null)
            {
                Feed.SaveXml(path);
                return;
            }

            var openPgp = OpenPgpFactory.CreateDefault();
            using (var stream = new MemoryStream())
            {
                Feed.SaveXml(stream, stylesheet: @"feed.xsl");
                stream.Position = 0;

                FeedUtils.SignFeed(stream, SecretKey, passphrase, openPgp);
                stream.CopyToFile(path);
            }
            string directory = Path.GetDirectoryName(path);
            if (directory != null)
            {
                openPgp.DeployPublicKey(SecretKey, directory);
                FeedUtils.DeployStylesheet(directory, @"feed");
            }
        }
        #endregion

Usage Example

示例#1
0
        /// <summary>
        /// Saves feed to an XML file, adds the default stylesheet and signs it with <see cref="Publish.SignedFeed.SecretKey"/> (if specified).
        /// </summary>
        /// <remarks>Writing and signing the feed file are performed as an atomic operation (i.e. if signing fails an existing file remains unchanged).</remarks>
        /// <param name="path">The file to save to.</param>
        /// <exception cref="IOException">A problem occurred while writing the file.</exception>
        /// <exception cref="UnauthorizedAccessException">Write access to the file is not permitted.</exception>
        /// <exception cref="KeyNotFoundException">The specified <see cref="Publish.SignedFeed.SecretKey"/> could not be found on the system.</exception>
        /// <exception cref="WrongPassphraseException"><see cref="Passphrase"/> was incorrect.</exception>
        public override void Save(string path)
        {
            SignedFeed.Save(path, Passphrase);

            Path = path;
            ClearUndo();
        }
All Usage Examples Of ZeroInstall.Publish.SignedFeed::Save