mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Porting of the vast majority of Azure-related code from SSDT. This is very large, so I want to put this out as one large "lift and shift" PR before I do the tools-service specific JSON-RPC service handlers, connect a new account handler (as the code to get necessary info from accounts and subscriptions isn't fully complete) and add tests over these **What's in this PR**: - Created 3 new projects: - Microsoft.SqlTools.ResourceProvider will host the executable that accepts requests for Azure-related actions over the JSON-RPC protocol. This must be separate from other DLLs since a direct dependency on the Azure SDK DLLs fails (they're NetStandard 1.4 and you can't reference them if you have RuntimeIdentifiers in your .csproj file) - Microsoft.SqlTools.ResourceProvider.Core is where all the main business logic is, including definitions and logic on how to navigate over resources and create firewall rules, etc. - Microsoft.SqlTools.ResourceProvider.DefaultImpl is the actual Azure implementation of the resource provider APIs. The reason for separating this is to support eventual integration back into other tools (since their Azure and Identity services will be different). - Implemented the AzureResourceManager that connects to Azure via ARM APIs and handles creating firewall rule and querying databases. The dependent DLLs have had major breaking changes, so will need additional verification to ensure this works as expected - Ported the unit tests for all code that was not a viewmodel. Viewmodel test code will be ported in a future update as we plumb through a service-equivalent to these. Also, the DependencyManager code which has overlap with our service provider code is commented out. Will work to uncomment in a future update as it has value to test some scenarios **What's not in this PR**: - Identity Services. We currently just have a stub for the interface, and even that will likely change a little - anything JSON-RPC or registered service related. These will be adapted from the viewmodels and added in a separate PR
103 lines
3.9 KiB
C#
103 lines
3.9 KiB
C#
//
|
|
// 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;
|
|
|
|
namespace Microsoft.SqlTools.ResourceProvider.Core
|
|
{
|
|
/// <summary>
|
|
/// Utilities used by resource provider related code
|
|
/// </summary>
|
|
public static class CommonUtil
|
|
{
|
|
private const int KeyValueNameLength = 1024; // 1024 should be enough for registry key value name.
|
|
|
|
//********************************************************************************************
|
|
/// <summary>
|
|
/// Throw an exception if the object is null.
|
|
/// </summary>
|
|
/// <param name="var">the object to check</param>
|
|
/// <param name="varName">the variable or parameter name to display</param>
|
|
//********************************************************************************************
|
|
public static void CheckForNull(Object var, string varName)
|
|
{
|
|
if (var == null)
|
|
{
|
|
throw new ArgumentNullException(varName);
|
|
}
|
|
}
|
|
|
|
//********************************************************************************************
|
|
/// <summary>
|
|
/// 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>
|
|
//********************************************************************************************
|
|
public static void CheckStringForNullOrEmpty(string stringVar, string stringVarName)
|
|
{
|
|
CheckStringForNullOrEmpty(stringVar, stringVarName, false);
|
|
}
|
|
|
|
//********************************************************************************************
|
|
/// <summary>
|
|
/// 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>
|
|
/// <param name="trim">If true, will trim the string after it is determined not to be null</param>
|
|
//********************************************************************************************
|
|
public static void CheckStringForNullOrEmpty(string stringVar, string stringVarName, bool trim)
|
|
{
|
|
CheckForNull(stringVar, stringVarName);
|
|
if (trim == true)
|
|
{
|
|
stringVar = stringVar.Trim();
|
|
}
|
|
if (stringVar.Length == 0)
|
|
{
|
|
throw new ArgumentException("EmptyStringNotAllowed", stringVarName);
|
|
}
|
|
}
|
|
|
|
public static bool SameString(string value1, string value2)
|
|
{
|
|
return (value1 == null && value2 == null) || (value2 != null && value2.Equals(value1));
|
|
}
|
|
|
|
public static bool SameUri(Uri value1, Uri value2)
|
|
{
|
|
return (value1 == null && value2 == null) || (value2 != null && value2.Equals(value1));
|
|
}
|
|
|
|
public static bool SameSubscriptionIdentifier(IAzureSubscriptionIdentifier value1,
|
|
IAzureSubscriptionIdentifier value2)
|
|
{
|
|
return (value1 == null && value2 == null) || (value2 != null && value2.Equals(value1));
|
|
}
|
|
|
|
public static bool SameUserAccount(IAzureUserAccount value1, IAzureUserAccount value2)
|
|
{
|
|
return (value1 == null && value2 == null) || (value2 != null && value2.Equals(value1));
|
|
}
|
|
|
|
public static string GetExceptionMessage(Exception e)
|
|
{
|
|
string message;
|
|
|
|
#if DEBUG
|
|
string nl2 = Environment.NewLine + Environment.NewLine;
|
|
message = e.Message + nl2 + "DEBUG ONLY:" + nl2 + e.ToString();
|
|
#else
|
|
message = e.Message;
|
|
#endif
|
|
|
|
return message;
|
|
}
|
|
|
|
}
|
|
}
|