mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-25 17:24:17 -05:00
Adding more features to restore operation (#420)
* Adding more features to restore operations and added tests
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Linq;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Class includes information about a file related to a database operation.
|
||||
/// Can be used for backup set files or restored database files
|
||||
/// </summary>
|
||||
public class DatabaseFileInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// The property name used for ids
|
||||
/// </summary>
|
||||
public const string IdPropertyName = "Id";
|
||||
|
||||
public DatabaseFileInfo(LocalizedPropertyInfo[] properties)
|
||||
{
|
||||
Validate.IsNotNull("properties", properties);
|
||||
|
||||
this.Properties = properties;
|
||||
if (this.Properties != null )
|
||||
{
|
||||
var idProperty = this.Properties.FirstOrDefault(x => x.PropertyName == IdPropertyName);
|
||||
Id = idProperty == null || idProperty.PropertyValue == null ? string.Empty : idProperty.PropertyValue.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Properties
|
||||
/// </summary>
|
||||
public LocalizedPropertyInfo[] Properties { get; private set; }
|
||||
|
||||
public string GetPropertyValueAsString(string name)
|
||||
{
|
||||
string value = string.Empty;
|
||||
if (Properties != null)
|
||||
{
|
||||
var property = Properties.FirstOrDefault(x => x.PropertyName == name);
|
||||
value = property == null || property.PropertyValue == null ? string.Empty : property.PropertyValue.ToString();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unique id for this item
|
||||
/// </summary>
|
||||
public string Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the item is selected in client
|
||||
/// </summary>
|
||||
public bool IsSelected { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// 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.Globalization;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
|
||||
{
|
||||
public class LocalizedPropertyInfo
|
||||
{
|
||||
|
||||
private string propertyValueDisplayName;
|
||||
private string propertyDisplayName;
|
||||
|
||||
/// <summary>
|
||||
/// Property name
|
||||
/// </summary>
|
||||
public string PropertyName { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Property value
|
||||
/// </summary>
|
||||
public object PropertyValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Property display name
|
||||
/// </summary>
|
||||
public string PropertyDisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.IsNullOrEmpty(this.propertyDisplayName) ? PropertyName : this.propertyDisplayName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.propertyDisplayName = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Property display name for the value
|
||||
/// </summary>
|
||||
public string PropertyValueDisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.IsNullOrEmpty(propertyValueDisplayName) ? GetLocalizedPropertyValue() : propertyValueDisplayName;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.propertyValueDisplayName = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetLocalizedPropertyValue()
|
||||
{
|
||||
string displayName = string.Empty;
|
||||
if(PropertyValue is DateTime)
|
||||
{
|
||||
displayName = ((DateTime)PropertyValue) != DateTime.MinValue ? Convert.ToString(PropertyValue, CultureInfo.CurrentCulture) : string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
displayName = Convert.ToString(PropertyValue, CultureInfo.CurrentCulture);
|
||||
}
|
||||
return displayName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,33 +5,106 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Restore request parameters
|
||||
/// </summary>
|
||||
public class RestoreParams
|
||||
public class RestoreParams : GeneralRequestDetails
|
||||
{
|
||||
public string SessionId
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetOptionValue<string>("sessionId");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetOptionValue("sessionId", value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Uri to find the connection to do the restore operations
|
||||
/// </summary>
|
||||
public string OwnerUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The backup file path
|
||||
/// Comma delimited list of backup files
|
||||
/// </summary>
|
||||
public string BackupFilePath { get; set; }
|
||||
public string BackupFilePaths
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetOptionValue<string>("backupFilePaths");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetOptionValue("backupFilePaths", value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Target Database name to restore to
|
||||
/// </summary>
|
||||
public string DatabaseName { get; set; }
|
||||
public string TargetDatabaseName
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetOptionValue<string>("targetDatabaseName");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetOptionValue("targetDatabaseName", value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Source Database name to restore from
|
||||
/// </summary>
|
||||
public string SourceDatabaseName
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetOptionValue<string>("sourceDatabaseName");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetOptionValue("sourceDatabaseName", value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If set to true, the db files will be relocated to default data location in the server
|
||||
/// </summary>
|
||||
public bool RelocateDbFiles { get; set; }
|
||||
public bool RelocateDbFiles
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetOptionValue<bool>("relocateDbFiles");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetOptionValue("relocateDbFiles", value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ids of the backup set to restore
|
||||
/// </summary>
|
||||
public string[] SelectedBackupSets
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetOptionValue<string[]>("selectedBackupSets");
|
||||
}
|
||||
set
|
||||
{
|
||||
SetOptionValue("selectedBackupSets", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,10 +160,9 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
|
||||
/// </summary>
|
||||
public class RestorePlanResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// The backup file path
|
||||
/// </summary>
|
||||
public string BackupFilePath { get; set; }
|
||||
public string RestoreSessionId { get; set; }
|
||||
|
||||
public DatabaseFileInfo[] BackupSetsToRestore { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the restore operation is supported
|
||||
@@ -107,6 +179,11 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
|
||||
/// </summary>
|
||||
public IEnumerable<RestoreDatabaseFileInfo> DbFiles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Database names extracted from backup sets
|
||||
/// </summary>
|
||||
public string[] DatabaseNamesFromBackupSets { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Server name
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user