Example #1
0
    /// <summary>
    /// Calculates a <see cref="ManifestDigest"/> for a retrieval method. Sets missing properties in the process.
    /// </summary>
    /// <param name="retrievalMethod">The retrieval method.</param>
    /// <param name="executor">Used to modify properties in an undoable fashion.</param>
    /// <param name="handler">A callback object used when the the user is to be informed about progress.</param>
    /// <param name="format">The manifest format. Leave <c>null</c> for default.</param>
    /// <returns>The generated digest.</returns>
    /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
    /// <exception cref="WebException">A file could not be downloaded from the internet.</exception>
    public static ManifestDigest CalculateDigest(this RetrievalMethod retrievalMethod, ICommandExecutor executor, ITaskHandler handler, ManifestFormat?format = null)
    {
        #region Sanity checks
        if (retrievalMethod == null)
        {
            throw new ArgumentNullException(nameof(retrievalMethod));
        }
        if (executor == null)
        {
            throw new ArgumentNullException(nameof(executor));
        }
        if (handler == null)
        {
            throw new ArgumentNullException(nameof(handler));
        }
        #endregion

        var builder = new ManifestBuilder(format ?? ManifestFormat.Sha256New);
        builder.Add(retrievalMethod, executor, handler);

        var digest = new ManifestDigest(builder.Manifest.CalculateDigest());
        if (digest.PartialEquals(ManifestDigest.Empty))
        {
            Log.Warn(Resources.EmptyImplementation);
        }
        return(digest);
    }