Example #1
0
        public void Test_DiagramAdded()
        {
            // Arrange.
            DiagramFileAddedEventArgs args = null;
            EventHandler <DiagramFileAddedEventArgs> addHandler = (o, e) => args = e;

            diagramIO.DiagramFileAdded += addHandler;

            // Act.
            monitor.Raise(m => m.Created += null,
                          new FileSystemEventArgs(WatcherChangeTypes.Created, currentDirectory.FullName, "class.puml"));

            // Assert.
            Assert.NotNull(args);
            Assert.Equal(Path.Combine(currentDirectory.FullName, "class.puml"), args.NewDiagramFile.FullName);
        }
Example #2
0
 void diagramIO_DiagramFileAdded(object sender, DiagramFileAddedEventArgs e)
 {
     Task.Factory.StartNew(async() =>
     {
         // Make sure a preview doesn't already exist for the file and make sure the current directory still matches.
         bool previewExists = PreviewDiagrams.Select(pd => pd.Diagram.File).Contains(e.NewDiagramFile, FileComparer);
         if (!previewExists && e.NewDiagramFile.Directory?.FullName.Trim('\\') == DiagramLocation.FullName.Trim('\\'))
         {
             var newlyAddedDiagram = await _diagramIO.ReadAsync(e.NewDiagramFile);
             if (newlyAddedDiagram != null)
             {
                 PreviewDiagrams.Add(_previewDiagramFactory(newlyAddedDiagram));
             }
         }
     }, CancellationToken.None, TaskCreationOptions.None, _uiScheduler);
 }