Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #763 from dotnet/improve-folder-performance
Improve folder workspace performance
- Loading branch information
Showing
14 changed files
with
210 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.Json; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.CodeAnalysis.Tools | ||
{ | ||
internal static class ReportWriter | ||
{ | ||
public static void Write(string reportPath, IEnumerable<FormattedFile> formattedFiles, ILogger logger) | ||
{ | ||
var reportFilePath = GetReportFilePath(reportPath); | ||
var reportFolderPath = Path.GetDirectoryName(reportFilePath); | ||
|
||
if (!Directory.Exists(reportFolderPath)) | ||
{ | ||
Directory.CreateDirectory(reportFolderPath); | ||
} | ||
|
||
logger.LogInformation(Resources.Writing_formatting_report_to_0, reportFilePath); | ||
|
||
var seralizerOptions = new JsonSerializerOptions | ||
{ | ||
WriteIndented = true | ||
}; | ||
var formattedFilesJson = JsonSerializer.Serialize(formattedFiles, seralizerOptions); | ||
|
||
File.WriteAllText(reportFilePath, formattedFilesJson); | ||
} | ||
|
||
private static string GetReportFilePath(string reportPath) | ||
{ | ||
var defaultReportName = "format-report.json"; | ||
if (reportPath.EndsWith(".json")) | ||
{ | ||
return reportPath; | ||
} | ||
else if (reportPath == ".") | ||
{ | ||
return Path.Combine(Environment.CurrentDirectory, defaultReportName); | ||
} | ||
else | ||
{ | ||
return Path.Combine(reportPath, defaultReportName); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.