66
77namespace GitHub . Unity
88{
9- class UsageTracker : IUsageTracker
9+ class UsageTrackerSync : IUsageTracker
1010 {
1111 private static ILogging Logger { get ; } = LogHelper . GetLogger < UsageTracker > ( ) ;
1212
@@ -22,16 +22,7 @@ class UsageTracker : IUsageTracker
2222
2323 public IMetricsService MetricsService { get ; set ; }
2424
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 ,
3526 string unityVersion , string instanceId )
3627 {
3728 this . userSettings = userSettings ;
@@ -123,7 +114,7 @@ private void SendUsage()
123114 }
124115 }
125116
126- public void IncrementNumberOfStartups ( )
117+ public virtual void IncrementNumberOfStartups ( )
127118 {
128119 lock ( _lock )
129120 {
@@ -134,7 +125,7 @@ public void IncrementNumberOfStartups()
134125 }
135126 }
136127
137- public void IncrementProjectsInitialized ( )
128+ public virtual void IncrementProjectsInitialized ( )
138129 {
139130 lock ( _lock )
140131 {
@@ -145,7 +136,7 @@ public void IncrementProjectsInitialized()
145136 }
146137 }
147138
148- public void IncrementChangesViewButtonCommit ( )
139+ public virtual void IncrementChangesViewButtonCommit ( )
149140 {
150141 lock ( _lock )
151142 {
@@ -156,7 +147,7 @@ public void IncrementChangesViewButtonCommit()
156147 }
157148 }
158149
159- public void IncrementHistoryViewToolbarFetch ( )
150+ public virtual void IncrementHistoryViewToolbarFetch ( )
160151 {
161152 lock ( _lock )
162153 {
@@ -167,7 +158,7 @@ public void IncrementHistoryViewToolbarFetch()
167158 }
168159 }
169160
170- public void IncrementHistoryViewToolbarPush ( )
161+ public virtual void IncrementHistoryViewToolbarPush ( )
171162 {
172163 lock ( _lock )
173164 {
@@ -178,7 +169,7 @@ public void IncrementHistoryViewToolbarPush()
178169 }
179170 }
180171
181- public void IncrementHistoryViewToolbarPull ( )
172+ public virtual void IncrementHistoryViewToolbarPull ( )
182173 {
183174 lock ( _lock )
184175 {
@@ -189,7 +180,7 @@ public void IncrementHistoryViewToolbarPull()
189180 }
190181 }
191182
192- public void IncrementBranchesViewButtonCreateBranch ( )
183+ public virtual void IncrementBranchesViewButtonCreateBranch ( )
193184 {
194185 lock ( _lock )
195186 {
@@ -200,7 +191,7 @@ public void IncrementBranchesViewButtonCreateBranch()
200191 }
201192 }
202193
203- public void IncrementBranchesViewButtonDeleteBranch ( )
194+ public virtual void IncrementBranchesViewButtonDeleteBranch ( )
204195 {
205196 lock ( _lock )
206197 {
@@ -211,7 +202,7 @@ public void IncrementBranchesViewButtonDeleteBranch()
211202 }
212203 }
213204
214- public void IncrementBranchesViewButtonCheckoutLocalBranch ( )
205+ public virtual void IncrementBranchesViewButtonCheckoutLocalBranch ( )
215206 {
216207 lock ( _lock )
217208 {
@@ -222,7 +213,7 @@ public void IncrementBranchesViewButtonCheckoutLocalBranch()
222213 }
223214 }
224215
225- public void IncrementBranchesViewButtonCheckoutRemoteBranch ( )
216+ public virtual void IncrementBranchesViewButtonCheckoutRemoteBranch ( )
226217 {
227218 lock ( _lock )
228219 {
@@ -233,7 +224,7 @@ public void IncrementBranchesViewButtonCheckoutRemoteBranch()
233224 }
234225 }
235226
236- public void IncrementSettingsViewButtonLfsUnlock ( )
227+ public virtual void IncrementSettingsViewButtonLfsUnlock ( )
237228 {
238229 lock ( _lock )
239230 {
@@ -244,7 +235,7 @@ public void IncrementSettingsViewButtonLfsUnlock()
244235 }
245236 }
246237
247- public void IncrementAuthenticationViewButtonAuthentication ( )
238+ public virtual void IncrementAuthenticationViewButtonAuthentication ( )
248239 {
249240 lock ( _lock )
250241 {
@@ -255,7 +246,7 @@ public void IncrementAuthenticationViewButtonAuthentication()
255246 }
256247 }
257248
258- public void IncrementUnityProjectViewContextLfsLock ( )
249+ public virtual void IncrementUnityProjectViewContextLfsLock ( )
259250 {
260251 lock ( _lock )
261252 {
@@ -266,7 +257,7 @@ public void IncrementUnityProjectViewContextLfsLock()
266257 }
267258 }
268259
269- public void IncrementUnityProjectViewContextLfsUnlock ( )
260+ public virtual void IncrementUnityProjectViewContextLfsUnlock ( )
270261 {
271262 lock ( _lock )
272263 {
@@ -277,7 +268,7 @@ public void IncrementUnityProjectViewContextLfsUnlock()
277268 }
278269 }
279270
280- public void IncrementPublishViewButtonPublish ( )
271+ public virtual void IncrementPublishViewButtonPublish ( )
281272 {
282273 lock ( _lock )
283274 {
@@ -288,7 +279,7 @@ public void IncrementPublishViewButtonPublish()
288279 }
289280 }
290281
291- public void IncrementApplicationMenuMenuItemCommandLine ( )
282+ public virtual void IncrementApplicationMenuMenuItemCommandLine ( )
292283 {
293284 lock ( _lock )
294285 {
@@ -299,18 +290,24 @@ public void IncrementApplicationMenuMenuItemCommandLine()
299290 }
300291 }
301292
302- public void UpdateRepoSize ( int kilobytes )
293+ public virtual void UpdateRepoSize ( int kilobytes )
303294 {
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+ }
307301 }
308302
309- public void UpdateLfsDiskUsage ( int kilobytes )
303+ public virtual void UpdateLfsDiskUsage ( int kilobytes )
310304 {
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+ }
314311 }
315312
316313 public bool Enabled
@@ -337,6 +334,39 @@ public bool Enabled
337334 }
338335 }
339336
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+
340370 interface IUsageLoader
341371 {
342372 UsageStore Load ( string userId ) ;
0 commit comments