//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Data;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
{
public class ColumnInfo
{
///
/// Name of this column
///
public string Name { get; set; }
public string DataTypeName { get; set; }
public ColumnInfo()
{
}
public ColumnInfo(string name, string dataTypeName)
{
this.Name = name;
this.DataTypeName = dataTypeName;
}
}
public interface ISerializationParams
{
///
/// Path to file that the serialized results will be stored in
///
string FilePath { get; set; }
///
/// Results that are to be serialized into 'SaveFormat' format
///
DbCellValue[][] Rows { get; set; }
///
/// Whether the current set of Rows passed in is the last for this file
//
bool IsLastBatch { get; set; }
}
///
/// Class used for storing results and how the results are to be serialized
///
public class SerializeDataContinueRequestParams : ISerializationParams
{
///
/// Path to file that the serialized results will be stored in
///
public string FilePath { get; set; }
///
/// Results that are to be serialized into 'SaveFormat' format
///
public DbCellValue[][] Rows { get; set; }
///
/// Whether the current set of Rows passed in is the last for this file
//
public bool IsLastBatch { get; set; }
}
///
/// Class used for storing results and how the results are to be serialized
///
public class SerializeDataStartRequestParams : GeneralRequestDetails, ISerializationParams
{
///
/// String representation of the type that service is supposed to serialize to
/// E.g. "json" or "csv"
///
public string SaveFormat { get; set; }
///
/// Path to file that the serialized results will be stored in
///
public string FilePath { get; set; }
///
/// Results that are to be serialized into 'SaveFormat' format
///
public DbCellValue[][] Rows { get; set; }
public ColumnInfo[] Columns { get; set; }
///
/// Whether this is the only request expected for this file.
//
public bool IsLastBatch { get; set; }
public SerializeDataStartRequestParams()
{
}
///
/// Constructor
///
public SerializeDataStartRequestParams(string saveFormat,
string savePath,
DbCellValue[][] rows,
bool isLast)
{
this.SaveFormat = saveFormat;
this.FilePath = savePath;
this.Rows = rows;
this.IsLastBatch = isLast;
}
internal bool IncludeHeaders
{
get { return this.GetOptionValue(SerializationOptionsHelper.IncludeHeaders); }
set { this.SetOptionValue(SerializationOptionsHelper.IncludeHeaders, value); }
}
internal string Delimiter
{
get { return this.GetOptionValue(SerializationOptionsHelper.Delimiter); }
set { this.SetOptionValue(SerializationOptionsHelper.Delimiter, value); }
}
internal string LineSeparator
{
get { return this.GetOptionValue(SerializationOptionsHelper.LineSeparator); }
set { this.SetOptionValue(SerializationOptionsHelper.LineSeparator, value); }
}
internal string TextIdentifier
{
get { return this.GetOptionValue(SerializationOptionsHelper.TextIdentifier); }
set { this.SetOptionValue(SerializationOptionsHelper.TextIdentifier, value); }
}
internal string Encoding
{
get { return this.GetOptionValue(SerializationOptionsHelper.Encoding); }
set { this.SetOptionValue(SerializationOptionsHelper.Encoding, value); }
}
internal bool Formatted
{
get { return this.GetOptionValue(SerializationOptionsHelper.Formatted); }
set { this.SetOptionValue(SerializationOptionsHelper.Formatted, value); }
}
internal int MaxCharsToStore
{
get { return this.GetOptionValue(SerializationOptionsHelper.MaxCharsToStore); }
set { this.SetOptionValue(SerializationOptionsHelper.Formatted, value); }
}
}
public class SerializeDataResult
{
public string Messages { get; set; }
public bool Succeeded { get; set; }
}
public class SerializeStartRequest
{
public static readonly RequestType Type = RequestType.Create("serialize/start");
}
public class SerializeContinueRequest
{
public static readonly RequestType Type = RequestType.Create("serialize/continue");
}
class SerializationOptionsHelper
{
internal const string IncludeHeaders = "includeHeaders";
internal const string Delimiter = "delimiter";
internal const string LineSeparator = "lineSeparator";
internal const string TextIdentifier = "textIdentifier";
internal const string Encoding = "encoding";
internal const string Formatted = "formatted";
internal const string MaxCharsToStore = "maxchars";
}
}