private void Document_Changed(object sender, DocumentChangeEventArgs e) { Packages.Clear(); if (string.IsNullOrEmpty(Document.Text)) { return; } try { var spec = SpecUtils.Deserialize(Document.Text); // initially specs do not have Ids - generate them once and keep them bool idsGenerated = false; foreach (var cluster in spec.Packages.SelectMany(p => p.Clusters)) { if (cluster.Id == null) { cluster.Id = Guid.NewGuid().ToString(); idsGenerated = true; } } if (idsGenerated) { // we cannot change the doc while handling a doc change Application.Current.Dispatcher.BeginInvoke(new Action(() => { Document.Text = SpecUtils.Serialize(spec); Save(); })); } Packages.AddRange(spec.Packages.Select(p => p.Name)); } catch (Exception ex) { StatusMessageService.Publish(new StatusMessage("ERROR:" + ex)); } CreateGraphCommand.RaiseCanExecuteChanged(); }
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 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; } }