예제 #1
0
        private async Task AddNewDiagramAsync(Uri newDiagramUri)
        {
            string newFilePath = newDiagramUri.LocalPath;

            if (String.IsNullOrEmpty(Path.GetExtension(newFilePath)))
            {
                newFilePath += FileExtension;
            }

            var newDiagram = new Diagram
            {
                File    = new FileInfo(newFilePath),
                Content = String.Format(NewDiagramTemplate, Path.GetFileNameWithoutExtension(newFilePath) + ".png")
            };

            _diagramLocation.Value = new DirectoryInfo(Path.GetDirectoryName(newFilePath));

            var progress = _notifications.StartProgress(false);

            try
            {
                await _diagramIO.SaveAsync(newDiagram, false);

                var refreshedDiagram = await _diagramIO.ReadAsync(newDiagram.File);

                var preview = PreviewDiagrams.SingleOrDefault(p => FileComparer.Equals(p.Diagram.File, refreshedDiagram.File));
                if (preview == null)
                {
                    preview = _previewDiagramFactory(refreshedDiagram);
                    PreviewDiagrams.Add(preview);
                }

                CurrentPreviewDiagram = preview;
                OnOpenPreviewRequested(preview);

                progress.Report(ProgressUpdate.Completed(string.Empty));
            }
            catch (Exception e)
            {
                progress.Report(ProgressUpdate.Failed(e));
            }
        }
예제 #2
0
        /// <see cref="IDiagramExplorer.OpenDiagramAsync"/>
        public async Task <Diagram> OpenDiagramAsync(Uri diagramPath)
        {
            var fileToOpen = new FileInfo(diagramPath.LocalPath);

            Diagram diagram;
            var     preview = PreviewDiagrams.SingleOrDefault(p => FileComparer.Equals(p.Diagram.File, fileToOpen));

            if (preview == null)
            {
                diagram = await _diagramIO.ReadAsync(fileToOpen);

                preview = _previewDiagramFactory(diagram);
            }
            else
            {
                diagram = preview.Diagram;
            }

            OnOpenPreviewRequested(preview);
            return(diagram);
        }