using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Controls; using HeuristicLab.BackgroundProcessing; using System.Windows; using HeuristicLab.MainForm.WPF; using HeuristicLab.MainForm; using System.IO; namespace HeuristicLab.OKB.Cockpit.Admin { public class PersistenceHacker { public static void Upload(OKBData.EntityType type, int id) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog() { FileName = "Entity", DefaultExt = ".zip", Filter = "Zip Files (HL 3.3) (.zip)|*.zip|GZip Files (HL 2.5) (*.gz)|*.gz", CheckFileExists = true, CheckPathExists = true, }; if (dlg.ShowDialog() != true) return; var saver = new ObservableBackgroundWorker("uploading implementation"); saver.DoWork += (s, a) => { var stream = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read); byte[] data = new byte[stream.Length]; stream.Read(data, 0, (int)stream.Length); stream.Close(); new DataClientHelper(saver, a).Save(type, id, data); }; saver.RunWorkerAsync(); } public static void Download(OKBData.EntityType type, int id) { var loader = new ObservableBackgroundWorker("downloading implementation"); byte[] data = null; loader.DoWork += (s, a) => { data = new DataClientHelper(loader, a).Load(type, id); }; loader.RunWorkerCompleted += (s, a) => { if (data == null) return; Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog() { FileName = "Entity", DefaultExt = ".zip", Filter = "Zip Files (HL 3.3) (.zip)|*.zip|GZip Files (HL 2.5)|*.gz", OverwritePrompt = true, CheckPathExists = true, }; if (dlg.ShowDialog() != true) return; var stream = new FileStream(dlg.FileName, FileMode.Create); stream.Write(data, 0, data.Length); stream.Close(); }; loader.RunWorkerAsync(); } } }