Beispiel #1
0
        internal static SymbolTreeInfo ReadFrom(ObjectReader reader)
        {
            try
            {
                var formatVersion = reader.ReadString();
                if (!string.Equals(formatVersion, SerializationFormat, StringComparison.Ordinal))
                {
                    return(null);
                }

                var version = VersionStamp.ReadFrom(reader);

                var count = reader.ReadInt32();
                if (count == 0)
                {
                    return(new SymbolTreeInfo(version, ImmutableArray <Node> .Empty));
                }

                var nodes = new Node[count];
                for (var i = 0; i < count; i++)
                {
                    var name        = reader.ReadString();
                    var parentIndex = reader.ReadInt32();

                    nodes[i] = new Node(name, parentIndex);
                }

                return(new SymbolTreeInfo(version, nodes));
            }
            catch (Exception)
            {
            }

            return(null);
        }
            protected override Data TryGetExistingData(Stream stream, Document value, CancellationToken cancellationToken)
            {
                var list = SharedPools.Default <List <TodoItem> >().AllocateAndClear();

                try
                {
                    using (var reader = new ObjectReader(stream))
                    {
                        var format = reader.ReadString();
                        if (!string.Equals(format, FormatVersion))
                        {
                            return(null);
                        }

                        var textVersion = VersionStamp.ReadFrom(reader);
                        var dataVersion = VersionStamp.ReadFrom(reader);

                        AppendItems(reader, value, list, cancellationToken);

                        return(new Data(textVersion, dataVersion, list.ToImmutableArray <TodoItem>()));
                    }
                }
                catch (Exception)
                {
                    return(null);
                }
                finally
                {
                    SharedPools.Default <List <TodoItem> >().ClearAndFree(list);
                }
            }
        private static bool TryReadVersion(ObjectReader reader, string formatVersion, out VersionStamp version)
        {
            version = VersionStamp.Default;
            if (reader.ReadString() != formatVersion)
            {
                return(false);
            }

            version = VersionStamp.ReadFrom(reader);
            return(true);
        }
Beispiel #4
0
        public void VersionStamp_RoundTripText()
        {
            using var writerStream = new MemoryStream();
            using var writer       = new ObjectWriter(writerStream);
            var versionStamp = VersionStamp.Create();

            versionStamp.WriteTo(writer);

            using var readerStream = new MemoryStream(writerStream.ToArray());
            using var reader       = ObjectReader.TryGetReader(readerStream);
            var deserializedVersionStamp = VersionStamp.ReadFrom(reader);

            Assert.Equal(versionStamp, deserializedVersionStamp);
        }
        private static SymbolTreeInfo ReadSymbolTreeInfo(
            ObjectReader reader,
            Func <VersionStamp, ImmutableArray <Node>, Task <SpellChecker> > createSpellCheckerTask)
        {
            try
            {
                var formatVersion = reader.ReadString();
                if (string.Equals(formatVersion, SerializationFormat, StringComparison.Ordinal))
                {
                    var version = VersionStamp.ReadFrom(reader);

                    var nodeCount = reader.ReadInt32();

                    var nodeBuilder = ImmutableArray.CreateBuilder <Node>(nodeCount);
                    for (var i = 0; i < nodeCount; i++)
                    {
                        var name        = reader.ReadString();
                        var parentIndex = reader.ReadInt32();

                        nodeBuilder.Add(new Node(name, parentIndex));
                    }

                    var nodes = nodeBuilder.MoveToImmutable();

                    var inheritanceMap         = new OrderPreservingMultiDictionary <int, int>();
                    var inheritanceMapKeyCount = reader.ReadInt32();
                    for (var i = 0; i < inheritanceMapKeyCount; i++)
                    {
                        var key        = reader.ReadInt32();
                        var valueCount = reader.ReadInt32();

                        for (var j = 0; j < valueCount; j++)
                        {
                            var value = reader.ReadInt32();
                            inheritanceMap.Add(key, value);
                        }
                    }

                    var spellCheckerTask = createSpellCheckerTask(version, nodes);
                    return(new SymbolTreeInfo(version, nodes, inheritanceMap, spellCheckerTask));
                }
            }
            catch
            {
                Logger.Log(FunctionId.SymbolTreeInfo_ExceptionInCacheRead);
            }

            return(null);
        }
Beispiel #6
0
        private static SymbolTreeInfo ReadSymbolTreeInfo(
            ObjectReader reader,
            Func <VersionStamp, string, Node[], Task <SpellChecker> > createSpellCheckerTask)
        {
            try
            {
                var formatVersion = reader.ReadString();
                if (string.Equals(formatVersion, SerializationFormat, StringComparison.Ordinal))
                {
                    var version = VersionStamp.ReadFrom(reader);

                    var concatenatedNames = reader.ReadString();

                    var nodeCount = reader.ReadInt32();
                    var nodes     = new Node[nodeCount];
                    for (var i = 0; i < nodeCount; i++)
                    {
                        var start       = reader.ReadInt32();
                        var length      = reader.ReadInt32();
                        var parentIndex = reader.ReadInt32();

                        nodes[i] = new Node(new TextSpan(start, length), parentIndex);
                    }

                    var inheritanceMap         = new OrderPreservingMultiDictionary <int, int>();
                    var inheritanceMapKeyCount = reader.ReadInt32();
                    for (var i = 0; i < inheritanceMapKeyCount; i++)
                    {
                        var key        = reader.ReadInt32();
                        var valueCount = reader.ReadInt32();

                        for (var j = 0; j < valueCount; j++)
                        {
                            var value = reader.ReadInt32();
                            inheritanceMap.Add(key, value);
                        }
                    }

                    var spellCheckerTask = createSpellCheckerTask(version, concatenatedNames, nodes);
                    return(new SymbolTreeInfo(version, concatenatedNames, nodes, spellCheckerTask, inheritanceMap));
                }
            }
            catch
            {
                Logger.Log(FunctionId.SymbolTreeInfo_ExceptionInCacheRead);
            }

            return(null);
        }
        private VersionStamp GetIdentifierSetVersion(int projectId, int documentId, int identifierId, object unused1, object unused2, CancellationToken cancellationToken)
        {
            using (var accessor = _esentStorage.GetIdentifierLocationTableAccessor())
                using (var stream = accessor.GetReadStream(projectId, documentId, identifierId))
                {
                    if (stream == null)
                    {
                        return(VersionStamp.Default);
                    }

                    using (var reader = new ObjectReader(stream))
                    {
                        return(VersionStamp.ReadFrom(reader));
                    }
                }
        }
        public static async Task <DesignerAttributeProjectData> ReadAsync(
            Project project, CancellationToken cancellationToken)
        {
            try
            {
                var solution       = project.Solution;
                var storageService = (IPersistentStorageService2)solution.Workspace.Services.GetService <IPersistentStorageService>();

                using (var persistenceService = storageService.GetStorage(solution, checkBranchId: false))
                    using (var stream = await persistenceService.ReadStreamAsync(project, StreamName, cancellationToken).ConfigureAwait(false))
                        using (var reader = ObjectReader.TryGetReader(stream, cancellationToken))
                        {
                            if (reader != null)
                            {
                                var version = reader.ReadString();
                                if (version == FormatVersion)
                                {
                                    var semanticVersion = VersionStamp.ReadFrom(reader);

                                    var resultCount = reader.ReadInt32();
                                    var builder     = ImmutableDictionary.CreateBuilder <string, DesignerAttributeDocumentData>();

                                    for (var i = 0; i < resultCount; i++)
                                    {
                                        var filePath       = reader.ReadString();
                                        var attribute      = reader.ReadString();
                                        var containsErrors = reader.ReadBoolean();
                                        var notApplicable  = reader.ReadBoolean();

                                        builder[filePath] = new DesignerAttributeDocumentData(filePath, attribute, containsErrors, notApplicable);
                                    }

                                    return(new DesignerAttributeProjectData(semanticVersion, builder.ToImmutable()));
                                }
                            }
                        }
            }
            catch (Exception e) when(IOUtilities.IsNormalIOException(e))
            {
                // Storage APIs can throw arbitrary exceptions.
            }

            return(null);
        }
            private AnalysisData TryGetExistingData(Stream stream, Project project, Document document, CancellationToken cancellationToken)
            {
                var list = SharedPools.Default <List <DiagnosticData> >().AllocateAndClear();

                try
                {
                    using (var reader = new ObjectReader(stream))
                    {
                        var format = reader.ReadInt32();
                        if (format != FormatVersion)
                        {
                            return(null);
                        }

                        // saved data is for same analyzer of different version of dll
                        var analyzerVersion = VersionStamp.ReadFrom(reader);
                        if (analyzerVersion != _version)
                        {
                            return(null);
                        }

                        var textVersion = VersionStamp.ReadFrom(reader);
                        var dataVersion = VersionStamp.ReadFrom(reader);

                        if (dataVersion == VersionStamp.Default)
                        {
                            return(null);
                        }

                        AppendItems(reader, project, document, list, cancellationToken);

                        return(new AnalysisData(textVersion, dataVersion, list.ToImmutableArray()));
                    }
                }
                catch (Exception)
                {
                    return(null);
                }
                finally
                {
                    SharedPools.Default <List <DiagnosticData> >().ClearAndFree(list);
                }
            }
            protected override Data TryGetExistingData(Stream stream, Document value, CancellationToken cancellationToken)
            {
                using var reader = ObjectReader.TryGetReader(stream, leaveOpen: true, cancellationToken);

                if (reader != null)
                {
                    var format = reader.ReadString();
                    if (string.Equals(format, FormatVersion, StringComparison.InvariantCulture))
                    {
                        var textVersion = VersionStamp.ReadFrom(reader);
                        var dataVersion = VersionStamp.ReadFrom(reader);
                        var designerAttributeArgument = reader.ReadString();

                        return(new Data(textVersion, dataVersion, designerAttributeArgument));
                    }
                }

                return(null);
            }
Beispiel #11
0
        private static bool TryReadFrom(Project project, string keyName, out Versions versions)
        {
            versions = default(Versions);

            var service = project.Solution.Workspace.Services.GetService <IPersistentStorageService>();

            if (service == null)
            {
                return(false);
            }

            using (var storage = service.GetStorage(project.Solution))
                using (var stream = storage.ReadStreamAsync(keyName, CancellationToken.None).WaitAndGetResult(CancellationToken.None))
                {
                    if (stream == null)
                    {
                        return(false);
                    }

                    try
                    {
                        using (var reader = new ObjectReader(stream))
                        {
                            var formatVersion = reader.ReadInt32();
                            if (formatVersion != SerializationFormat)
                            {
                                return(false);
                            }

                            var persistedProjectVersion  = VersionStamp.ReadFrom(reader);
                            var persistedSemanticVersion = VersionStamp.ReadFrom(reader);

                            versions = new Versions(persistedProjectVersion, persistedSemanticVersion);
                            return(true);
                        }
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
        }
Beispiel #12
0
        internal static SpellChecker ReadFrom(ObjectReader reader)
        {
            try
            {
                var formatVersion = reader.ReadString();
                if (string.Equals(formatVersion, SerializationFormat, StringComparison.Ordinal))
                {
                    var version = VersionStamp.ReadFrom(reader);
                    var bkTree  = BKTree.ReadFrom(reader);
                    if (bkTree != null)
                    {
                        return(new SpellChecker(version, bkTree));
                    }
                }
            }
            catch
            {
                Logger.Log(FunctionId.SpellChecker_ExceptionInCacheRead);
            }

            return(null);
        }
Beispiel #13
0
            protected override Data TryGetExistingData(Stream stream, Document value, CancellationToken cancellationToken)
            {
                using var reader = ObjectReader.TryGetReader(stream, leaveOpen: true, cancellationToken);

                if (reader != null)
                {
                    var format = reader.ReadString();
                    if (string.Equals(format, FormatVersion))
                    {
                        var textVersion = VersionStamp.ReadFrom(reader);
                        var dataVersion = VersionStamp.ReadFrom(reader);

                        using var listDisposer = ArrayBuilder <TodoItem> .GetInstance(out var list);

                        AppendItems(reader, value, list, cancellationToken);

                        return(new Data(textVersion, dataVersion, list.ToImmutable()));
                    }
                }

                return(null);
            }
Beispiel #14
0
        private StrongBox <ImmutableArray <DiagnosticData> > ReadFrom(ObjectReader reader, Project project, Document document, CancellationToken cancellationToken)
        {
            try
            {
                using (var pooledObject = SharedPools.Default <List <DiagnosticData> >().GetPooledObject())
                {
                    var list = pooledObject.Object;

                    var format = reader.ReadInt32();
                    if (format != FormatVersion)
                    {
                        return(null);
                    }

                    // saved data is for same analyzer of different version of dll
                    var analyzerVersion = VersionStamp.ReadFrom(reader);
                    if (analyzerVersion != AnalyzerVersion)
                    {
                        return(null);
                    }

                    var version = VersionStamp.ReadFrom(reader);
                    if (version != VersionStamp.Default && version != Version)
                    {
                        return(null);
                    }

                    ReadFrom(reader, project, document, list, cancellationToken);

                    return(new StrongBox <ImmutableArray <DiagnosticData> >(list.ToImmutableArray()));
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
        private static SymbolTreeInfo ReadSymbolTreeInfo(
            ObjectReader reader, Func <VersionStamp, Node[], Task <SpellChecker> > createSpellCheckerTask)
        {
            try
            {
                var formatVersion = reader.ReadString();
                if (string.Equals(formatVersion, SerializationFormat, StringComparison.Ordinal))
                {
                    var version = VersionStamp.ReadFrom(reader);

                    var count = reader.ReadInt32();
                    if (count == 0)
                    {
                        return(new SymbolTreeInfo(version, ImmutableArray <Node> .Empty,
                                                  Task.FromResult(new SpellChecker(version, BKTree.Empty))));
                    }

                    var nodes = new Node[count];
                    for (var i = 0; i < count; i++)
                    {
                        var name        = reader.ReadString();
                        var parentIndex = reader.ReadInt32();

                        nodes[i] = new Node(name, parentIndex);
                    }

                    var spellCheckerTask = createSpellCheckerTask(version, nodes);
                    return(new SymbolTreeInfo(version, nodes, spellCheckerTask));
                }
            }
            catch
            {
                Logger.Log(FunctionId.SymbolTreeInfo_ExceptionInCacheRead);
            }

            return(null);
        }
Beispiel #16
0
            protected override Data TryGetExistingData(Stream stream, Document value, CancellationToken cancellationToken)
            {
                try
                {
                    using (var reader = new ObjectReader(stream))
                    {
                        var format = reader.ReadString();
                        if (!string.Equals(format, FormatVersion, StringComparison.InvariantCulture))
                        {
                            return(null);
                        }

                        var textVersion = VersionStamp.ReadFrom(reader);
                        var dataVersion = VersionStamp.ReadFrom(reader);
                        var designerAttributeArgument = reader.ReadString();

                        return(new Data(textVersion, dataVersion, designerAttributeArgument));
                    }
                }
                catch (Exception)
                {
                    return(null);
                }
            }