protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); LibraryData = new LibraryData("BookShelf.dat"); LibraryData.watcher.Changed += Watcher_Changed; UpdatePlugins(); }
public void Watcher_Changed(object sender, FileSystemEventArgs e) { var result = MessageBox.Show("File has been updated. Would you like to load update version?", "File update", MessageBoxButton.YesNo, MessageBoxImage.Error); if (result == MessageBoxResult.Yes) { LibraryData.watcher.Dispose(); LibraryData = LibraryData.Load(LibraryData.storagePath); LibraryData.watcher.Changed += Watcher_Changed; LibraryData.watcher.EnableRaisingEvents = true; } }
public static LibraryData Load(String path) { var formatter = new BinaryFormatter(); using (Stream s = File.OpenRead(path)) { using (var ds = new DeflateStream(s, CompressionMode.Decompress)) { var libraryData = new LibraryData(formatter.Deserialize(ds) as LibraryData); libraryData.watcher = new FileSystemWatcher(Path.GetDirectoryName(path)); libraryData.watcher.Filter = Path.GetFileName(path); libraryData.storagePath = path; return(libraryData); } } }
private void LoadFile() { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { try { (Application.Current as App).LibraryData.watcher?.Dispose(); (Application.Current as App).LibraryData = LibraryData.Load(openFileDialog.FileName); (Application.Current as App).LibraryData.watcher.Changed += (Application.Current as App).Watcher_Changed; (Application.Current as App).LibraryData.watcher.EnableRaisingEvents = true; } catch (NotSupportedException) { MessageBox.Show("Corrupted data", "Serialization error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public LibraryData(LibraryData library) : this(library.Books, library.Authors, library.Publishers) { }