Create remote file browser service (#448)

* code refactoring

* Add filebrowser service and tests

* change dataset reference

* Address pr comments

* add more tests

* address pr comments

* address pr comments and added more tests

* minor change

* minor fix

* Fix test break and add dataset result check
This commit is contained in:
Kate Shin
2017-09-08 13:57:56 -07:00
committed by GitHub
parent 784f4c5d05
commit 14ec5be961
29 changed files with 1942 additions and 59 deletions
@@ -0,0 +1,45 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
{
/// <summary>
/// Parameters to pass to close file browser
/// </summary>
public class FileBrowserCloseParams
{
/// <summary>
/// Connection uri
/// </summary>
public string OwnerUri;
}
/// <summary>
/// Response for closing the browser
/// </summary>
public class FileBrowserCloseResponse
{
/// <summary>
/// Result of the operation
/// </summary>
public bool Succeeded;
/// <summary>
/// Error message if any
/// </summary>
public string Message;
}
/// <summary>
/// Requst to close the file browser
/// </summary>
class FileBrowserCloseRequest
{
public static readonly
RequestType<FileBrowserCloseParams, FileBrowserCloseResponse> Type =
RequestType<FileBrowserCloseParams, FileBrowserCloseResponse>.Create("filebrowser/close");
}
}
@@ -0,0 +1,40 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
{
/// <summary>
/// Event params for expanding a node
/// </summary>
public class FileBrowserExpandCompleteParams
{
/// <summary>
/// Expanded node
/// </summary>
public FileTreeNode ExpandedNode;
/// <summary>
/// Result of the operation
/// </summary>
public bool Succeeded;
/// <summary>
/// Error message if any
/// </summary>
public string Message;
}
/// <summary>
/// Notification for expand completion
/// </summary>
public class FileBrowserExpandCompleteNotification
{
public static readonly
EventType<FileBrowserExpandCompleteParams> Type =
EventType<FileBrowserExpandCompleteParams>.Create("filebrowser/expandcomplete");
}
}
@@ -0,0 +1,34 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
{
/// <summary>
/// Parameters for expanding a folder node
/// </summary>
public class FileBrowserExpandParams
{
/// <summary>
/// Connection uri
/// </summary>
public string OwnerUri;
/// <summary>
/// The path to expand the nodes for
/// </summary>
public string ExpandPath;
}
/// <summary>
/// Request to expand a node in the file browser
/// </summary>
public class FileBrowserExpandRequest
{
public static readonly
RequestType<FileBrowserExpandParams, bool> Type =
RequestType<FileBrowserExpandParams, bool>.Create("filebrowser/expand");
}
}
@@ -0,0 +1,42 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
{
/// <summary>
/// Event params for opening a file browser
/// Returns full directory structure on the server side
/// </summary>
public class FileBrowserOpenCompleteParams
{
/// <summary>
/// Entire file/folder tree
/// </summary>
public FileTree FileTree;
/// <summary>
/// Result of the operation
/// </summary>
public bool Succeeded;
/// <summary>
/// Error message
/// </summary>
public string Message;
}
/// <summary>
/// Notification for completing file browser opening
/// </summary>
public class FileBrowserOpenCompleteNotification
{
public static readonly
EventType<FileBrowserOpenCompleteParams> Type =
EventType<FileBrowserOpenCompleteParams>.Create("filebrowser/opencomplete");
}
}
@@ -0,0 +1,40 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
{
/// <summary>
/// Parameters for opening file browser
/// </summary>
public class FileBrowserOpenParams
{
/// <summary>
/// Connection uri
/// </summary>
public string OwnerUri;
/// <summary>
/// The initial path to expand the nodes for (e.g. Backup will set this path to default backup folder)
/// </summary>
public string ExpandPath;
/// <summary>
/// File extension filter (e.g. *.bak)
/// </summary>
public string[] FileFilters;
}
/// <summary>
/// Request to open a file browser
/// </summary>
public class FileBrowserOpenRequest
{
public static readonly
RequestType<FileBrowserOpenParams, bool> Type =
RequestType<FileBrowserOpenParams, bool>.Create("filebrowser/open");
}
}
@@ -0,0 +1,35 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
{
/// <summary>
/// Event params for validation completion
/// </summary>
public class FileBrowserValidateCompleteParams
{
/// <summary>
/// Result of the operation
/// </summary>
public bool Succeeded;
/// <summary>
/// Error message if any
/// </summary>
public string Message;
}
/// <summary>
/// Notification for validation completion
/// </summary>
public class FileBrowserValidateCompleteNotification
{
public static readonly
EventType<FileBrowserValidateCompleteParams> Type =
EventType<FileBrowserValidateCompleteParams>.Create("filebrowser/validatecomplete");
}
}
@@ -0,0 +1,39 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
{
/// <summary>
/// Parameters for validating selected file paths
/// </summary>
public class FileBrowserValidateParams
{
/// <summary>
/// Connection uri
/// </summary>
public string OwnerUri;
/// <summary>
/// Type of service that uses the file browser
/// </summary>
public string ServiceType;
/// <summary>
/// Selected files
/// </summary>
public string[] SelectedFiles;
}
/// <summary>
/// Requst to validate the selected file paths
/// </summary>
class FileBrowserValidateRequest
{
public static readonly
RequestType<FileBrowserValidateParams, bool> Type =
RequestType<FileBrowserValidateParams, bool>.Create("filebrowser/validate");
}
}
@@ -0,0 +1,31 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
{
/// <summary>
/// Tree to represent file/folder structure
/// </summary>
public class FileTree
{
/// <summary>
/// Root node of the tree
/// </summary>
public FileTreeNode RootNode { get; private set; }
/// <summary>
/// Selected node of the tree
/// </summary>
public FileTreeNode SelectedNode { get; set; }
/// <summary>
/// Constructor
/// </summary>
public FileTree()
{
this.RootNode = new FileTreeNode();
}
}
}
@@ -0,0 +1,55 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
{
/// <summary>
/// Tree node to represent file or folder
/// </summary>
public class FileTreeNode
{
/// <summary>
/// Constructor
/// </summary>
public FileTreeNode()
{
this.Children = new List<FileTreeNode>();
}
/// <summary>
/// Parent node
/// </summary>
public FileTreeNode Parent { get; private set; }
/// <summary>
/// List of children nodes
/// </summary>
public List<FileTreeNode> Children { get; private set; }
// Indicates if the node is expanded, applicable to a folder.
public bool IsExpanded { get; set; }
// Indicates if the node is file or folder
public bool IsFile { get; set; }
/// <summary>
/// File or folder name
/// </summary>
public string Name { get; set; }
/// <summary>
/// Full path
/// </summary>
public string FullPath { get; set; }
public void AddChildNode(FileTreeNode item)
{
item.Parent = this;
this.Children.Add(item);
}
}
}