Example #1
0
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     LibraryData = new LibraryData("BookShelf.dat");
     LibraryData.watcher.Changed += Watcher_Changed;
     UpdatePlugins();
 }
Example #2
0
        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;
            }
        }
Example #3
0
        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);
                }
            }
        }
Example #4
0
        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);
                }
            }
        }
Example #5
0
 public LibraryData(LibraryData library) : this(library.Books, library.Authors, library.Publishers)
 {
 }