mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 09:35:38 -05:00
Feature/delete peek scripts (#174)
* Delete temp script folder * Delete folder and refactor code * Add unit tests * create folder per workspace * Refactor and move creation to FileUtils * Separate multiple assignment
This commit is contained in:
@@ -8,6 +8,46 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
{
|
||||
internal static class FileUtils
|
||||
{
|
||||
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}", FileUtils.PeekDefinitionTempFolder, DateTime.Now.ToString("yyyyMMddHHmmssffff"));
|
||||
DirectoryInfo tempScriptDirectory = Directory.CreateDirectory(tempFolder);
|
||||
FileUtils.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(FileUtils.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>
|
||||
@@ -42,5 +82,40 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
}
|
||||
}
|
||||
|
||||
/// <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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
{
|
||||
public static class TextUtilities
|
||||
{
|
||||
{
|
||||
/// <summary>
|
||||
/// Find the position of the cursor in the SQL script content buffer and return previous new line position
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user