//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.IO;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage
{
///
/// Factory that creates file reader/writers that process rows in an internal, non-human readable file format
///
public class ServiceBufferFileStreamFactory : IFileStreamFactory
{
#region Properties
///
/// The settings for query execution
///
public QueryExecutionSettings ExecutionSettings { get; set; }
#endregion
///
/// Creates a new temporary file
///
/// The name of the temporary file
public string CreateFile()
{
return Path.GetTempFileName();
}
///
/// Creates a new for reading values back from
/// an SSMS formatted buffer file, file share is ReadWrite to allow concurrent reads/writes to the file.
///
/// The file to read values from
/// A
public IFileStreamReader GetReader(string fileName)
{
return new ServiceBufferFileStreamReader(new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), ExecutionSettings);
}
///
/// Creates a new for writing values out to an
/// SSMS formatted buffer file, file share is ReadWrite to allow concurrent reads/writes to the file.
///
/// The file to write values to
/// A
public IFileStreamWriter GetWriter(string fileName)
{
return new ServiceBufferFileStreamWriter(new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite), ExecutionSettings);
}
///
/// Disposes of a file created via this factory
///
/// The file to dispose of
public void DisposeFile(string fileName)
{
FileUtilities.SafeFileDelete(fileName);
}
}
}