private void OnWroteSTAThread(object s, FileSystemEventArgs a) { if (YNDialogW.Ask("Открыть файл заново", "Файл был изменен. Открыть новый файл??")) { Reopening?.Invoke(); BinaryFormatter formatter = new BinaryFormatter(); /* var stream = File.Open(System.IO.Path.Combine(watcher.Path, FileName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); * DeflateStream deflstr = new DeflateStream(stream, CompressionMode.Decompress); * rent = (AudioRent)formatter.Deserialize(deflstr); * deflstr.Dispose(); * stream.Dispose();*/ using (var stream = File.Open(System.IO.Path.Combine(watcher.Path, FileName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (DeflateStream deflstr = new DeflateStream(stream, CompressionMode.Decompress)) { try { rent = (AudioRent)formatter.Deserialize(deflstr); } catch { MessageBox.Show("Файл поврежден!!!"); return; } } } } }
public static AudioRent Initialize() // предварительно созданная фонотека { AudioRent V = new AudioRent(); V.Libraries.Add(new Library("iTunes")); List <Track> l2 = new List <Track>(3); DateTime t0 = new DateTime(2013, 04, 12); DateTime t1 = new DateTime(2014, 11, 20); DateTime t2 = new DateTime(2015, 04, 09); V.Tracks.Add(new Track("Пока мы молоды", t0, "his1")); V.Tracks.Add(new Track("Вечность", t1, "ист2")); V.Tracks.Add(new Track("Beautiful Life", t2, "his3")); l2.Add(V.Tracks[0]); l2.Add(V.Tracks[1]); l2.Add(V.Tracks[2]); V.Albums.Add(new Album("Пока мы молоды", "Лирика", 12, 2015, V.Libraries[0], l2, "Images/PMM.jpg")); V.Libraries.Add(new Library("VK Music")); List <Track> l3 = new List <Track>(4); DateTime t3 = new DateTime(2018, 01, 12); DateTime t4 = new DateTime(2018, 02, 19); DateTime t5 = new DateTime(2018, 03, 11); DateTime t6 = new DateTime(2018, 01, 16); V.Tracks.Add(new Track("Forever", t3, "his4")); V.Tracks.Add(new Track("That's How You Write a song", t4, "his5")); V.Tracks.Add(new Track("Mercy", t5, "his6")); V.Tracks.Add(new Track("Stones", t6, "his7")); l3.Add(V.Tracks[3]); l3.Add(V.Tracks[4]); l3.Add(V.Tracks[5]); l3.Add(V.Tracks[6]); V.Albums.Add(new Album("Eurovision 2018", "Pop", 6, 2018, V.Libraries[1], l3, "Images/Eurovision.jpg")); V.Libraries.Add(new Library("MediaFire")); List <Track> l4 = new List <Track>(4); DateTime t7 = new DateTime(2015, 06, 12); DateTime t8 = new DateTime(2013, 09, 12); DateTime t9 = new DateTime(2013, 03, 12); DateTime t10 = new DateTime(2013, 08, 12); V.Tracks.Add(new Track("Sing", t7, "his9")); V.Tracks.Add(new Track("Let It Go", t8, "his10")); V.Tracks.Add(new Track("Daft Punk", t9, "his11")); V.Tracks.Add(new Track("Aha!", t10, "his12")); l4.Add(V.Tracks[7]); l4.Add(V.Tracks[8]); l4.Add(V.Tracks[9]); l4.Add(V.Tracks[10]); V.Albums.Add(new Album("Pentatonix", "A-kapella", 12, 2016, V.Libraries[2], l4, "Images/PTX.png")); return(V); }
internal ListW(IEnumerable <Obj> list, Type t, AudioRent rent) { InitializeComponent(); List = list.ToList <Obj>(); Rent = rent; T = t; foreach (Obj o in list) { LBox.Items.Add(o.Name); } ((MainWindow)Application.Current.MainWindow).Reopening += () => { Close(); }; }
private void Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog dial = new OpenFileDialog() { AddExtension = true, //можно не указывать расширение CheckFileExists = true, //нельзя указывать несуществующие файлы InitialDirectory = Environment.CurrentDirectory, //откуда начинать Filter = "AudioRent files(.rent)|*.rent" }; var t = dial.ShowDialog(); if (t.GetValueOrDefault(false)) { BinaryFormatter formatter = new BinaryFormatter(); using (var stream = File.Open(dial.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (DeflateStream deflstr = new DeflateStream(stream, CompressionMode.Decompress))//разжимаем { try { rent = (AudioRent)formatter.Deserialize(deflstr); } catch { MessageBox.Show("Файл поврежден!!!"); return; } } } watcher = new FileSystemWatcher(System.IO.Path.GetDirectoryName(dial.FileName), "*.rent"); FileName = System.IO.Path.GetFileName(dial.FileName); watcher.NotifyFilter = NotifyFilters.LastWrite; watcher.Changed += new FileSystemEventHandler(OnWrote); watcher.EnableRaisingEvents = true; } }
public MainWindow() { InitializeComponent(); rent = AudioRent.Initialize(); FindPlugins(); }