예제 #1
0
        internal static void VerifyChecksumInService(ISolutionSynchronizationService snapshotService, Checksum checksum, string kind)
        {
            Assert.NotNull(checksum);
            var otherObject = snapshotService.GetRemotableData(checksum, CancellationToken.None);

            ChecksumEqual(checksum, kind, otherObject.Checksum, otherObject.Kind);
        }
예제 #2
0
        internal static async Task <T> VerifyAssetSerializationAsync <T>(
            ISolutionSynchronizationService service,
            Checksum checksum,
            string kind,
            Func <T, string, Serializer, RemotableData> assetGetter)
        {
            // re-create asset from object
            var syncService = (SolutionSynchronizationServiceFactory.Service)service;
            var syncObject  = service.GetRemotableData(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);
        }
예제 #3
0
        public static async Task <T> GetValueAsync <T>(this ISolutionSynchronizationService service, Checksum checksum)
        {
            var syncService = (SolutionSynchronizationServiceFactory.Service)service;
            var syncObject  = service.GetRemotableData(checksum, CancellationToken.None);

            using (var stream = SerializableBytes.CreateWritableStream())
                using (var writer = new StreamObjectWriter(stream))
                {
                    // serialize asset to bits
                    await syncObject.WriteObjectToAsync(writer, CancellationToken.None).ConfigureAwait(false);

                    stream.Position = 0;
                    using (var reader = new StreamObjectReader(stream))
                    {
                        // deserialize bits to object
                        var serializer = syncService.Serializer_TestOnly;
                        return(serializer.Deserialize <T>(syncObject.Kind, reader, CancellationToken.None));
                    }
                }
        }