diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs
index 1aabc31f..07d1c5bc 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/AdminService.cs
@@ -131,9 +131,26 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
});
}
- private static DatabaseTaskHelper CreateDatabaseTaskHelper(ConnectionInfo connInfo)
+ ///
+ /// Return database info for a specific database
+ ///
+ ///
+ ///
+ internal static DatabaseInfo GetDatabaseInfo(ConnectionInfo connInfo)
+ {
+ DatabaseTaskHelper taskHelper = CreateDatabaseTaskHelper(connInfo, true);
+ return DatabaseTaskHelper.DatabasePrototypeToDatabaseInfo(taskHelper.Prototype);
+ }
+
+ ///
+ /// Create database task helper
+ ///
+ /// connection info
+ /// flag indicating whether to create taskhelper for existing database or not
+ ///
+ private static DatabaseTaskHelper CreateDatabaseTaskHelper(ConnectionInfo connInfo, bool databaseExists = false)
{
- XmlDocument xmlDoc = CreateDataContainerDocument(connInfo);
+ XmlDocument xmlDoc = CreateDataContainerDocument(connInfo, databaseExists);
char[] passwordArray = connInfo.ConnectionDetails.Password.ToCharArray();
CDataContainer dataContainer;
@@ -169,10 +186,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
return taskHelper;
}
- private static XmlDocument CreateDataContainerDocument(ConnectionInfo connInfo)
+ ///
+ /// Create data container document
+ ///
+ /// connection info
+ /// flag indicating whether to create document for existing database or not
+ ///
+ private static XmlDocument CreateDataContainerDocument(ConnectionInfo connInfo, bool databaseExists)
{
- string xml =
- string.Format(@"
+ string xml = string.Empty;
+
+ if (!databaseExists)
+ {
+ xml =
+ string.Format(@"
{0}
{0} (SQLServer, user = {1})
@@ -182,7 +209,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
",
connInfo.ConnectionDetails.ServerName.ToUpper(),
connInfo.ConnectionDetails.UserName);
-
+ }
+ else
+ {
+ xml =
+ string.Format(@"
+
+ {0}
+ {0} (SQLServer, user = {1})
+ sql
+ Server[@Name='{0}']
+ {2}
+ ",
+ connInfo.ConnectionDetails.ServerName.ToUpper(),
+ connInfo.ConnectionDetails.UserName,
+ connInfo.ConnectionDetails.DatabaseName);
+ }
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
return xmlDoc;
diff --git a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs
index 481fcf75..232f5b1b 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabaseTaskHelper.cs
@@ -134,7 +134,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Admin
string itemPrefix = AdminServicesProviderOptionsHelper.DatabaseFiles + "." + i + ".";
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.Name, file.Name);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.PhysicalName, file.PhysicalName);
- databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.Autogrowth, file.DefaultAutogrowth.ToString());
+ databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.Autogrowth, (file.DefaultAutogrowth != null ? file.DefaultAutogrowth.ToString() : string.Empty));
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.DatabaseFileType, file.DatabaseFileType.ToString());
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.Folder, file.DefaultFolder);
databaseInfo.Options.Add(itemPrefix + AdminServicesProviderOptionsHelper.Size, file.DefaultSize);
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupFactory.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupUtilities.cs
similarity index 86%
rename from src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupFactory.cs
rename to src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupUtilities.cs
index 620002fa..19d3cae0 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupFactory.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupUtilities.cs
@@ -5,23 +5,22 @@
using System;
using System.Collections;
-using System.ComponentModel;
+using System.Collections.Generic;
using System.Data.SqlClient;
+using Microsoft.Data.Tools.DataSets;
+using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.Smo;
-using Microsoft.SqlServer.Management.Common;
-using Microsoft.SqlTools.ServiceLayer.Common;
-using Microsoft.Data.Tools.DataSets;
+using Microsoft.SqlTools.ServiceLayer.Admin;
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
{
- public class BackupFactory
+ public class BackupUtilities
{
private CDataContainer dataContainer;
private ServerConnection serverConnection;
- private BackupRestoreUtil backupRestoreUtil = null;
- private UrlControl urlControl;
+ private CommonUtilities backupRestoreUtil = null;
///
/// Constants
@@ -91,7 +90,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
///
/// Ctor
///
- public BackupFactory()
+ public BackupUtilities()
{
}
@@ -101,12 +100,15 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
///
///
///
- public void Initialize(CDataContainer dataContainer, SqlConnection sqlConnection, BackupInfo input)
+ public void Initialize(CDataContainer dataContainer, SqlConnection sqlConnection)
{
this.dataContainer = dataContainer;
- this.serverConnection = new ServerConnection(sqlConnection); // @@ check the value!
- this.backupRestoreUtil = new BackupRestoreUtil(this.dataContainer, this.serverConnection);
- //this.urlControl.SqlServer = dataContainer.Server;
+ this.serverConnection = new ServerConnection(sqlConnection);
+ this.backupRestoreUtil = new CommonUtilities(this.dataContainer, this.serverConnection);
+ }
+
+ public void SetBackupInput(BackupInfo input)
+ {
this.backupInfo = input;
// convert the types
@@ -118,22 +120,45 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
{
this.isLocalPrimaryReplica = this.backupRestoreUtil.IsLocalPrimaryReplica(this.backupInfo.DatabaseName);
}
-
- //TODO: when is backup device not null?
- //bStatus = param.GetParam("backupdevice", ref this.initialBackupDestination);
}
#endregion
#region Methods for UI logic
-
- // Return recovery model of the current database
- private string GetRecoveryModel()
+
+ public BackupConfigInfo GetBackupConfigInfo(string databaseName)
{
- RecoveryModel recoveryModel = this.backupRestoreUtil.GetRecoveryModel(this.backupInfo.DatabaseName);
+ BackupConfigInfo databaseInfo = new BackupConfigInfo();
+ databaseInfo.RecoveryModel = this.GetRecoveryModel(databaseName);
+ databaseInfo.DefaultBackupFolder = this.GetDefaultBackupFolder();
+ databaseInfo.LatestBackups = this.GetLatestBackupLocations(databaseName);
+ return databaseInfo;
+ }
+
+ ///
+ /// Return recovery model of the database
+ ///
+ ///
+ public string GetRecoveryModel(string databaseName)
+ {
+ RecoveryModel recoveryModel = this.backupRestoreUtil.GetRecoveryModel(databaseName);
return recoveryModel.ToString();
}
+ public string GetDefaultBackupFolder()
+ {
+ return this.backupRestoreUtil.GetDefaultBackupFolder();
+ }
+
+ ///
+ /// Return the latest backup locations
+ ///
+ ///
+ public List GetLatestBackupLocations(string databaseName)
+ {
+ return this.backupRestoreUtil.GetLatestBackupLocations(databaseName);
+ }
+
///
/// Return true if backup to URL is supported in the current SQL Server version
///
@@ -141,9 +166,9 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
{
return BackupRestoreBase.IsBackupUrlDeviceSupported(this.dataContainer.Server.PingSqlServerVersion(this.dataContainer.ServerName)); //@@ originally, DataContainer.Server.ServerVersion
}
-
+
#endregion
-
+
private string GetDefaultBackupSetName()
{
string bkpsetName = this.backupInfo.DatabaseName + "-"
@@ -247,7 +272,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
for (int i = 0; i < this.backupInfo.BackupPathList.Count; i++)
{
string DestName = Convert.ToString(this.backupInfo.BackupPathList[i], System.Globalization.CultureInfo.InvariantCulture);
- int deviceType = (int)(this.backupInfo.arChangesList[DestName]);
+ int deviceType = (int)(this.backupInfo.BackupPathDevices[DestName]);
switch (deviceType)
{
case (int)DeviceType.LogicalDevice:
@@ -276,27 +301,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
}
}
}
- else
- {
- /*if (this.urlControl.ListBakDestUrls.Count > 0)
- {
- // Append the URL filename to the URL prefix
- foreach (string urlPath in this.urlControl.ListBakDestUrls.ToArray())
- {
- if (!String.IsNullOrWhiteSpace(urlPath))
- {
- bk.Devices.AddDevice(urlPath, DeviceType.Url);
- }
- }
- }*/
- }
- /*
- if (this.dataContainer.HashTable.ContainsKey(bk.BackupSetName))
- {
- this.dataContainer.HashTable.Remove(bk.BackupSetName);
- }
- this.dataContainer.HashTable.Add(bk.BackupSetName, bk);*/
-
+
//TODO: This should be changed to get user inputs
bk.FormatMedia = false;
bk.Initialize = false;
@@ -312,14 +317,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
{
}
}
-
-
- private ArrayList getBackupDestinationList()
- {
- //TODO: return the latest backup destination paths to show to UI dialog
- return null;
- }
-
+
private int GetDeviceType(string deviceName)
{
Enumerator en = new Enumerator();
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/DataContainer.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/DataContainer.cs
deleted file mode 100644
index a3f94386..00000000
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/DataContainer.cs
+++ /dev/null
@@ -1,2203 +0,0 @@
-//
-// 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.Collections;
-using System.Collections.Generic;
-using System.ComponentModel;
-//using System.Data;
-// using System.Drawing;
-using System.Globalization;
-using System.IO;
-using System.Reflection;
-using System.Security;
-using System.Xml;
-// using Microsoft.AnalysisServices;
-// using Microsoft.SqlServer.Common;
-using Microsoft.SqlServer.Management.Common;
-using Microsoft.SqlServer.Management.Diagnostics;
-using Microsoft.SqlServer.Management.Sdk.Sfc;
-using Microsoft.SqlServer.Management.Smo;
-// using Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer;
-using Assembly = System.Reflection.Assembly;
-using System.Xml.Linq;
-using Microsoft.Data.Tools.DataSets;
-//This is used only for non-express sku
-
-
-namespace Microsoft.SqlTools.ServiceLayer.Common
-{
- ///
- /// CDataContainer
- ///
- public class CDataContainer : IDisposable
- {
- #region Nested types
-
- public enum ServerType
- {
- SQL,
- OLAP, //This type is used only for non-express sku
- SQLCE,
- UNKNOWN
- }
-
- #endregion
-
- #region Fields
-
- private ServerConnection serverConnection;
- private Server m_server = null;
-
- //This member is used for non-express sku only
- // private AnalysisServices.Server m_amoServer = null;
- private ISandboxLoader sandboxLoader;
-
- //protected XDocument m_doc = null;
- protected XmlDocument m_doc = null;
- private XmlDocument originalDocument = null;
- private SqlOlapConnectionInfoBase connectionInfo = null;
- private SqlConnectionInfoWithConnection sqlCiWithConnection;
- private bool ownConnection = true;
- private IManagedConnection managedConnection;
- protected string serverName;
-
- //This member is used for non-express sku only
- protected string olapServerName;
-
- protected string sqlceFilename;
-
- private ServerType serverType = ServerType.UNKNOWN;
-
- private Hashtable m_hashTable = null;
-
- private string objectNameKey = "object-name-9524b5c1-e996-4119-a433-b5b947985566";
- private string objectSchemaKey = "object-schema-ccaf2efe-8fa3-4f62-be79-62ef3cbe7390";
-
- private SqlSmoObject sqlDialogSubject = null;
-
- private int sqlServerVersion = 0;
- private int sqlServerEffectiveVersion = 0;
-
-
- #endregion
-
- #region Public properties
-
- ///
- /// gets/sets XmlDocument with parameters
- ///
- public XmlDocument Document
- {
- get
- {
- return this.m_doc;
- }
- set
- {
- this.m_doc = value;
-
- if (value != null)
- {
- //this.originalDocument = (XmlDocument) value.Clone();
- this.originalDocument = value;
- }
- else
- {
- this.originalDocument = null;
- }
- }
- }
-
-
- ///
- /// returns the Hashtable that can be used to store generic information
- ///
- public Hashtable HashTable
- {
- get
- {
- if (m_hashTable == null)
- {
- m_hashTable = new Hashtable();
- }
-
- return m_hashTable;
- }
- }
-
-
- ///
- /// gets/sets SMO server object
- ///
- public Server Server
- {
- get
- {
- return m_server;
- }
- set
- {
- m_server = value;
- }
- }
-
- ///
- /// gets/sets AMO server object
- /// This member is used for non-express sku only
- ///
- //public AnalysisServices.Server OlapServer
- //{
- // get
- // {
- // return m_amoServer;
- // }
- // set
- // {
- // m_amoServer = value;
- // }
- //}
-
- public ISandboxLoader SandboxLoader
- {
- get { return this.sandboxLoader; }
- }
-
- ///
- /// connection info that should be used by the dialogs
- ///
- public SqlOlapConnectionInfoBase ConnectionInfo
- {
- get
- {
- //// update the database name in the serverconnection object to set the correct database context when connected to Azure
- //var conn = this.connectionInfo as SqlConnectionInfoWithConnection;
-
- //if (conn != null && conn.ServerConnection.DatabaseEngineType == DatabaseEngineType.SqlAzureDatabase)
- //{
- // if (this.RelevantDatabaseName != null)
- // {
- // IComparer dbNamesComparer = ServerConnection.ConnectionFactory.GetInstance(conn.ServerConnection).ServerComparer as IComparer;
- // if (dbNamesComparer.Compare(this.RelevantDatabaseName, conn.DatabaseName) != 0)
- // {
- // ServerConnection serverConnection = conn.ServerConnection.GetDatabaseConnection(this.RelevantDatabaseName, true, conn.AccessToken);
- // ((SqlConnectionInfoWithConnection)this.connectionInfo).ServerConnection = serverConnection;
- // }
- // }
- //}
-
- return this.connectionInfo;
- }
- }
-
- ///
- /// returns SMO server connection object constructed off the connectionInfo.
- /// This method cannot work until ConnectionInfo property has been set
- ///
- public ServerConnection ServerConnection
- {
- get
- {
- if (this.serverConnection == null)
- {
- if (this.serverType != ServerType.SQL)
- {
- throw new InvalidOperationException();
- }
-
- if (this.connectionInfo == null)
- {
- throw new InvalidOperationException();
- }
-
-
- if (this.sqlCiWithConnection != null)
- {
- this.serverConnection = this.sqlCiWithConnection.ServerConnection;
- }
- else
- {
- SqlConnectionInfo sci = this.connectionInfo as SqlConnectionInfo;
- this.serverConnection = new ServerConnection(sci);
- }
- }
-
-
- return this.serverConnection;
- }
- }
-
- ///
- /// returns SMO server connection object constructed off the connectionInfo.
- /// This method cannot work until ConnectionInfo property has been set
- ///
- public SqlConnectionInfoWithConnection SqlInfoWithConnection
- {
- get
- {
- if (this.serverConnection == null)
- {
- if (this.serverType != ServerType.SQL)
- {
- throw new InvalidOperationException();
- }
-
- if (this.connectionInfo == null)
- {
- throw new InvalidOperationException();
- }
-
-
- if (this.sqlCiWithConnection != null)
- {
- this.serverConnection = this.sqlCiWithConnection.ServerConnection;
- }
- else
- {
- SqlConnectionInfo sci = this.connectionInfo as SqlConnectionInfo;
- this.serverConnection = new ServerConnection(sci);
- }
- }
-
- return this.sqlCiWithConnection;
- }
- }
-
- public string ServerName
- {
- get
- {
- return this.serverName;
- }
- set
- {
- this.serverName = value;
- }
- }
-
- public ServerType ContainerServerType
- {
- get
- {
- return this.serverType;
- }
- set
- {
- this.serverType = value;
- }
- }
-
- public string SqlCeFileName
- {
- get
- {
- return this.sqlceFilename;
- }
- set
- {
- this.sqlceFilename = value;
- }
- }
-
- //This member is used for non-express sku only
- public string OlapServerName
- {
- get
- {
- return this.olapServerName;
- }
- set
- {
- this.olapServerName = value;
- }
- }
-
- ///
- /// Whether we are creating a new object
- ///
- public bool IsNewObject
- {
- get
- {
- string itemType = this.GetDocumentPropertyString("itemtype");
- return (itemType.Length != 0);
- }
- }
-
- ///
- /// The URN to the parent of the object we are creating/modifying
- ///
- public string ParentUrn
- {
- get
- {
- string result = String.Empty;
- string documentUrn = this.GetDocumentPropertyString("urn");
-
- if (this.IsNewObject)
- {
- result = documentUrn;
- }
- else
- {
- Urn urn = new Urn(documentUrn);
- result = urn.Parent.ToString();
- }
-
- return result;
- }
- }
-
- ///
- /// The URN to the object we are creating/modifying
- ///
- public string ObjectUrn
- {
- get
- {
- string result = String.Empty;
-
- if (this.IsNewObject)
- {
- string objectName = this.ObjectName;
- string objectSchema = this.ObjectSchema;
-
- if (0 == objectName.Length)
- {
- throw new InvalidOperationException("object name is not known, so URN for object can't be formed");
- }
-
- if (0 == objectSchema.Length)
- {
- result = String.Format(CultureInfo.InvariantCulture,
- "{0}/{1}[@Name='{2}']",
- this.ParentUrn,
- this.ObjectType,
- Urn.EscapeString(objectName));
- }
- else
- {
- result = String.Format(CultureInfo.InvariantCulture,
- "{0}/{1}[@Schema='{2}' and @Name='{3}']",
- this.ParentUrn,
- this.ObjectType,
- Urn.EscapeString(objectSchema),
- Urn.EscapeString(objectName));
- }
- }
- else
- {
- result = this.GetDocumentPropertyString("urn");
- }
-
- return result;
- }
- }
-
- ///
- /// The name of the object we are modifying
- ///
- public string ObjectName
- {
- get
- {
- return this.GetDocumentPropertyString(objectNameKey);
- }
-
- set
- {
- this.SetDocumentPropertyValue(objectNameKey, value);
- }
- }
-
- ///
- /// The schema of the object we are modifying
- ///
- public string ObjectSchema
- {
- get
- {
- return this.GetDocumentPropertyString(objectSchemaKey);
- }
-
- set
- {
- this.SetDocumentPropertyValue(objectSchemaKey, value);
- }
- }
-
- ///
- /// The type of the object we are creating (as it appears in URNs)
- ///
- public string ObjectType
- {
- get
- {
- // note that the itemtype property is only set for new objects
-
- string result = String.Empty;
- string itemtype = this.GetDocumentPropertyString("itemtype");
-
- // if this is not a new object
- if (0 == itemtype.Length)
- {
- string documentUrn = this.GetDocumentPropertyString("urn");
- Urn urn = new Urn(documentUrn);
-
- result = urn.Type;
- }
- else
- {
- result = itemtype;
- }
-
- return result;
- }
-
-
- }
-
- ///
- /// The SQL SMO object that is the subject of the dialog.
- ///
- public SqlSmoObject SqlDialogSubject
- {
- get
- {
- SqlSmoObject result = null;
-
- if (this.sqlDialogSubject != null)
- {
- result = this.sqlDialogSubject;
- }
- else
- {
- result = this.Server.GetSmoObject(this.ObjectUrn);
- }
-
- return result;
- }
-
- set
- {
- this.sqlDialogSubject = value;
- }
- }
-
- ///
- /// Whether the logged in user is a system administrator
- ///
- public bool LoggedInUserIsSysadmin
- {
- get
- {
- bool result = false;
-
- if (this.Server != null && this.Server.ConnectionContext != null)
- {
- result = this.Server.ConnectionContext.IsInFixedServerRole(FixedServerRoles.SysAdmin);
- }
-
- return result;
- }
- }
-
- ///
- /// Get the name of the Database that contains (or is) the subject of the dialog.
- /// If no there is no relevant database, then an empty string is returned.
- ///
- public string RelevantDatabaseName
- {
- get
- {
- string result = String.Empty;
- string urnText = this.GetDocumentPropertyString("urn");
-
- if (urnText.Length != 0)
- {
- Urn urn = new Urn(urnText);
-
- while ((urn != null) && (urn.Type != "Database"))
- {
- urn = urn.Parent;
- }
-
- if ((urn != null) && (urn.Type == "Database"))
- {
- result = urn.GetAttribute("Name");
- }
- }
-
- return result;
- }
- }
-
- ///
- /// The server major version number
- ///
- public int SqlServerVersion
- {
- get
- {
- if (this.sqlServerVersion == 0)
- {
- this.sqlServerVersion = 9;
-
- if ((this.ConnectionInfo != null) && (ServerType.SQL == this.ContainerServerType))
- {
- Enumerator enumerator = new Enumerator();
- Urn urn = "Server/Information";
- string[] fields = new string[] { "VersionMajor" };
- DataTable dataTable = enumerator.Process(this.ConnectionInfo, new Request(urn, fields));
-
- if (dataTable.Rows.Count != 0)
- {
- this.sqlServerVersion = (int)dataTable.Rows[0][0];
- }
- }
- }
-
- return this.sqlServerVersion;
- }
-
- }
-
- ///
- /// The server version the database is emulating. If database compatibility level is
- /// not relevant to the subject, then this just returns the actual server version.
- ///
- public int EffectiveSqlServerVersion
- {
- get
- {
- if (this.sqlServerEffectiveVersion == 0)
- {
- this.sqlServerEffectiveVersion = 9;
-
- if ((this.ConnectionInfo != null) && (ServerType.SQL == this.ContainerServerType))
- {
- string databaseName = this.RelevantDatabaseName;
-
- if (databaseName.Length != 0)
- {
- Enumerator enumerator = new Enumerator();
- Urn urn = String.Format("Server/Database[@Name='{0}']", Urn.EscapeString(databaseName));
- string[] fields = new string[] { "CompatibilityLevel" };
- DataTable dataTable = enumerator.Process(this.ConnectionInfo, new Request(urn, fields));
-
- if (dataTable.Rows.Count != 0)
- {
-
- CompatibilityLevel level = (CompatibilityLevel)dataTable.Rows[0][0];
-
- switch (level)
- {
- case CompatibilityLevel.Version60:
- case CompatibilityLevel.Version65:
-
- this.sqlServerEffectiveVersion = 6;
- break;
-
- case CompatibilityLevel.Version70:
-
- this.sqlServerEffectiveVersion = 7;
- break;
-
- case CompatibilityLevel.Version80:
-
- this.sqlServerEffectiveVersion = 8;
- break;
-
- case CompatibilityLevel.Version90:
-
- this.sqlServerEffectiveVersion = 9;
- break;
- case CompatibilityLevel.Version100:
-
- this.sqlServerEffectiveVersion = 10;
- break;
- case CompatibilityLevel.Version110:
-
- this.sqlServerEffectiveVersion = 11;
- break;
- case CompatibilityLevel.Version120:
-
- this.sqlServerEffectiveVersion = 12;
- break;
-
- case CompatibilityLevel.Version130:
- this.sqlServerEffectiveVersion = 13;
- break;
-
- case CompatibilityLevel.Version140:
- this.sqlServerEffectiveVersion = 14;
- break;
-
- default:
-
- this.sqlServerEffectiveVersion = 14;
- break;
- }
- }
- else
- {
- this.sqlServerEffectiveVersion = this.SqlServerVersion;
- }
- }
- else
- {
- this.sqlServerEffectiveVersion = this.SqlServerVersion;
- }
- }
- }
-
- return this.sqlServerEffectiveVersion;
- }
- }
-
- #endregion
-
- #region Constructors, finalizer
-
- public CDataContainer()
- {
- }
-
- ///
- /// contructs the object and initializes its SQL ConnectionInfo and ServerConnection properties
- /// using the specified connection info containing live connection.
- ///
- /// connection info containing live connection
- public CDataContainer(object ciObj, bool ownConnection)
- {
- SqlConnectionInfoWithConnection ci = (SqlConnectionInfoWithConnection)ciObj;
- if (ci == null)
- {
- throw new ArgumentNullException("ci");
- }
- ApplyConnectionInfo(ci, ownConnection);
- }
-
- ///
- /// contructs the object and initializes its SQL ConnectionInfo and ServerConnection properties
- /// using the specified connection info containing live connection.
- ///
- /// in addition creates a server of the given server type
- ///
- /// connection info containing live connection
- public CDataContainer(ServerType serverType, object ciObj, bool ownConnection)
- {
- SqlConnectionInfoWithConnection ci = (SqlConnectionInfoWithConnection)ciObj;
- if (ci == null)
- {
- throw new ArgumentNullException("ci");
- }
-
- this.serverType = serverType;
- ApplyConnectionInfo(ci, ownConnection);
-
- if (serverType == ServerType.SQL)
- {
- //NOTE: ServerConnection property will constuct the object if needed
- m_server = new Server(ServerConnection);
- }
- else
- {
- throw new ArgumentException("SRError.UnknownServerType(serverType.ToString()), serverType");
- }
- }
-
- ///
- /// Constructor
- ///
- /// Server type
- /// Server name
- /// true if connection is trused. If true user name and password are ignored
- /// User name for not trusted connections
- /// Password for not trusted connections
- /// XML string with parameters
- public CDataContainer(ServerType serverType, string serverName, bool trusted, string userName, SecureString password, string xmlParameters)
- {
- this.serverType = serverType;
- this.serverName = serverName;
-
- if (serverType == ServerType.SQL)
- {
- //does some extra initialization
- ApplyConnectionInfo(GetTempSqlConnectionInfoWithConnection(serverName, trusted, userName, password), true);
-
- //NOTE: ServerConnection property will constuct the object if needed
- m_server = new Server(ServerConnection);
- }
- else
- {
- throw new ArgumentException("SRError.UnknownServerType(serverType.ToString()), serverType");
- }
-
- if (xmlParameters != null)
- {
- this.Document = GenerateXmlDocumentFromString(xmlParameters);
- }
-
- if (ServerType.SQL == serverType)
- {
- this.InitializeObjectNameAndSchema();
- }
- }
-
- ///
- ///
- ///
- /// Data container
- /// XML string with parameters
- public CDataContainer(CDataContainer dataContainer, string xmlParameters)
- {
- Server = dataContainer.Server;
- this.serverName = dataContainer.serverName;
- this.serverType = dataContainer.serverType;
- this.connectionInfo = dataContainer.connectionInfo;
- this.ownConnection = dataContainer.ownConnection;
-
- this.sqlCiWithConnection = dataContainer.connectionInfo as SqlConnectionInfoWithConnection;
- if (this.sqlCiWithConnection != null)
- {
- //we want to be notified if it is closed
- this.sqlCiWithConnection.ConnectionClosed += new EventHandler(OnSqlConnectionClosed);
- }
-
- if (xmlParameters != null)
- {
- XmlDocument doc = GenerateXmlDocumentFromString(xmlParameters);
- this.Init(doc);
- }
- }
-
- ~CDataContainer()
- {
- Dispose(false);
- }
-
- #endregion
-
- #region Public virtual methods
-
- ///
- /// Initialization routine that is a convience fuction for clients with the data in a string
- ///
- /// The string that contains the xml data
- public virtual void Init(string xmlText)
- {
- XmlDocument xmlDoc = GenerateXmlDocumentFromString(xmlText);
-
- this.Init(xmlDoc);
- }
-
- ///
- /// Overload of basic Init which takes a IServiceProvider and initializes
- /// what it can of the container with elements provided by IServcieProvider
- ///
- /// Today this is only the IManagedProvider if available but this function
- /// could be modified to init other things provided by the ServiceProvider
- ///
- ///
- ///
- public virtual void Init(XmlDocument doc, IServiceProvider site)
- {
-
- if (site != null)
- {
- //see if service provider supports INodeInformation interface from the object explorer
- try
- {
- //NOTE: we're trying to forcefully set connection information on the data container.
- //If this code doesn't execute, then dc.Init call below will result in CDataContainer
- //initializing its ConnectionInfo member with a new object contructed off the parameters
- //in the XML doc [server name, user name etc]
- IManagedConnection managedConnection = site.GetService(typeof(IManagedConnection)) as IManagedConnection;
- if (managedConnection != null)
- {
- this.SetManagedConnection(managedConnection);
- }
- }
- catch (Exception ex)
- {
- // keep the exception flowing
- throw ex;
- }
- }
-
- this.Document = doc;
- LoadData();
-
- // finish the initialization
- this.Init(doc);
- }
-
-
- ///
- /// main initialization method - the object is unusable until this method is called
- /// NOTE: it will ensure the ConnectionInfo and ServerConnetion objects are constructed
- /// for the appropriate server types
- ///
- ///
- public virtual void Init(XmlDocument doc)
- {
- //First, we read the data from XML by calling LoadData
- this.Document = doc;
-
- LoadData();
-
- //Second, create the rignt server and connection objects
- if (this.serverType == ServerType.SQL)
- {
- //ensure that we have a valid ConnectionInfo
- if (ConnectionInfo == null)
- {
- throw new InvalidOperationException();
- }
-
- if (m_server == null)
- {
- //NOTE: ServerConnection property will constuct the object if needed
- m_server = new Server(ServerConnection);
- }
- }
- else if (this.serverType == ServerType.SQLCE)
- {
- // do nothing; originally we were only distinguishing between two
- // types of servers (OLAP/SQL); as a result for SQLCE we were
- // executing the same codepath as for OLAP server which was
- // resulting in an exception;
- }
- }
-
- ///
- /// loads data into internal members from the XML document and detects the server type
- /// [SQL, OLAP etc] based on the info in the XML doc
- ///
- public virtual void LoadData()
- {
- STParameters param;
- bool bStatus;
-
- param = new STParameters();
-
- param.SetDocument(m_doc);
-
- // DEVNOTE: chrisze 02/25/03
- // This is an ugly way to distinguish between different server types
- // Maybe we should pass server type as one of the parameters?
- //
- bStatus = param.GetParam("servername", ref this.serverName);
-
- if (!bStatus || this.serverName.Length == 0)
- {
-
- {
- bStatus = param.GetParam("database", ref this.sqlceFilename);
-
- if (bStatus && !String.IsNullOrEmpty(this.sqlceFilename))
- {
- this.serverType = ServerType.SQLCE;
- }
- else if (this.sqlCiWithConnection != null)
- {
- this.serverType = ServerType.SQL;
- }
- else
- {
- this.serverType = ServerType.UNKNOWN;
- }
- }
- }
- else
- {
- //OK, let's see if was specified in the parameters. It it was, use
- //it to double check that it is SQL
- string specifiedServerType = "";
- bStatus = param.GetParam("servertype", ref specifiedServerType);
- if (bStatus)
- {
- if (specifiedServerType != null && "sql" != specifiedServerType.ToLowerInvariant())
- {
- this.serverType = ServerType.UNKNOWN;//we know only about 3 types, and 2 of them were excluded by if branch above
- }
- else
- {
- this.serverType = ServerType.SQL;
- }
- }
- else
- {
- this.serverType = ServerType.SQL;
- }
- }
-
- // Ensure there is no password in the XML document
- string temp = String.Empty;
- if (param.GetParam("password", ref temp))
- {
- temp = null;
- throw new SecurityException();
- }
-
- if (ServerType.SQL == this.serverType)
- {
- this.InitializeObjectNameAndSchema();
- }
- }
-
- #endregion
-
- #region Public methods
-
- ///
- /// we need to store it as context from the OE
- ///
- ///
- internal void SetManagedConnection(IManagedConnection managedConnection)
- {
- this.managedConnection = managedConnection;
-
- ApplyConnectionInfo(managedConnection.Connection, true);//it will do some extra initialization
- }
-
- ///
- /// Get the named property value from the XML document
- ///
- /// The name of the property to get
- /// The property value
- public object GetDocumentPropertyValue(string propertyName)
- {
- object result = null;
- STParameters param = new STParameters(this.Document);
-
- param.GetBaseParam(propertyName, ref result);
-
- return result;
- }
-
- ///
- /// Get the named property value from the XML document
- ///
- /// The name of the property to get
- /// The property value
- public string GetDocumentPropertyString(string propertyName)
- {
- object result = GetDocumentPropertyValue(propertyName);
- if (result == null)
- {
- result = String.Empty;
- }
-
- return (string)result;
- }
-
- ///
- /// Set the named property value in the XML document
- ///
- /// The name of the property to set
- /// The property value
- public void SetDocumentPropertyValue(string propertyName, string propertyValue)
- {
- STParameters param = new STParameters(this.Document);
-
- param.SetParam(propertyName, propertyValue);
- }
-
- #endregion
-
- #region internal methods
-
- ///
- /// Reset the data container to its state from just after it was last initialized or reset
- ///
- internal void Reset()
- {
- if (this.originalDocument != null)
- {
- this.Init(this.originalDocument);
- }
-
- if (this.m_hashTable != null)
- {
- this.m_hashTable = new Hashtable();
- }
- }
-
-
- #endregion
-
- #region Private helpers
-
- ///
- /// Get the font size specified in the STParameters structure
- ///
- /// The structure from which to extract font data
- //private float GetFontSize(STParameters param)
- //{
- // float result = 8.0f;
- // string fontSize = String.Empty;
-
- // if (param.GetParam("fontsize", ref fontSize) && (0 != fontSize.Length))
- // {
- // result = Convert.ToSingle(fontSize, CultureInfo.InvariantCulture);
- // }
-
- // return result;
- //}
-
- ///
- /// Get the font style specified in the STParameters structure
- ///
- /// The structure from which to extract font data
- //private FontStyle GetFontStyle(STParameters param)
- //{
- // FontStyle style = FontStyle.Regular;
- // string fontStyle = String.Empty;
-
- // if (param.GetParam("fontstyle", ref fontStyle) && (0 != fontStyle.Length))
- // {
- // bool styleIsInitialized = false;
- // string fontStyleUpper = fontStyle.ToUpperInvariant();
-
- // if (-1 != fontStyleUpper.IndexOf("BOLD",StringComparison.Ordinal))
- // {
- // style = FontStyle.Bold;
- // styleIsInitialized = true;
- // }
-
- // if (-1 != fontStyleUpper.IndexOf("ITALIC",StringComparison.Ordinal))
- // {
- // if (styleIsInitialized)
- // {
- // style |= FontStyle.Italic;
- // }
- // else
- // {
- // style = FontStyle.Italic;
- // styleIsInitialized = true;
- // }
- // }
-
- // if (-1 != fontStyleUpper.IndexOf("REGULAR",StringComparison.Ordinal))
- // {
- // if (styleIsInitialized)
- // {
- // style |= FontStyle.Regular;
- // }
- // else
- // {
- // style = FontStyle.Regular;
- // styleIsInitialized = true;
- // }
- // }
-
- // if (-1 != fontStyleUpper.IndexOf("STRIKEOUT",StringComparison.Ordinal))
- // {
- // if (styleIsInitialized)
- // {
- // style |= FontStyle.Strikeout;
- // }
- // else
- // {
- // style = FontStyle.Strikeout;
- // styleIsInitialized = true;
- // }
- // }
-
- // if (-1 != fontStyleUpper.IndexOf("UNDERLINE",StringComparison.Ordinal))
- // {
- // if (styleIsInitialized)
- // {
- // style |= FontStyle.Underline;
- // }
- // else
- // {
- // style = FontStyle.Underline;
- // styleIsInitialized = true;
- // }
- // }
- // }
-
- // return style;
- //}
-
- ///
- /// Get the name and schema (if applicable) for the object we are referring to
- ///
- private void InitializeObjectNameAndSchema()
- {
- string documentUrn = this.GetDocumentPropertyString("urn");
-
- if (documentUrn.Length != 0)
- {
- Urn urn = new Urn(documentUrn);
- string name = urn.GetAttribute("Name");
- string schema = urn.GetAttribute("Schema");
-
- if ((name != null) && (name.Length != 0))
- {
- this.ObjectName = name;
- }
-
- if ((schema != null) && (schema.Length != 0))
- {
- this.ObjectSchema = schema;
- }
- }
- }
-
- ///
- /// returns SqlConnectionInfoWithConnection object constructed using our internal vars
- ///
- ///
- private SqlConnectionInfoWithConnection GetTempSqlConnectionInfoWithConnection(
- string serverName,
- bool trusted,
- string userName,
- SecureString password)
- {
- SqlConnectionInfoWithConnection tempCI = new SqlConnectionInfoWithConnection(serverName);
- tempCI.SingleConnection = false;
- tempCI.Pooled = false;
- //BUGBUG - set the right application name?
- if (trusted)
- {
- tempCI.UseIntegratedSecurity = true;
- }
- else
- {
- tempCI.UseIntegratedSecurity = false;
- tempCI.UserName = userName;
- tempCI.SecurePassword = password;
- }
-
- return tempCI;
- }
-
-
- ///
- /// our handler of sqlCiWithConnection.ConnectionClosed
- ///
- ///
- ///
- private void OnSqlConnectionClosed(object sender, EventArgs e)
- {
- //nothing - per MRaheem we'll let user deal with this situation
- }
-
- ///
- /// stores specified connection info and performs some extra initialization steps
- /// that can only be done after we have the connection information
- ///
- ///
- private void ApplyConnectionInfo(SqlOlapConnectionInfoBase ci, bool ownConnection)
- {
-
- this.connectionInfo = ci;
- this.ownConnection = ownConnection;
-
- //cache the cast value. It is OK that it is null for non SQL types
- this.sqlCiWithConnection = ci as SqlConnectionInfoWithConnection;
-
- if (this.sqlCiWithConnection != null)
- {
- //we want to be notified if it is closed
- this.sqlCiWithConnection.ConnectionClosed += new EventHandler(OnSqlConnectionClosed);
- }
- }
-
- /////
- ///// returns string that should be specified to AMO Server.Connect method
- ///// This member is used for non-express sku only
- /////
- /////
- //internal string OlapConnectionString
- //{
- // get
- // {
- // OlapConnectionInfo olapCi = this.ConnectionInfo as OlapConnectionInfo;
- // if (olapCi != null)
- // {
- // return olapCi.ConnectionString;
- // }
- // else
- // {
- // STrace.Assert(this.olapServerName != null);
- // return string.Format(CultureInfo.InvariantCulture, "Data Source={0}", this.olapServerName);
- // }
-
- // }
- //}
-
- private static bool MustRethrow(Exception exception)
- {
- bool result = false;
-
- switch (exception.GetType().Name)
- {
- case "ExecutionEngineException":
- case "OutOfMemoryException":
- case "AccessViolationException":
- case "BadImageFormatException":
- case "InvalidProgramException":
-
- result = true;
- break;
- }
-
- return result;
- }
-
- ///
- /// Generates an XmlDocument from a string, avoiding exploits available through
- /// DTDs
- ///
- ///
- ///
- private XmlDocument GenerateXmlDocumentFromString(string sourceXml)
- {
- if (sourceXml == null)
- {
- throw new ArgumentNullException("sourceXml");
- }
- if (sourceXml.Length == 0)
- {
- throw new ArgumentException("sourceXml");
- }
-
- MemoryStream memoryStream = new MemoryStream();
- StreamWriter streamWriter = new StreamWriter(memoryStream);
-
- // Writes the xml to the memory stream
- streamWriter.Write(sourceXml);
- streamWriter.Flush();
-
- // Resets the stream to the beginning
- memoryStream.Seek(0, SeekOrigin.Begin);
-
- // Creates the XML reader from the stream
- // and moves it to the correct node
- XmlReader xmlReader = XmlReader.Create(memoryStream);
- xmlReader.MoveToContent();
-
- // generate the xml document
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.PreserveWhitespace = true;
- xmlDocument.LoadXml(xmlReader.ReadOuterXml());
-
- return xmlDocument;
- }
-
- #endregion
-
- #region ICustomTypeDescriptor
-
- //AttributeCollection ICustomTypeDescriptor.GetAttributes()
- //{
- // return AttributeCollection.Empty;
- //}
-
- //string ICustomTypeDescriptor.GetClassName()
- //{
- // return TypeDescriptor.GetClassName(this, true);
- //}
-
- //string ICustomTypeDescriptor.GetComponentName()
- //{
- // return TypeDescriptor.GetComponentName(this, true);
- //}
-
- //TypeConverter ICustomTypeDescriptor.GetConverter()
- //{
- // return TypeDescriptor.GetConverter(GetType());
- //}
-
- //EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
- //{
- // return TypeDescriptor.GetDefaultEvent(GetType());
- //}
-
- //PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
- //{
- // return TypeDescriptor.GetDefaultProperty(GetType());
- //}
-
- //object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
- //{
- // return TypeDescriptor.GetEditor(GetType(), editorBaseType);
- //}
-
- //EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
- //{
- // return EventDescriptorCollection.Empty;
- //}
-
- //EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
- //{
- // return EventDescriptorCollection.Empty;
- //}
-
- //PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
- //{
- // return PropertyDescriptorCollection.Empty;
- //}
-
- //PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
- //{
- // PropertyDescriptorCollection propertyDescriptorCollection = new PropertyDescriptorCollection(null);
-
- // if (this.serverType == ServerType.SQL)
- // {
- // bool serverIsAvailable = false;
- // int queryTimeout = 30;
-
- // try
- // {
- // // five seconds should be plenty to determine the network name of the server
- // queryTimeout = this.m_server.ConnectionContext.StatementTimeout;
- // this.m_server.ConnectionContext.StatementTimeout = 5;
- // serverIsAvailable = this.m_server.Information.NetName != null;
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
- // }
- // finally
- // {
- // this.m_server.ConnectionContext.StatementTimeout = queryTimeout;
- // }
-
- // PropertyDescriptor propertyDescriptor;
- // /////////////////////////////ServerEnvironment////////////////////////////////
- // // Computer Name
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ? this.m_server.Information.NetName : SR.ServerIsUnavailable,
- // SR.ComputerName,
- // SR.ServerEnvironment,
- // SR.ComputerNameDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.ComputerName,
- // SR.ServerEnvironment,
- // SR.ComputerNameDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Platform
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // ((this.m_server.Information.Platform == null) ?
- // String.Empty :
- // this.m_server.Information.Platform) :
- // SR.ServerIsUnavailable,
- // SR.Platform,
- // SR.ServerEnvironment,
- // SR.PlatformDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.Platform,
- // SR.ServerEnvironment,
- // SR.PlatformDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Operating System
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ? this.m_server.Information.OSVersion : SR.ServerIsUnavailable,
- // SR.OperatingSystem,
- // SR.ServerEnvironment,
- // SR.OperatingSystemDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.OperatingSystem,
- // SR.ServerEnvironment,
- // SR.OperatingSystemDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Processors
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // this.m_server.Information.Processors.ToString() :
- // SR.ServerIsUnavailable,
- // SR.Processors,
- // SR.ServerEnvironment,
- // SR.ProcessorsDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.Processors,
- // SR.ServerEnvironment,
- // SR.ProcessorsDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Operating System Memory
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // this.m_server.Information.PhysicalMemory.ToString() :
- // SR.ServerIsUnavailable,
- // SR.OperatingSystemMemory,
- // SR.ServerEnvironment,
- // SR.OperatingSystemMemoryDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.OperatingSystemMemory,
- // SR.ServerEnvironment,
- // SR.OperatingSystemMemoryDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // /////////////////////////////ProductCategory////////////////////////////////
- // // Product Name
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // (this.m_server.Information.Product + " " + this.m_server.Information.Edition) :
- // SR.ServerIsUnavailable,
- // SR.ProductName,
- // SR.ProductCategory,
- // SR.ProductNameDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.ProductName,
- // SR.ProductCategory,
- // SR.ProductNameDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Product Version
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // (this.m_server.Information.Version + " " + this.m_server.Information.ProductLevel) :
- // SR.ServerIsUnavailable,
- // SR.ProductVersion,
- // SR.ProductCategory,
- // SR.ProductVersionDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.ProductVersion,
- // SR.ProductCategory,
- // SR.ProductVersionDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Server Name
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ? this.m_server.Name : SR.ServerIsUnavailable,
- // SR.ServerName,
- // SR.ProductCategory,
- // SR.ServerNameDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.ServerName,
- // SR.ProductCategory,
- // SR.ServerNameDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Instance Name
- // try
- // {
- // string instanceName = serverIsAvailable ? this.m_server.InstanceName : SR.ServerIsUnavailable;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (instanceName != null) ? instanceName : String.Empty,
- // SR.InstanceName,
- // SR.ProductCategory,
- // SR.InstanceNameDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.InstanceName,
- // SR.ProductCategory,
- // SR.InstanceNameDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Language
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ? this.m_server.Information.Language : SR.ServerIsUnavailable,
- // SR.Language,
- // SR.ProductCategory,
- // SR.LanguageDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.Language,
- // SR.ProductCategory,
- // SR.LanguageDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Collation
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ? this.m_server.Information.Collation : SR.ServerIsUnavailable,
- // SR.Collation,
- // SR.ProductCategory,
- // SR.CollationDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.Collation,
- // SR.ProductCategory,
- // SR.CollationDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // /////////////////////////////ConnectionCategory////////////////////////////////
- // // Database
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // this.m_server.ConnectionContext.SqlConnectionObject.Database :
- // SR.ServerIsUnavailable,
- // SR.Database,
- // SR.ConnectionCategory,
- // SR.DatabaseDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.Database,
- // SR.ConnectionCategory,
- // SR.DatabaseDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // SPID
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // this.m_server.ConnectionContext.ProcessID.ToString() :
- // SR.ServerIsUnavailable,
- // SR.Spid,
- // SR.ConnectionCategory,
- // SR.SpidDescription);
- // }
- // catch (InvalidCastException)
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // String.Empty,
- // SR.Spid,
- // SR.ConnectionCategory,
- // SR.SpidDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.Spid,
- // SR.ConnectionCategory,
- // SR.SpidDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Network Protocol
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // (this.m_server.ConnectionContext.NetworkProtocol == NetworkProtocol.NotSpecified ?
- // SR.Default :
- // this.m_server.ConnectionContext.NetworkProtocol.ToString()) :
- // SR.ServerIsUnavailable,
- // SR.NetworkProtocol,
- // SR.ConnectionCategory,
- // SR.NetworkProtocolDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.NetworkProtocol,
- // SR.ConnectionCategory,
- // SR.NetworkProtocolDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Network Packet Size
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // this.m_server.ConnectionContext.PacketSize.ToString() :
- // SR.ServerIsUnavailable,
- // SR.NetworkPacketSize,
- // SR.ConnectionCategory,
- // SR.NetworkPacketSizeDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.NetworkPacketSize,
- // SR.ConnectionCategory,
- // SR.NetworkPacketSizeDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Connect Timeout
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // this.m_server.ConnectionContext.ConnectTimeout.ToString() :
- // SR.ServerIsUnavailable,
- // SR.ConnectTimeout,
- // SR.ConnectionCategory,
- // SR.ConnectTimeoutDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.ConnectTimeout,
- // SR.ConnectionCategory,
- // SR.ConnectTimeoutDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Statement Timeout
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ?
- // this.m_server.ConnectionContext.StatementTimeout.ToString() :
- // SR.ServerIsUnavailable,
- // SR.StatementTimeout,
- // SR.ConnectionCategory,
- // SR.StatementTimeoutDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.StatementTimeout,
- // SR.ConnectionCategory,
- // SR.StatementTimeoutDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Encryption
- // try
- // {
- // string encryptAsString = SR.NoString;
-
- // if (serverIsAvailable)
- // {
- // if (this.m_server.ConnectionContext.EncryptConnection)
- // {
- // encryptAsString = SR.YesString;
- // }
- // }
- // else
- // {
- // encryptAsString = SR.ServerIsUnavailable;
- // }
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // encryptAsString,
- // SR.EncryptedConnection,
- // SR.ConnectionCategory,
- // SR.EncryptedConnectionDescription);
- // }
- // catch (InvalidCastException)
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // String.Empty,
- // SR.EncryptedConnection,
- // SR.ConnectionCategory,
- // SR.EncryptedConnectionDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.EncryptedConnection,
- // SR.ConnectionCategory,
- // SR.EncryptedConnectionDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // /////////////////////////////Authentication////////////////////////////////
- // // Authentication
- // try
- // {
- // string authenticationType;
-
- // if (!serverIsAvailable)
- // {
- // authenticationType = SR.ServerIsUnavailable;
- // }
- // else if (this.m_server.ConnectionContext.LoginSecure)
- // {
- // authenticationType = SR.WindowsAuthentication;
- // }
- // else
- // {
- // authenticationType = SR.SqlServerAuthentication;
- // }
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // authenticationType,
- // SR.AuthenticationMethod,
- // SR.AuthenticationCategory,
- // SR.AuthenticationMethodDescription);
-
- // }
- // catch (PropertyNotAvailableException e)
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message == null) ? String.Empty : e.Message,
- // SR.AuthenticationMethod,
- // SR.AuthenticationCategory,
- // SR.AuthenticationMethodDescription);
-
- // }
- // catch (Exception exception)
- // {
- // if (MustRethrow(exception))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (exception.Message != null) ? exception.Message : SR.ServerIsUnavailable,
- // SR.EncryptedConnection,
- // SR.ConnectionCategory,
- // SR.EncryptedConnectionDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // TrueLogin
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // serverIsAvailable ? this.m_server.ConnectionContext.TrueLogin : SR.ServerIsUnavailable,
- // SR.UserName,
- // SR.AuthenticationCategory,
- // SR.UserNameDescription);
- // }
- // catch (Exception e)
- // {
- // if (MustRethrow(e))
- // {
- // throw;
- // }
-
- // serverIsAvailable = false;
-
- // propertyDescriptor = new PropertyDescriptorWrapper(
- // (e.Message != null) ? e.Message : SR.ServerIsUnavailable,
- // SR.UserName,
- // SR.AuthenticationCategory,
- // SR.UserNameDescription);
- // }
-
- // propertyDescriptorCollection.Add(propertyDescriptor);
- // }
- // else if (!Utils.IsSsmsMinimalSet())
- // {
- // if (this.serverType == ServerType.OLAP)
- // {
- // PropertyDescriptor propertyDescriptor;
-
- // /////////////////////////////ServerEnvironment////////////////////////////////
-
- // /////////////////////////////ProductCategory////////////////////////////////
- // // Product Version
- // propertyDescriptor = new PropertyDescriptorWrapper(this.m_amoServer.Version, SR.ProductVersion, SR.ProductCategory, SR.ProductVersionDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
- // // Server Name
- // propertyDescriptor = new PropertyDescriptorWrapper(this.m_amoServer.Name, SR.ServerName, SR.ProductCategory, SR.ServerNameDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
- // // Language
- // int langAsInt = Convert.ToInt32(this.m_amoServer.ServerProperties[@"Language"].Value, CultureInfo.InvariantCulture);
- // if (langAsInt > 0)
- // {
- // try
- // {
- // propertyDescriptor = new PropertyDescriptorWrapper(new CultureInfo(langAsInt).ToString(), SR.Language, SR.ProductCategory, SR.LanguageDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
- // }
- // catch //eat it - CultureInfo might not be creatable from this ID
- // { }
- // }
- // // Collation
- // propertyDescriptor = new PropertyDescriptorWrapper(this.m_amoServer.ServerProperties[@"CollationName"].Value, SR.Collation, SR.ProductCategory, SR.CollationDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // /////////////////////////////ConnectionCategory////////////////////////////////
- // // Database
- // propertyDescriptor = new PropertyDescriptorWrapper(this.ConnectionInfo.DatabaseName, SR.Database, SR.ConnectionCategory, SR.DatabaseDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
- // // Connect Timeout
- // propertyDescriptor = new PropertyDescriptorWrapper(this.ConnectionInfo.ConnectionTimeout, SR.ConnectTimeout, SR.ConnectionCategory, SR.ConnectTimeoutDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
- // // Execution Timeout
- // propertyDescriptor = new PropertyDescriptorWrapper(this.ConnectionInfo.QueryTimeout, SR.StatementTimeout, SR.ConnectionCategory, SR.StatementTimeoutDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // //whether connection is encrypted or not
- // OlapConnectionInfo olapCi = this.ConnectionInfo as OlapConnectionInfo;
- // if (olapCi != null)
- // {
- // string encryptAsString = SR.NoString;
- // if (olapCi.EncryptConnection)
- // {
- // encryptAsString = SR.YesString;
- // }
- // propertyDescriptor = new PropertyDescriptorWrapper(encryptAsString, SR.EncryptedConnection, SR.ConnectionCategory, SR.EncryptedConnectionDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
- // }
-
- // // Authentication
- // if (this.ConnectionInfo.UseIntegratedSecurity)
- // propertyDescriptor = new PropertyDescriptorWrapper(SR.WindowsAuthentication, SR.AuthenticationMethod, SR.AuthenticationCategory, SR.AuthenticationMethodDescription);
- // else
- // propertyDescriptor = new PropertyDescriptorWrapper(SR.SqlServerAuthentication, SR.AuthenticationMethod, SR.AuthenticationCategory, SR.AuthenticationMethodDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
- // // TrueLogin
- // propertyDescriptor = new PropertyDescriptorWrapper(this.ConnectionInfo.UserName, SR.UserName, SR.AuthenticationCategory, SR.UserNameDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
- // }
- // else if (this.serverType == ServerType.SQLCE)
- // {
- // PropertyDescriptor propertyDescriptor;
-
- // // Create an instance of SQLCE engine through reflection
- // //
- // Assembly asm = SfcUtility.LoadSqlCeAssembly(
- // "Microsoft.SqlServerCe.Client.dll");
- // Type type = asm.GetType("Microsoft.SqlServerCe.Client.SqlCeEngine", true);
-
- // // Create SqlCeEngine instance
- // //
- // ConstructorInfo constructor = type.GetConstructor(new Type[] { });
- // object instance = constructor.Invoke(new object[] { });
-
- // // Call GetDatabaseProperties
- // //
- // Type[] types = { typeof(String) };
- // MethodInfo mi = type.GetMethod("GetDatabaseProperties", types);
-
- // instance = mi.Invoke(instance, new object[] { SqlCeFileName });
-
- // // Call the accessors on the DatabaseProperties class
- // //
- // type = asm.GetType("Microsoft.SqlServerCe.Client.DatabaseProperties", true);
-
- // PropertyInfo pi = type.GetProperty("Platform");
- // string platform = (string)pi.GetValue(instance, new object[] { });
-
- // pi = type.GetProperty("OSVersion");
- // string osVersion = (string)pi.GetValue(instance, new object[] { });
-
- // pi = type.GetProperty("Version");
- // string sqlCeVersion = (string)pi.GetValue(instance, new object[] { });
-
- // pi = type.GetProperty("ClrVersion");
- // string clrVersion = (string)pi.GetValue(instance, new object[] { });
-
- // // Platform
- // propertyDescriptor = new PropertyDescriptorWrapper(platform, SR.Platform, SR.ServerEnvironment, SR.PlatformDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Operating System
- // propertyDescriptor = new PropertyDescriptorWrapper(osVersion, SR.OperatingSystem, SR.ServerEnvironment, SR.OperatingSystemDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // CLR version
- // propertyDescriptor = new PropertyDescriptorWrapper(clrVersion, SR.ClrVersion, SR.ServerEnvironment, SR.ClrVersionDescription);
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Product Name
- // propertyDescriptor = new PropertyDescriptorWrapper(SR.SqlServerCeName, SR.ProductName, SR.ProductCategory, SR.ProductNameDescriptionCE);
- // propertyDescriptorCollection.Add(propertyDescriptor);
-
- // // Product Version
- // propertyDescriptor = new PropertyDescriptorWrapper(sqlCeVersion, SR.ProductVersion, SR.ProductCategory, SR.ProductVersionDescriptionCE);
- // propertyDescriptorCollection.Add(propertyDescriptor);
- // }
- // }
- // return propertyDescriptorCollection;
- //}
-
- //object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
- //{
- // return this;
- //}
-
- #endregion
-
- #region IDisposable
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- ///
- /// MUST be called, as we'll be closing SQL connection inside this call
- ///
- private void Dispose(bool disposing)
- {
- try
- {
- //take care of live SQL connection
- if (this.sqlCiWithConnection != null)
- {
- this.sqlCiWithConnection.ConnectionClosed -= new EventHandler(OnSqlConnectionClosed);
-
- if (disposing)
- {
- //if we have the managed connection interface, then use it to disconnect.
- //Otherwise, Dispose on SqlConnectionInfoWithConnection should disconnect
- if (this.managedConnection != null)
- {
- //in this case we have gotten sqlCiWithConnection as this.managedConnection.Connection
- if (this.ownConnection)
- {
- this.managedConnection.Close();
- }
- this.managedConnection = null;
- }
- else
- {
- if (this.ownConnection)
- {
- this.sqlCiWithConnection.Dispose();//internally will decide whether to disconnect or not
- }
- }
- this.sqlCiWithConnection = null;
- }
- else
- {
- this.managedConnection = null;
- this.sqlCiWithConnection = null;
- }
- }
- else if (this.managedConnection != null)
- {
- if (disposing && this.ownConnection)
- {
- this.managedConnection.Close();
- }
- this.managedConnection = null;
- }
- }
- catch (Exception exToEat)
- {
- }
- }
-
- #endregion
- }
-}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/IManagedConnection.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/IManagedConnection.cs
deleted file mode 100644
index 492ad54e..00000000
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/IManagedConnection.cs
+++ /dev/null
@@ -1,198 +0,0 @@
-using System;
-using System.Collections;
-using Microsoft.SqlServer.Management.Common;
-using Microsoft.SqlServer.Management.Diagnostics;
-
-namespace Microsoft.SqlTools.ServiceLayer.Common
-{
-
- ///
- /// Provides connection and enumerator context for a node
- ///
- public interface IManagedConnection : IDisposable
- {
- ///
- /// Connection information.
- ///
- SqlOlapConnectionInfoBase Connection
- {
- get;
- }
-
- ///
- /// Free any resources for this connection
- ///
- void Close();
- }
-
- ///
- /// interface used by the objectexplorer. Allows us to "pool" the main connection
- ///
- internal interface IManagedConnection2 : IManagedConnection
- {
- }
-
- ///
- /// Implementation of IManagedConnection. Allows the use of a direct or indirect connection
- /// in the object explorer that takes care of the connection.
- ///
- internal class ManagedConnection : IManagedConnection2
- {
- #region private members
- private bool connectionAddedToActiveConnections = false;
- private bool closeOnDispose = false;
- private SqlOlapConnectionInfoBase connection;
- private bool closed = false;
- #endregion
-
- #region Construction
- ///
- /// Create a new managed connection
- ///
- /// connection wish to manage
- public ManagedConnection(SqlOlapConnectionInfoBase connection)
- : this(connection, false)
- {
- }
- ///
- /// create a new managed connection.
- ///
- /// connection
- /// true if we are going to try and reuse the
- /// connection if possible
- public ManagedConnection(SqlOlapConnectionInfoBase sourceConnection, bool attemptToPool)
- {
- // parameter check
- if (sourceConnection == null)
- {
- throw new ArgumentNullException("sourceConnection");
- }
-
- // see if the connection can restrict access (single user mode)
- IRestrictedAccess access = sourceConnection as IRestrictedAccess;
- // see if it is cloneable
- ICloneable cloneable = sourceConnection as ICloneable;
- lock (ActiveConnections)
- {
- // if it's not single user mode then we can see if the object can be cloned
- if (access == null || access.SingleConnection == false)
- {
- // if we are going to attempt to pool, see if the connection is in use
- if (attemptToPool && !ActiveConnections.Contains(SharedConnectionUtil.GetConnectionKeyName(sourceConnection)))
- {
- // add it to the hashtable to indicate use.
- ActiveConnections.Add(SharedConnectionUtil.GetConnectionKeyName(sourceConnection), sourceConnection);
- this.connection = sourceConnection;
- this.closeOnDispose = false;
- this.connectionAddedToActiveConnections = true;
- }
- else if (cloneable != null)
- {
- this.connection = (SqlOlapConnectionInfoBase)cloneable.Clone();
- this.closeOnDispose = true;
- }
- else if (sourceConnection is SqlConnectionInfoWithConnection)
- {
- this.connection = ((SqlConnectionInfoWithConnection)sourceConnection).Copy();
- this.closeOnDispose = true;
- }
- }
- }
- // if everything else has failed just use to passed in connection.
- if (this.connection == null)
- {
- this.connection = sourceConnection;
- }
-
- // always set the lock timeout to prevent the shell from not responding
- if (this.connection is SqlConnectionInfoWithConnection)
- {
- // set lock_timeout to 10 seconds
- ((SqlConnectionInfoWithConnection)this.connection).ServerConnection.LockTimeout = 10;
- }
- }
- #endregion
-
- #region IDisposable implementation
- public void Dispose()
- {
- Close();
- }
- #endregion
-
- #region IManagedConnection implementation
- ///
- /// Connection
- ///
- public SqlOlapConnectionInfoBase Connection
- {
- get
- {
- return this.connection;
- }
- }
-
- ///
- /// Close the current connection if applicable.
- ///
- public void Close()
- {
- if (this.closed)
- return;
-
- if (this.closeOnDispose)
- {
- IDisposable disp = this.connection as IDisposable;
- if (disp != null)
- {
- disp.Dispose();
- }
- }
- else
- {
- // if we are not closing the connection and it is a sql connection then ensure it
- // is left in the master database.
- SqlConnectionInfoWithConnection sqlConnection = this.connection as SqlConnectionInfoWithConnection;
- if (sqlConnection != null && sqlConnection.ServerConnection.DatabaseEngineType == DatabaseEngineType.Standalone)
- {
- try
- {
- sqlConnection.ServerConnection.ExecuteNonQuery("use [master]");
- }
- // don't error if this fails
- catch
- { }
- }
- }
- if (this.connectionAddedToActiveConnections)
- {
- lock (ActiveConnections)
- {
- ActiveConnections.Remove(SharedConnectionUtil.GetConnectionKeyName(connection));
- }
- }
-
- this.connection = null;
- this.closed = true;
- }
- #endregion
-
- #region static helpers
- ///
- /// hashtable we use to keep track of actively used main connections
- ///
- private static Hashtable activeConnections = null;
- private Hashtable ActiveConnections
- {
- get
- {
- if (activeConnections == null)
- {
- activeConnections = new Hashtable();
- }
- return activeConnections;
- }
- }
- #endregion
- }
-}
\ No newline at end of file
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/ISandboxLoader.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/ISandboxLoader.cs
deleted file mode 100644
index b7d2adf1..00000000
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/ISandboxLoader.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information.
-//
-
-using System;
-
-namespace Microsoft.SqlTools.ServiceLayer.Common
-{
- ///
- /// To access DataModelingSandbox from NavigableItem
- ///
- public interface ISandboxLoader
- {
- ///
- /// Get sandbox
- ///
- /// DataModelingSandbox object associated with this NavigableItem
- object GetSandbox();
-
- ///
- /// Refresh sandbox data associated with this NavigableItem
- ///
- void RefreshSandboxData();
-
- ///
- /// Delete sandbox from cache
- ///
- void DeleteSandbox();
- }
-}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/STParameters.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/STParameters.cs
deleted file mode 100644
index fc9f0488..00000000
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/STParameters.cs
+++ /dev/null
@@ -1,488 +0,0 @@
-//
-// 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.Xml;
-using System.Collections;
-using System.Diagnostics;
-
-namespace Microsoft.SqlTools.ServiceLayer.Common
-{
- ///
- /// SqlTools Parameters, used to define what goes into starting up a Workbench Form
- /// AKA a dbCommander, AKA a "dialog"
- /// These parameters are xml snippets
- ///
- public class STParameters
- {
- public XmlDocument m_doc;
-
- ///
- /// The data type we are interested in
- ///
- public enum STType { eNULL, eInt, eLong, eString };
-
- ///
- /// default constructor
- ///
- public STParameters()
- {
- //
- // TODO: Add constructor logic here
- //
- }
-
- ///
- /// Constructor
- ///
- /// The xml snippet used to control the dbCommander
- public STParameters(XmlDocument xmlDoc)
- {
- m_doc = xmlDoc;
- }
-
- ///
- /// Changing the xml snippet we are using
- ///
- /// the new xml snippet
- public void SetDocument(XmlDocument xmlDoc)
- {
- m_doc = xmlDoc;
- }
-
- ///
- /// Access to the xml we are using for dbCommander parameters
- ///
- /// our current parameters
- public XmlDocument GetDocument()
- {
- return m_doc;
- }
-
- ///
- /// Search for an xml tag, and return its value
- ///
- /// the xml tag name
- /// the value of that tag
- /// flag that is true if the data was found, false if not
- public bool GetBaseParam(string parameterName, ref object value)
- {
- XmlNodeList nodeList = null;
- bool parameterExists;
-
- if (m_doc == null)
- return false;
-
- parameterExists = false;
- nodeList = m_doc.GetElementsByTagName(parameterName);
-
- if (nodeList.Count > 1)
- {
- value = null;
- }
- else if (nodeList.Count != 0) // anything there?
- {
- try
- {
- XmlNode node = nodeList.Item(0);
- if (null != node)
- {
- value = node.InnerText as object;
- parameterExists = true;
- }
- }
- catch (Exception /*e*/)
- {
- }
-
- }
-
- return parameterExists;
- }
-
- ///
- /// Finds an existing xml tag, and sets it to a new value, or if the tag is not found
- /// create it and set it's value
- ///
- /// tag name
- /// new value
- /// flag that is true if the tag was set, false if not
- public bool SetBaseParam(string parameterName, object value)
- {
- XmlNodeList nodeList;
- bool success = false;
-
- nodeList = m_doc.GetElementsByTagName(parameterName);
-
- if (nodeList.Count == 1)
- {
- try
- {
- nodeList.Item(0).InnerText = (string)value;
- success = true;
- }
- catch (InvalidCastException /*e*/)
- {
- success = false;
- }
-
- }
-
- if (nodeList.Count == 0)
- {
- try
- {
- XmlElement xmlElement = m_doc.CreateElement(parameterName);
- XmlNode root = m_doc.DocumentElement;
-
- nodeList = m_doc.GetElementsByTagName("params");
-
- if (nodeList.Count == 1 && value is string)
- {
- xmlElement.InnerText = (string)value;
- nodeList.Item(0).InsertAfter(xmlElement, nodeList.Item(0).LastChild);
-
- success = true;
- }
- }
- catch (Exception e)
- {
- string sz = e.ToString();
- success = false;
- }
-
- }
-
- return success;
-
- }
-
- ///
- /// Get back an interger parameter.
- /// NOTE: if the tag exists, but it contains non-numeric data, this will throw
- /// An exception of type 'System.FormatException'
- /// with Additional information: Could not find any parsible digits.
- ///
- /// xml tag name for the parameter of interest
- /// out value of parameter
- /// flag that is true if the data was found, false if not
- public bool GetParam(string parameterName, out int value)
- {
- bool parameterExists = false;
-
- value = 0;
-
- try
- {
- object oAux = null;
-
- if (parameterExists = GetBaseParam(parameterName, ref oAux))
- {
- try
- {
- value = Convert.ToInt32((string)oAux, 10); // data is always a string, it is the value of XmlNode.InnerText
- }
- catch (FormatException e)
- {
- Debug.WriteLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, "Non numeric data in tag: {0}", parameterName));
- Debug.WriteLine(e.Message);
- throw;
- }
- }
- }
- catch (InvalidCastException /*e*/)
- {
- }
-
- return parameterExists;
- }
-
- ///
- /// Accessor for a boolean parameter
- /// NOTE: if the tag exists, but it contains non-numeric data, this will throw
- /// An exception of type 'System.FormatException'
- /// with Additional information: Could not find any parsible digits.
- ///
- /// xml tag name for the parameter of interest
- /// out value of parameter
- /// flag that is true if the data was found, false if not
- public bool GetParam(string parameterName, ref bool value)
- {
- bool parameterExists = false;
-
- value = false;
-
- try
- {
- object oAux = null;
- if (parameterExists = GetBaseParam(parameterName, ref oAux))
- {
- try
- {
- value = Convert.ToBoolean((string)oAux, System.Globalization.CultureInfo.InvariantCulture); // data is always a string, it is the value of XmlNode.InnerText
- }
- catch (FormatException e)
- {
- Debug.WriteLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, "Non boolean data in tag: {0}", parameterName));
- Debug.WriteLine(e.Message);
- throw;
- }
- }
- }
- catch (InvalidCastException /*e*/)
- {
- }
-
- return parameterExists;
- }
-
- ///
- /// Accessor to a string parameter
- ///
- /// xml tag name for the parameter of interest
- /// out value of parameter
- /// flag that is true if the data was found, false if not
- public bool GetParam(string parameterName, ref string value)
- {
- bool parameterExists;
-
- value = "";
- parameterExists = false;
-
- try
- {
- object oAux = null;
-
- if (parameterExists = GetBaseParam(parameterName, ref oAux))
- {
- value = (string)oAux;
- }
- }
- catch (InvalidCastException /*e*/)
- {
- }
-
- return parameterExists;
-
- }
-
- ///
- /// Accessor to long parameter (Int64)
- /// NOTE: if the tag exists, but it contains non-numeric data, this will throw
- /// An exception of type 'System.FormatException'
- /// with Additional information: Could not find any parsible digits.
- ///
- /// xml tag name for the parameter of interest
- /// out value of parameter
- /// flag that is true if the data was found, false if not
- public bool GetParam(string parameterName, out long value)
- {
- bool parameterExists = false;
-
- value = 0;
-
- try
- {
- object oAux = null;
-
- if (parameterExists = GetBaseParam(parameterName, ref oAux))
- {
- try
- {
- value = Convert.ToInt64((string)oAux, 10); // data is always a string, it is the value of XmlNode.InnerText
- }
- catch (FormatException e)
- {
- Debug.WriteLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, "Non numeric data in tag: {0}", parameterName));
- Debug.WriteLine(e.Message);
- throw;
- }
- }
- }
- catch (InvalidCastException /*e*/)
- {
- }
-
- return parameterExists;
-
- }
-
-
- ///
- /// Set an int (Int32) parameter
- ///
- /// tag name for parameter
- /// integer value
- /// true if set was successful, false if not
- public bool SetParam(string parameterName, int value)
- {
- bool success;
-
- success = SetBaseParam(parameterName, (object)value);
-
- return success;
-
- }
-
- ///
- /// Set a string parameter
- ///
- /// tag name for parameter
- /// string value
- /// true if set was successful, false if not
- public bool SetParam(string parameterName, string value)
- {
- bool success;
-
- success = SetBaseParam(parameterName, (object)value);
-
- return success;
-
- }
-
- ///
- /// Set a long (Int64) parameter
- ///
- /// tag name for parameter
- /// long value
- /// true if set was successful, false if not
- public bool SetParam(string parameterName, long value)
- {
- bool success;
-
- success = SetBaseParam(parameterName, (object)value);
-
- return success;
-
- }
-
- ///
- /// Get a string collection parameter
- ///
- /// name of collection
- /// collection that gets filled up with parameters
- /// true if we want to get at inner nodes, false if not
- /// true if parameter(s) exist
- public bool GetParam(string parameterName, System.Collections.Specialized.StringCollection list, bool getInnerXml)
- {
- /// necessary for OALP objects path that is in an XML form
- if (true == getInnerXml)
- {
- XmlNodeList nodeList;
- bool parameterExists;
- long lCount;
-
- parameterExists = false;
- nodeList = m_doc.GetElementsByTagName(parameterName);
-
- list.Clear();
-
- lCount = nodeList.Count;
-
- if (lCount > 0)
- {
- parameterExists = true;
-
- for (long i = 0; i < lCount; i++)
- {
- list.Add(nodeList.Item((int)i).InnerXml);
- }
- }
- else
- {
- parameterExists = false;
- }
-
- return parameterExists;
- }
- else
- {
- return GetParam(parameterName, list);
- }
- }
-
- ///
- /// Access to a collection of parameters
- ///
- /// name of collection
- /// list to fill with parameters
- /// parameter(s) exist
- public bool GetParam(string parameterName, System.Collections.Specialized.StringCollection list)
- {
- XmlNodeList nodeList;
- bool parameterExists;
- long lCount;
-
- parameterExists = false;
- nodeList = m_doc.GetElementsByTagName(parameterName);
-
- list.Clear();
-
- lCount = nodeList.Count;
-
- if (lCount > 0)
- {
- parameterExists = true;
-
- for (long i = 0; i < lCount; i++)
- {
- list.Add(nodeList.Item((int)i).InnerText);
- }
- }
- else
- {
- parameterExists = false;
- }
-
- return parameterExists;
- }
-
- public bool GetParam(string parameterName, ref ArrayList list)
- {
- System.Collections.Specialized.StringCollection stringList = new System.Collections.Specialized.StringCollection();
- bool parameterExists = GetParam(parameterName, stringList);
- list.Clear();
- if (!parameterExists)
- {
- return false;
- }
- else
- {
- for (int i = 0; i < stringList.Count; i++)
- {
- list.Add(stringList[i]);
- }
- return true;
- }
- }
-
- ///
- /// This function does nothing but return false
- ///
- /// ignored
- /// ignored
- /// always false
- public bool GetParamType(string parameterName, STType type)
- {
- bool whatever = false;
-
- return whatever;
- }
-
- ///
- /// This function does nothing but return false
- ///
- /// ignored
- /// ignored
- /// always false
- public bool SetParamType(string parameterName, STType type)
- {
- bool whatever = false;
-
- return whatever;
- }
-
- }
-}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/SharedConnectionUtil.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/SharedConnectionUtil.cs
deleted file mode 100644
index cef590d5..00000000
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Common/SharedConnectionUtil.cs
+++ /dev/null
@@ -1,108 +0,0 @@
-//
-// 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 Microsoft.SqlServer.Management.AzureCredential;
-using Microsoft.SqlServer.Management.Common;
-//using Microsoft.SqlServer.Management.Smo.RegSvrEnum;
-using SFC = Microsoft.SqlServer.Management.Sdk.Sfc;
-//using Microsoft.SqlServer.StorageClient;
-//using Microsoft.SqlServer.Management.SqlMgmt;
-
-///
-/// Summary description for SharedConectionUtil
-/// Moved GetConnectionName static call in a public class acessible for both
-/// OEXM and OE
-///
-namespace Microsoft.SqlTools.ServiceLayer.Common
-{
- internal class SharedConnectionUtil
- {
- public SharedConnectionUtil()
- {
- }
-
- ///
- ///
- ///
- ///
- ///
- public static string GetConnectionKeyName(SqlOlapConnectionInfoBase ci)
- {
-
- //// Note that these strings are not localized. The returned string is used by OE in a
- //// hash of connections so it can tell if it already has such a connection open. This
- //// string is never seen by the user. For the string seen by the user, see
- //// ServerNameHandler.cs.
- string displayName = String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} (", ci.ServerName);
-
- if (!string.IsNullOrEmpty(ci.DatabaseName))
- {
- displayName += ", " + ci.DatabaseName;
- }
-
- return displayName;
-
- //switch (ci.ServerType)
- //{
- // case ConnectionType.AzureStorage:
- // AzureStorageConnectionInfo azureCI = ci as AzureStorageConnectionInfo;
- // displayName = "AzureStorage," + azureCI.BlobClient.BaseUri;
- // break;
- // case ConnectionType.AzureAccount:
- // if (ci is CertificateBasedAuthenticationInfo)
- // {
- // displayName = "AzureSubscription," + (ci as CertificateBasedAuthenticationInfo).SubscriptionId;
- // }
- // else
- // {
- // displayName = "AzureSubscription";
- // }
- // break;
- // case ConnectionType.Sql:
- // displayName += "SQLServer";
- // SqlConnectionInfo sqlCi = ci as SqlConnectionInfo;
- // if (sqlCi.UseIntegratedSecurity == true)
- // {
- // displayName += ", trusted";
- // }
- // else
- // {
- // displayName += String.Format(System.Globalization.CultureInfo.InvariantCulture, ", user = {0}", sqlCi.UserName);
- // //In Cloud a user can have access to only a few UDBs without access to master DB
- // // and hence need to show different OE hierarchy trees for each DB
- // //Same is the case with a contained user.
-
-
- // if (ServerInfoCache.GetDatabaseEngineType(ci.ServerName) == DatabaseEngineType.SqlAzureDatabase
- // || SFC.ExecuteSql.GetDatabaseEngineType(ci) == DatabaseEngineType.SqlAzureDatabase
- // || SFC.ExecuteSql.IsContainedAuthentication(ci))
- // {
- // if (!string.IsNullOrEmpty(ci.DatabaseName))
- // {
- // displayName += ", " + ci.DatabaseName;
- // }
- // }
- // }
- // break;
- // case ConnectionType.Olap:
- // displayName += "OLAP";
- // break;
- // case ConnectionType.SqlCE:
- // displayName += "SqlCE";
- // break;
- // case ConnectionType.ReportServer:
- // displayName += "Rs";
- // displayName += String.Format(System.Globalization.CultureInfo.InvariantCulture, ", connection = {0}", ci.ConnectionString);
- // break;
- // case ConnectionType.IntegrationServer:
- // displayName += "SSIS";
- // break;
- //}
- //displayName += ")";
- //return displayName;
- }
- }
-}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupRestoreUtil.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/CommonUtilities.cs
similarity index 98%
rename from src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupRestoreUtil.cs
rename to src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/CommonUtilities.cs
index a261eee0..7f05d899 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/BackupRestoreUtil.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/CommonUtilities.cs
@@ -5,12 +5,14 @@
using System;
using System.Collections;
+using System.Collections.Generic;
using Microsoft.Data.Tools.DataSets;
using Microsoft.SqlServer.Management.Common;
-using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Sdk.Sfc;
+using Microsoft.SqlServer.Management.Smo;
using SMO = Microsoft.SqlServer.Management.Smo;
-using Microsoft.SqlTools.ServiceLayer.Common;
+using Microsoft.SqlTools.ServiceLayer.Admin;
+
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
{
@@ -74,15 +76,15 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
}
///
- /// Summary description for SqlBackupRestoreBase.
+ /// Common methods used for backup and restore
///
- public class BackupRestoreUtil
+ public class CommonUtilities
{
private CDataContainer DataContainer;
private ServerConnection SqlConnection = null;
private ArrayList ExcludedDbs;
- public BackupRestoreUtil(CDataContainer dataContainer, ServerConnection sqlConnection)
+ public CommonUtilities(CDataContainer dataContainer, ServerConnection sqlConnection)
{
DataContainer = dataContainer;
this.SqlConnection = sqlConnection;
@@ -986,9 +988,9 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
}
- public ArrayList GetLatestBackupLocations(string DatabaseName)
+ public List GetLatestBackupLocations(string DatabaseName)
{
- ArrayList LatestLocations = new ArrayList();
+ List LatestLocations = new List();
Enumerator en = null;
DataSet ds = new DataSet();
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Contracts/BackupConfigInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Contracts/BackupConfigInfo.cs
new file mode 100644
index 00000000..fbee8538
--- /dev/null
+++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Contracts/BackupConfigInfo.cs
@@ -0,0 +1,25 @@
+//
+// 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;
+using System.Collections.Generic;
+using Microsoft.SqlTools.ServiceLayer.Admin.Contracts;
+
+namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
+{
+ ///
+ /// Provides database info for backup.
+ ///
+ public class BackupConfigInfo
+ {
+ public DatabaseInfo DatabaseInfo { get; set; }
+ public string RecoveryModel { get; set; }
+ public List LatestBackups { get; set; }
+ public string DefaultBackupFolder { get; set; }
+
+ public BackupConfigInfo()
+ {
+ }
+ }
+}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Contracts/BackupConfigInfoRequest.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Contracts/BackupConfigInfoRequest.cs
new file mode 100644
index 00000000..353b85c7
--- /dev/null
+++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Contracts/BackupConfigInfoRequest.cs
@@ -0,0 +1,22 @@
+//
+// 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;
+using Microsoft.SqlTools.ServiceLayer.Admin.Contracts;
+
+namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
+{
+
+ public class BackupConfigInfoResponse
+ {
+ public BackupConfigInfo BackupConfigInfo { get; set; }
+ }
+
+ public class BackupConfigInfoRequest
+ {
+ public static readonly
+ RequestType Type =
+ RequestType.Create("disasterrecovery/backupconfiginfo");
+ }
+}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Contracts/BackupInfo.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Contracts/BackupInfo.cs
index f6968c2e..9dceda40 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Contracts/BackupInfo.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/Contracts/BackupInfo.cs
@@ -3,7 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
-using System.Collections;
using System.Collections.Generic;
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
@@ -48,12 +47,12 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
///
/// List of {key: backup path, value: device type}
///
- public Dictionary arChangesList { get; set; }
+ public Dictionary BackupPathDevices { get; set; }
///
/// List of selected backup paths
///
- public ArrayList BackupPathList { get; set; }
+ public List BackupPathList { get; set; }
}
}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs
index f0d9dca4..0eba8357 100644
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs
+++ b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/DisasterRecoveryService.cs
@@ -2,19 +2,15 @@
// 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.Data.SqlClient;
+using System.Threading.Tasks;
using Microsoft.SqlTools.Hosting.Protocol;
+using Microsoft.SqlTools.ServiceLayer.Admin;
+using Microsoft.SqlTools.ServiceLayer.Admin.Contracts;
using Microsoft.SqlTools.ServiceLayer.Connection;
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts;
using Microsoft.SqlTools.ServiceLayer.Hosting;
-using Microsoft.SqlTools.ServiceLayer.SqlContext;
-using System;
-using System.Threading.Tasks;
-using Microsoft.SqlServer.Management.Smo;
-using Microsoft.SqlServer.Management.Common;
-using System.Collections.Generic;
-using System.Data.SqlClient;
-using Microsoft.SqlTools.ServiceLayer.Common;
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
{
@@ -22,14 +18,14 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
{
private static readonly Lazy instance = new Lazy(() => new DisasterRecoveryService());
private static ConnectionService connectionService = null;
- private BackupFactory backupFactory;
+ private BackupUtilities backupFactory;
///
/// Default, parameterless constructor.
///
internal DisasterRecoveryService()
{
- this.backupFactory = new BackupFactory();
+ this.backupFactory = new BackupUtilities();
}
///
@@ -64,27 +60,47 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
///
public void InitializeService(ServiceHost serviceHost)
{
+ // Get database info
+ serviceHost.SetRequestHandler(BackupConfigInfoRequest.Type, HandleBackupConfigInfoRequest);
+ // Create backup
serviceHost.SetRequestHandler(BackupRequest.Type, HandleBackupRequest);
}
- ///
- /// Handles a backup request
- ///
- internal static async Task HandleBackupRequest(
- BackupParams backupParams,
- RequestContext requestContext)
- {
+ public static async Task HandleBackupConfigInfoRequest(
+ DefaultDatabaseInfoParams optionsParams,
+ RequestContext requestContext)
+ {
+ var response = new BackupConfigInfoResponse();
ConnectionInfo connInfo;
DisasterRecoveryService.ConnectionServiceInstance.TryFindConnection(
- backupParams.OwnerUri,
+ optionsParams.OwnerUri,
out connInfo);
- CDataContainer dataContainer;
+
+ if (connInfo != null)
+ {
+ CDataContainer dataContainer = GetDataContainer(connInfo);
+ SqlConnection sqlConn = GetSqlConnection(connInfo);
+ if (sqlConn != null)
+ {
+ DisasterRecoveryService.Instance.InitializeBackup(dataContainer, sqlConn);
+ BackupConfigInfo backupConfigInfo = DisasterRecoveryService.Instance.GetDatabaseInfo(sqlConn.Database);
+ backupConfigInfo.DatabaseInfo = AdminService.GetDatabaseInfo(connInfo);
+ response.BackupConfigInfo = backupConfigInfo;
+ }
+ }
+
+ await requestContext.SendResult(response);
+ }
+
+ internal static CDataContainer GetDataContainer(ConnectionInfo connInfo)
+ {
+ CDataContainer dataContainer = null;
if (connInfo != null)
{
char[] passwordArray = connInfo.ConnectionDetails.Password.ToCharArray();
if (string.Equals(connInfo.ConnectionDetails.AuthenticationType, "SqlLogin", StringComparison.OrdinalIgnoreCase))
- {
+ {
unsafe
{
fixed (char* passwordPtr = passwordArray)
@@ -109,11 +125,32 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
null,
null);
}
+ }
+ return dataContainer;
+ }
+
+ ///
+ /// Handles a backup request
+ ///
+ internal static async Task HandleBackupRequest(
+ BackupParams backupParams,
+ RequestContext requestContext)
+ {
+ ConnectionInfo connInfo;
+ DisasterRecoveryService.ConnectionServiceInstance.TryFindConnection(
+ backupParams.OwnerUri,
+ out connInfo);
+ CDataContainer dataContainer;
+
+ if (connInfo != null)
+ {
+ dataContainer = GetDataContainer(connInfo);
SqlConnection sqlConn = GetSqlConnection(connInfo);
if (sqlConn != null)
{
- DisasterRecoveryService.Instance.InitializeBackup(dataContainer, sqlConn, backupParams.BackupInfo);
+ DisasterRecoveryService.Instance.InitializeBackup(dataContainer, sqlConn);
+ DisasterRecoveryService.Instance.SetBackupInput(backupParams.BackupInfo);
DisasterRecoveryService.Instance.PerformBackup();
}
}
@@ -147,15 +184,25 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
return null;
}
- private void InitializeBackup(CDataContainer dataContainer, SqlConnection sqlConnection, BackupInfo input)
+ private void InitializeBackup(CDataContainer dataContainer, SqlConnection sqlConnection)
+ {
+ this.backupFactory.Initialize(dataContainer, sqlConnection);
+ }
+
+ private void SetBackupInput(BackupInfo input)
{
- this.backupFactory.Initialize(dataContainer, sqlConnection, input);
+ this.backupFactory.SetBackupInput(input);
}
private void PerformBackup()
{
this.backupFactory.PerformBackup();
- }
+ }
+
+ private BackupConfigInfo GetDatabaseInfo(string databaseName)
+ {
+ return this.backupFactory.GetBackupConfigInfo(databaseName);
+ }
}
}
diff --git a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/UrlControl.cs b/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/UrlControl.cs
deleted file mode 100644
index 08587a9c..00000000
--- a/src/Microsoft.SqlTools.ServiceLayer/DisasterRecovery/UrlControl.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using System.Collections;
-
-namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
-{
- //TODO: Should URL be added to Carbon?
- public partial class UrlControl
- {
- ///
- /// Server
- ///
- public Microsoft.SqlServer.Management.Smo.Server SqlServer;
-
- ///
- /// list of Backup Urls
- ///
- private ArrayList listBakDestUrls;
-
- public UrlControl()
- {
- }
-
- ///
- /// List of backup urls
- ///
- public ArrayList ListBakDestUrls
- {
- get
- {
- return this.listBakDestUrls;
- }
- }
-
- }
-}