/// <summary>
        /// Optional path can be specified to check for "context related" configuration.
        /// </summary>
        /// <returns></returns>
        public IGraphPresentation CreatePresentation( string dataRoot )
        {
            if ( !string.IsNullOrEmpty( dataRoot ) )
            {
                ConfigurationService.Update( dataRoot );
            }

            var presentation = new GraphPresentation();

            if ( ConfigurationService.Config.NodeIdAsDefaultToolTip )
            {
                presentation.GetPropertySetFor<ToolTipContent>().DefaultProvider = id => new ToolTipContent( id, new TextBlock { Text = id } );
            }

            presentation.GetModule<CaptionModule>().LabelConverter = new GenericLabelConverter( ConfigurationService.Config.LabelConversion );

            return presentation;
        }
示例#2
0
        // Show only nodes which can reach the target cluster
        private GraphPresentation ReduceGraph(Cluster targetCluster, RelaxedGraphBuilder builder)
        {
            var presentation = new GraphPresentation();

            presentation.Graph = builder.Graph;

            var algo = new AddRemoveTransitiveHull(presentation);

            algo.Add     = false;
            algo.Reverse = true;
            var mask = algo.Compute(targetCluster.Nodes);

            mask.Invert(presentation);

            presentation.Masks().Push(mask);

            presentation.Masks().Push(new RemoveNodesWithoutSiblings(presentation).Compute());

            return(presentation);
        }
        /// <summary>
        /// Optional path can be specified to check for "context related" configuration.
        /// </summary>
        /// <returns></returns>
        public IGraphPresentation CreatePresentation(string dataRoot)
        {
            if (!string.IsNullOrEmpty(dataRoot))
            {
                ConfigurationService.Update(dataRoot);
            }

            var presentation = new GraphPresentation();

            if (ConfigurationService.Config.NodeIdAsDefaultToolTip)
            {
                presentation.GetPropertySetFor <ToolTipContent>().DefaultProvider = id => new ToolTipContent(id, new TextBlock {
                    Text = id
                });
            }

            presentation.GetModule <CaptionModule>().LabelConverter = new GenericLabelConverter(ConfigurationService.Config.LabelConversion);

            return(presentation);
        }
        private GraphPresentation BuildCallTree(List <Assembly> sources, List <MethodDesc> targets, GraphPresentation assemblyGraphPresentation)
        {
            var relevantNodes = assemblyGraphPresentation.Graph.Nodes
                                .Where(n => assemblyGraphPresentation.Picking.Pick(n))
                                .ToList();

            var interfaceImplementationsMap = new InterfaceImplementationsMap();

            interfaceImplementationsMap.Build(relevantNodes, targets.Select(t => t.myDeclaringType));

            var calls = TraceCalles(relevantNodes, interfaceImplementationsMap, targets, sources);

            Console.WriteLine();
            Console.WriteLine("NOT analyzed assemblies:");

            foreach (var x in myMonoLoader.SkippedAssemblies)
            {
                Shell.Warn($"    {x}");
            }

            return(Shell.Profile("Generating call graph ...", () =>
            {
                var builder = new RelaxedGraphBuilder();
                var edges = calls
                            .Select(call => (CreateMethodNode(call.From), CreateMethodNode(call.To)))
                            // we assume that usages within same class are not relevant
                            .Where(x => x.Item1.myDeclaringType != x.Item2.myDeclaringType)
                            .ToList();

                foreach (var edge in edges)
                {
                    builder.TryAddEdge(edge.Item1.myId, edge.Item2.myId);
                }

                var nodes = edges
                            .SelectMany(e => new[] { e.Item1, e.Item2 })
                            .Distinct(new MethodNodeComparer())
                            .ToList();

                var clusters = nodes
                               .GroupBy(n => n.myDeclaringType)
                               .Select(x => (R.TypeFullName(x.Key), x.Key.Name, x.Select(n => n.myId).ToList()))
                               .ToList();

                foreach (var cluster in clusters)
                {
                    builder.TryAddCluster(cluster.Item1, cluster.Item3);
                }

                builder.Freeze();

                var presentation = new GraphPresentation();
                presentation.Graph = builder.Graph;

                // add captions for readability
                var captions = presentation.GetModule <ICaptionModule>();

                foreach (var n in nodes)
                {
                    captions.Add(new Caption(n.myId, n.myCaption));
                }

                foreach (var cluster in clusters)
                {
                    captions.Add(new Caption(cluster.Item1, cluster.Item2));
                }

                return presentation;
            }));