Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Culture Specified by User in case it differs with that of OS #1712

Merged
merged 9 commits into from
Aug 3, 2018
18 changes: 18 additions & 0 deletions src/datacollector/DataCollectorMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Microsoft.VisualStudio.TestPlatform.DataCollector
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using PlatformAbstractions.Interfaces;
using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources;
using CoreUtilitiesConstants = Microsoft.VisualStudio.TestPlatform.CoreUtilities.Constants;
Expand Down Expand Up @@ -140,6 +141,23 @@ private void WaitForDebuggerIfEnabled()
}
}

private static void SetCultureSpecifiedByUser()
{
var userCultureSpecified = Environment.GetEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE");
if (!string.IsNullOrWhiteSpace(userCultureSpecified))
{
try
{
CultureInfo info = new CultureInfo(userCultureSpecified);
CultureInfo.DefaultThreadCurrentUICulture = info;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add example testing to PR description.

}
catch (Exception)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do EqtTrace here. ConsoleOutput not useful in datacollector process.

ConsoleOutput.Instance.WriteLine(string.Format("Invalid Culture Info: {0}", userCultureSpecified), OutputLevel.Information);
}
}
}

private void StartProcessing()
{
var timeout = EnvironmentHelper.GetConnectionTimeout();
Expand Down
20 changes: 19 additions & 1 deletion src/testhost.x86/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.TestHost
using System;
using System.Collections.Generic;
using System.Diagnostics;

using System.Globalization;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Tracing;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
Expand Down Expand Up @@ -52,6 +52,7 @@ public static void Main(string[] args)
public static void Run(string[] args)
{
WaitForDebuggerIfEnabled();
SetCultureSpecifiedByUser();
var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args);

// Invoke the engine with arguments
Expand Down Expand Up @@ -103,5 +104,22 @@ private static void WaitForDebuggerIfEnabled()
Debugger.Break();
}
}

private static void SetCultureSpecifiedByUser()
{
var userCultureSpecified = Environment.GetEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY.

if (!string.IsNullOrWhiteSpace(userCultureSpecified))
{
try
{
CultureInfo info = new CultureInfo(userCultureSpecified);
CultureInfo.DefaultThreadCurrentUICulture = info;
}
catch (Exception)
{
ConsoleOutput.Instance.WriteLine(string.Format("Invalid Culture Info: {0}", userCultureSpecified), OutputLevel.Information);
}
}
}
}
}
20 changes: 20 additions & 0 deletions src/vstest.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.TestPlatform.CommandLine
{
using System;
using System.Globalization;
using Microsoft.VisualStudio.TestPlatform.Utilities;

/// <summary>
Expand Down Expand Up @@ -36,7 +37,26 @@ public static int Main(string[] args)
System.Diagnostics.Debugger.Break();
}

SetCultureSpecifiedByUser();

return new Executor(ConsoleOutput.Instance).Execute(args);
}

private static void SetCultureSpecifiedByUser()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify where it should be common for all these 3 different application

{
var userCultureSpecified = Environment.GetEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE");
if(!string.IsNullOrWhiteSpace(userCultureSpecified))
{
try
{
CultureInfo info = new CultureInfo(userCultureSpecified);
CultureInfo.DefaultThreadCurrentUICulture = info;
}
catch(Exception)
{
ConsoleOutput.Instance.WriteLine(string.Format("Invalid Culture Info: {0}", userCultureSpecified), OutputLevel.Information);
}
}
}
}
}