예제 #1
0
        private void HandleNotebookChange(FileSystemEventArgs e)
        {
            string fileName = Path.GetFileName(e.FullPath);

            if (string.IsNullOrWhiteSpace(fileName))
            {
                return;
            }

            string idString = fileName.Replace("." + File.NotebookFileExtension, string.Empty);
            Guid   notebookId;

            if (Guid.TryParse(idString, out notebookId))
            {
                Notebook nb = GetNoteBook(notebookId);
                if (nb != null)
                {
                    if (e.ChangeType == WatcherChangeTypes.Changed)
                    {
                        Notebook tempNotebook = LoadObjectFromFile <Notebook>(new FileInfo(e.FullPath));
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            tempNotebook?.CopyProperties(nb);
                        });
                    }
                    else if (e.ChangeType == WatcherChangeTypes.Deleted)
                    {
                        DeleteNoteBook(nb);
                    }
                }
            }

            _log.Debug($"Handled changed notebook {e.Name}");
        }