[4311] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Windows.Controls;
|
---|
| 6 | using HeuristicLab.BackgroundProcessing;
|
---|
| 7 | using System.Windows;
|
---|
| 8 | using HeuristicLab.MainForm.WPF;
|
---|
| 9 | using HeuristicLab.MainForm;
|
---|
| 10 | using System.IO;
|
---|
| 11 |
|
---|
| 12 | namespace HeuristicLab.OKB.Cockpit.Admin {
|
---|
| 13 | public class PersistenceHacker {
|
---|
| 14 |
|
---|
| 15 | public static void Upload(OKBData.EntityType type, int id) {
|
---|
| 16 | Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog() {
|
---|
| 17 | FileName = "Entity",
|
---|
| 18 | DefaultExt = ".zip",
|
---|
| 19 | Filter = "Zip Files (HL 3.3) (.zip)|*.zip|GZip Files (HL 2.5) (*.gz)|*.gz",
|
---|
| 20 | CheckFileExists = true,
|
---|
| 21 | CheckPathExists = true,
|
---|
| 22 | };
|
---|
| 23 | if (dlg.ShowDialog() != true)
|
---|
| 24 | return;
|
---|
| 25 | var saver = new ObservableBackgroundWorker("uploading implementation");
|
---|
| 26 | saver.DoWork += (s, a) => {
|
---|
| 27 | var stream = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read);
|
---|
| 28 | byte[] data = new byte[stream.Length];
|
---|
| 29 | stream.Read(data, 0, (int)stream.Length);
|
---|
| 30 | stream.Close();
|
---|
| 31 | new DataClientHelper(saver, a).Save(type, id, data);
|
---|
| 32 | };
|
---|
| 33 | saver.RunWorkerAsync();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public static void Download(OKBData.EntityType type, int id) {
|
---|
| 37 | var loader = new ObservableBackgroundWorker("downloading implementation");
|
---|
| 38 | byte[] data = null;
|
---|
| 39 | loader.DoWork += (s, a) => {
|
---|
| 40 | data = new DataClientHelper(loader, a).Load(type, id);
|
---|
| 41 | };
|
---|
| 42 | loader.RunWorkerCompleted += (s, a) => {
|
---|
| 43 | if (data == null)
|
---|
| 44 | return;
|
---|
| 45 | Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog() {
|
---|
| 46 | FileName = "Entity",
|
---|
| 47 | DefaultExt = ".zip",
|
---|
| 48 | Filter = "Zip Files (HL 3.3) (.zip)|*.zip|GZip Files (HL 2.5)|*.gz",
|
---|
| 49 | OverwritePrompt = true,
|
---|
| 50 | CheckPathExists = true,
|
---|
| 51 | };
|
---|
| 52 | if (dlg.ShowDialog() != true)
|
---|
| 53 | return;
|
---|
| 54 | var stream = new FileStream(dlg.FileName, FileMode.Create);
|
---|
| 55 | stream.Write(data, 0, data.Length);
|
---|
| 56 | stream.Close();
|
---|
| 57 | };
|
---|
| 58 | loader.RunWorkerAsync();
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|