Files
octokit.net/Octokit/Models/Response
2021-02-25 10:40:25 -04:00
..
2020-10-06 09:47:36 -03:00
2019-10-30 13:51:20 -03:00
2017-01-21 14:42:02 +10:00
2020-10-06 09:47:36 -03:00
2020-10-06 09:47:36 -03:00
2020-10-06 09:47:36 -03:00
2020-02-18 09:28:51 -04:00
2019-10-30 13:51:20 -03:00
2019-02-24 21:29:03 +10:00
2016-04-03 23:04:46 +10:00
2019-10-30 13:51:20 -03:00
2016-07-17 16:29:32 +07:00
2020-10-06 09:47:36 -03:00
2020-10-06 09:47:36 -03:00

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using System.Threading.Tasks;

namespace Octokit
{
    [DebuggerDisplay("{DebuggerDisplay,nq}")]
    public class Readme
    {
        readonly Lazy<Task<string>> htmlContent;

        public Readme() { }

        internal Readme(ReadmeResponse response, IApiConnection client)
        {
            Ensure.ArgumentNotNull(response, nameof(response));
            Ensure.ArgumentNotNull(client, nameof(client));

            Name = response.Name;
            Url = response.Url;
            HtmlUrl = response.HtmlUrl;
            if (response.Encoding.Equals("base64", StringComparison.OrdinalIgnoreCase))
            {
                var contentAsBytes = Convert.FromBase64String(response.Content);
                Content = Encoding.UTF8.GetString(contentAsBytes, 0, contentAsBytes.Length);
            }
            htmlContent = new Lazy<Task<string>>(async () => await client.GetHtml(new Uri(Url)).ConfigureAwait(false));
        }

        public Readme(Lazy<Task<string>> htmlContent, string content, string name, string htmlUrl, string url)
        {
            this.htmlContent = htmlContent;
            Content = content;
            Name = name;
            HtmlUrl = htmlUrl;
            Url = url;
        }

        public string Content { get; private set; }
        public string Name { get; private set; }
        public string HtmlUrl { get; private set; }
        public string Url { get; private set; }

        [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
            Justification = "Makes a network request")]
        public Task<string> GetHtmlContent()
        {
            return htmlContent.Value;
        }

        internal string DebuggerDisplay
        {
            get
            {
                return string.Format(CultureInfo.InvariantCulture, "Name: {0} ", Name);
            }
        }
    }
}