8
8
using Microsoft . WindowsAPICodePack . Dialogs ;
9
9
using System ;
10
10
using System . Collections . Generic ;
11
+ using System . Collections . ObjectModel ;
11
12
using System . ComponentModel ;
12
13
using System . Linq ;
13
14
using System . Runtime . CompilerServices ;
17
18
using System . Windows ;
18
19
using System . Windows . Input ;
19
20
using System . Windows . Media . Animation ;
21
+ using System . Windows . Threading ;
20
22
21
23
namespace Frogy . ViewModels
22
24
{
@@ -27,112 +29,141 @@ class OverViewViewModel : INotifyPropertyChanged
27
29
/// </summary>
28
30
/// <param name="TodayOverview">今日OverView</param>
29
31
/// <returns>List<OverViewItem></returns>
30
- private List < OverViewItem > PrintOverview ( Dictionary < string , Software > TodayOverview )
32
+ private Task < List < OverViewItem > > PrintOverview ( Dictionary < string , Software > TodayOverview )
31
33
{
32
- List < OverViewItem > result = new List < OverViewItem > ( ) ;
33
- //排序
34
- var dicSort = from objDic in TodayOverview orderby objDic . Value . Duration descending select objDic ;
35
-
36
- foreach ( KeyValuePair < string , Software > kvp in dicSort )
34
+ return Task . Run ( ( ) =>
37
35
{
38
- OverViewItem tmp =
39
- new OverViewItem ( )
40
- {
41
- AppName = kvp . Key ,
42
- AppDuration = kvp . Value . Duration . ToString ( ) ,
43
- AppIcon = kvp . Value . Icon
44
- } ;
45
- result . Add ( tmp ) ;
46
- }
36
+ List < OverViewItem > result = new List < OverViewItem > ( ) ;
37
+ //排序
38
+ var dicSort = from objDic in TodayOverview orderby objDic . Value . Duration descending select objDic ;
47
39
48
- return result ;
40
+ foreach ( KeyValuePair < string , Software > kvp in dicSort )
41
+ {
42
+ OverViewItem tmp =
43
+ new OverViewItem ( )
44
+ {
45
+ AppName = kvp . Key ,
46
+ AppDuration = kvp . Value . Duration . ToString ( ) ,
47
+ AppIcon = kvp . Value . Icon
48
+ } ;
49
+ result . Add ( tmp ) ;
50
+ }
51
+
52
+ return result ;
53
+ } ) ;
49
54
}
50
55
51
56
/// <summary>
52
57
/// 打印表格
53
58
/// </summary>
54
59
/// <param name="mies"></param>
55
- private SeriesCollection PrintOverviewChart ( List < MyTimeDuration > tmp )
60
+ private Task < SeriesCollection > PrintOverviewChart ( List < MyTimeDuration > tmp )
56
61
{
57
- SeriesCollection result = new SeriesCollection { } ;
58
- Dictionary < string , ChartValues < double > > tmpdic = new Dictionary < string , ChartValues < double > > ( ) ;
59
- foreach ( MyTimeDuration duration in tmp )
62
+ return Task . Run ( ( ) =>
60
63
{
61
- string appName = duration . TimeDurationTask . ApplicationName ;
62
- if ( string . IsNullOrEmpty ( appName ) || appName == "Frogy" ) continue ;
64
+ SeriesCollection result = new SeriesCollection { } ;
65
+ Dictionary < string , ChartValues < double > > tmpdic = new Dictionary < string , ChartValues < double > > ( ) ;
66
+ foreach ( MyTimeDuration duration in tmp )
67
+ {
68
+ string appName = duration . TimeDurationTask . ApplicationName ;
69
+ if ( string . IsNullOrEmpty ( appName ) || appName == "Frogy" ) continue ;
63
70
64
- if ( ! tmpdic . ContainsKey ( appName ) ) tmpdic . Add ( appName ,
65
- new ChartValues < double > { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ) ;
71
+ if ( ! tmpdic . ContainsKey ( appName ) ) tmpdic . Add ( appName ,
72
+ new ChartValues < double > { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ) ;
66
73
67
- TimeSpan start = duration . StartTime ;
68
- TimeSpan stop = duration . StopTime ;
69
- TimeSpan spent = duration . Duration ;
74
+ TimeSpan start = duration . StartTime ;
75
+ TimeSpan stop = duration . StopTime ;
76
+ TimeSpan spent = duration . Duration ;
70
77
71
- if ( start . Hours == stop . Hours )
72
- tmpdic [ appName ] [ start . Hours ] += Math . Round ( spent . TotalMinutes , 2 ) ;
73
- else
74
- {
75
- if ( stop . Hours - start . Hours == 1 )
76
- {
77
- tmpdic [ appName ] [ start . Hours ] += Math . Round ( ( 59.59d - start . Minutes ) , 2 ) ;
78
- tmpdic [ appName ] [ stop . Hours ] += stop . Minutes ;
79
- }
78
+ if ( start . Hours == stop . Hours )
79
+ tmpdic [ appName ] [ start . Hours ] += Math . Round ( spent . TotalMinutes , 2 ) ;
80
80
else
81
81
{
82
- if ( stop . Hours - start . Hours > 1 )
82
+ if ( stop . Hours - start . Hours == 1 )
83
83
{
84
- int tmpint = stop . Hours - start . Hours ;
85
-
86
84
tmpdic [ appName ] [ start . Hours ] += Math . Round ( ( 59.59d - start . Minutes ) , 2 ) ;
87
85
tmpdic [ appName ] [ stop . Hours ] += stop . Minutes ;
86
+ }
87
+ else
88
+ {
89
+ if ( stop . Hours - start . Hours > 1 )
90
+ {
91
+ int tmpint = stop . Hours - start . Hours ;
88
92
89
- for ( int i = 1 ; i <= tmpint ; i ++ )
90
- tmpdic [ appName ] [ start . Hours + i ] = 59.59d ;
93
+ tmpdic [ appName ] [ start . Hours ] += Math . Round ( ( 59.59d - start . Minutes ) , 2 ) ;
94
+ tmpdic [ appName ] [ stop . Hours ] += stop . Minutes ;
95
+
96
+ for ( int i = 1 ; i < tmpint ; i ++ )
97
+ tmpdic [ appName ] [ start . Hours + i ] = 59.59d ;
98
+ }
91
99
}
92
100
}
93
101
}
94
- }
95
102
96
- Application . Current . Dispatcher . Invoke ( delegate
97
- {
103
+ ChartValues < double > sumTime = new ChartValues < double > { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
98
104
foreach ( string key in tmpdic . Keys )
99
105
{
100
- result . Add ( new StackedColumnSeries
106
+ for ( int i = 0 ; i < tmpdic [ key ] . Count ( ) ; i ++ )
101
107
{
102
- Values = tmpdic [ key ] ,
103
- DataLabels = false ,
104
- Title = key ,
105
- IsHitTestVisible = false
106
- } ) ;
108
+ sumTime [ i ] += tmpdic [ key ] [ i ] ;
109
+ }
107
110
}
108
- } ) ;
109
111
110
- return result ;
112
+ foreach ( string key in tmpdic . Keys )
113
+ {
114
+ for ( int j = 0 ; j < tmpdic [ key ] . Count ( ) ; j ++ )
115
+ {
116
+ if ( tmpdic [ key ] [ j ] / sumTime [ j ] < 0.01 )
117
+ {
118
+ tmpdic [ key ] [ j ] = 0 ;
119
+ }
120
+ }
121
+ }
122
+
123
+ Application . Current . Dispatcher . Invoke ( delegate
124
+ {
125
+ foreach ( string key in tmpdic . Keys )
126
+ {
127
+ result . Add ( new StackedColumnSeries
128
+ {
129
+ Values = tmpdic [ key ] ,
130
+ DataLabels = false ,
131
+ Title = key ,
132
+ IsHitTestVisible = false
133
+ } ) ;
134
+ }
135
+ } ) ;
136
+
137
+ return result ;
138
+ } ) ;
111
139
}
112
140
113
141
/// <summary>
114
142
/// 打印SummaryView
115
143
/// </summary>
116
144
/// <returns></returns>
117
- private List < DetailViewItem > PrintSummaryView ( List < MyTimeDuration > durations )
145
+ private Task < List < DetailViewItem > > PrintSummaryView ( List < MyTimeDuration > durations )
118
146
{
119
- List < DetailViewItem > result = new List < DetailViewItem > ( ) ;
120
-
121
- foreach ( MyTimeDuration timeSpan in durations )
147
+ return Task . Run ( ( ) =>
122
148
{
123
- DetailViewItem tmp = new DetailViewItem ( )
149
+ List < DetailViewItem > result = new List < DetailViewItem > ( ) ;
150
+
151
+ foreach ( MyTimeDuration timeSpan in durations )
124
152
{
125
- StartTime = timeSpan . StartTime . ToString ( ) ,
126
- StopTime = timeSpan . StopTime . ToString ( ) ,
127
- AppDuration = timeSpan . Duration . ToString ( ) ,
128
- AppIcon = MyDataHelper . BitmapToBitmapImage ( MyDataHelper . Base64StringToImage ( timeSpan . TimeDurationTask . ApplicationIcon_Base64 ) ) ,
129
- AppName = timeSpan . TimeDurationTask . ApplicationName ,
130
- WindowTitle = timeSpan . TimeDurationTask . ApplicationTitle ,
131
- SystemState = timeSpan . TimeDurationTask . ComputerStatus . ToString ( )
132
- } ;
133
- result . Add ( tmp ) ;
134
- }
135
- return result ;
153
+ DetailViewItem tmp = new DetailViewItem ( )
154
+ {
155
+ StartTime = timeSpan . StartTime . ToString ( ) ,
156
+ StopTime = timeSpan . StopTime . ToString ( ) ,
157
+ AppDuration = timeSpan . Duration . ToString ( ) ,
158
+ AppIcon = MyDataHelper . BitmapToBitmapImage ( MyDataHelper . Base64StringToImage ( timeSpan . TimeDurationTask . ApplicationIcon_Base64 ) ) ,
159
+ AppName = timeSpan . TimeDurationTask . ApplicationName ,
160
+ WindowTitle = timeSpan . TimeDurationTask . ApplicationTitle ,
161
+ SystemState = timeSpan . TimeDurationTask . ComputerStatus . ToString ( )
162
+ } ;
163
+ result . Add ( tmp ) ;
164
+ }
165
+ return result ;
166
+ } ) ;
136
167
}
137
168
138
169
public OverViewViewModel ( )
@@ -149,37 +180,46 @@ public OverViewViewModel()
149
180
150
181
private async void Update ( )
151
182
{
183
+ DateChangeable = false ;
184
+ Loading = Visibility . Visible ;
185
+
152
186
( ( App ) Application . Current ) . appData . Load ( displayDate ) ;
153
187
MyDay today = ( ( App ) Application . Current ) . appData . AllDays [ displayDate ] ;
154
188
155
- await Task . Run ( ( ) =>
156
- {
157
- Overview = PrintOverview ( today . GetOverView ( ) ) ;
189
+ var a = await PrintOverview ( today . GetOverView ( ) ) ;
190
+ var b = await PrintOverviewChart ( today . GetTimeline ( ) ) ;
191
+ #if DEBUG
192
+ var c = await PrintSummaryView ( today . GetTimeline ( ) ) ;
193
+ #endif
158
194
159
- #if DEBUG
160
- DetailView = PrintSummaryView ( today . GetTimeline ( ) ) ;
161
- #endif
162
- } ) ;
195
+ Overview . Clear ( ) ;
196
+ DetailView . Clear ( ) ;
197
+ OverviewChart = b ;
163
198
164
- OverviewChart . Clear ( ) ;
165
- await Task . Run ( ( ) =>
199
+ foreach ( OverViewItem d in a )
166
200
{
167
- SeriesCollection OverviewChart_tmp = PrintOverviewChart ( today . GetTimeline ( ) ) ;
168
- foreach ( StackedColumnSeries i in OverviewChart_tmp )
169
- {
170
- OverviewChart . Add ( i ) ;
171
- //Thread.Sleep(20);
172
- }
173
- } ) ;
201
+ Overview . Add ( d ) ;
202
+ MyDeviceHelper . DoEvents ( ) ;
203
+ }
174
204
205
+ #if DEBUG
206
+ foreach ( DetailViewItem f in c )
207
+ {
208
+ DetailView . Add ( f ) ;
209
+ MyDeviceHelper . DoEvents ( ) ;
210
+ }
211
+ #endif
175
212
UpdateTime = LanguageHelper . InquireLocalizedWord ( "General_LastUpdate" ) + DateTime . Now . ToString ( "H:mm" ) ;
213
+
214
+ DateChangeable = true ;
215
+ Loading = Visibility . Hidden ;
176
216
}
177
217
178
218
/// <summary>
179
219
/// 详细数据
180
220
/// </summary>
181
- private List < DetailViewItem > detailView ;
182
- public List < DetailViewItem > DetailView
221
+ private ObservableCollection < DetailViewItem > detailView = new ObservableCollection < DetailViewItem > ( ) ;
222
+ public ObservableCollection < DetailViewItem > DetailView
183
223
{
184
224
get
185
225
{
@@ -195,8 +235,8 @@ public List<DetailViewItem> DetailView
195
235
/// <summary>
196
236
/// 整体视图
197
237
/// </summary>
198
- private List < OverViewItem > overview ;
199
- public List < OverViewItem > Overview
238
+ private ObservableCollection < OverViewItem > overview = new ObservableCollection < OverViewItem > ( ) ;
239
+ public ObservableCollection < OverViewItem > Overview
200
240
{
201
241
get
202
242
{
@@ -241,6 +281,34 @@ public string UpdateTime
241
281
}
242
282
}
243
283
284
+ private bool dateChangeable = true ;
285
+ public bool DateChangeable
286
+ {
287
+ get
288
+ {
289
+ return dateChangeable ;
290
+ }
291
+ set
292
+ {
293
+ dateChangeable = value ;
294
+ OnPropertyChanged ( ) ;
295
+ }
296
+ }
297
+
298
+ private Visibility loading = Visibility . Hidden ;
299
+ public Visibility Loading
300
+ {
301
+ get
302
+ {
303
+ return loading ;
304
+ }
305
+ set
306
+ {
307
+ loading = value ;
308
+ OnPropertyChanged ( ) ;
309
+ }
310
+ }
311
+
244
312
#region 表格
245
313
/// <summary>
246
314
/// 表格
0 commit comments