Ejemplo n.º 1
0
        /// <summary>
        ///   Write dates.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="block">The block.</param>
        /// <param name="commits">The commits.</param>
        private void WriteDates(StreamWriter writer, TextBlock block, Commit[] commits)
        {
            var token = "{date}";
            var lineToken = "{lines}";

            foreach (var commit in commits)
            {
                // Work with the copy dummy.
                string line = block.Text;
                int idx;

                // Search for date tokens.
                while ((idx = line.IndexOf(token, StringComparison.CurrentCultureIgnoreCase)) > -1)
                {
                    line = line.Replace(line.Substring(idx, token.Length), ConvertToJavascriptTimestamp(commit.Date).ToString());
                }

                // Search for line tokens.
                while ((idx = line.IndexOf(lineToken, StringComparison.CurrentCultureIgnoreCase)) > -1)
                {
                    line = line.Replace(line.Substring(idx, lineToken.Length), commit.LinesOfChange.ToString());
                }

                if (!string.IsNullOrEmpty(block.PostText))
                {
                    var last = commits.Last();

                    // Add the separator if it is not the last route.
                    if (last != commit)
                    {
                        line += block.PostText;
                    }
                }

                // Finally...
                writer.Write(line);
                writer.Flush();
            }
        }