Skip to content

Commit

Permalink
Initialize strings when reading binlog records
Browse files Browse the repository at this point in the history
Fixes #736
  • Loading branch information
KirillOsenkov committed Dec 19, 2023
1 parent abda033 commit 83a97d0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/BinlogTool/BinlogTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.0.8</Version>
<Version>1.0.9</Version>
<TargetFramework>net7.0</TargetFramework>
<RollForward>major</RollForward>
<LangVersion>latest</LangVersion>
Expand Down
23 changes: 23 additions & 0 deletions src/StructuredLogger/BinaryLogger/BuildEventArgsReader.Viewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ private BuildEventArgs SynthesizePropertyReassignment(BuildEventArgsFields field
return e;
}

private bool sawCulture;

private void OnMessageRead(BuildMessageEventArgs args)
{
if (sawCulture)
{
return;
}

if (args.SenderName == "BinaryLogger" &&
args.Message is string message &&
message.StartsWith("CurrentUICulture", StringComparison.Ordinal))
{
sawCulture = true;
var kvp = TextUtilities.ParseNameValue(message);
string culture = kvp.Value;
if (!string.IsNullOrEmpty(culture))
{
Strings.Initialize(culture);
}
}
}

private string GetTargetStartedMessage(string projectFile, string targetFile, string parentTarget, string targetName)
{
if (string.Equals(projectFile, targetFile, StringComparison.OrdinalIgnoreCase))
Expand Down
6 changes: 5 additions & 1 deletion src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ private BuildEventArgs ReadBuildMessageEventArgs()
return SynthesizePropertyReassignment(fields);
}

e = new BuildMessageEventArgs(
var buildMessageEventArgs = new BuildMessageEventArgs(
fields.Subcategory,
fields.Code,
fields.File,
Expand All @@ -915,6 +915,10 @@ private BuildEventArgs ReadBuildMessageEventArgs()
{
ProjectFile = fields.ProjectFile,
};

e = buildMessageEventArgs;

OnMessageRead(buildMessageEventArgs);
}
else
{
Expand Down
16 changes: 0 additions & 16 deletions src/StructuredLogger/Construction/Construction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ public void TaskFinished(object sender, TaskFinishedEventArgs args)
}
}

private bool sawCulture = false;

public void MessageRaised(object sender, BuildMessageEventArgs args)
{
try
Expand All @@ -478,20 +476,6 @@ public void MessageRaised(object sender, BuildMessageEventArgs args)
return;
}

if (!sawCulture &&
args.SenderName == "BinaryLogger" &&
args.Message is string message &&
message.StartsWith("CurrentUICulture", StringComparison.Ordinal))
{
sawCulture = true;
var kvp = TextUtilities.ParseNameValue(message);
string culture = kvp.Value;
if (!string.IsNullOrEmpty(culture))
{
Strings.Initialize(culture);
}
}

messageProcessor.Process(args);
}
}
Expand Down

0 comments on commit 83a97d0

Please sign in to comment.