private void SerializeBinary(AnalysisDocument doc, string file)
 {
     using (var stream = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write))
     {
         var formatter = new BinaryFormatter();
         formatter.Serialize(stream, doc);
     }
 }
        private void SerializeJson(AnalysisDocument doc, string file)
        {
            var serializer = new JsonSerializer();

            using (var sw = new StreamWriter(file))
            {
                using (var writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, doc);
                }
            }
        }
Exemplo n.º 3
0
        private AnalysisDocument GenerateDocument(IReadOnlyCollection <Reference> edges)
        {
            var doc = new AnalysisDocument();

            var nodesWithEdgesIndex = new HashSet <Type>();

            if (UsedTypesOnly)
            {
                foreach (var edge in edges)
                {
                    nodesWithEdgesIndex.Add(edge.From);
                    nodesWithEdgesIndex.Add(edge.To);
                }
            }

            var relevantNotesWithCluster = myPackageToTypesMap
                                           .Select(e => new
            {
                Package = myRelevantPackages.Single(p => p.Name == e.Key),
                Types   = e.Value
            })
                                           .SelectMany((e, idx) => e.Types
                                                       .Select(t => new
            {
                Type         = t,
                Package      = e.Package,
                PackageIndex = idx
            }))
                                           .AsParallel()
                                           .Where(e => !UsedTypesOnly || nodesWithEdgesIndex.Contains(e.Type))
                                           .Select(e => new
            {
                Node         = GraphUtils.Node(e.Type),
                Cluster      = GetCluster(e.Package, e.Type),
                PackageIndex = e.PackageIndex
            });

            foreach (var entry in relevantNotesWithCluster)
            {
                doc.Add(entry.Node);

                if (entry.Cluster != null)
                {
                    doc.AddToCluster(entry.Node, entry.Cluster);
                }

                if (myPackageToTypesMap.Count > 1)
                {
                    // color coding of nodes we only need if multiple packages were analyzed
                    doc.AddNodeColor(entry.Node, Colors[entry.PackageIndex % Colors.Length]);
                }
            }

            foreach (var edge in edges)
            {
                doc.Add(edge);

                var color = GetEdgeColor(edge);
                if (color != null)
                {
                    doc.AddEdgeColor(edge, color);
                }
            }

            return(doc);
        }
 internal void Serialize(AnalysisDocument doc, string file)
 {
     //SerializeJson(doc, file);
     SerializeBinary(doc, file);
 }