//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.IO;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
{
///
/// Factory for creating a reader/writer pair that will read from the temporary buffer file
/// and output to a Excel file.
///
public class SaveAsExcelFileStreamFactory : IFileStreamFactory
{
#region Properties
///
/// Settings for query execution
///
public QueryExecutionSettings QueryExecutionSettings { get; set; }
///
/// Parameters for the save as Excel request
///
public SaveResultsAsExcelRequestParams SaveRequestParams { get; set; }
#endregion
///
/// File names are not meant to be created with this factory.
///
/// Thrown all times
[Obsolete]
public string CreateFile()
{
throw new NotImplementedException();
}
///
/// Returns a new service buffer reader for reading results back in from the temporary buffer files
///
/// Path to the temp buffer file
/// Stream reader
public IFileStreamReader GetReader(string fileName)
{
return new ServiceBufferFileStreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read), QueryExecutionSettings);
}
///
/// Returns a new Excel writer for writing results to a Excel file
///
/// Path to the Excel output file
/// Stream writer
public IFileStreamWriter GetWriter(string fileName)
{
return new SaveAsExcelFileStreamWriter(new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite), SaveRequestParams);
}
///
/// Safely deletes the file
///
/// Path to the file to delete
public void DisposeFile(string fileName)
{
FileUtilities.SafeFileDelete(fileName);
}
}
}