Export to Markdown Support (#1705)

* Adding file writer for Markdown tables. No testing yet.

* Unit tests for the markdown writer

* Wiring up the factory and and request types

* Wiring up changes for Markdown serialization in serialization service

* Couple last minute tweaks

* Changes as per PR comments

* Revert temp testing code. 🙈

* Fluent assertions in SerializationServiceTests.cs

Co-authored-by: Ben Russell <russellben@microsoft.com>
This commit is contained in:
Benjamin Russell
2022-09-27 13:55:43 -05:00
committed by GitHub
parent 5c20f92312
commit af2c0c77e7
10 changed files with 905 additions and 54 deletions

View File

@@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using Microsoft.SqlTools.Utility;
@@ -106,6 +107,37 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
FileStream.Flush();
}
/// <summary>
/// Attempts to parse the provided <paramref name="encoding"/> and return an encoding that
/// matches the encoding name or codepage number.
/// </summary>
/// <param name="encoding">Encoding name or codepage number to parse.</param>
/// <param name="fallbackEncoding">
/// Encoding to return if no encoding of provided name/codepage number exists.
/// </param>
/// <returns>
/// Desired encoding object or the <paramref name="fallbackEncoding"/> if the desired
/// encoding could not be found.
/// </returns>
protected static Encoding ParseEncoding(string encoding, Encoding fallbackEncoding)
{
// If the encoding is a number, we try to look up a codepage encoding using the
// parsed number as a codepage. If it is not a number, attempt to look up an
// encoding with the provided encoding name. If getting the encoding fails in
// either case, we will return the fallback encoding.
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
try
{
return int.TryParse(encoding, out int codePage)
? Encoding.GetEncoding(codePage)
: Encoding.GetEncoding(encoding);
}
catch
{
return fallbackEncoding;
}
}
#region IDisposable Implementation
private bool disposed;