mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
- TSqlFormatterService with support for formatting document and text range inside document - Settings support for all formatting options. - Extensibility support so that the service can be initialized using MEF extensibility, and can find all necessary TSqlFormatters using the same process Fix Initialize request error on startup - Messages were being read from the input channel before all request handlers were registered - In particular, the Initialize request which is key for any server to talk to the client was getting lost because the message reader thread begins consuming, and we take an extra few hundred milliseconds due to MEF startup before we register the handler - The solution is to initialize the message handler so request handlers can register, but not actually start processing incoming messages until all handers are ready. This is a safer way to go and should improve reliability overall Improvements from internal prototype: - Normalizing baselines to handle the line ending differences on Mac & Linux vs. Windows - Significantly shortened most lines by implementing base class methods to wrap common objects from Visitor.Context and removing unnecessary "this." syntax - Refactored the SqlCommonTableExpressionFormatter and related classes to reduce code count significantly. This provides a pattern to follow when refactoring other classes for similar clarity. It's likely a lot of common logic could be found and reused across these. - Reduced overall code size by adding utility methods
116 lines
4.0 KiB
C#
116 lines
4.0 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 System.IO;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.TestEnvConfig
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
{
|
|
string arg = args[0];
|
|
|
|
if (arg.Equals("-?", StringComparison.OrdinalIgnoreCase) ||
|
|
arg.Equals("/?", StringComparison.OrdinalIgnoreCase) ||
|
|
arg.Equals("-help", StringComparison.OrdinalIgnoreCase) ||
|
|
arg.Equals("/help", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
ShowUsage();
|
|
}
|
|
else if (!File.Exists(arg))
|
|
{
|
|
Console.WriteLine("setting file {0} does not exist.", arg);
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
SaveSettings(arg);
|
|
Console.WriteLine("Completed saving the settings");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine("Error encountered: {0}", ex.Message);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShowUsage();
|
|
}
|
|
}
|
|
|
|
private static void ShowUsage()
|
|
{
|
|
Console.WriteLine(@"Usage:
|
|
TestEnvConfig
|
|
Show this help message
|
|
|
|
TestEnvConfig -?
|
|
Show this help message
|
|
|
|
TestEnvConfig setting_file
|
|
Run the program as a command line application
|
|
The program reads the test configurations from the setting_file and
|
|
saves them locally. the passwords will be stored in the credential store
|
|
|
|
The following is an example of a setting_file:
|
|
|
|
<Configuration>
|
|
<Instance Name=""defaultSql2005"">
|
|
<DataSource>SQL2005 servername</DataSource>
|
|
<BackupMethod>RemoteShare</BackupMethod>
|
|
<RemoteShare>SQL 2005 remote share</RemoteShare>
|
|
</Instance>
|
|
<Instance Name=""defaultSql2008"">
|
|
<DataSource>SQL2008 servername</DataSource>
|
|
<BackupMethod>RemoteShare</BackupMethod>
|
|
<RemoteShare>SQL 2008 remote share</RemoteShare>
|
|
</Instance>
|
|
<Instance Name=""defaultSql2011"">
|
|
<DataSource>SQL2011 servername</DataSource>
|
|
<BackupMethod>RemoteShare</BackupMethod>
|
|
<RemoteShare>SQL 20011 remote share</RemoteShare>
|
|
</Instance>
|
|
<Instance Name=""defaultSqlAzureV12"">
|
|
<DataSource>SQLAzure servername</DataSource>
|
|
<BackupMethod>RemoteShare</BackupMethod>
|
|
<RemoteShare>SQLAzure remote share</RemoteShare>
|
|
<UserId>user id</UserId>
|
|
<Password>password</Password>
|
|
</Instance>
|
|
</Configuration>
|
|
");
|
|
}
|
|
|
|
private static void SaveSettings(string settingFile)
|
|
{
|
|
|
|
var xdoc = XDocument.Load(settingFile);
|
|
var settings =
|
|
from setting in xdoc.Descendants("Instance")
|
|
select new InstanceInfo(setting.Attribute("VersionKey").Value) // VersionKey is required
|
|
{
|
|
ServerName = setting.Element("DataSource").Value, // DataSource is required
|
|
ConnectTimeoutAsString = (string)setting.Element("ConnectTimeout"), //ConnectTimeout is optional
|
|
User = (string)setting.Element("UserId"), // UserID is optional
|
|
Password = (string)setting.Element("Password"),
|
|
RemoteSharePath = (string)setting.Element("RemoteShare"), // RemoteShare is optional
|
|
AuthenticationType = string.IsNullOrEmpty((string)setting.Element("UserId")) ? AuthenticationType.Integrated : AuthenticationType.SqlLogin
|
|
};
|
|
|
|
TestConfigPersistenceHelper.Write(settings);
|
|
|
|
}
|
|
}
|
|
}
|