Add linting for copyright and unused usings (#1416)

* Add linting for copyright and unused usings

* Add one more + comment

* Enforce in build and fix errors

* Fix build
This commit is contained in:
Charles Gagnon
2022-03-04 15:17:29 -08:00
committed by GitHub
parent 025f9af4fd
commit c248400a6c
233 changed files with 1323 additions and 364 deletions

View File

@@ -1,6 +1,7 @@
//
// 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.Threading.Tasks;
@@ -9,11 +10,11 @@ using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
{
/// <summary>
/// An account manager has the information of currently logged in user and can authenticate the user
/// An account manager has the information of currently logged in user and can authenticate the user
/// Implementing classes must add a <see cref="ExportableAttribute" />
/// to the class in order to be found by the extension manager,
/// and to define the type and category supported
/// </summary>
/// </summary>
public interface IAccountManager : IExportable
{
/// <summary>
@@ -46,7 +47,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
/// </summary>
bool HasLoginDialog
{
get;
get;
}
/// <summary>

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -8,7 +9,7 @@ using System.Threading.Tasks;
namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
{
/// <summary>
/// Provides functionality to authenticate to Azure and discover associated accounts and subscriptions
/// Provides functionality to authenticate to Azure and discover associated accounts and subscriptions
/// </summary>
public interface IAzureAuthenticationManager : IAccountManager
{
@@ -38,6 +39,6 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
/// <summary>
/// Stores the selected subscriptions given the ids
/// </summary>
Task<bool> SetSelectedSubscriptionsAsync(IEnumerable<string> subscriptionIds);
Task<bool> SetSelectedSubscriptionsAsync(IEnumerable<string> subscriptionIds);
}
}

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
@@ -30,6 +31,6 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
string SubscriptionId
{
get;
}
}
}
}

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
{
@@ -16,7 +17,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
{
get;
}
/// <summary>
/// Display ID
/// </summary>
@@ -24,6 +25,6 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
{
get;
}
}
}

View File

@@ -1,6 +1,7 @@
//
// 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.Generic;

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
@@ -18,6 +19,6 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
IAzureUserAccount UserAccount
{
get;
}
}
}
}

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
{
@@ -16,7 +17,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
{
get;
}
/// <summary>
/// Returns true if user needs reauthentication
/// </summary>
@@ -24,6 +25,6 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Authentication
{
get;
}
}
}

View File

@@ -30,12 +30,12 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
public AuthenticationService()
{
}
public override void InitializeService(IProtocolEndpoint serviceHost)
{
Logger.Write(TraceEventType.Verbose, "AuthenticationService initialized");
}
public async Task<IUserAccount> SetCurrentAccountAsync(Account account, Dictionary<string, AccountSecurityToken> securityTokenMappings)
{
var authManager = ServiceProvider.GetService<IAzureAuthenticationManager>();

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
@@ -13,7 +14,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// </summary>
public static class CommonUtil
{
private const int KeyValueNameLength = 1024; // 1024 should be enough for registry key value name.
private const int KeyValueNameLength = 1024; // 1024 should be enough for registry key value name.
//********************************************************************************************
/// <summary>
@@ -44,7 +45,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
//********************************************************************************************
/// <summary>
/// Throw an exception if a string is null or empty.
/// Throw an exception if a string is null or empty.
/// </summary>
/// <param name="stringVar">string to check</param>
/// <param name="stringVarName">the variable or parameter name to display</param>
@@ -97,6 +98,6 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
return message;
}
}
}

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ResourceProvider.Core
{

View File

@@ -1,6 +1,7 @@
//
// 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.Common;
@@ -18,7 +19,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// Returns true if given exception if any of the inner exceptions is UserNeedsAuthenticationException
/// </summary>
internal static bool IsUserNeedsReauthenticateException(this Exception ex)
{
{
return ex.IsExceptionType(typeof(UserNeedsAuthenticationException));
}

View File

@@ -1,6 +1,7 @@
//
// 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.Runtime.Serialization;
@@ -8,7 +9,7 @@ using System.Runtime.Serialization;
namespace Microsoft.SqlTools.ResourceProvider.Core
{
/// <summary>
/// The exception is used if any operation fails as a request failed due to an expired token
/// The exception is used if any operation fails as a request failed due to an expired token
/// </summary>
public class ExpiredTokenException : ServiceExceptionBase
{
@@ -29,11 +30,11 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
}
/// <summary>
/// Initializes a new instance of the ServiceFailedException class with a specified error message
/// Initializes a new instance of the ServiceFailedException class with a specified error message
/// and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception. </param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// (Nothing in Visual Basic) if no inner exception is specified</param>
public ExpiredTokenException(string message, Exception innerException)
: base(message, innerException)

View File

@@ -35,11 +35,11 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// </summary>
/// <param name="message">The error message that explains the reason for the exception. </param>
/// <param name="httpStatusCode">The Http error code. </param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// (Nothing in Visual Basic) if no inner exception is specified</param>
public ServiceExceptionBase(string message, HttpStatusCode httpStatusCode, Exception innerException = null)
: this(message, (int)httpStatusCode, innerException)
{
{
}
/// <summary>
@@ -47,7 +47,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// </summary>
/// <param name="message">The error message that explains the reason for the exception. </param>
/// <param name="httpStatusCode">The Http error code. </param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// (Nothing in Visual Basic) if no inner exception is specified</param>
public ServiceExceptionBase(string message, int httpStatusCode, Exception innerException)
: base(message, innerException)
@@ -57,11 +57,11 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
}
/// <summary>
/// Initializes a new instance of the AuthenticationFailedException class with a specified error message
/// Initializes a new instance of the AuthenticationFailedException class with a specified error message
/// and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception. </param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// (Nothing in Visual Basic) if no inner exception is specified</param>
protected ServiceExceptionBase(string message, Exception innerException)
: base(message, innerException)

View File

@@ -32,11 +32,11 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
}
/// <summary>
/// Initializes a new instance of the ServiceFailedException class with a specified error message
/// Initializes a new instance of the ServiceFailedException class with a specified error message
/// and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception. </param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// (Nothing in Visual Basic) if no inner exception is specified</param>
public ServiceFailedException(string message, Exception innerException)
: base(message, innerException)
@@ -54,13 +54,13 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
}
/// <summary>
/// Creates a new instance of ServiceFailedException by adding the server definition info to the given message
/// Creates a new instance of ServiceFailedException by adding the server definition info to the given message
/// </summary>
internal static ServiceFailedException CreateException(string message, ServerDefinition serverDefinition, Exception innerException)
{
return new ServiceFailedException(
string.Format(CultureInfo.CurrentCulture, message,
serverDefinition != null ? serverDefinition.ServerType : string.Empty,
string.Format(CultureInfo.CurrentCulture, message,
serverDefinition != null ? serverDefinition.ServerType : string.Empty,
serverDefinition != null ? serverDefinition.Category : string.Empty), innerException);
}
}

View File

@@ -1,6 +1,7 @@
//
// 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.Runtime.Serialization;
@@ -8,7 +9,7 @@ using System.Runtime.Serialization;
namespace Microsoft.SqlTools.ResourceProvider.Core
{
/// <summary>
/// The exception is used if any operation fails becauase user needs to reauthenticate
/// The exception is used if any operation fails becauase user needs to reauthenticate
/// </summary>
public class UserNeedsAuthenticationException : ServiceExceptionBase
{
@@ -29,11 +30,11 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
}
/// <summary>
/// Initializes a new instance of the ServiceFailedException class with a specified error message
/// Initializes a new instance of the ServiceFailedException class with a specified error message
/// and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception. </param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// (Nothing in Visual Basic) if no inner exception is specified</param>
public UserNeedsAuthenticationException(string message, Exception innerException)
: base(message, innerException)

View File

@@ -68,13 +68,13 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Contracts
public class ProviderSettings
{
/// <summary>
/// Display name of the provider
/// Display name of the provider
/// </summary>
public string DisplayName;
/// <summary>
/// ID of the provider
/// </summary>
/// </summary>
public string Id;
/// <summary>
/// Settings for the provider itself

View File

@@ -28,7 +28,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Contracts
/// </summary>
public Account Account { get; set; }
/// <summary>
/// Per-tenant token mappings. Ideally would be set independently of this call, but for
/// Per-tenant token mappings. Ideally would be set independently of this call, but for
/// now this allows us to get the tokens necessary to find a server and open a firewall rule
/// </summary>
public Dictionary<string,AccountSecurityToken> SecurityTokenMappings { get; set; }
@@ -47,7 +47,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Contracts
/// End of the IP address range
/// </summary>
public string EndIpAddress { get; set; }
}
public class CreateFirewallRuleResponse : TokenReliantResponse
@@ -61,7 +61,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Contracts
public class CanHandleFirewallRuleRequest
{
public static readonly
RequestType<HandleFirewallRuleParams, HandleFirewallRuleResponse> Type =
RequestType<HandleFirewallRuleParams, HandleFirewallRuleResponse> Type =
RequestType<HandleFirewallRuleParams, HandleFirewallRuleResponse>.Create("resource/handleFirewallRule");
}

View File

@@ -1,6 +1,7 @@
//
// 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.Generic;
@@ -16,8 +17,8 @@ using Microsoft.SqlTools.Utility;
namespace Microsoft.SqlTools.ResourceProvider.Core
{
/// <summary>
/// Default implementation for <see cref="IDatabaseDiscoveryProvider"/> for Azure Sql databases.
/// A discovery provider capable of finding Sql Azure databases for a specific Azure user account.
/// Default implementation for <see cref="IDatabaseDiscoveryProvider"/> for Azure Sql databases.
/// A discovery provider capable of finding Sql Azure databases for a specific Azure user account.
/// </summary>
[Exportable(
@@ -35,7 +36,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
public AzureDatabaseDiscoveryProvider()
{
// Duplicate the exportable attribute as at present we do not support filtering using extensiondescriptor.
// The attribute is preserved in order to simplify ability to backport into existing tools
// The attribute is preserved in order to simplify ability to backport into existing tools
Metadata = new ExportableMetadata(
ServerTypes.SqlServer,
Categories.Azure,
@@ -90,9 +91,9 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
}
/// <summary>
/// Returns the databases for given connection info.
/// Returns the databases for given connection info.
/// The connection info should be used to make the connection for getting databases not the account manager
/// </summary>
/// </summary>
//public async Task<ServiceResponse<DatabaseInstanceInfo>> GetDatabaseInstancesAsync(UIConnectionInfo uiConnectionInfo, CancellationToken cancellationToken)
//{
// ServiceResponse<DatabaseInstanceInfo> result = null;
@@ -109,7 +110,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// <summary>
/// Returns the databases for given server name. Using the account manager to get the databases
/// </summary>
/// </summary>
public async Task<ServiceResponse<DatabaseInstanceInfo>> GetDatabaseInstancesAsync(string serverName, CancellationToken cancellationToken)
{
ServiceResponse<DatabaseInstanceInfo> result = null;
@@ -120,7 +121,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
//if connection is passed, we need to search all subscriptions not selected ones
IEnumerable<IAzureUserAccountSubscriptionContext> subscriptions = await GetSubscriptionsAsync(string.IsNullOrEmpty(serverName));
if (!cancellationToken.IsCancellationRequested)
{
{
result = await AzureUtil.ExecuteGetAzureResourceAsParallel((object)null, subscriptions, serverName, cancellationToken,
GetDatabaseForSubscriptionAsync);
}
@@ -159,7 +160,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
get
{
return (_azureAccountManager = _azureAccountManager ?? GetService<IAzureAuthenticationManager>());
}
}
}
/// <summary>
@@ -206,11 +207,11 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// <summary>
/// There was a wired nullReferencedException was running the tasks parallel. It only got fixed when I put the getting from cache insed an async method
/// </summary>
/// </summary>
private Task<ServiceResponse<DatabaseInstanceInfo>> GetFromCacheAsync(string key)
{
return Task.Factory.StartNew(() => _cache.Get(key));
}
}
/// <summary>
/// Returns a list of Azure sql databases for given subscription
@@ -235,7 +236,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
else if (shouldFilter)
{
//we should filter the result because the cached data includes databases for all servers
result = new ServiceResponse<DatabaseInstanceInfo>(result.Data.Where(x => x.ServerInstanceInfo.FullyQualifiedDomainName == serverName),
result = new ServiceResponse<DatabaseInstanceInfo>(result.Data.Where(x => x.ServerInstanceInfo.FullyQualifiedDomainName == serverName),
result.Errors);
}
@@ -243,7 +244,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
if (!shouldFilter && !cancellationToken.IsCancellationRequested)
{
result = _cache.UpdateCache(key, result);
}
}
}
catch (Exception ex)
{
@@ -261,7 +262,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
CancellationToken cancellationToken, CancellationToken internalCancellationToken)
{
ServiceResponse<DatabaseInstanceInfo> result = null;
try
{
if (!cancellationToken.IsCancellationRequested && !internalCancellationToken.IsCancellationRequested)
@@ -295,7 +296,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
return result ?? new ServiceResponse<DatabaseInstanceInfo>();
}
private async Task<ServiceResponse<DatabaseInstanceInfo>> GetDatabasesForSubscriptionServersAsync(IAzureResourceManagementSession session,
private async Task<ServiceResponse<DatabaseInstanceInfo>> GetDatabasesForSubscriptionServersAsync(IAzureResourceManagementSession session,
IList<IAzureSqlServerResource> filteredServersList, CancellationToken cancellationToken)
{
ServiceResponse<DatabaseInstanceInfo> result = null;

View File

@@ -1,6 +1,7 @@
//
// 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.Generic;
@@ -43,7 +44,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
result = await AzureUtil.ExecuteGetAzureResourceAsParallel(_session, serverResources, null, cancellationToken, GetDatabasesForServerFromService);
}
return result;
}
}
private async Task<ServiceResponse<DatabaseInstanceInfo>> GetDatabasesForServerFromService(
IAzureResourceManagementSession session,
@@ -108,7 +109,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// <summary>
/// Converts the resource to DatabaseInstanceInfo
/// </summary>
/// </summary>
private DatabaseInstanceInfo ConvertToModel(ServerInstanceInfo serverInstanceInfo, IAzureResource azureResource)
{
DatabaseInstanceInfo databaseInstance = new DatabaseInstanceInfo(serverInstanceInfo)

View File

@@ -1,6 +1,7 @@
//
// 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.Generic;
@@ -12,11 +13,11 @@ using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
namespace Microsoft.SqlTools.ResourceProvider.Core
{
/// <summary>
/// Default implementation for <see cref="IServerDiscoveryProvider"/> for Azure Sql servers.
/// A discovery provider capable of finding Sql Azure servers for a specific Azure user account.
/// Default implementation for <see cref="IServerDiscoveryProvider"/> for Azure Sql servers.
/// A discovery provider capable of finding Sql Azure servers for a specific Azure user account.
/// </summary>
[Exportable(
ServerTypes.SqlServer,
ServerTypes.SqlServer,
Categories.Azure,
typeof(IServerDiscoveryProvider),
"Microsoft.SqlServer.ConnectionServices.Azure.AzureServerDiscoveryProvider")]
@@ -28,7 +29,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
public AzureSqlServerDiscoveryProvider()
{
// Duplicate the exportable attribute as at present we do not support filtering using extensiondescriptor.
// The attribute is preserved in order to simplify ability to backport into existing tools
// The attribute is preserved in order to simplify ability to backport into existing tools
Metadata = new ExportableMetadata(
ServerTypes.SqlServer,
Categories.Azure,
@@ -120,6 +121,6 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
{
_azureAccountManager = value as IAzureAuthenticationManager;
}
}
}
}
}

View File

@@ -1,6 +1,7 @@
//
// 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.Generic;

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
@@ -12,7 +13,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
public class DatabaseInstanceInfo
{
/// <summary>
/// Default constructor to initialize the instance
/// Default constructor to initialize the instance
/// </summary>
/// <param name="serverInstanceInfo"></param>
public DatabaseInstanceInfo(ServerInstanceInfo serverInstanceInfo)
@@ -34,7 +35,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// </summary>
public ServerInstanceInfo ServerInstanceInfo
{
get;
get;
private set;
}

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ResourceProvider.Core
{

View File

@@ -1,6 +1,7 @@
//
// 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.SqlTools.ResourceProvider.Core.Authentication;
@@ -11,7 +12,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// A session used by <see cref="IAzureResourceManager" />. Includes all the clients that the resource management needs to get ther resources
/// </summary>
public interface IAzureResourceManagementSession : IDisposable
{
{
/// <summary>
/// Closes the session
/// </summary>

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -24,7 +25,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// <returns>The list of databases</returns>
Task<IEnumerable<IAzureResource>> GetAzureDatabasesAsync(
IAzureResourceManagementSession azureResourceManagementSession,
string resourceGroupName,
string resourceGroupName,
string serverName);
/// <summary>
@@ -43,8 +44,8 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// <param name="firewallRuleRequest">Firewall rule request including the name and IP address range</param>
/// <returns></returns>
Task<FirewallRuleResponse> CreateFirewallRuleAsync(
IAzureResourceManagementSession azureResourceManagementSession,
IAzureSqlServerResource azureSqlServer,
IAzureResourceManagementSession azureResourceManagementSession,
IAzureSqlServerResource azureSqlServer,
FirewallRuleRequest firewallRuleRequest
);
@@ -52,7 +53,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// <summary>
/// Gets all subscription contexts under a specific user account. Queries all tenants for the account and uses these to log in
/// Gets all subscription contexts under a specific user account. Queries all tenants for the account and uses these to log in
/// and retrieve subscription information as needed
/// <param name="userAccount">Account whose subscriptions should be queried</param>
/// </summary>

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ResourceProvider.Core
{
@@ -11,7 +12,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
{
/// <summary>
/// Fully qualified domain name
/// </summary>
/// </summary>
string FullyQualifiedDomainName
{
get;

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Threading;
using System.Threading.Tasks;
@@ -8,10 +9,10 @@ using System.Threading.Tasks;
namespace Microsoft.SqlTools.ResourceProvider.Core
{
/// <summary>
/// Defines a class as cachable
/// </summary>
/// Defines a class as cachable
/// </summary>
public interface ICacheable<T>
{
{
/// <summary>
/// Clears the cache for current user
/// </summary>

View File

@@ -1,6 +1,7 @@
//
// 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.Generic;
@@ -11,23 +12,23 @@ using Microsoft.SqlTools.ResourceProvider.Core.Extensibility;
namespace Microsoft.SqlTools.ResourceProvider.Core
{
/// <summary>
/// A discovery provider capable of finding databases for a given server type and category.
/// For example: finding SQL Server databases in Azure, or on the local network.
/// Implementing classes must add a <see cref="ExportableAttribute" />
/// to the class in order to be found by the extension manager,
/// A discovery provider capable of finding databases for a given server type and category.
/// For example: finding SQL Server databases in Azure, or on the local network.
/// Implementing classes must add a <see cref="ExportableAttribute" />
/// to the class in order to be found by the extension manager,
/// and to define the type and category supported
/// </summary>
public interface IDatabaseDiscoveryProvider : IExportable
{
/// <summary>
/// Returns the databases for given server name.
/// </summary>
/// Returns the databases for given server name.
/// </summary>
Task<ServiceResponse<DatabaseInstanceInfo>> GetDatabaseInstancesAsync(string serverName, CancellationToken cancellationToken);
/// <summary>
/// Returns the databases for given connection info.
/// Returns the databases for given connection info.
/// The connection info should be used to make the connection for getting databases not the account manager
/// </summary>
/// </summary>
//Task<ServiceResponse<DatabaseInstanceInfo>> GetDatabaseInstancesAsync(UIConnectionInfo uiConnectionInfo, CancellationToken cancellationToken);
/// <summary>

View File

@@ -1,14 +1,15 @@
//
// 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.ResourceProvider.Core.Authentication;
namespace Microsoft.SqlTools.ResourceProvider.Core
{
/// <summary>
/// Defines a class as secure which requires an account to function
/// </summary>
/// Defines a class as secure which requires an account to function
/// </summary>
public interface ISecureService
{
/// <summary>

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -14,12 +15,12 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// Implementing classes must add a <see cref="ExportableAttribute" />
/// to the class in order to be found by the extension manager,
/// and to define the type and category supported
/// </summary>
/// </summary>
public interface IServerDiscoveryProvider : IExportable
{
{
/// <summary>
/// Discovers the server instances
/// </summary>
Task<ServiceResponse<ServerInstanceInfo>> GetServerInstancesAsync();
Task<ServiceResponse<ServerInstanceInfo>> GetServerInstancesAsync();
}
}

View File

@@ -1,20 +1,21 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ResourceProvider.Core
{
/// <summary>
/// Defines a server grouping based on the type of server connection supported (SQL Server, Reporting Server, Analysis Server)
/// and a Category by which these should be shown to the user.
/// Built in examples of categories include Local, Network, and Azure and additional categories can be defined as needed.
/// Note that the Connection Dialog UI may require Category to be set for some resource types such as<see cref="IServerDiscoveryProvider" />.
/// Defines a server grouping based on the type of server connection supported (SQL Server, Reporting Server, Analysis Server)
/// and a Category by which these should be shown to the user.
/// Built in examples of categories include Local, Network, and Azure and additional categories can be defined as needed.
/// Note that the Connection Dialog UI may require Category to be set for some resource types such as<see cref="IServerDiscoveryProvider" />.
/// In addition a UI section matching that category may be required, or else the provider will not be used by any UI part and never be called.
/// </summary>
public interface IServerDefinition
{
/// <summary>
/// Category by which resources can be grouped. Built in examples of categories include Local, Network, and Azure and additional categories can be defined as needed.
/// Category by which resources can be grouped. Built in examples of categories include Local, Network, and Azure and additional categories can be defined as needed.
/// </summary>
string Category
{

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ResourceProvider.Core
{
@@ -18,12 +19,12 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
}
public ServerInstanceInfo()
{
{
}
public IServerDefinition ServerDefinition
{
get; private set;
get; private set;
}
/// <summary>

View File

@@ -1,14 +1,15 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ResourceProvider.Core
{
/// <summary>
/// List of built-in server types used in <see cref="ExportableAttribute" />.
/// List of built-in server types used in <see cref="ExportableAttribute" />.
/// Defines a server grouping based on the type of server connection supported (SQL Server, Reporting Server, Analysis Server)
/// Additional server types can be defined as needed.
/// Note that the Connection Dialog UI may require server type to be set for some resource types such as<see cref="IServerDiscoveryProvider" />.
/// Note that the Connection Dialog UI may require server type to be set for some resource types such as<see cref="IServerDiscoveryProvider" />.
/// In addition a UI section matching that category may be required, or else the provider will not be used by any UI part and never be called.
/// </summary>
public static class ServerTypes
@@ -38,7 +39,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// List of built-in categories used in <see cref="ExportableAttribute" />
/// Defines a server grouping based on the category of server connection supported (Network, Local, Azure)
/// Additional categories can be defined as needed.
/// Note that the Connection Dialog UI may require Category to be set for some resource types such as<see cref="IServerDiscoveryProvider" />.
/// Note that the Connection Dialog UI may require Category to be set for some resource types such as<see cref="IServerDiscoveryProvider" />.
/// In addition a UI section matching that category may be required, or else the provider will not be used by any UI part and never be called.
/// </summary>
public static class Categories

View File

@@ -1,6 +1,7 @@
//
// 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.Generic;
@@ -27,14 +28,14 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
/// Creates new instance given errors
/// </summary>
public ServiceResponse(IEnumerable<Exception> errors) : this(Enumerable.Empty<T>(), errors)
{
{
}
/// <summary>
/// Creates new instance given data
/// </summary>
public ServiceResponse(IEnumerable<T> data) : this(data, Enumerable.Empty<Exception>())
{
{
}
/// <summary>
@@ -83,7 +84,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
}
return message;
}
}
}
/// <summary>
/// Returns true if a response already found. it's used when we need to filter the responses

View File

@@ -10,7 +10,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
{
/// <summary>
/// Attribute defining a service export, and the metadata about that service. Implements IServiceMetadata,
/// which should be used on the importer side to ensure type consistency. Services and providers have to add this property
/// which should be used on the importer side to ensure type consistency. Services and providers have to add this property
/// in order to be found by the extension manager
/// </summary>
[MetadataAttribute]
@@ -27,11 +27,11 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// <param name="priority">The priority of the exportable. The extension manager will pick the exportable with the highest priority if multiple found</param>
/// <param name="displayName">The display name of the exportable. This field is optional</param>
public ExportableAttribute(
string serverType,
string serverType,
string category,
Type type,
string id,
int priority = 0,
Type type,
string id,
int priority = 0,
string displayName = null) : base(type)
{
Category = category;
@@ -40,7 +40,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
DisplayName = displayName;
Priority = priority;
}
/// <summary>
/// The constructor to define an exportable by type, id and priority only. To be used by the exportables that support all server types and categories.
/// For example: the implementation of <see cref="ITrace" /> can be used for all server types and categories.
@@ -60,8 +60,8 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// </summary>
public string Category
{
get;
private set;
get;
private set;
}
/// <summary>
@@ -69,8 +69,8 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// </summary>
public string ServerType
{
get;
private set;
get;
private set;
}
/// <summary>
@@ -87,7 +87,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// </summary>
public string Id
{
get;
get;
private set;
}
@@ -96,7 +96,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// </summary>
public string DisplayName
{
get;
get;
private set;
}
@@ -105,7 +105,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// </summary>
public int Priority
{
get;
get;
private set;
}
}

View File

@@ -26,7 +26,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// </summary>
public IExportableMetadata Metadata
{
get;
get;
set;
}
@@ -36,7 +36,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// </summary>
public IMultiServiceProvider ServiceProvider
{
get;
get;
private set;
}
@@ -53,7 +53,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// <returns>A service of type T or null if not found</returns>
protected T GetService<T>()
where T : IExportable
{
{
return GetService<T>(Metadata);
}
@@ -90,7 +90,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
}
/// <summary>
/// ServerDefinition created from the metadata
/// ServerDefinition created from the metadata
/// </summary>
protected ServerDefinition ServerDefinition
{

View File

@@ -26,7 +26,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
public string ErrorMessage { get; set; }
/// <summary>
/// An info link to navigate to
/// An info link to navigate to
/// </summary>
public string InfoLink { get; set; }
}

View File

@@ -11,7 +11,7 @@ using Microsoft.SqlTools.Extensibility;
namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
{
/// <summary>
/// Extension methods for exportable and service
/// Extension methods for exportable and service
/// </summary>
public static class ExtensionUtils
{
@@ -48,14 +48,14 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
{
return null;
}
//Get all the possible matches
//Get all the possible matches
IEnumerable<T> allMatched = serverDefinition != null ?
exportables.Where(x => Match(x.Metadata, serverDefinition)).ToList() : exportables;
IList<T> list = allMatched.ToList();
//If specific server type requested and the list has any item with that server type remove the others.
//for instance is there's server for all server types and one specifically for sql and give metadata is asking for sql then
//we should return the sql one even if the other service has higher priority
//we should return the sql one even if the other service has higher priority
IList<T> withSameServerType = list.Where(x => serverDefinition.HasSameServerName(x.Metadata)).ToList();
if (withSameServerType.Any())
@@ -101,7 +101,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
}
return false;
}
internal static string GetServerDefinitionKey(this IServerDefinition serverDefinition)
{
string key = string.Empty;
@@ -126,7 +126,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
}
return false;
}
internal static bool EmptyOrEqual(this string value1, string value2)
{
if (string.IsNullOrEmpty(value1) && string.IsNullOrEmpty(value2))
@@ -143,12 +143,12 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// <summary>
/// Returns true if the metadata matches the given server definition
/// </summary>
/// </summary>
public static bool Match(this IServerDefinition first, IServerDefinition other)
{
if (first == null)
{
// TODO should we handle this differently?
// TODO should we handle this differently?
return false;
}
if (other == null)
@@ -158,10 +158,10 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
return MatchMetaData(first.ServerType, other.ServerType)
&& MatchMetaData(first.Category, other.Category);
}
/// <summary>
/// Returns true if the metadata value matches the given value
/// </summary>
/// </summary>
private static bool MatchMetaData(string metaData, string requestedMetaData)
{
if (string.IsNullOrEmpty(metaData) || string.IsNullOrEmpty(requestedMetaData))

View File

@@ -19,7 +19,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
{
set; get;
}
/// <summary>
/// Returns the status of the exportable
/// </summary>

View File

@@ -13,7 +13,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// Provides facility to trace code execution through calls to Trace* methods.
/// Implementing classes must add a <see cref="ExportableAttribute" />
/// to the class in order to be found by the extension manager
/// </summary>
/// </summary>
public interface ITrace : IExportable
{
/// <summary>
@@ -40,5 +40,5 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
bool TraceException(TraceEventType eventType, int traceId, Exception exception, string message,
[CallerLineNumber] int lineNumber = 0, [CallerFilePath] string fileName = "",
[CallerMemberName] string memberName = "");
}
}
}

View File

@@ -66,7 +66,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// <summary>
/// Trace Id for network browse traces
/// </summary>
NetworkSection = 11,
NetworkSection = 11,
/// <summary>
/// Trace Id for main dialog traces

View File

@@ -19,13 +19,13 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// </summary>
public abstract ITrace Trace
{
get;
get;
set;
}
/// <summary>
/// Write a trace event message to the underlying trace source.
/// </summary>
/// </summary>
public bool TraceEvent(TraceEventType eventType, TraceId traceId, string format, params object[] args)
{
return TraceEvent(eventType, (int)traceId, format, args);
@@ -33,16 +33,16 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// <summary>
/// Write a trace event message to the underlying trace source.
/// </summary>
/// </summary>
public bool TraceEvent(TraceEventType eventType, int traceId, string format, params object[] args)
{
return SafeTrace(eventType, traceId, format, args);
}
}
/// <summary>
/// Write a formatted trace event message to the underlying trace source and issue a Debug.Fail() call
/// if condition is false.
/// </summary>
/// </summary>
public bool AssertTraceEvent(bool condition, TraceEventType eventType, TraceId traceId, string message)
{
return AssertTraceEvent(condition, eventType, (int)traceId, message);
@@ -51,7 +51,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// <summary>
/// Write a formatted trace event message to the underlying trace source and issue a Debug.Fail() call
/// if condition is false.
/// </summary>
/// </summary>
public bool AssertTraceEvent(bool condition, TraceEventType eventType, int traceId, string message)
{
if (!condition)
@@ -129,7 +129,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
return DebugTraceException(eventType, traceId, exception, message);
}
return true;
}
}
/// <summary>
/// Write a trace event with a message and exception details to the underlying trace source and issue a
@@ -195,7 +195,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// <summary>
/// Verifies ITrace instance is not null before tracing
/// </summary>
/// </summary>
private bool SafeTrace(TraceEventType eventType, int traceId, string format, params object[] args)
{
if (Trace != null)
@@ -207,7 +207,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Extensibility
/// <summary>
/// Verifies ITrace instance is not null before tracing the exception
/// </summary>
/// </summary>
private bool SafeTraceException(TraceEventType eventType, int traceId, Exception exception, string message,
[CallerLineNumber] int lineNumber = 0, [CallerFilePath] string fileName = "",
[CallerMemberName] string memberName = "")

View File

@@ -1,6 +1,7 @@
//
// 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.Data.SqlClient;
@@ -12,15 +13,15 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
internal interface IFirewallErrorParser
{
/// <summary>
/// Parses given error message and error code to see if it's firewall rule error
/// Parses given error message and error code to see if it's firewall rule error
/// and finds the blocked ip address
/// </summary>
FirewallParserResponse ParseErrorMessage(string errorMessage, int errorCode);
/// <summary>
/// Parses given error message and error code to see if it's firewall rule error
/// Parses given error message and error code to see if it's firewall rule error
/// and finds the blocked ip address
/// </summary>
/// </summary>
FirewallParserResponse ParseException(SqlException sqlException);
}
@@ -30,9 +31,9 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
public class FirewallErrorParser : IFirewallErrorParser
{
/// <summary>
/// Parses given error message and error code to see if it's firewall rule error
/// Parses given error message and error code to see if it's firewall rule error
/// and finds the blocked ip address
/// </summary>
/// </summary>
public FirewallParserResponse ParseException(SqlException sqlException)
{
CommonUtil.CheckForNull(sqlException, "sqlException");
@@ -40,9 +41,9 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
}
/// <summary>
/// Parses given error message and error code to see if it's firewall rule error
/// Parses given error message and error code to see if it's firewall rule error
/// and finds the blocked ip address
/// </summary>
/// </summary>
public FirewallParserResponse ParseErrorMessage(string errorMessage, int errorCode)
{
CommonUtil.CheckForNull(errorMessage, "errorMessage");
@@ -62,7 +63,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
/// <summary>
/// Parses the given message to find the blocked ip address
/// </summary>
/// </summary>
private static bool TryParseClientIp(string message, out IPAddress clientIp)
{
clientIp = null;
@@ -91,7 +92,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
/// <summary>
/// Returns true if given error code is firewall rule blocked error code
/// </summary>
/// </summary>
private bool IsSqlAzureFirewallBlocked(int errorCode)
{
return errorCode == SqlAzureFirewallBlockedErrorNumber;

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Net;

View File

@@ -1,6 +1,7 @@
//
// 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.Net;
@@ -34,7 +35,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
/// </summary>
/// <param name="message">The error message that explains the reason for the exception. </param>
/// <param name="httpStatusCode">The Http error code. </param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// (Nothing in Visual Basic) if no inner exception is specified</param>
public FirewallRuleException(string message, HttpStatusCode httpStatusCode, Exception innerException = null)
: base(message, httpStatusCode, innerException)
@@ -46,7 +47,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
/// </summary>
/// <param name="message">The error message that explains the reason for the exception. </param>
/// <param name="httpStatusCode">The Http error code. </param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// (Nothing in Visual Basic) if no inner exception is specified</param>
public FirewallRuleException(string message, int httpStatusCode, Exception innerException = null)
: base(message, httpStatusCode, innerException)
@@ -55,11 +56,11 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
}
/// <summary>
/// Initializes a new instance of the AuthenticationFailedException class with a specified error message
/// Initializes a new instance of the AuthenticationFailedException class with a specified error message
/// and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception. </param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// (Nothing in Visual Basic) if no inner exception is specified</param>
public FirewallRuleException(string message, Exception innerException)
: base(message, innerException)

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.Globalization;
@@ -12,7 +13,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
/// Includes all the information needed to create a firewall rule
/// </summary>
public class FirewallRuleRequest
{
{
/// <summary>
/// Start IP address
/// </summary>
@@ -21,7 +22,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
/// <summary>
/// End IP address
/// </summary>
public IPAddress EndIpAddress { get; set; }
public IPAddress EndIpAddress { get; set; }
/// <summary>
/// Firewall rule name

View File

@@ -1,6 +1,7 @@
//
// 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.ResourceProvider.Core.Authentication;
@@ -20,7 +21,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
/// Azure Subscription
/// </summary>
public IAzureUserAccountSubscriptionContext SubscriptionContext { get; set; }
/// <summary>
/// Returns true if the resource and subscription are not null

View File

@@ -1,6 +1,7 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
{

View File

@@ -1,6 +1,7 @@
//
// 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.Generic;
@@ -19,13 +20,13 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
{
/// <summary>
/// Creates firewall rule for given server name and IP address range. Throws exception if operation fails
/// </summary>
/// </summary>
Task<FirewallRuleResponse> CreateFirewallRuleAsync(string serverName, string startIpAddressValue, string endIpAddressValue);
/// <summary>
/// Creates firewall rule for given server name and IP address range. Throws exception if operation fails
/// </summary>
/// </summary>
Task<FirewallRuleResponse> CreateFirewallRuleAsync(string serverName, IPAddress startIpAddress, IPAddress endIpAddress);
@@ -53,7 +54,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
{
/// <summary>
/// Creates firewall rule for given server name and IP address range. Throws exception if operation fails
/// </summary>
/// </summary>
public async Task<FirewallRuleResponse> CreateFirewallRuleAsync(string serverName, string startIpAddressValue, string endIpAddressValue)
{
IPAddress startIpAddress = ConvertToIpAddress(startIpAddressValue);
@@ -63,7 +64,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
/// <summary>
/// Creates firewall rule for given server name and IP address range. Throws exception if operation fails
/// </summary>
/// </summary>
public async Task<FirewallRuleResponse> CreateFirewallRuleAsync(string serverName, IPAddress startIpAddress, IPAddress endIpAddress)
{
try
@@ -87,7 +88,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
return firewallRuleResponse;
}
catch (ServiceExceptionBase)
{
{
throw;
}
catch (Exception ex)
@@ -108,7 +109,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
/// <summary>
/// Creates firewall rule for given subscription and IP address range
/// </summary>
/// </summary>
private async Task<FirewallRuleResponse> CreateFirewallRule(FirewallRuleResource firewallRuleResource, IPAddress startIpAddress, IPAddress endIpAddress)
{
CommonUtil.CheckForNull(firewallRuleResource, "firewallRuleResource");
@@ -135,7 +136,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
catch (ServiceExceptionBase)
{
throw;
}
}
catch (Exception ex)
{
throw new FirewallRuleException(string.Format(CultureInfo.CurrentCulture, SR.FirewallRuleCreationFailedWithError, ex.Message), ex);
@@ -161,9 +162,9 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
throw new FirewallRuleException(SR.NoSubscriptionsFound);
}
ServiceResponse<FirewallRuleResource> response = await AzureUtil.ExecuteGetAzureResourceAsParallel((object)null,
ServiceResponse<FirewallRuleResource> response = await AzureUtil.ExecuteGetAzureResourceAsParallel((object)null,
subscriptions, serverName, new CancellationToken(), TryFindAzureResourceForSubscriptionAsync);
if (response != null)
{
if (response.Data != null && response.Data.Any())
@@ -190,7 +191,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
throw new FirewallRuleException(SR.FirewallRuleCreationFailed, ex);
}
}
/// <summary>
/// Returns a list of Azure sql databases for given subscription
/// </summary>
@@ -222,7 +223,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
/// <summary>
/// Throws a firewallRule exception based on give status code
/// </summary>
private void HandleError(ServiceExceptionBase exception, string serverName,
private void HandleError(ServiceExceptionBase exception, string serverName,
IAzureUserAccountSubscriptionContext subscription)
{
var accountName = subscription != null && subscription.UserAccount != null &&
@@ -262,19 +263,19 @@ namespace Microsoft.SqlTools.ResourceProvider.Core.Firewall
{
return resource;
}
}
}
}
catch (ServiceExceptionBase ex)
{
HandleError(ex, serverName, session.SubscriptionContext);
}
}
catch (Exception ex)
{
throw new FirewallRuleException(SR.FirewallRuleCreationFailed, ex);
}
}
return null;
}
private IPAddress ConvertToIpAddress(string ipAddressValue)
{
IPAddress ipAddress;

View File

@@ -30,7 +30,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
public ResourceProviderService()
{
}
public override void InitializeService(IProtocolEndpoint serviceHost)
{
Logger.Write(TraceEventType.Verbose, "ResourceProvider initialized");
@@ -43,7 +43,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
ResourceManager = ServiceProvider.GetService<IAzureResourceManager>()
};
}
/// <summary>
/// Handles a firewall rule creation request. It does this by matching the server name to an Azure Server resource,
/// then issuing the command to create a new firewall rule for the specified IP address against that instance
@@ -88,7 +88,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
}
return result;
}
public async Task ProcessHandleFirewallRuleRequest(HandleFirewallRuleParams canHandleRuleParams, RequestContext<HandleFirewallRuleResponse> requestContext)
{
Func<Task<HandleFirewallRuleResponse>> requestHandler = () =>
@@ -110,7 +110,7 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
};
await HandleRequest(requestHandler, null, requestContext, "HandleCreateFirewallRuleRequest");
}
private async Task HandleRequest<T>(Func<Task<T>> handler, Func<ExpiredTokenException, T> expiredTokenHandler, RequestContext<T> requestContext, string requestType)
{
Logger.Write(TraceEventType.Verbose, requestType);
@@ -140,6 +140,6 @@ namespace Microsoft.SqlTools.ResourceProvider.Core
// Send just the error message back for now as stack trace isn't useful
await requestContext.SendError(ex.Message);
}
}
}
}
}