Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.OKB.Cockpit.Admin/PersistenceHacker.cs @ 5599

Last change on this file since 5599 was 4311, checked in by swagner, 14 years ago

Integrated OKB clients for HL 3.3 (#1166)

File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Controls;
6using HeuristicLab.BackgroundProcessing;
7using System.Windows;
8using HeuristicLab.MainForm.WPF;
9using HeuristicLab.MainForm;
10using System.IO;
11
12namespace 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}
Note: See TracBrowser for help on using the repository browser.