-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
165 lines (138 loc) · 4.73 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
165 lines (138 loc) · 4.73 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
namespace MinEBoks
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
private static readonly Timer KontrolTimer = new Timer();
private readonly Eboks _eboks = new Eboks();
public MainWindow()
{
InitializeComponent();
settings.HentIDList();
if (string.IsNullOrEmpty(settings.response) || string.IsNullOrEmpty(settings.brugernavn) ||
!_eboks.GetSessionForAccountRest())
{
RunKonfiguration();
}
// Initialize menuItemExit
var menuItemExit = new MenuItem
{
Index = 0,
Text = "E&xit"
};
menuItemExit.Click += MenuItemExitClick;
// Initialize menuItemHent
var menuItemHent = new MenuItem
{
Index = 1,
Text = "&Hent"
};
menuItemHent.Click += MenuItemHentClick;
// Initialize menuItemÅbn
var menuItemÅbn = new MenuItem
{
Index = 1,
Text = "&Åbn hentet"
};
menuItemÅbn.Click += MenuItemÅbnClick;
var contextMenu = new ContextMenu();
contextMenu.MenuItems.Add(menuItemExit);
contextMenu.MenuItems.Add(menuItemHent);
contextMenu.MenuItems.Add(menuItemÅbn);
// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
settings.Notification.ContextMenu = contextMenu;
settings.Notification.Icon = new Icon("eboksdownloader.ico");
settings.Notification.Visible = false;
settings.Notification.DoubleClick +=
delegate
{
Show();
WindowState = WindowState.Normal;
};
// Kontroller hver 4. time
KontrolTimer.Tick += TimerHentDokumenter;
KontrolTimer.Interval = 1000*60*240;
KontrolTimer.Start();
if (settings.startminimeret)
{
settings.Notification.Visible = true;
Hide();
}
HentDokumenter();
}
protected override void OnStateChanged(EventArgs e)
{
if (WindowState == WindowState.Minimized)
{
Hide();
settings.Notification.Visible = true;
}
else
settings.Notification.Visible = false;
base.OnStateChanged(e);
}
private void TimerHentDokumenter(object myObject, EventArgs myEventArgs)
{
System.Threading.Thread.Sleep(1000*60*2); // Vent 2 minutter hvis pc'en lige er vågnet fra standby
settings.Notification.Visible = true;
HentDokumenter();
if (WindowState != WindowState.Minimized)
{
settings.Notification.Visible = false;
}
}
private void MenuItemExitClick(object Sender, EventArgs e)
{
// Close the form, which closes the application.
Close();
}
private async void MenuItemHentClick(object Sender, EventArgs e)
{
await HentDokumenter();
}
private async void MenuItemÅbnClick(object Sender, EventArgs e)
{
Process.Start(settings.savepath);
}
private async void HentMenuItem_OnClick(object sender, RoutedEventArgs e)
{
await HentDokumenter();
}
private async Task HentDokumenter()
{
var progress =
new Progress<string>(
s => listView.Items.Insert(0, DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + " " + s));
await
Task.Factory.StartNew(() => _eboks.DownloadFromEBoks(progress),
TaskCreationOptions.LongRunning);
}
private void MenuItem_OnClick(object sender, RoutedEventArgs e)
{
KontrolTimer.Stop();
RunKonfiguration();
KontrolTimer.Start();
}
private void MainWindow_OnClosing(object sender, CancelEventArgs e)
{
settings.Notification.Visible = false;
}
private void RunKonfiguration()
{
var konfig = new Konfiguration();
konfig.ShowDialog();
if (!konfig.Konfigok)
Close();
}
}
}