Esempio n. 1
0
        /// <summary>
        /// Generate header.
        /// </summary>
        /// <returns></returns>
        public static string GetHeader(this CommitData commitData, LinkFactory linkFactory, bool showRevisionsAsLinks)
        {
            StringBuilder header      = new StringBuilder();
            string        authorEmail = GetEmail(commitData.Author);

            header.AppendLine(
                FillToLength(WebUtility.HtmlEncode(Strings.GetAuthorText()) + ":", COMMITHEADER_STRING_LENGTH) +
                linkFactory.CreateLink(commitData.Author, "mailto:" + authorEmail));
            header.AppendLine(
                FillToLength(WebUtility.HtmlEncode(Strings.GetAuthorDateText()) + ":",
                             COMMITHEADER_STRING_LENGTH) +
                WebUtility.HtmlEncode(
                    LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.AuthorDate.UtcDateTime) + " (" +
                    LocalizationHelpers.GetFullDateString(commitData.AuthorDate) + ")"));
            string committerEmail = GetEmail(commitData.Committer);

            header.AppendLine(
                FillToLength(WebUtility.HtmlEncode(Strings.GetCommitterText()) + ":",
                             COMMITHEADER_STRING_LENGTH) +
                linkFactory.CreateLink(commitData.Committer, "mailto:" + committerEmail));
            header.AppendLine(
                FillToLength(WebUtility.HtmlEncode(Strings.GetCommitDateText()) + ":",
                             COMMITHEADER_STRING_LENGTH) +
                WebUtility.HtmlEncode(
                    LocalizationHelpers.GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + " (" +
                    LocalizationHelpers.GetFullDateString(commitData.CommitDate) + ")"));
            header.Append(
                FillToLength(WebUtility.HtmlEncode(Strings.GetCommitHashText()) + ":",
                             COMMITHEADER_STRING_LENGTH) +
                WebUtility.HtmlEncode(commitData.Guid));

            if (commitData.ChildrenGuids != null && commitData.ChildrenGuids.Count != 0)
            {
                header.AppendLine();
                string commitsString;
                if (showRevisionsAsLinks)
                {
                    commitsString = commitData.ChildrenGuids.Select(g => linkFactory.CreateCommitLink(g)).Join(" ");
                }
                else
                {
                    commitsString = commitData.ChildrenGuids.Select(guid => guid.Substring(0, 10)).Join(" ");
                }
                header.Append(FillToLength(WebUtility.HtmlEncode(Strings.GetChildrenText()) + ":",
                                           COMMITHEADER_STRING_LENGTH) + commitsString);
            }

            var parentGuids = commitData.ParentGuids.Where(s => !String.IsNullOrEmpty(s));

            if (parentGuids.Any())
            {
                header.AppendLine();
                string commitsString;
                if (showRevisionsAsLinks)
                {
                    commitsString = parentGuids.Select(g => linkFactory.CreateCommitLink(g)).Join(" ");
                }
                else
                {
                    commitsString = parentGuids.Select(guid => guid.Substring(0, 10)).Join(" ");
                }
                header.Append(FillToLength(WebUtility.HtmlEncode(Strings.GetParentsText()) + ":",
                                           COMMITHEADER_STRING_LENGTH) + commitsString);
            }

            return(RemoveRedundancies(header.ToString()));
        }