/// <summary>
        /// Generates the <see cref="ManifestDigest"/> for a directory.
        /// </summary>
        /// <param name="path">The path of the directory to generate the digest for.</param>
        /// <param name="handler">A callback object used when the the user is to be informed about progress.</param>
        /// <param name="keepDownloads"><see langword="true"/> to store the directory as an implementation in the default <see cref="IStore"/>.</param>
        /// <returns>The newly generated digest.</returns>
        /// <exception cref="OperationCanceledException">The user canceled the operation.</exception>
        /// <exception cref="IOException">There is a problem access a temporary file.</exception>
        /// <exception cref="UnauthorizedAccessException">Read or write access to a temporary file is not permitted.</exception>
        public static ManifestDigest GenerateDigest([NotNull] string path, [NotNull] ITaskHandler handler, bool keepDownloads = false)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            #endregion

            var digest = new ManifestDigest();

            // Generate manifest for each available format...
            foreach (var format in ManifestFormat.Recommended)
            // ... and add the resulting digest to the return value
            {
                var generator = new ManifestGenerator(path, format);
                handler.RunTask(generator);
                digest.ParseID(generator.Result.CalculateDigest());
            }

            if (digest.PartialEquals(ManifestDigest.Empty))
            {
                Log.Warn(Resources.EmptyImplementation);
            }

            if (keepDownloads)
            {
                try
                {
                    StoreFactory.CreateDefault().AddDirectory(path, digest, handler);
                }
                catch (ImplementationAlreadyInStoreException)
                {}
            }

            return(digest);
        }
Example #2
0
        private OptionSet BuildOptions()
        {
            var options = new OptionSet
            {
                // Version information
                {
                    "V|version", () => Resources.OptionVersion, _ =>
                    {
                        Console.WriteLine(AppInfo.Current.Name + @" " + AppInfo.Current.Version + Environment.NewLine + AppInfo.Current.Copyright + Environment.NewLine + Resources.LicenseInfo);
                        throw new OperationCanceledException(); // Don't handle any of the other arguments
                    }
                },

                // Mode selection
                {
                    "catalog=", () => Resources.OptionCatalog, delegate(string catalogFile)
                    {
                        if (string.IsNullOrEmpty(catalogFile))
                        {
                            return;
                        }
                        _mode        = OperationMode.Catalog;
                        _catalogFile = catalogFile;
                    }
                },

                // Modifications
                { "add-missing", () => Resources.OptionAddMissing, _ => _addMissing = true },
                { "keep-downloads", () => Resources.OptionsKeepDownloads, _ => _keepDownloads = StoreFactory.CreateDefault() },

                // Signatures
                { "x|xmlsign", () => Resources.OptionXmlSign, _ => _xmlSign = true },
                { "u|unsign", () => Resources.OptionUnsign, _ => _unsign = true },
                { "k|key=", () => Resources.OptionKey, user => _key = user },
                { "gpg-passphrase=", () => Resources.OptionGnuPGPassphrase, passphrase => _openPgpPassphrase = passphrase }
            };

            options.Add("h|help|?", () => Resources.OptionHelp, _ =>
            {
                Console.WriteLine(Resources.Usage);
                // ReSharper disable once LocalizableElement
                Console.WriteLine("\t0publish [OPTIONS] feed.xml");
                Console.WriteLine();
                Console.WriteLine(Resources.Options);
                options.WriteOptionDescriptions(Console.Out);

                // Don't handle any of the other arguments
                throw new OperationCanceledException();
            });
            return(options);
        }