Beispiel #1
0
        public T Deserialize <T>(WellKnownSynchronizationKind kind, ObjectReader reader, CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.Serializer_Deserialize, kind.ToString(), cancellationToken))
            {
                cancellationToken.ThrowIfCancellationRequested();

                switch (kind)
                {
                case WellKnownSynchronizationKind.Null:
                    return(default);

                case WellKnownSynchronizationKind.SolutionState:
                case WellKnownSynchronizationKind.ProjectState:
                case WellKnownSynchronizationKind.DocumentState:
                case WellKnownSynchronizationKind.Projects:
                case WellKnownSynchronizationKind.Documents:
                case WellKnownSynchronizationKind.TextDocuments:
                case WellKnownSynchronizationKind.ProjectReferences:
                case WellKnownSynchronizationKind.MetadataReferences:
                case WellKnownSynchronizationKind.AnalyzerReferences:
                    return((T)(object)DeserializeChecksumWithChildren(reader, cancellationToken));

                case WellKnownSynchronizationKind.SolutionAttributes:
                    return((T)(object)SolutionInfo.SolutionAttributes.ReadFrom(reader));

                case WellKnownSynchronizationKind.ProjectAttributes:
                    return((T)(object)ProjectInfo.ProjectAttributes.ReadFrom(reader));

                case WellKnownSynchronizationKind.DocumentAttributes:
                    return((T)(object)DocumentInfo.DocumentAttributes.ReadFrom(reader));

                case WellKnownSynchronizationKind.CompilationOptions:
                    return((T)(object)DeserializeCompilationOptions(reader, cancellationToken));

                case WellKnownSynchronizationKind.ParseOptions:
                    return((T)(object)DeserializeParseOptions(reader, cancellationToken));

                case WellKnownSynchronizationKind.ProjectReference:
                    return((T)(object)DeserializeProjectReference(reader, cancellationToken));

                case WellKnownSynchronizationKind.MetadataReference:
                    return((T)(object)DeserializeMetadataReference(reader, cancellationToken));

                case WellKnownSynchronizationKind.AnalyzerReference:
                    return((T)(object)DeserializeAnalyzerReference(reader, cancellationToken));

                case WellKnownSynchronizationKind.SourceText:
                    return((T)(object)DeserializeSourceText(reader, cancellationToken));

                case WellKnownSynchronizationKind.OptionSet:
                    return((T)(object)DeserializeOptionSet(reader, cancellationToken));

                default:
                    throw ExceptionUtilities.UnexpectedValue(kind);
                }
            }
        }
Beispiel #2
0
        private static Checksum CreateChecksumFromStreamWriter(WellKnownSynchronizationKind kind, Action <ObjectWriter, CancellationToken> writer)
        {
            using var stream       = SerializableBytes.CreateWritableStream();
            using var objectWriter = new ObjectWriter(stream);

            objectWriter.WriteInt32((int)kind);
            writer(objectWriter, CancellationToken.None);
            return(Checksum.Create(stream));
        }
Beispiel #3
0
        public static Checksum Create(WellKnownSynchronizationKind kind, IObjectWritable @object)
        {
            using var stream       = SerializableBytes.CreateWritableStream();
            using var objectWriter = new ObjectWriter(stream);
            objectWriter.WriteInt32((int)kind);
            @object.WriteTo(objectWriter);

            return(Create(stream));
        }
            public ChecksumObjectCollection(SerializationValidator validator, ChecksumCollection collection)
            {
                Checksum = collection.Checksum;
                Kind     = collection.GetWellKnownSynchronizationKind();

                // using .Result here since we don't want to convert all calls to this to async.
                // and none of ChecksumWithChildren actually use async
                Children = ImmutableArray.CreateRange(collection.Select(c => validator.GetValueAsync <T>(c).Result));
            }
Beispiel #5
0
 public static Checksum Create <T>(WellKnownSynchronizationKind kind, T value, ISerializerService serializer)
 {
     using (var stream = SerializableBytes.CreateWritableStream())
         using (var objectWriter = new ObjectWriter(stream))
         {
             objectWriter.WriteInt32((int)kind);
             serializer.Serialize(value, objectWriter, CancellationToken.None);
             return(Create(stream));
         }
 }
Beispiel #6
0
        public SolutionAsset(object?value, Checksum checksum, WellKnownSynchronizationKind kind)
        {
            // SolutionAsset is not allowed to hold strong references to SourceText. SerializableSourceText is used
            // instead to allow data to be released from process address space when it is also held in temporary
            // storage.
            // https://github.com/dotnet/roslyn/issues/43802
            Contract.ThrowIfTrue(kind is WellKnownSynchronizationKind.SourceText);

            Checksum = checksum;
            Kind     = kind;
            Value    = value;
        }
Beispiel #7
0
        public static Checksum Create(WellKnownSynchronizationKind kind, ImmutableArray <byte> bytes)
        {
            using var stream = SerializableBytes.CreateWritableStream();
            using var writer = new ObjectWriter(stream);
            writer.WriteInt32((int)kind);

            for (var i = 0; i < bytes.Length; i++)
            {
                writer.WriteByte(bytes[i]);
            }

            return(Create(stream));
        }
Beispiel #8
0
        public static Checksum Create(WellKnownSynchronizationKind kind, IEnumerable <Checksum> checksums)
        {
            using var stream = SerializableBytes.CreateWritableStream();
            using var writer = new ObjectWriter(stream);
            writer.WriteInt32((int)kind);

            foreach (var checksum in checksums)
            {
                checksum.WriteTo(writer);
            }

            return(Create(stream));
        }
        internal static async Task <T> VerifyAssetSerializationAsync <T>(
            IRemotableDataService service,
            Checksum checksum,
            WellKnownSynchronizationKind kind,
            Func <T, WellKnownSynchronizationKind, ISerializerService, RemotableData> assetGetter)
        {
            // re-create asset from object
            var syncService = (RemotableDataServiceFactory.Service)service;
            var syncObject  = syncService.GetRemotableData_TestOnly(checksum, CancellationToken.None);

            var recoveredValue = await service.GetValueAsync <T>(checksum);

            var recreatedSyncObject = assetGetter(recoveredValue, kind, syncService.Serializer_TestOnly);

            // make sure original object and re-created object are same.
            SynchronizationObjectEqual(syncObject, recreatedSyncObject);

            return(recoveredValue);
        }
        internal static async Task VerifyChecksumInServiceAsync(IRemotableDataService snapshotService, Checksum checksum, WellKnownSynchronizationKind kind)
        {
            Assert.NotNull(checksum);
            var service     = (RemotableDataServiceFactory.Service)snapshotService;
            var otherObject = (await service.TestOnly_GetRemotableDataAsync(checksum, CancellationToken.None).ConfigureAwait(false)) !;

            ChecksumEqual(checksum, kind, otherObject.Checksum, otherObject.Kind);
        }
        internal static async Task VerifyCollectionInService(IRemotableDataService snapshotService, ChecksumCollection checksums, int expectedCount, WellKnownSynchronizationKind expectedItemKind)
        {
            await VerifyChecksumInServiceAsync(snapshotService, checksums.Checksum, checksums.GetWellKnownSynchronizationKind()).ConfigureAwait(false);

            Assert.Equal(checksums.Count, expectedCount);

            foreach (var checksum in checksums)
            {
                await VerifyChecksumInServiceAsync(snapshotService, checksum, expectedItemKind).ConfigureAwait(false);
            }
        }
Beispiel #12
0
 protected SolutionAsset(Checksum checksum, WellKnownSynchronizationKind kind)
     : base(checksum, kind)
 {
 }
Beispiel #13
0
 public ChecksumWithChildren(WellKnownSynchronizationKind kind, params object[] children)
 {
     Checksum = CreateChecksum(kind, children);
     Children = children;
 }
        internal static void VerifyChecksumInService(IRemotableDataService snapshotService, Checksum checksum, WellKnownSynchronizationKind kind)
        {
            Assert.NotNull(checksum);
            var service     = (RemotableDataServiceFactory.Service)snapshotService;
            var otherObject = service.GetRemotableData_TestOnly(checksum, CancellationToken.None);

            ChecksumEqual(checksum, kind, otherObject.Checksum, otherObject.Kind);
        }
Beispiel #15
0
 protected ChecksumCollection(WellKnownSynchronizationKind kind, Checksum[] checksums) : this(kind, (object[])checksums)
 {
 }
Beispiel #16
0
 public static string ToStringFast(this WellKnownSynchronizationKind kind)
 => s_strings[(int)kind];
Beispiel #17
0
 public SimpleCustomAsset(WellKnownSynchronizationKind kind, Action <ObjectWriter, CancellationToken> writer)
     : base(CreateChecksumFromStreamWriter(kind, writer), kind)
 {
     // unlike SolutionAsset which gets checksum from solution states, this one build one by itself.
     _writer = writer;
 }
Beispiel #18
0
 public CustomAsset(Checksum checksum, WellKnownSynchronizationKind kind) : base(checksum, kind)
 {
 }
Beispiel #19
0
 public SolutionAsset(object?value, Checksum checksum, WellKnownSynchronizationKind kind)
 {
     Checksum = checksum;
     Kind     = kind;
     Value    = value;
 }
 private static Checksum CreateChecksum(WellKnownSynchronizationKind kind, object[] children)
 {
     // given children must be either Checksum or Checksums (collection of a checksum)
     return(Checksum.Create(kind, children.Select(c => c as Checksum ?? ((ChecksumCollection)c).Checksum)));
 }
Beispiel #21
0
 protected ChecksumCollection(WellKnownSynchronizationKind kind, object[] checksums) : base(kind, checksums)
 {
 }
Beispiel #22
0
 public T Deserialize <T>(WellKnownSynchronizationKind kind, ObjectReader reader, CancellationToken cancellationToken)
 {
     return(s_serializer.Deserialize <T>(kind, reader, cancellationToken));
 }
        internal static void VerifyCollectionInService(IRemotableDataService snapshotService, ChecksumCollection checksums, int expectedCount, WellKnownSynchronizationKind expectedItemKind)
        {
            VerifyChecksumInService(snapshotService, checksums.Checksum, checksums.GetWellKnownSynchronizationKind());
            Assert.Equal(checksums.Count, expectedCount);

            foreach (var checksum in checksums)
            {
                VerifyChecksumInService(snapshotService, checksum, expectedItemKind);
            }
        }
Beispiel #24
0
 public RemotableData(Checksum checksum, WellKnownSynchronizationKind kind)
 {
     Checksum = checksum;
     Kind     = kind;
 }
 internal static void ChecksumEqual(Checksum checksum1, WellKnownSynchronizationKind kind1, Checksum checksum2, WellKnownSynchronizationKind kind2)
 {
     Assert.Equal(checksum1, checksum2);
     Assert.Equal(kind1, kind2);
 }
        internal static void VerifyChecksumInService(ISolutionSynchronizationService snapshotService, Checksum checksum, WellKnownSynchronizationKind kind)
        {
            Assert.NotNull(checksum);
            var otherObject = snapshotService.GetRemotableData(checksum, CancellationToken.None);

            ChecksumEqual(checksum, kind, otherObject.Checksum, otherObject.Kind);
        }