mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 17:23:52 -05:00
* Initial commit for GitHub IO pages * Add initial doxfx content * Update manifest.json * Update manifest.json * Set theme jekyll-theme-cayman * Set theme jekyll-theme-slate * Set theme jekyll-theme-minimal * Set theme jekyll-theme-tactile * Clear out theme setting * Remove API docs * Revert "Adding Milliseconds to DateTime fields (#173)" (#197) This reverts commit431dfa4156. * ported new BatchParser * added BatchParser tests * fixing merge conflicts * fix build issues * cleaned code and addressed comments from code review * addressed code review and made BatchParser logic more efficient * fixed batch parser tests * changed class name to fix build issues * fixed merge conflicts * added path for lab mode baseline tests * changed env path for lab mode * added env variable to appveyor * testing env variable for appveyor * fixed lab build * debug appveyor build * testing changes for appveyor * changed trace env path * debugging appveyor build * changed baseline env path * debugging * debugging * debugging * switched on trace flag * debugging * debugging * changed build config * changed baseline files * checking baseline output * changed baseline files * debug baseline tests * debugging baseline * debugging * debugging * debug * debugging * testing baseline format * debug * debug * debug * debug * debug * newline debug * changed baseline file * debug * test * try new way to read * added execution engine tests * change test * testing file encoding * moved execution engine tests to integration * try compare without spaces * removed no op test * added env variable for travis * put batch parser tests to integration too * put batch parser in integration * try new baseline string match * compare baseline test logic changed * changed baseline logic as well as cleaned tests * fix build for travis CI * fix travis CI issues * fixed highlighting bugs on vscode * code review changes * ported new BatchParser * added BatchParser tests * Initial commit for GitHub IO pages * Add initial doxfx content * Update manifest.json * Update manifest.json * Set theme jekyll-theme-cayman * Set theme jekyll-theme-slate * Set theme jekyll-theme-minimal * Set theme jekyll-theme-tactile * Clear out theme setting * Remove API docs * Revert "Adding Milliseconds to DateTime fields (#173)" (#197) This reverts commit431dfa4156. * fixing merge conflicts * fix build issues * cleaned code and addressed comments from code review * addressed code review and made BatchParser logic more efficient * fixed batch parser tests * changed class name to fix build issues * fixed merge conflicts * added path for lab mode baseline tests changed env path for lab mode added env variable to appveyor testing env variable for appveyor fixed lab build debug appveyor build testing changes for appveyor changed trace env path debugging appveyor build changed baseline env path debugging debugging debugging switched on trace flag debugging debugging changed build config changed baseline files checking baseline output changed baseline files debug baseline tests debugging baseline debugging debugging debug debugging testing baseline format debug debug debug debug debug newline debug changed baseline file debug test try new way to read added execution engine tests change test testing file encoding moved execution engine tests to integration try compare without spaces removed no op test added env variable for travis * put batch parser tests to integration too * put batch parser in integration try new baseline string match * compare baseline test logic changed * changed baseline logic as well as cleaned tests * fix build for travis CI * fix travis CI issues * fixed highlighting bugs on vscode * code review changes * fixed filestream writer test * added localization string * added localization string * generated new string files again * code review changes
143 lines
4.4 KiB
C#
143 lines
4.4 KiB
C#
//
|
|
// 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;
|
|
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|
{
|
|
internal static class FileUtilities
|
|
{
|
|
internal static string PeekDefinitionTempFolder = Path.GetTempPath() + "mssql_definition";
|
|
internal static bool PeekDefinitionTempFolderCreated = false;
|
|
|
|
internal static string GetPeekDefinitionTempFolder()
|
|
{
|
|
string tempPath;
|
|
if (!PeekDefinitionTempFolderCreated)
|
|
{
|
|
try
|
|
{
|
|
// create new temp folder
|
|
string tempFolder = string.Format("{0}_{1}", FileUtilities.PeekDefinitionTempFolder, DateTime.Now.ToString("yyyyMMddHHmmssffff"));
|
|
DirectoryInfo tempScriptDirectory = Directory.CreateDirectory(tempFolder);
|
|
FileUtilities.PeekDefinitionTempFolder = tempScriptDirectory.FullName;
|
|
tempPath = tempScriptDirectory.FullName;
|
|
PeekDefinitionTempFolderCreated = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// swallow exception and use temp folder to store scripts
|
|
tempPath = Path.GetTempPath();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
// use tempDirectory name created previously
|
|
DirectoryInfo tempScriptDirectory = Directory.CreateDirectory(FileUtilities.PeekDefinitionTempFolder);
|
|
tempPath = tempScriptDirectory.FullName;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// swallow exception and use temp folder to store scripts
|
|
tempPath = Path.GetTempPath();
|
|
}
|
|
}
|
|
return tempPath;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if file exists and swallows exceptions, if any
|
|
/// </summary>
|
|
/// <param name="path"> path of the file</param>
|
|
/// <returns></returns>
|
|
internal static bool SafeFileExists(string path)
|
|
{
|
|
try
|
|
{
|
|
return File.Exists(path);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// Swallow exception
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes a file and swallows exceptions, if any
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
internal static void SafeFileDelete(string path)
|
|
{
|
|
try
|
|
{
|
|
File.Delete(path);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// Swallow exception, do nothing
|
|
}
|
|
}
|
|
|
|
internal static int WriteWithLength(Stream stream, byte[] buffer, int length)
|
|
{
|
|
stream.Write(buffer, 0, length);
|
|
return length;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if file exists and swallows exceptions, if any
|
|
/// </summary>
|
|
/// <param name="path"> path of the file</param>
|
|
/// <returns></returns>
|
|
internal static bool SafeDirectoryExists(string path)
|
|
{
|
|
try
|
|
{
|
|
return Directory.Exists(path);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// Swallow exception
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Deletes a directory and swallows exceptions, if any
|
|
/// </summary>
|
|
/// <param name="path"></param>
|
|
internal static void SafeDirectoryDelete(string path, bool recursive)
|
|
{
|
|
try
|
|
{
|
|
Directory.Delete(path, recursive);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// Swallow exception, do nothing
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Turns off the read-only attribute for this file
|
|
/// </summary>
|
|
/// <param name="fullFilePath"></param>
|
|
|
|
internal static void SetFileReadWrite(string fullFilePath)
|
|
{
|
|
if (!string.IsNullOrEmpty(fullFilePath) &&
|
|
File.Exists(fullFilePath))
|
|
{
|
|
File.SetAttributes(fullFilePath, FileAttributes.Normal);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} |