public static MetadataOnlyImage Create(ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken)) { // TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that // we don't allocate anything for skeleton assembly. using (var stream = SerializableBytes.CreateWritableStream()) { // note: cloning compilation so we don't retain all the generated symbols after its emitted. // * REVIEW * is cloning clone p2p reference compilation as well? var emitResult = compilation.Clone().EmitMetadataOnly(stream, cancellationToken: cancellationToken); if (emitResult.Success) { var storage = service.CreateTemporaryStorage(cancellationToken); stream.Position = 0; storage.WriteStream(stream, cancellationToken); return(new MetadataOnlyImage(storage, compilation.AssemblyName)); } } } return(Empty); }
public static MetadataOnlyImage Create(ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FeatureId.SkeletonAssembly, FunctionId.SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken)) { // TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that // we don't allocate anything for skeleton assembly. using (var stream = SerializableBytes.CreateWritableStream()) { // note: cloning compilation so we don't retain all the generated symbols after its emitted. // * REVIEW * is cloning clone p2p reference compilation as well? var emitResult = compilation.Clone().EmitMetadataOnly(stream, cancellationToken: cancellationToken); if (emitResult.Success) { var storage = service.CreateTemporaryStorage(cancellationToken); stream.Position = 0; storage.WriteStream(stream, cancellationToken); return new MetadataOnlyImage(storage, compilation.AssemblyName); } } } return Empty; }
private void TestTemporaryStorage(ITemporaryStorageService temporaryStorageService, SourceText text) { // create a temporary storage location var temporaryStorage = temporaryStorageService.CreateTemporaryStorage(System.Threading.CancellationToken.None); // write text into it temporaryStorage.WriteTextAsync(text).Wait(); // read text back from it var text2 = temporaryStorage.ReadTextAsync().Result; Assert.NotSame(text, text2); Assert.Equal(text.ToString(), text2.ToString()); temporaryStorage.Dispose(); }
private void TestTemporaryStorage(ITemporaryStorageService temporaryStorageService, SourceText text) { // create a temporary storage location var temporaryStorage = temporaryStorageService.CreateTemporaryStorage(System.Threading.CancellationToken.None); // write text into it temporaryStorage.WriteTextAsync(text).Wait(); // read text back from it var text2 = temporaryStorage.ReadTextAsync().Result; Assert.NotSame(text, text2); Assert.Equal(text.ToString(), text2.ToString()); temporaryStorage.Dispose(); }
public void Store(SyntaxTree tree, SyntaxNode root, ITemporaryStorageService service, CancellationToken cancellationToken) { ITemporaryStorage storage; if (map.TryGetValue(tree, out storage)) { // we already have it serialized to temporary storage return; } // tree will be always held alive in memory, but nodes come and go. serialize nodes to storage using (var stream = SerializableBytes.CreateWritableStream()) { root.SerializeTo(stream, cancellationToken); stream.Position = 0; storage = service.CreateTemporaryStorage(cancellationToken); storage.WriteStream(stream, cancellationToken); } SaveTreeToMap(tree, storage); }
public void Store(SyntaxTree tree, SyntaxNode root, ITemporaryStorageService service, CancellationToken cancellationToken) { ITemporaryStorage storage; if (map.TryGetValue(tree, out storage)) { // we already have it serialized to temporary storage return; } // tree will be always held alive in memory, but nodes come and go. serialize nodes to storage using (var stream = SerializableBytes.CreateWritableStream()) { root.SerializeTo(stream, cancellationToken); stream.Position = 0; storage = service.CreateTemporaryStorage(cancellationToken); storage.WriteStream(stream, cancellationToken); } SaveTreeToMap(tree, storage); }