Ejemplo n.º 1
0
    /// <summary>
    /// Adds a downloaded file to the implementation.
    /// </summary>
    /// <param name="builder">The builder.</param>
    /// <param name="retrievalMethod">The metadata of the file.</param>
    /// <param name="stream">The contents of the file.</param>
    /// <param name="handler">A callback object used when the the user needs to be informed about IO tasks.</param>
    /// <param name="tag">A <see cref="ITask.Tag"/> used to group progress bars. Usually <see cref="ManifestDigest.Best"/>.</param>
    /// <exception cref="UnauthorizedAccessException">Access to a resource was denied.</exception>
    /// <exception cref="IOException">An IO operation failed.</exception>
    public static void Add(this IBuilder builder, DownloadRetrievalMethod retrievalMethod, Stream stream, ITaskHandler handler, object?tag = null)
    {
        switch (retrievalMethod)
        {
        case SingleFile singleFile:
            builder.AddFile(singleFile, stream);
            break;

        case Archive archive:
            builder.AddArchive(archive, stream, handler, tag);
            break;

        default:
            throw new NotSupportedException($"Unknown download retrieval method: ${retrievalMethod}");
        }
    }