blob: 6f2afa91ccd7ec15aea4a4e1069a59b61dcffe07 (
plain)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.UI;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Weather;
using MediaBrowser.UI.Controller;
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace MediaBrowser.UI
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : BaseApplication, IApplication
{
private Timer ClockTimer { get; set; }
private Timer ServerConfigurationTimer { get; set; }
public static App Instance
{
get
{
return Application.Current as App;
}
}
public DtoUser CurrentUser
{
get
{
return UIKernel.Instance.CurrentUser;
}
set
{
UIKernel.Instance.CurrentUser = value;
OnPropertyChanged("CurrentUser");
}
}
public ServerConfiguration ServerConfiguration
{
get
{
return UIKernel.Instance.ServerConfiguration;
}
set
{
UIKernel.Instance.ServerConfiguration = value;
OnPropertyChanged("ServerConfiguration");
}
}
private DateTime _currentTime = DateTime.Now;
public DateTime CurrentTime
{
get
{
return _currentTime;
}
private set
{
_currentTime = value;
OnPropertyChanged("CurrentTime");
}
}
private WeatherInfo _currentWeather;
public WeatherInfo CurrentWeather
{
get
{
return _currentWeather;
}
private set
{
_currentWeather = value;
OnPropertyChanged("CurrentWeather");
}
}
private BaseTheme _currentTheme;
public BaseTheme CurrentTheme
{
get
{
return _currentTheme;
}
private set
{
_currentTheme = value;
OnPropertyChanged("CurrentTheme");
}
}
[STAThread]
public static void Main()
{
RunApplication<App>("MediaBrowserUI");
}
#region BaseApplication Overrides
protected override IKernel InstantiateKernel()
{
return new UIKernel();
}
protected override Window InstantiateMainWindow()
{
return new MainWindow();
}
protected override void OnKernelLoaded()
{
base.OnKernelLoaded();
PropertyChanged += AppPropertyChanged;
// Update every 10 seconds
ClockTimer = new Timer(ClockTimerCallback, null, 0, 10000);
// Update every 30 minutes
ServerConfigurationTimer = new Timer(ServerConfigurationTimerCallback, null, 0, 1800000);
CurrentTheme = UIKernel.Instance.Plugins.OfType<BaseTheme>().First();
foreach (var resource in CurrentTheme.GlobalResources)
{
Resources.MergedDictionaries.Add(resource);
}
}
#endregion
async void AppPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName.Equals("ServerConfiguration"))
{
if (string.IsNullOrEmpty(ServerConfiguration.WeatherZipCode))
{
CurrentWeather = null;
}
else
{
CurrentWeather = await UIKernel.Instance.ApiClient.GetWeatherInfoAsync(ServerConfiguration.WeatherZipCode);
}
}
}
private void ClockTimerCallback(object stateInfo)
{
CurrentTime = DateTime.Now;
}
private async void ServerConfigurationTimerCallback(object stateInfo)
{
ServerConfiguration = await UIKernel.Instance.ApiClient.GetServerConfigurationAsync();
}
public async Task<Image> GetImage(string url)
{
var image = new Image();
image.Source = await GetBitmapImage(url);
return image;
}
public async Task<BitmapImage> GetBitmapImage(string url)
{
Stream stream = await UIKernel.Instance.ApiClient.GetImageStreamAsync(url);
BitmapImage bitmap = new BitmapImage();
bitmap.CacheOption = BitmapCacheOption.Default;
bitmap.BeginInit();
bitmap.StreamSource = stream;
bitmap.EndInit();
return bitmap;
}
public async Task LogoutUser()
{
CurrentUser = null;
if (ServerConfiguration.EnableUserProfiles)
{
Navigate(CurrentTheme.LoginPageUri);
}
else
{
DtoUser defaultUser = await UIKernel.Instance.ApiClient.GetDefaultUserAsync();
CurrentUser = defaultUser;
Navigate(new Uri("/Pages/HomePage.xaml", UriKind.Relative));
}
}
public void Navigate(Uri uri)
{
(MainWindow as MainWindow).Navigate(uri);
}
}
}
|