ZeroInstall.Publish.FeedUtils.DeployStylesheet C# (CSharp) Method

DeployStylesheet() public static method

Writes an XSL stylesheet with its accompanying CSS file unless there is already an XSL in place.
Failed to write the sytelsheet files. Write access to the directory is not permitted.
public static DeployStylesheet ( [ path, [ name ) : void
path [ The directory to write the stylesheet files to.
name [ The name of the stylesheet to deploy. Must be "feed" or "catalog".
return void
        public static void DeployStylesheet([NotNull] string path, [NotNull] string name)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(path)) throw new ArgumentNullException(nameof(path));
            #endregion

            if (!File.Exists(Path.Combine(path, name + ".xsl")))
            {
                typeof(FeedUtils).CopyEmbeddedToFile(name + ".xsl", Path.Combine(path, name + ".xsl"));
                typeof(FeedUtils).CopyEmbeddedToFile(name + ".css", Path.Combine(path, name + ".css"));
            }
        }

Usage Example

        /// <summary>
        /// Saves <see cref="Catalog"/> to an XML file, adds the default stylesheet and sign it it with <see cref="SecretKey"/> (if specified).
        /// </summary>
        /// <remarks>Writing and signing the catalog 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 in.</param>
        /// <param name="passphrase">The passphrase to use to unlock the secret key; can be <c>null</c> if <see cref="SecretKey"/> is <c>null</c>.</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="SecretKey"/> could not be found on the system.</exception>
        /// <exception cref="WrongPassphraseException"><paramref name="passphrase"/> was incorrect.</exception>
        public void Save(string path, string?passphrase = null)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            #endregion

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

            using (var stream = new MemoryStream())
            {
                Catalog.SaveXml(stream, stylesheet: @"catalog.xsl");
                stream.Position = 0;

                FeedUtils.SignFeed(stream, SecretKey, passphrase, _openPgp);
                stream.CopyToFile(path);
            }
            string directory = Path.GetDirectoryName(path);
            _openPgp.DeployPublicKey(SecretKey, directory);
            FeedUtils.DeployStylesheet(directory, @"catalog");
        }
All Usage Examples Of ZeroInstall.Publish.FeedUtils::DeployStylesheet