예제 #1
0
        internal static ProjectDependencyGraph ReadGraph(Solution solution, ObjectReader reader, CancellationToken cancellationToken)
        {
            var references = new List <ProjectId>();
            var map        = ImmutableDictionary.Create <ProjectId, ImmutableHashSet <ProjectId> >();
            var reverseMap = ImmutableDictionary.Create <ProjectId, ImmutableHashSet <ProjectId> >();

            var format = reader.ReadString();

            if (!string.Equals(format, SerializationFormat, StringComparison.Ordinal))
            {
                return(null);
            }

            var graphVersion = VersionStamp.ReadFrom(reader);

            var projectCount = reader.ReadInt32();

            for (var i = 0; i < projectCount; i++)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var referenceCount = reader.ReadInt32();
                if (referenceCount < 0)
                {
                    continue;
                }

                references.Clear();
                var projectFilePath = reader.ReadString();

                for (var j = 0; j < referenceCount; j++)
                {
                    var referenceFilePath = reader.ReadString();
                    var referenceProject  = GetProject(solution, referenceFilePath);
                    if (referenceProject == null)
                    {
                        return(null);
                    }

                    references.Add(referenceProject.Id);
                }

                var project = GetProject(solution, projectFilePath);
                if (project == null)
                {
                    return(null);
                }

                map        = map.Add(project.Id, ImmutableHashSet.CreateRange <ProjectId>(references));
                reverseMap = reverseMap.AddAll(references, project.Id);
            }

            return(new ProjectDependencyGraph(solution, graphVersion, map, reverseMap));
        }
예제 #2
0
        private static bool TryReadVersion(ObjectReader reader, out VersionStamp persistedVersion)
        {
            persistedVersion = VersionStamp.Default;
            if (reader?.ReadString() != SerializationFormat)
            {
                return(false);
            }

            persistedVersion = VersionStamp.ReadFrom(reader);
            return(true);
        }