Exemple #1
0
            public override async Task WriteObjectToAsync(ObjectWriter writer, CancellationToken cancellationToken)
            {
                var text = await _state.GetTextAsync(cancellationToken).ConfigureAwait(false);

                // TODO: make TextDocumentState to implement ISupportTemporaryStorage?
                _serializer.SerializeSourceText(_state.Storage as ITemporaryStorageWithName, text, writer, cancellationToken);
            }
Exemple #2
0
 internal void WriteTo(ObjectWriter writer)
 {
     writer.WriteInt32(WordSpan.Start);
     writer.WriteInt32(WordSpan.Length);
     writer.WriteInt32(EdgeCount);
     writer.WriteInt32(FirstEdgeIndex);
 }
        public void SerializeChecksumWithChildren(ChecksumWithChildren checksums, ObjectWriter writer, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var kind = checksums.GetWellKnownSynchronizationKind();
            writer.WriteString(kind);
            checksums.Checksum.WriteTo(writer);

            writer.WriteInt32(checksums.Children.Count);
            foreach (var child in checksums.Children)
            {
                var checksum = child as Checksum;
                if (checksum != null)
                {
                    writer.WriteByte(ChecksumKind);
                    checksum.WriteTo(writer);
                    continue;
                }

                var checksumCollection = child as ChecksumCollection;
                if (checksumCollection != null)
                {
                    writer.WriteByte(ChecksumWithChildrenKind);
                    SerializeChecksumWithChildren(checksumCollection, writer, cancellationToken);
                    continue;
                }

                throw ExceptionUtilities.UnexpectedValue(child);
            }
        }
 internal override void WriteTo(ObjectWriter writer)
 {
     base.WriteTo(writer);
     writer.WriteValue(_child0);
     writer.WriteValue(_child1);
     writer.WriteValue(_child2);
 }
        private static void WriteBitArray(ObjectWriter writer, BitArray bitArray)
        {
            // Our serialization format doesn't round-trip bit arrays of non-byte lengths
            Contract.ThrowIfTrue(bitArray.Length % 8 != 0);

            writer.WriteInt32(bitArray.Length / 8);

            // This will hold the byte that we will write out after we process every 8 bits. This is
            // LSB, so we push bits into it from the MSB.
            byte b = 0;

            for (var i = 0; i < bitArray.Length; i++)
            {
                if (bitArray[i])
                {
                    b = (byte)(0x80 | b >> 1);
                }
                else
                {
                    b >>= 1;
                }

                if ((i + 1) % 8 == 0)
                {
                    // End of a byte, write out the byte
                    writer.WriteByte(b);
                }
            }
        }
        private void WriteTo(Stream stream, ImmutableArray<DiagnosticData> items, CancellationToken cancellationToken)
        {
            using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
            {
                writer.WriteInt32(FormatVersion);

                AnalyzerVersion.WriteTo(writer);
                Version.WriteTo(writer);

                writer.WriteInt32(items.Length);

                foreach (var item in items)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    writer.WriteString(item.Id);
                    writer.WriteString(item.Category);

                    writer.WriteString(item.Message);
                    writer.WriteString(item.ENUMessageForBingSearch);
                    writer.WriteString(item.Title);
                    writer.WriteString(item.Description);
                    writer.WriteString(item.HelpLink);
                    writer.WriteInt32((int)item.Severity);
                    writer.WriteInt32((int)item.DefaultSeverity);
                    writer.WriteBoolean(item.IsEnabledByDefault);
                    writer.WriteBoolean(item.IsSuppressed);
                    writer.WriteInt32(item.WarningLevel);

                    if (item.HasTextSpan)
                    {
                        // document state
                        writer.WriteInt32(item.TextSpan.Start);
                        writer.WriteInt32(item.TextSpan.Length);
                    }
                    else
                    {
                        // project state
                        writer.WriteInt32(0);
                        writer.WriteInt32(0);
                    }

                    WriteTo(writer, item.DataLocation, cancellationToken);
                    WriteTo(writer, item.AdditionalLocations, cancellationToken);

                    writer.WriteInt32(item.CustomTags.Count);
                    foreach (var tag in item.CustomTags)
                    {
                        writer.WriteString(tag);
                    }

                    writer.WriteInt32(item.Properties.Count);
                    foreach (var property in item.Properties)
                    {
                        writer.WriteString(property.Key);
                        writer.WriteString(property.Value);
                    }
                }
            }
        }
        public async Task SerializeChecksumObjectWithChildrenAsync(ChecksumObjectWithChildren checksumObject, ObjectWriter writer, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            writer.WriteString(checksumObject.Kind);
            checksumObject.Checksum.WriteTo(writer);

            writer.WriteInt32(checksumObject.Children.Length);
            foreach (var child in checksumObject.Children)
            {
                var checksum = child as Checksum;
                if (checksum != null)
                {
                    writer.WriteByte(ChecksumKind);
                    checksum.WriteTo(writer);
                    continue;
                }

                var checksumCollection = child as ChecksumCollection;
                if (checksumCollection != null)
                {
                    writer.WriteByte(ChecksumCollectionKind);
                    await SerializeChecksumObjectWithChildrenAsync(checksumCollection, writer, cancellationToken).ConfigureAwait(false);
                    continue;
                }

                throw ExceptionUtilities.UnexpectedValue(child);
            }
        }
 public void WriteTo(ObjectWriter writer)
 {
     writer.WriteString(SerializationFormat);
     writer.WriteBoolean(_isCaseSensitive);
     writer.WriteInt32(_hashFunctionCount);
     _bitArray.WriteTo(writer);
 }
 public void WriteTo(ObjectWriter writer)
 {
     writer.WriteInt32(DeclaredSymbolInfos.Length);
     foreach (var declaredSymbolInfo in DeclaredSymbolInfos)
     {
         declaredSymbolInfo.WriteTo(writer);
     }
 }
        public override void WriteTo(CompilationOptions options, ObjectWriter writer, CancellationToken cancellationToken)
        {
            WriteCompilationOptionsTo(options, writer, cancellationToken);

            var csharpOptions = (CSharpCompilationOptions)options;
            writer.WriteValue(csharpOptions.Usings.ToArray());
            writer.WriteBoolean(csharpOptions.AllowUnsafe);
        }
 public override void WriteTo(ObjectWriter writer)
 {
     writer.WriteInt32(DeclaredSymbolInfos.Count());
     foreach (var declaredSymbolInfo in DeclaredSymbolInfos)
     {
         declaredSymbolInfo.WriteTo(writer);
     }
 }
        public override void WriteTo(ParseOptions options, ObjectWriter writer, CancellationToken cancellationToken)
        {
            WriteParseOptionsTo(options, writer, cancellationToken);

            var csharpOptions = (CSharpParseOptions)options;
            writer.WriteInt32((int)csharpOptions.LanguageVersion);
            writer.WriteValue(options.PreprocessorSymbolNames.ToArray());
        }
        public override void WriteTo(OptionSet options, ObjectWriter writer, CancellationToken cancellationToken)
        {
            WriteOptionSetTo(options, LanguageNames.CSharp, writer, cancellationToken);

            WriteOptionTo(options, CSharpCodeStyleOptions.UseImplicitTypeForIntrinsicTypes, writer, cancellationToken);
            WriteOptionTo(options, CSharpCodeStyleOptions.UseImplicitTypeWhereApparent, writer, cancellationToken);
            WriteOptionTo(options, CSharpCodeStyleOptions.UseImplicitTypeWherePossible, writer, cancellationToken);
        }
        // this is temporary solution until option is supported in compiler layer natively
        // this won't serialize all options but some we pre-selected
        public void SerializeOptionSet(OptionSet options, string language, ObjectWriter writer, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            writer.WriteString(language);

            var serializationService = GetOptionsSerializationService(language);
            serializationService.WriteTo(options, writer, cancellationToken);
        }
        public override void WriteTo(OptionSet options, ObjectWriter writer, CancellationToken cancellationToken)
        {
            WriteOptionSetTo(options, LanguageNames.CSharp, writer, cancellationToken);

            foreach (var option in CSharpCodeStyleOptions.GetCodeStyleOptions())
            {
                WriteOptionTo(options, option, writer, cancellationToken);
            }
        }
Exemple #16
0
 private static Checksum CreateChecksumFromStreamWriter(string kind, Action<ObjectWriter, CancellationToken> writer)
 {
     using (var stream = SerializableBytes.CreateWritableStream())
     using (var objectWriter = new ObjectWriter(stream))
     {
         objectWriter.WriteString(kind);
         writer(objectWriter, CancellationToken.None);
         return Checksum.Create(stream);
     }
 }
 internal void WriteTo(ObjectWriter writer)
 {
     writer.WriteString(Name);
     writer.WriteString(ContainerDisplayName);
     writer.WriteString(FullyQualifiedContainerName);
     writer.WriteByte((byte)Kind);
     writer.WriteInt32(Span.Start);
     writer.WriteInt32(Span.Length);
     writer.WriteUInt16(ParameterCount);
     writer.WriteUInt16(TypeParameterCount);
 }
Exemple #18
0
        public void SerializeSolutionSnapshotInfo(SolutionChecksumObjectInfo info, ObjectWriter writer, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            SerializeSolutionId(info.Id, writer, cancellationToken);

            // TODO: figure out a way to send version info over as well.
            //       right now, version get updated automatically, so 2 can't be exactly match
            // info.Version.WriteTo(writer);
            writer.WriteString(info.FilePath);
        }
        public Checksum CreateChecksum(AnalyzerReference reference, CancellationToken cancellationToken)
        {
            using (var stream = SerializableBytes.CreateWritableStream())
            using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
            {
                WriteTo(reference, writer, cancellationToken);

                stream.Position = 0;
                return Checksum.Create(stream);
            }
        }
Exemple #20
0
        public void SerializeCompilationOptions(CompilationOptions options, ObjectWriter writer, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var language = options.Language;

            // TODO: once compiler team adds ability to serialize compilation options to ObjectWriter directly, we won't need this.
            writer.WriteString(language);

            var service = GetOptionsSerializationService(language);
            service.WriteTo(options, writer, cancellationToken);
        }
        public SerializableVersionStamp(VersionStamp versionStamp)
        {
            using (var memoryStream = new MemoryStream())
            {
                using (var objectWriter = new ObjectWriter(memoryStream))
                {
                    versionStamp.WriteTo(objectWriter);
                }

                _bytes = memoryStream.ToArray();
            }
        }
        public void WriteTo(ObjectWriter writer)
        {
            writer.WriteString(SerializationFormat);
            _version.WriteTo(writer);

            writer.WriteInt32(_nodes.Count);
            foreach (var node in _nodes)
            {
                writer.WriteString(node.Name);
                writer.WriteInt32(node.ParentIndex);
            }
        }
Exemple #23
0
        public void SerializeDocumentSnapshotInfo(DocumentChecksumObjectInfo info, ObjectWriter writer, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            SerializeDocumentId(info.Id, writer, cancellationToken);

            writer.WriteString(info.Name);
            writer.WriteValue(info.Folders.ToArray());
            writer.WriteInt32((int)info.SourceCodeKind);
            writer.WriteString(info.FilePath);
            writer.WriteBoolean(info.IsGenerated);
        }
        private async Task SerializeDiagnosticResultAsync(string streamName, DiagnosticAnalysisResultMap<string, DiagnosticAnalysisResultBuilder> result)
        {
            using (var stream = await DirectStream.GetAsync(streamName, CancellationToken).ConfigureAwait(false))
            {
                using (var writer = new ObjectWriter(stream))
                {
                    DiagnosticResultSerializer.Serialize(writer, result, CancellationToken);
                }

                await stream.FlushAsync(CancellationToken).ConfigureAwait(false);
            }
        }
        private async Task SerializeDiagnosticResultAsync(string streamName, DiagnosticAnalysisResultMap<string, DiagnosticAnalysisResultBuilder> result)
        {
            using (RoslynLogger.LogBlock(FunctionId.CodeAnalysisService_SerializeDiagnosticResultAsync, GetResultLogInfo, result, CancellationToken))
            using (var stream = await DirectStream.GetAsync(streamName, CancellationToken).ConfigureAwait(false))
            {
                using (var writer = new ObjectWriter(stream))
                {
                    DiagnosticResultSerializer.Serialize(writer, result, CancellationToken);
                }

                await stream.FlushAsync(CancellationToken).ConfigureAwait(false);
            }
        }
            internal override void WriteTo(ObjectWriter writer)
            {
                base.WriteTo(writer);

                // PERF: Write the array out manually.Profiling shows that this is cheaper than converting to 
                // an array in order to use writer.WriteValue.
                writer.WriteInt32(this.children.Length);

                for (var i = 0; i < this.children.Length; i++)
                {
                    writer.WriteValue(this.children[i].Value);
                }
            }
        protected void WriteCompilationOptionsTo(CompilationOptions options, ObjectWriter writer, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            writer.WriteInt32((int)options.OutputKind);
            writer.WriteBoolean(options.ReportSuppressedDiagnostics);
            writer.WriteString(options.ModuleName);
            writer.WriteString(options.MainTypeName);
            writer.WriteString(options.ScriptClassName);
            writer.WriteInt32((int)options.OptimizationLevel);
            writer.WriteBoolean(options.CheckOverflow);

            // REVIEW: is it okay this being not part of snapshot?
            writer.WriteString(options.CryptoKeyContainer);
            writer.WriteString(options.CryptoKeyFile);

            writer.WriteValue(options.CryptoPublicKey.ToArray());
            writer.WriteBoolean(options.DelaySign.HasValue);
            if (options.DelaySign.HasValue)
            {
                writer.WriteBoolean(options.DelaySign.Value);
            }

            writer.WriteInt32((int)options.Platform);
            writer.WriteInt32((int)options.GeneralDiagnosticOption);

            writer.WriteInt32(options.WarningLevel);

            // REVIEW: I don't think there is a guarantee on ordering of elements in the immutable dictionary.
            //         unfortunately, we need to sort them to make it deterministic
            writer.WriteInt32(options.SpecificDiagnosticOptions.Count);
            foreach (var kv in options.SpecificDiagnosticOptions.OrderBy(o => o.Key))
            {
                writer.WriteString(kv.Key);
                writer.WriteInt32((int)kv.Value);
            }

            writer.WriteBoolean(options.ConcurrentBuild);
            writer.WriteBoolean(options.Deterministic);
            writer.WriteBoolean(options.PublicSign);

            // REVIEW: What should I do with these. we probably need to implement either out own one
            //         or somehow share these as service....
            //
            // XmlReferenceResolver xmlReferenceResolver
            // SourceReferenceResolver sourceReferenceResolver
            // MetadataReferenceResolver metadataReferenceResolver
            // AssemblyIdentityComparer assemblyIdentityComparer
            // StrongNameProvider strongNameProvider
        }
        /// <summary>
        /// this is for a project in a solution
        /// </summary>
        private static async Task<ValueTuple<bool, SymbolTreeInfo>> LoadOrCreateAsync(Project project, CancellationToken cancellationToken)
        {
            if (await project.IsForkedProjectWithSemanticChangesAsync(cancellationToken).ConfigureAwait(false))
            {
                return ValueTuple.Create(false, await CreateAsync(project, cancellationToken).ConfigureAwait(false));
            }

            var persistentStorageService = project.Solution.Workspace.Services.GetService<IPersistentStorageService>();
            var version = await project.GetSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

            // attempt to load from persisted state
            SymbolTreeInfo info;
            var succeeded = false;
            using (var storage = persistentStorageService.GetStorage(project.Solution))
            {
                using (var stream = await storage.ReadStreamAsync(project, ProjectSymbolTreeInfoPersistenceName, cancellationToken).ConfigureAwait(false))
                {
                    if (stream != null)
                    {
                        using (var reader = new ObjectReader(stream))
                        {
                            info = ReadFrom(reader);
                            if (info != null && VersionStamp.CanReusePersistedVersion(version, info.version))
                            {
                                return ValueTuple.Create(true, info);
                            }
                        }
                    }
                }

                cancellationToken.ThrowIfCancellationRequested();

                // compute it if we couldn't load it from cache
                info = await CreateAsync(project, cancellationToken).ConfigureAwait(false);
                if (info != null)
                {
                    using (var stream = SerializableBytes.CreateWritableStream())
                    using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
                    {
                        info.WriteTo(writer);
                        stream.Position = 0;

                        succeeded = await storage.WriteStreamAsync(project, ProjectSymbolTreeInfoPersistenceName, stream, cancellationToken).ConfigureAwait(false);
                    }
                }
            }

            return ValueTuple.Create(succeeded, info);
        }
Exemple #29
0
        public void SerializeProjectSnapshotInfo(ProjectChecksumObjectInfo info, ObjectWriter writer, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            SerializeProjectId(info.Id, writer, cancellationToken);

            // TODO: figure out a way to send version info over as well
            // info.Version.WriteTo(writer);

            writer.WriteString(info.Name);
            writer.WriteString(info.AssemblyName);
            writer.WriteString(info.Language);
            writer.WriteString(info.FilePath);
            writer.WriteString(info.OutputFilePath);
        }
        public static void WriteTo(this BitArray bitArray, ObjectWriter writer)
        {
            // TODO : think about a way to use pool for byte array.
            // BitArray will internally allocate another int array. probably need to drop BitArray usage.
            var bytes = new byte[(bitArray.Length + 7) / 8];
            bitArray.CopyTo(bytes, 0);

            writer.WriteString(SerializationFormat);
            writer.WriteInt32(bytes.Length);

            for (var i = 0; i < bytes.Length; i++)
            {
                writer.WriteByte(bytes[i]);
            }
        }
Exemple #31
0
 internal void WriteTo(ObjectWriter writer)
 {
     _bkTree.WriteTo(writer);
 }
Exemple #32
0
 internal void WriteTo(ObjectWriter writer)
 {
     writer.WriteString(SerializationFormat);
     Version.WriteTo(writer);
     _bkTree.WriteTo(writer);
 }