Fix issues in file browser service (#469)

* fix file browser service bug

* modify filebrowser service

* change filebrowser contract

* fix contract

* fix file browser add/expand event contracts

* remove commented code
This commit is contained in:
Kate Shin
2017-09-28 13:02:57 -07:00
committed by GitHub
parent 3510ad7d5c
commit b46c4b4381
8 changed files with 53 additions and 35 deletions

View File

@@ -9,8 +9,13 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
/// <summary>
/// Event params for expanding a node
/// </summary>
public class FileBrowserExpandCompleteParams
public class FileBrowserExpandedParams
{
/// <summary>
/// Connection uri
/// </summary>
public string OwnerUri;
/// <summary>
/// Expanded node
/// </summary>
@@ -30,11 +35,11 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
/// <summary>
/// Notification for expand completion
/// </summary>
public class FileBrowserExpandCompleteNotification
public class FileBrowserExpandedNotification
{
public static readonly
EventType<FileBrowserExpandCompleteParams> Type =
EventType<FileBrowserExpandCompleteParams>.Create("filebrowser/expandcomplete");
EventType<FileBrowserExpandedParams> Type =
EventType<FileBrowserExpandedParams>.Create("filebrowser/expandcomplete");
}
}

View File

@@ -11,8 +11,13 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
/// Event params for opening a file browser
/// Returns full directory structure on the server side
/// </summary>
public class FileBrowserOpenCompleteParams
public class FileBrowserOpenedParams
{
/// <summary>
/// Connection uri
/// </summary>
public string OwnerUri;
/// <summary>
/// Entire file/folder tree
/// </summary>
@@ -32,11 +37,11 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
/// <summary>
/// Notification for completing file browser opening
/// </summary>
public class FileBrowserOpenCompleteNotification
public class FileBrowserOpenedNotification
{
public static readonly
EventType<FileBrowserOpenCompleteParams> Type =
EventType<FileBrowserOpenCompleteParams>.Create("filebrowser/opencomplete");
EventType<FileBrowserOpenedParams> Type =
EventType<FileBrowserOpenedParams>.Create("filebrowser/opencomplete");
}
}

View File

@@ -9,7 +9,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
/// <summary>
/// Event params for validation completion
/// </summary>
public class FileBrowserValidateCompleteParams
public class FileBrowserValidatedParams
{
/// <summary>
/// Result of the operation
@@ -25,11 +25,11 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
/// <summary>
/// Notification for validation completion
/// </summary>
public class FileBrowserValidateCompleteNotification
public class FileBrowserValidatedNotification
{
public static readonly
EventType<FileBrowserValidateCompleteParams> Type =
EventType<FileBrowserValidateCompleteParams>.Create("filebrowser/validatecomplete");
EventType<FileBrowserValidatedParams> Type =
EventType<FileBrowserValidatedParams>.Create("filebrowser/validatecomplete");
}
}

View File

@@ -20,11 +20,6 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
this.Children = new List<FileTreeNode>();
}
/// <summary>
/// Parent node
/// </summary>
public FileTreeNode Parent { get; private set; }
/// <summary>
/// List of children nodes
/// </summary>
@@ -48,7 +43,6 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser.Contracts
public void AddChildNode(FileTreeNode item)
{
item.Parent = this;
this.Children.Add(item);
}
}

View File

@@ -175,7 +175,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
internal async Task RunFileBrowserOpenTask(FileBrowserOpenParams fileBrowserParams)
{
FileBrowserOpenCompleteParams result = new FileBrowserOpenCompleteParams();
FileBrowserOpenedParams result = new FileBrowserOpenedParams();
try
{
@@ -197,7 +197,14 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
{
FileBrowserOperation browser = new FileBrowserOperation(conn, fileBrowserParams.ExpandPath, fileBrowserParams.FileFilters);
browser.PopulateFileTree();
if (this.ownerToFileBrowserMap.ContainsKey(fileBrowserParams.OwnerUri))
{
this.ownerToFileBrowserMap.Remove(fileBrowserParams.OwnerUri);
}
this.ownerToFileBrowserMap.Add(fileBrowserParams.OwnerUri, browser);
result.OwnerUri = fileBrowserParams.OwnerUri;
result.FileTree = browser.FileTree;
result.Succeeded = true;
}
@@ -212,18 +219,19 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
result.Message = ex.Message;
}
await ServiceHost.SendEvent(FileBrowserOpenCompleteNotification.Type, result);
await ServiceHost.SendEvent(FileBrowserOpenedNotification.Type, result);
}
internal async Task RunFileBrowserExpandTask(FileBrowserExpandParams fileBrowserParams)
{
FileBrowserExpandCompleteParams result = new FileBrowserExpandCompleteParams();
FileBrowserExpandedParams result = new FileBrowserExpandedParams();
try
{
if (this.ownerToFileBrowserMap.ContainsKey(fileBrowserParams.OwnerUri))
{
FileBrowserOperation browser = this.ownerToFileBrowserMap[fileBrowserParams.OwnerUri];
browser.ExpandSelectedNode(fileBrowserParams.ExpandPath);
result.OwnerUri = fileBrowserParams.OwnerUri;
result.ExpandedNode = browser.FileTree.SelectedNode;
result.Succeeded = true;
}
@@ -238,12 +246,12 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
result.Message = ex.Message;
}
await ServiceHost.SendEvent(FileBrowserExpandCompleteNotification.Type, result);
await ServiceHost.SendEvent(FileBrowserExpandedNotification.Type, result);
}
internal async Task RunFileBrowserValidateTask(FileBrowserValidateParams fileBrowserParams)
{
FileBrowserValidateCompleteParams result = new FileBrowserValidateCompleteParams();
FileBrowserValidatedParams result = new FileBrowserValidatedParams();
try
{
@@ -276,7 +284,7 @@ namespace Microsoft.SqlTools.ServiceLayer.FileBrowser
result.Message = ex.Message;
}
await ServiceHost.SendEvent(FileBrowserValidateCompleteNotification.Type, result);
await ServiceHost.SendEvent(FileBrowserValidatedNotification.Type, result);
}
}
}

View File

@@ -12,6 +12,7 @@ using Microsoft.SqlTools.ServiceLayer.Admin;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery;
using Microsoft.SqlTools.ServiceLayer.EditData;
using Microsoft.SqlTools.ServiceLayer.FileBrowser;
using Microsoft.SqlTools.ServiceLayer.Hosting;
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
using Microsoft.SqlTools.ServiceLayer.Metadata;
@@ -95,8 +96,11 @@ namespace Microsoft.SqlTools.ServiceLayer
DisasterRecoveryService.Instance.InitializeService(serviceHost);
serviceProvider.RegisterSingleService(DisasterRecoveryService.Instance);
FileBrowserService.Instance.InitializeService(serviceHost);
serviceProvider.RegisterSingleService(FileBrowserService.Instance);
ProfilerService.Instance.InitializeService(serviceHost);
serviceProvider.RegisterSingleService(ProfilerService.Instance);
serviceProvider.RegisterSingleService(ProfilerService.Instance);
InitializeHostedServices(serviceProvider, serviceHost);
serviceHost.ServiceProvider = serviceProvider;

View File

@@ -265,8 +265,8 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
await service.RunFileBrowserOpenTask(openParams);
// Verify complete notification event was fired and the result
serviceHostMock.Verify(x => x.SendEvent(FileBrowserOpenCompleteNotification.Type,
It.Is<FileBrowserOpenCompleteParams>(p => p.Succeeded == true
serviceHostMock.Verify(x => x.SendEvent(FileBrowserOpenedNotification.Type,
It.Is<FileBrowserOpenedParams>(p => p.Succeeded == true
&& p.FileTree != null
&& p.FileTree.RootNode != null
&& p.FileTree.RootNode.Children != null
@@ -286,9 +286,11 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
await service.RunFileBrowserExpandTask(expandParams);
// Verify result
serviceHostMock.Verify(x => x.SendEvent(FileBrowserExpandCompleteNotification.Type,
It.Is<FileBrowserExpandCompleteParams>(p => p.Succeeded == true
&& p.ExpandedNode.FullPath == backupConfigInfo.DefaultBackupFolder)),
serviceHostMock.Verify(x => x.SendEvent(FileBrowserExpandedNotification.Type,
It.Is<FileBrowserExpandedParams>(p => p.Succeeded == true
&& p.ExpandedNode != null
&& p.ExpandedNode.Children != null
&& p.ExpandedNode.Children.Count > 0)),
Times.Once());
var validateParams = new FileBrowserValidateParams
@@ -302,7 +304,7 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
await service.RunFileBrowserValidateTask(validateParams);
// Verify complete notification event was fired and the result
serviceHostMock.Verify(x => x.SendEvent(FileBrowserValidateCompleteNotification.Type, It.Is<FileBrowserValidateCompleteParams>(p => p.Succeeded == true)), Times.Once());
serviceHostMock.Verify(x => x.SendEvent(FileBrowserValidatedNotification.Type, It.Is<FileBrowserValidatedParams>(p => p.Succeeded == true)), Times.Once());
// Remove the backup file
if (File.Exists(backupPath))

View File

@@ -115,8 +115,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.FileBrowser
await service.RunFileBrowserOpenTask(openParams);
// Verify complete notification event was fired and the result
serviceHostMock.Verify(x => x.SendEvent(FileBrowserOpenCompleteNotification.Type,
It.Is<FileBrowserOpenCompleteParams>(p => p.Succeeded == true
serviceHostMock.Verify(x => x.SendEvent(FileBrowserOpenedNotification.Type,
It.Is<FileBrowserOpenedParams>(p => p.Succeeded == true
&& p.FileTree != null
&& p.FileTree.RootNode != null
&& p.FileTree.RootNode.Children != null
@@ -145,7 +145,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.FileBrowser
await service.RunFileBrowserValidateTask(validateParams);
// Verify complete notification event was fired and the result
serviceHostMock.Verify(x => x.SendEvent(FileBrowserValidateCompleteNotification.Type, It.Is<FileBrowserValidateCompleteParams>(p => p.Succeeded == true)), Times.Once());
serviceHostMock.Verify(x => x.SendEvent(FileBrowserValidatedNotification.Type, It.Is<FileBrowserValidatedParams>(p => p.Succeeded == true)), Times.Once());
}
[Fact]
@@ -168,7 +168,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.FileBrowser
await service.RunFileBrowserValidateTask(validateParams);
// Verify complete notification event was fired and the result
serviceHostMock.Verify(x => x.SendEvent(FileBrowserValidateCompleteNotification.Type, It.Is<FileBrowserValidateCompleteParams>(p => p.Succeeded == false)), Times.Once());
serviceHostMock.Verify(x => x.SendEvent(FileBrowserValidatedNotification.Type, It.Is<FileBrowserValidatedParams>(p => p.Succeeded == false)), Times.Once());
}
#region private methods