This repository was archived by the owner on Dec 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorageController.cs
More file actions
124 lines (104 loc) · 3.83 KB
/
StorageController.cs
File metadata and controls
124 lines (104 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using MultiAppLauncher.Properties;
namespace MultiAppLauncher
{
public class StorageController
{
private readonly IMainFormView _view;
public StorageController(IMainFormView view)
{
_view = view;
}
public void SaveAs()
{
_view.ToolStripFileName = null;
Save();
}
public void Save()
{
if (String.IsNullOrEmpty(_view.ToolStripFileName))
{
var sfd = new SaveFileDialog
{
DefaultExt = ".xml",
Filter = Resources.DialogFilter
};
if (sfd.ShowDialog(_view) == DialogResult.OK)
{
_view.ToolStripFileName = sfd.FileName;
}
}
if (!String.IsNullOrEmpty(_view.ToolStripFileName))
{
try
{
CreateSettingsDocument().Save(_view.ToolStripFileName);
}
catch (Exception ex)
{
_view.ToolStripFileName = null;
var builder = new StringBuilder();
builder.AppendFormat("Failed to write file. Try another filename. {0}", ex);
MessageBox.Show(_view,
builder.ToString(),
Resources.CaptionError,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private SettingsDocument CreateSettingsDocument()
{
var doc = new SettingsDocument
{
SoftStart = _view.SoftStartSeconds,
FileNames = new List<FileSettings>()
};
foreach (ListViewItem item in _view.GetListViewItems())
{
doc.FileNames.Add(new FileSettings
{
Name = item.Text,
Profile = item.SubItems[Columns.Profile].Text
});
}
return doc;
}
public void Open()
{
var ofd = new OpenFileDialog { Filter = Resources.DialogFilter };
if (ofd.ShowDialog(_view) == DialogResult.OK)
{
_view.ToolStripFileName = ofd.FileName;
var settings = SettingsDocument.Load(ofd.FileName);
_view.SoftStartSeconds = settings.SoftStart;
_view.ClearListView();
foreach (var entry in settings.FileNames)
{
AddFileNameToList(entry.Name, entry.Profile);
}
}
}
private void AddFileNameToList(string fileName, string profile)
{
_view.AddListViewItem(new ListViewItem(new[]
{
fileName,
profile,
String.Empty,
String.Empty
}));
}
public void ChangeProperties()
{
var dlg = new PropertyDialog { Timeout = _view.SoftStartSeconds };
if (dlg.ShowDialog(_view) == DialogResult.OK)
{
_view.SoftStartSeconds = dlg.Timeout;
}
}
}
}