6
6
7
7
namespace GitHub . Unity
8
8
{
9
- class UsageTracker : IUsageTracker
9
+ class UsageTrackerSync : IUsageTracker
10
10
{
11
11
private static ILogging Logger { get ; } = LogHelper . GetLogger < UsageTracker > ( ) ;
12
12
@@ -22,16 +22,7 @@ class UsageTracker : IUsageTracker
22
22
23
23
public IMetricsService MetricsService { get ; set ; }
24
24
25
- public UsageTracker ( ISettings userSettings ,
26
- IEnvironment environment , string instanceId )
27
- : this ( userSettings ,
28
- new UsageLoader ( environment . UserCachePath . Combine ( Constants . UsageFile ) ) ,
29
- environment . UnityVersion , instanceId )
30
- {
31
- }
32
-
33
- public UsageTracker ( ISettings userSettings ,
34
- IUsageLoader usageLoader ,
25
+ public UsageTrackerSync ( ISettings userSettings , IUsageLoader usageLoader ,
35
26
string unityVersion , string instanceId )
36
27
{
37
28
this . userSettings = userSettings ;
@@ -123,7 +114,7 @@ private void SendUsage()
123
114
}
124
115
}
125
116
126
- public void IncrementNumberOfStartups ( )
117
+ public virtual void IncrementNumberOfStartups ( )
127
118
{
128
119
lock ( _lock )
129
120
{
@@ -134,7 +125,7 @@ public void IncrementNumberOfStartups()
134
125
}
135
126
}
136
127
137
- public void IncrementProjectsInitialized ( )
128
+ public virtual void IncrementProjectsInitialized ( )
138
129
{
139
130
lock ( _lock )
140
131
{
@@ -145,7 +136,7 @@ public void IncrementProjectsInitialized()
145
136
}
146
137
}
147
138
148
- public void IncrementChangesViewButtonCommit ( )
139
+ public virtual void IncrementChangesViewButtonCommit ( )
149
140
{
150
141
lock ( _lock )
151
142
{
@@ -156,7 +147,7 @@ public void IncrementChangesViewButtonCommit()
156
147
}
157
148
}
158
149
159
- public void IncrementHistoryViewToolbarFetch ( )
150
+ public virtual void IncrementHistoryViewToolbarFetch ( )
160
151
{
161
152
lock ( _lock )
162
153
{
@@ -167,7 +158,7 @@ public void IncrementHistoryViewToolbarFetch()
167
158
}
168
159
}
169
160
170
- public void IncrementHistoryViewToolbarPush ( )
161
+ public virtual void IncrementHistoryViewToolbarPush ( )
171
162
{
172
163
lock ( _lock )
173
164
{
@@ -178,7 +169,7 @@ public void IncrementHistoryViewToolbarPush()
178
169
}
179
170
}
180
171
181
- public void IncrementHistoryViewToolbarPull ( )
172
+ public virtual void IncrementHistoryViewToolbarPull ( )
182
173
{
183
174
lock ( _lock )
184
175
{
@@ -189,7 +180,7 @@ public void IncrementHistoryViewToolbarPull()
189
180
}
190
181
}
191
182
192
- public void IncrementBranchesViewButtonCreateBranch ( )
183
+ public virtual void IncrementBranchesViewButtonCreateBranch ( )
193
184
{
194
185
lock ( _lock )
195
186
{
@@ -200,7 +191,7 @@ public void IncrementBranchesViewButtonCreateBranch()
200
191
}
201
192
}
202
193
203
- public void IncrementBranchesViewButtonDeleteBranch ( )
194
+ public virtual void IncrementBranchesViewButtonDeleteBranch ( )
204
195
{
205
196
lock ( _lock )
206
197
{
@@ -211,7 +202,7 @@ public void IncrementBranchesViewButtonDeleteBranch()
211
202
}
212
203
}
213
204
214
- public void IncrementBranchesViewButtonCheckoutLocalBranch ( )
205
+ public virtual void IncrementBranchesViewButtonCheckoutLocalBranch ( )
215
206
{
216
207
lock ( _lock )
217
208
{
@@ -222,7 +213,7 @@ public void IncrementBranchesViewButtonCheckoutLocalBranch()
222
213
}
223
214
}
224
215
225
- public void IncrementBranchesViewButtonCheckoutRemoteBranch ( )
216
+ public virtual void IncrementBranchesViewButtonCheckoutRemoteBranch ( )
226
217
{
227
218
lock ( _lock )
228
219
{
@@ -233,7 +224,7 @@ public void IncrementBranchesViewButtonCheckoutRemoteBranch()
233
224
}
234
225
}
235
226
236
- public void IncrementSettingsViewButtonLfsUnlock ( )
227
+ public virtual void IncrementSettingsViewButtonLfsUnlock ( )
237
228
{
238
229
lock ( _lock )
239
230
{
@@ -244,7 +235,7 @@ public void IncrementSettingsViewButtonLfsUnlock()
244
235
}
245
236
}
246
237
247
- public void IncrementAuthenticationViewButtonAuthentication ( )
238
+ public virtual void IncrementAuthenticationViewButtonAuthentication ( )
248
239
{
249
240
lock ( _lock )
250
241
{
@@ -255,7 +246,7 @@ public void IncrementAuthenticationViewButtonAuthentication()
255
246
}
256
247
}
257
248
258
- public void IncrementUnityProjectViewContextLfsLock ( )
249
+ public virtual void IncrementUnityProjectViewContextLfsLock ( )
259
250
{
260
251
lock ( _lock )
261
252
{
@@ -266,7 +257,7 @@ public void IncrementUnityProjectViewContextLfsLock()
266
257
}
267
258
}
268
259
269
- public void IncrementUnityProjectViewContextLfsUnlock ( )
260
+ public virtual void IncrementUnityProjectViewContextLfsUnlock ( )
270
261
{
271
262
lock ( _lock )
272
263
{
@@ -277,7 +268,7 @@ public void IncrementUnityProjectViewContextLfsUnlock()
277
268
}
278
269
}
279
270
280
- public void IncrementPublishViewButtonPublish ( )
271
+ public virtual void IncrementPublishViewButtonPublish ( )
281
272
{
282
273
lock ( _lock )
283
274
{
@@ -288,7 +279,7 @@ public void IncrementPublishViewButtonPublish()
288
279
}
289
280
}
290
281
291
- public void IncrementApplicationMenuMenuItemCommandLine ( )
282
+ public virtual void IncrementApplicationMenuMenuItemCommandLine ( )
292
283
{
293
284
lock ( _lock )
294
285
{
@@ -299,18 +290,24 @@ public void IncrementApplicationMenuMenuItemCommandLine()
299
290
}
300
291
}
301
292
302
- public void UpdateRepoSize ( int kilobytes )
293
+ public virtual void UpdateRepoSize ( int kilobytes )
303
294
{
304
- var usage = usageLoader . Load ( userId ) ;
305
- usage . GetCurrentMeasures ( appVersion , unityVersion , instanceId ) . GitRepoSize = kilobytes ;
306
- usageLoader . Save ( usage ) ;
295
+ lock ( _lock )
296
+ {
297
+ var usage = usageLoader . Load ( userId ) ;
298
+ usage . GetCurrentMeasures ( appVersion , unityVersion , instanceId ) . GitRepoSize = kilobytes ;
299
+ usageLoader . Save ( usage ) ;
300
+ }
307
301
}
308
302
309
- public void UpdateLfsDiskUsage ( int kilobytes )
303
+ public virtual void UpdateLfsDiskUsage ( int kilobytes )
310
304
{
311
- var usage = usageLoader . Load ( userId ) ;
312
- usage . GetCurrentMeasures ( appVersion , unityVersion , instanceId ) . LfsDiskUsage = kilobytes ;
313
- usageLoader . Save ( usage ) ;
305
+ lock ( _lock )
306
+ {
307
+ var usage = usageLoader . Load ( userId ) ;
308
+ usage . GetCurrentMeasures ( appVersion , unityVersion , instanceId ) . LfsDiskUsage = kilobytes ;
309
+ usageLoader . Save ( usage ) ;
310
+ }
314
311
}
315
312
316
313
public bool Enabled
@@ -337,6 +334,39 @@ public bool Enabled
337
334
}
338
335
}
339
336
337
+ class UsageTracker : UsageTrackerSync
338
+ {
339
+ public UsageTracker ( ITaskManager taskManager , ISettings userSettings ,
340
+ IEnvironment environment , string instanceId )
341
+ : base ( userSettings ,
342
+ new UsageLoader ( environment . UserCachePath . Combine ( Constants . UsageFile ) ) ,
343
+ environment . UnityVersion , instanceId )
344
+ {
345
+ TaskManager = taskManager ;
346
+ }
347
+
348
+ public override void IncrementApplicationMenuMenuItemCommandLine ( ) => TaskManager . Run ( base . IncrementApplicationMenuMenuItemCommandLine ) ;
349
+ public override void IncrementAuthenticationViewButtonAuthentication ( ) => TaskManager . Run ( base . IncrementAuthenticationViewButtonAuthentication ) ;
350
+ public override void IncrementBranchesViewButtonCheckoutLocalBranch ( ) => TaskManager . Run ( base . IncrementBranchesViewButtonCheckoutLocalBranch ) ;
351
+ public override void IncrementBranchesViewButtonCheckoutRemoteBranch ( ) => TaskManager . Run ( base . IncrementBranchesViewButtonCheckoutRemoteBranch ) ;
352
+ public override void IncrementBranchesViewButtonCreateBranch ( ) => TaskManager . Run ( base . IncrementBranchesViewButtonCreateBranch ) ;
353
+ public override void IncrementBranchesViewButtonDeleteBranch ( ) => TaskManager . Run ( base . IncrementBranchesViewButtonDeleteBranch ) ;
354
+ public override void IncrementChangesViewButtonCommit ( ) => TaskManager . Run ( base . IncrementChangesViewButtonCommit ) ;
355
+ public override void IncrementHistoryViewToolbarFetch ( ) => TaskManager . Run ( base . IncrementHistoryViewToolbarFetch ) ;
356
+ public override void IncrementHistoryViewToolbarPull ( ) => TaskManager . Run ( base . IncrementHistoryViewToolbarPull ) ;
357
+ public override void IncrementHistoryViewToolbarPush ( ) => TaskManager . Run ( base . IncrementHistoryViewToolbarPush ) ;
358
+ public override void IncrementNumberOfStartups ( ) => TaskManager . Run ( base . IncrementNumberOfStartups ) ;
359
+ public override void IncrementProjectsInitialized ( ) => TaskManager . Run ( base . IncrementProjectsInitialized ) ;
360
+ public override void IncrementPublishViewButtonPublish ( ) => TaskManager . Run ( base . IncrementPublishViewButtonPublish ) ;
361
+ public override void IncrementSettingsViewButtonLfsUnlock ( ) => TaskManager . Run ( base . IncrementSettingsViewButtonLfsUnlock ) ;
362
+ public override void IncrementUnityProjectViewContextLfsLock ( ) => TaskManager . Run ( base . IncrementUnityProjectViewContextLfsLock ) ;
363
+ public override void IncrementUnityProjectViewContextLfsUnlock ( ) => TaskManager . Run ( base . IncrementUnityProjectViewContextLfsUnlock ) ;
364
+ public override void UpdateLfsDiskUsage ( int kilobytes ) => TaskManager . Run ( ( ) => base . UpdateLfsDiskUsage ( kilobytes ) ) ;
365
+ public override void UpdateRepoSize ( int kilobytes ) => TaskManager . Run ( ( ) => base . UpdateRepoSize ( kilobytes ) ) ;
366
+
367
+ protected ITaskManager TaskManager { get ; }
368
+ }
369
+
340
370
interface IUsageLoader
341
371
{
342
372
UsageStore Load ( string userId ) ;
0 commit comments