зеркало из https://github.com/dotnet/razor.git
Remove RazorProjectInfoFileSerializer
This commit is contained in:
Родитель
cb203a189d
Коммит
76ab7e465f
|
@ -26,7 +26,6 @@ using Microsoft.CodeAnalysis.Razor.DocumentMapping;
|
|||
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
|
||||
using Microsoft.CodeAnalysis.Razor.Protocol;
|
||||
using Microsoft.CodeAnalysis.Razor.SemanticTokens;
|
||||
using Microsoft.CodeAnalysis.Razor.Serialization;
|
||||
using Microsoft.CodeAnalysis.Razor.Workspaces;
|
||||
using Microsoft.CommonLanguageServerProtocol.Framework;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Razor.ProjectSystem;
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Razor.Serialization;
|
||||
|
||||
internal interface IRazorProjectInfoFileSerializer
|
||||
{
|
||||
Task<string> SerializeToTempFileAsync(RazorProjectInfo projectInfo, CancellationToken cancellationToken);
|
||||
Task<RazorProjectInfo> DeserializeFromFileAndDeleteAsync(string filePath, CancellationToken cancellationToken);
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. 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.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MessagePack;
|
||||
using MessagePack.Resolvers;
|
||||
using Microsoft.AspNetCore.Razor.ProjectSystem;
|
||||
using Microsoft.AspNetCore.Razor.Serialization.MessagePack.Resolvers;
|
||||
using Microsoft.CodeAnalysis.Razor.Logging;
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Razor.Serialization;
|
||||
|
||||
internal class RazorProjectInfoFileSerializer(ILoggerFactory loggerFactory) : IRazorProjectInfoFileSerializer, IDisposable
|
||||
{
|
||||
private static readonly MessagePackSerializerOptions s_options = MessagePackSerializerOptions.Standard
|
||||
.WithResolver(CompositeResolver.Create(
|
||||
RazorProjectInfoResolver.Instance,
|
||||
StandardResolver.Instance));
|
||||
|
||||
private readonly ILogger _logger = loggerFactory.GetOrCreateLogger<RazorProjectInfoFileSerializer>();
|
||||
private readonly List<string> _filePathsToDelete = [];
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_filePathsToDelete.Count > 0)
|
||||
{
|
||||
foreach (var filePath in _filePathsToDelete)
|
||||
{
|
||||
DeleteFile(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> SerializeToTempFileAsync(RazorProjectInfo projectInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
var filePath = Path.GetTempFileName();
|
||||
|
||||
using var stream = File.OpenWrite(filePath);
|
||||
await MessagePackSerializer.SerializeAsync(stream, projectInfo, s_options, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public async Task<RazorProjectInfo> DeserializeFromFileAndDeleteAsync(string filePath, CancellationToken cancellationToken)
|
||||
{
|
||||
RazorProjectInfo projectInfo;
|
||||
|
||||
using (var stream = File.OpenRead(filePath))
|
||||
{
|
||||
projectInfo = await MessagePackSerializer.DeserializeAsync<RazorProjectInfo>(stream, s_options, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (!DeleteFile(filePath))
|
||||
{
|
||||
_filePathsToDelete.Add(filePath);
|
||||
}
|
||||
|
||||
return projectInfo;
|
||||
}
|
||||
|
||||
private bool DeleteFile(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.Delete(filePath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"{ex.GetType().FullName} encountered when attempting to delete '{filePath}'");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT license. See License.txt in the project root for license information.
|
||||
|
||||
using System.ComponentModel.Composition;
|
||||
using Microsoft.CodeAnalysis.Razor.Logging;
|
||||
using Microsoft.CodeAnalysis.Razor.Serialization;
|
||||
|
||||
namespace Microsoft.VisualStudio.Razor.LanguageClient.ProjectSystem;
|
||||
|
||||
[Export(typeof(IRazorProjectInfoFileSerializer))]
|
||||
[method: ImportingConstructor]
|
||||
internal sealed class VisualStudioRazorProjectInfoFileSerializer(ILoggerFactory loggerFactory)
|
||||
: RazorProjectInfoFileSerializer(loggerFactory)
|
||||
{
|
||||
}
|
Загрузка…
Ссылка в новой задаче