Ejemplo n.º 1
0
        private void OpenDocument(string path)
        {
            var presentation = PresentationCreationService.CreatePresentation(Path.GetDirectoryName(path));

            var processor = new BasicDocumentProcessor(presentation);

            processor.Process(path);

            if (processor.FailedItems.Any())
            {
                var sb = new StringBuilder();
                sb.AppendLine("Following items could not be loaded successfully:");
                sb.AppendLine();
                foreach (var item in processor.FailedItems)
                {
                    sb.AppendLine(string.Format("{0}: {1}", item.FailureReason, item.Item));
                }
                StatusMessageService.Publish(new StatusMessage(sb.ToString()));
            }

            Model.Presentation = presentation;

            myFileWatcher        = new FileSystemWatcher();
            myFileWatcher.Path   = Path.GetDirectoryName(path);
            myFileWatcher.Filter = Path.GetFileName(path);
            // http://stackoverflow.com/questions/19905151/system-io-filesystemwatcher-does-not-watch-file-changed-by-visual-studio-2013
            myFileWatcher.NotifyFilter        = NotifyFilters.LastWrite | NotifyFilters.CreationTime;
            myFileWatcher.Changed            += OnCurrentFileChanged;
            myFileWatcher.Error              += OnFileWatcherError;
            myFileWatcher.EnableRaisingEvents = true;

            // only synchronize presentations where we know the doc type and which were created from this module
            if (Path.GetExtension(path).Equals(".dot", StringComparison.OrdinalIgnoreCase))
            {
                myGraphToDotSynchronizer.Attach(presentation, p =>
                                                // enqueue to have less blocking of UI
                                                Application.Current.Dispatcher.BeginInvoke(new Action(() => SyncToDocument(p, path))));
            }
        }
        private void BuildGraph(AnalysisDocument response)
        {
            if (!response.Nodes.Any() && !response.Edges.Any())
            {
                MessageBox.Show("Neither nodes nor edges found");
                return;
            }

            var presentation = PresentationCreationService.CreatePresentation(Path.GetTempPath());

            var builder = new RelaxedGraphBuilder();

            foreach (var edge in response.Edges)
            {
                builder.TryAddEdge(edge.Item1, edge.Item2);
            }

            foreach (var node in response.Nodes)
            {
                builder.TryAddNode(node);
            }

            foreach (var cluster in response.Clusters)
            {
                builder.TryAddCluster(cluster.Key, cluster.Value);
            }

            var captionModule = presentation.GetPropertySetFor <Caption>();

            // add potentially empty clusters
            {
                var spec          = SpecUtils.Deserialize(Document.Text);
                var emptyClusters = spec.Packages
                                    .Where(p => PackagesToAnalyze == null || PackagesToAnalyze.Contains(p.Name))
                                    .SelectMany(p => p.Clusters)
                                    .Where(cluster => !response.Clusters.Any(c => c.Key == cluster.Id));

                foreach (var cluster in emptyClusters)
                {
                    builder.TryAddCluster(cluster.Id, Enumerable.Empty <string>());
                    captionModule.Add(new Caption(cluster.Id, cluster.Name));
                }
            }

            presentation.Graph = builder.Graph;

            foreach (var caption in response.Captions)
            {
                captionModule.Add(new Caption(caption.Key, caption.Value));
            }

            var converter = new BrushConverter();

            var nodeStyles = presentation.GetPropertySetFor <NodeStyle>();

            foreach (var style in response.NodeStyles)
            {
                var brush = (Brush)converter.ConvertFromString(style.Value);
                brush.Freeze();
                nodeStyles.Add(new NodeStyle(style.Key)
                {
                    FillColor = brush
                });
            }

            var edgeStyles = presentation.GetPropertySetFor <EdgeStyle>();

            foreach (var style in response.EdgeStyles)
            {
                var brush = (Brush)converter.ConvertFromString(style.Value);
                brush.Freeze();
                edgeStyles.Add(new EdgeStyle(style.Key)
                {
                    Color = brush
                });
            }

            Model.Presentation = presentation;

            // only synchronize our own presentation
            myGraphToSpecSynchronizer.Presentation = presentation;
        }
Ejemplo n.º 3
0
        private void OnInheritanceGraphCompleted(TypeRelationshipDocument document)
        {
            try
            {
                if (document == null)
                {
                    return;
                }

                if (!document.Graph.Nodes.Any())
                {
                    MessageBox.Show("No nodes found");
                    return;
                }

                var presentation = PresentationCreationService.CreatePresentation(Path.GetDirectoryName(AssemblyToAnalyseLocation));

                var captionModule   = presentation.GetPropertySetFor <Caption>();
                var tooltipModule   = presentation.GetPropertySetFor <ToolTipContent>();
                var edgeStyleModule = presentation.GetPropertySetFor <EdgeStyle>();

                presentation.Graph = document.Graph;

                foreach (var desc in document.Descriptors)
                {
                    captionModule.Add(new Caption(desc.Id, desc.Name));
                    tooltipModule.Add(new ToolTipContent(desc.Id, desc.FullName));
                }

                foreach (var entry in document.EdgeTypes)
                {
                    edgeStyleModule.Add(new EdgeStyle(entry.Key)
                    {
                        Color = entry.Value == ReferenceType.DerivesFrom ? Brushes.Black : Brushes.Blue
                    });
                }

                if (myAddToGraph && Model.Presentation != null && Model.Presentation.Graph != null)
                {
                    presentation = Model.Presentation.UnionWith(presentation,
                                                                () => PresentationCreationService.CreatePresentation(Path.GetDirectoryName(AssemblyToAnalyseLocation)));

                    myAddToGraph = false;
                }

                if (document.FailedItems.Any())
                {
                    foreach (var item in document.FailedItems)
                    {
                        var sb = new StringBuilder();
                        sb.AppendLine("Loading failed");
                        sb.AppendFormat("Item: {0}", item.Item);
                        sb.AppendLine();
                        sb.AppendFormat("Reason: {0}", item.FailureReason);
                        StatusMessageService.Publish(new StatusMessage(sb.ToString()));
                    }
                }

                Model.Presentation = presentation;
            }
            finally
            {
                myCancelBackgroundProcessing = null;
                ProgressValue = 0;
                IsReady       = true;
            }
        }