mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-22 17:24:07 -05:00
Adding more features to restore operation (#420)
* Adding more features to restore operations and added tests
This commit is contained in:
@@ -100,7 +100,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
/// <summary>
|
||||
/// Callback for ondisconnect handler
|
||||
/// </summary>
|
||||
public delegate Task OnDisconnectHandler(ConnectionSummary summary, string ownerUri);
|
||||
public delegate Task OnDisconnectHandler(IConnectionSummary summary, string ownerUri);
|
||||
|
||||
/// <summary>
|
||||
/// List of onconnection handlers
|
||||
@@ -1007,7 +1007,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection
|
||||
|
||||
// Fire a connection changed event
|
||||
ConnectionChangedParams parameters = new ConnectionChangedParams();
|
||||
ConnectionSummary summary = info.ConnectionDetails;
|
||||
IConnectionSummary summary = info.ConnectionDetails;
|
||||
parameters.Connection = summary.Clone();
|
||||
parameters.OwnerUri = ownerUri;
|
||||
ServiceHost.SendEvent(ConnectionChangedNotification.Type, parameters);
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
{
|
||||
@@ -16,18 +13,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
/// <remarks>
|
||||
/// If this contract is ever changed, be sure to update ConnectionDetailsExtensions methods.
|
||||
/// </remarks>
|
||||
public class ConnectionDetails : ConnectionSummary
|
||||
public class ConnectionDetails : GeneralRequestDetails, IConnectionSummary
|
||||
{
|
||||
public ConnectionDetails()
|
||||
public ConnectionDetails() : base()
|
||||
{
|
||||
Options = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or Sets the connection options
|
||||
/// </summary>
|
||||
public Dictionary<string, object> Options { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the connection password
|
||||
/// </summary>
|
||||
@@ -46,7 +37,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
/// <summary>
|
||||
/// Gets or sets the connection server name
|
||||
/// </summary>
|
||||
public override string ServerName
|
||||
public string ServerName
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -62,7 +53,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
/// <summary>
|
||||
/// Gets or sets the connection database name
|
||||
/// </summary>
|
||||
public override string DatabaseName
|
||||
public string DatabaseName
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -78,7 +69,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
/// <summary>
|
||||
/// Gets or sets the connection user name
|
||||
/// </summary>
|
||||
public override string UserName
|
||||
public string UserName
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -459,49 +450,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
}
|
||||
}
|
||||
|
||||
private T GetOptionValue<T>(string name)
|
||||
{
|
||||
T result = default(T);
|
||||
if (Options != null && Options.ContainsKey(name))
|
||||
{
|
||||
object value = Options[name];
|
||||
try
|
||||
{
|
||||
if (value != null && (typeof(T) != value.GetType()))
|
||||
{
|
||||
if (typeof(T) == typeof(int) || typeof(T) == typeof(int?))
|
||||
{
|
||||
value = Convert.ToInt32(value);
|
||||
}
|
||||
else if (typeof(T) == typeof(bool) || typeof(T) == typeof(bool?))
|
||||
{
|
||||
value = Convert.ToBoolean(value);
|
||||
}
|
||||
}
|
||||
result = value != null ? (T)value : default(T);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = default(T);
|
||||
Logger.Write(LogLevel.Warning, string.Format(CultureInfo.InvariantCulture,
|
||||
"Cannot convert option value {0}:{1} to {2}", name, value ?? "", typeof(T)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SetOptionValue<T>(string name, T value)
|
||||
{
|
||||
Options = Options ?? new Dictionary<string, object>();
|
||||
if (Options.ContainsKey(name))
|
||||
{
|
||||
Options[name] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
Options.Add(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsComparableTo(ConnectionDetails other)
|
||||
{
|
||||
|
||||
@@ -3,12 +3,32 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
{
|
||||
|
||||
public interface IConnectionSummary
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the connection server name
|
||||
/// </summary>
|
||||
string ServerName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the connection database name
|
||||
/// </summary>
|
||||
string DatabaseName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the connection user name
|
||||
/// </summary>
|
||||
string UserName { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Provides high level information about a connection.
|
||||
/// </summary>
|
||||
public class ConnectionSummary
|
||||
public class ConnectionSummary : IConnectionSummary
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the connection server name
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
/// <summary>
|
||||
/// Create a copy of a ConnectionSummary object
|
||||
/// </summary>
|
||||
public static ConnectionSummary Clone(this ConnectionSummary summary)
|
||||
public static ConnectionSummary Clone(this IConnectionSummary summary)
|
||||
{
|
||||
return new ConnectionSummary()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user