-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainPage.xaml.cs
More file actions
95 lines (77 loc) · 3.37 KB
/
MainPage.xaml.cs
File metadata and controls
95 lines (77 loc) · 3.37 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
using PocketTDPControlWidget.MainServiceReference;
using System;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace PocketTDPControlWidget
{
public sealed partial class MainPage : Page
{
private TDPViewModel ViewModel;
private ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
ConcurrentQueue<int> TDPQueue = new ConcurrentQueue<int>();
public MainPage()
{
this.InitializeComponent();
ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)localSettings.Values[nameof(this.ViewModel)];
this.ViewModel = new TDPViewModel();
if (composite != null)
{
this.ViewModel.CurrentTDP = (int)composite[nameof(this.ViewModel.CurrentTDP)];
this.ViewModel.PresetTDP = (int)composite[nameof(this.ViewModel.PresetTDP)];
this.ViewModel.ReadingTDP = (int)composite[nameof(this.ViewModel.ReadingTDP)];
}
else
{
composite = new ApplicationDataCompositeValue();
composite[nameof(this.ViewModel.CurrentTDP)] = this.ViewModel.CurrentTDP;
composite[nameof(this.ViewModel.PresetTDP)] = this.ViewModel.PresetTDP;
composite[nameof(this.ViewModel.ReadingTDP)] = this.ViewModel.ReadingTDP;
localSettings.Values[nameof(this.ViewModel)] = composite;
}
Task t = new Task(() =>
{
while (true) {
if (TDPQueue.IsEmpty) {
Thread.Sleep(100);
continue;
}
TDPQueue.TryDequeue(out var tdp);
var client = new MainServiceClient();
client.AdjustAsync("a", tdp);
client.AdjustAsync("b", tdp);
client.AdjustAsync("c", tdp);
}
});
t.Start();
this.DataContext = this.ViewModel;
this.ViewModel.PropertyChanged += OnPropertyChanged;
}
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
TDPQueue.Enqueue(this.ViewModel.CurrentTDP);
}
private void AdjustButton_Click(object sender, RoutedEventArgs e)
{
Button clickedButton = sender as Button;
int tdp = Convert.ToInt32(clickedButton.Content.ToString());
this.ViewModel.CurrentTDP = tdp;
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
this.ViewModel.PresetTDP = this.ViewModel.CurrentTDP;
}
private void Window_Closing(object sender, CancelEventArgs e)
{
ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)localSettings.Values[nameof(this.ViewModel)];
composite[nameof(this.ViewModel.CurrentTDP)] = this.ViewModel.CurrentTDP;
composite[nameof(this.ViewModel.PresetTDP)] = this.ViewModel.PresetTDP;
composite[nameof(this.ViewModel.ReadingTDP)] = this.ViewModel.ReadingTDP;
localSettings.Values[nameof(this.ViewModel)] = composite;
}
}
}