public async ValueTask <ImmutableArray <DiagnosticData> > DeserializeAsync(IPersistentStorageService persistentService, Project project, Document?document, string key, CancellationToken cancellationToken) { Contract.ThrowIfFalse(document == null || document.Project == project); using var storage = persistentService.GetStorage(project.Solution); var readTask = (document != null) ? storage.ReadStreamAsync(document, key, cancellationToken) : storage.ReadStreamAsync(project, key, cancellationToken); using var stream = await readTask.ConfigureAwait(false); using var reader = ObjectReader.TryGetReader(stream); if (reader == null) { return(default);
public async Task <bool> SerializeAsync(IPersistentStorageService persistentService, Project project, Document?document, string key, ImmutableArray <DiagnosticData> items, CancellationToken cancellationToken) { Contract.ThrowIfFalse(document == null || document.Project == project); using var stream = SerializableBytes.CreateWritableStream(); using var writer = new ObjectWriter(stream, cancellationToken: cancellationToken); WriteDiagnosticData(writer, items, cancellationToken); using var storage = persistentService.GetStorage(project.Solution); stream.Position = 0; var writeTask = (document != null) ? storage.WriteStreamAsync(document, key, stream, cancellationToken) : storage.WriteStreamAsync(project, key, stream, cancellationToken); return(await writeTask.ConfigureAwait(false)); }
public async ValueTask <ImmutableArray <DiagnosticData> > DeserializeAsync(IPersistentStorageService persistentService, Project project, TextDocument?textDocument, string key, CancellationToken cancellationToken) { Contract.ThrowIfFalse(textDocument == null || textDocument.Project == project); using var storage = persistentService.GetStorage(project.Solution); var readTask = (textDocument != null) ? textDocument is Document document? storage.ReadStreamAsync(document, key, cancellationToken) : storage.ReadStreamAsync(GetSerializationKeyForNonSourceDocument(textDocument, key), cancellationToken) : storage.ReadStreamAsync(project, key, cancellationToken); using var stream = await readTask.ConfigureAwait(false); using var reader = ObjectReader.TryGetReader(stream, cancellationToken: cancellationToken); if (reader == null || !TryReadDiagnosticData(reader, project, textDocument, cancellationToken, out var data)) { return(default);