/// <summary> /// To stream. /// </summary> /// <param name="commiters">The commiters.</param> /// <param name="outputStream">The output stream.</param> /// <returns>A stream containing markup contents.</returns> public Stream ToStream(Commit[] commiters, Stream outputStream = null) { MemoryStream memory = new MemoryStream(); StreamWriter writer; if (outputStream == null) { writer = new StreamWriter(memory); } else { writer = new StreamWriter(outputStream); } foreach (TextBlock block in this._blocks) { switch (block.Type) { case BlockType.Author: var uniqueAuthors = commiters.Select(x => x.Author).Distinct(); foreach (var author in uniqueAuthors) { this.WriteAuthors( writer, block, commiters.Where(x => x.Author.Equals(author)).ToArray()); if (!string.IsNullOrEmpty(block.PostText)) { var last = uniqueAuthors.Last(); // Add the separator if it is not the last route. if (last != author) { writer.Write(block.PostText); writer.Flush(); } } } break; case BlockType.Date: // Stub. break; default: int idx; // Search for y-min tokens. while ((idx = block.Text.IndexOf("{ymin}", StringComparison.CurrentCultureIgnoreCase)) > -1) { block.Text = block.Text.Replace( block.Text.Substring(idx, "{ymin}".Length), commiters.Min(x => x.LinesOfChange).ToString()); } // Search for y-max tokens. while ((idx = block.Text.IndexOf("{ymax}", StringComparison.CurrentCultureIgnoreCase)) > -1) { block.Text = block.Text.Replace( block.Text.Substring(idx, "{ymax}".Length), commiters.Max(x => x.LinesOfChange).ToString()); } // Search for y-min tokens. while ((idx = block.Text.IndexOf("{xmin}", StringComparison.CurrentCultureIgnoreCase)) > -1) { block.Text = block.Text.Replace( block.Text.Substring(idx, "{xmin}".Length), ConvertToJavascriptTimestamp(commiters.Min(x => x.Date)).ToString()); } // Search for y-max tokens. while ((idx = block.Text.IndexOf("{xmax}", StringComparison.CurrentCultureIgnoreCase)) > -1) { block.Text = block.Text.Replace( block.Text.Substring(idx, "{xmax}".Length), ConvertToJavascriptTimestamp(commiters.Max(x => x.Date)).ToString()); } // Nothing to see here. writer.Write(block.Text); writer.Flush(); break; } } writer.Flush(); writer.Close(); memory.Seek(0, SeekOrigin.Begin); return memory; }