@@ -50,10 +50,10 @@ public Repository(NPath localPath, ICacheContainer container)
5050 RemoteBranchListChanged ? . Invoke ( cacheUpdateEvent ) ;
5151 LocalAndRemoteBranchListChanged ? . Invoke ( cacheUpdateEvent ) ;
5252 } } ,
53- { CacheType . GitAheadBehind , TrackingStatusChanged . SafeInvoke } ,
54- { CacheType . GitLocks , LocksChanged . SafeInvoke } ,
55- { CacheType . GitLog , LogChanged . SafeInvoke } ,
56- { CacheType . GitStatus , StatusEntriesChanged . SafeInvoke } ,
53+ { CacheType . GitAheadBehind , c => TrackingStatusChanged ? . Invoke ( c ) } ,
54+ { CacheType . GitLocks , c => LocksChanged ? . Invoke ( c ) } ,
55+ { CacheType . GitLog , c => LogChanged ? . Invoke ( c ) } ,
56+ { CacheType . GitStatus , c => StatusEntriesChanged ? . Invoke ( c ) } ,
5757 { CacheType . GitUser , cacheUpdateEvent => { } } ,
5858 { CacheType . RepositoryInfo , cacheUpdateEvent => {
5959 CurrentBranchChanged ? . Invoke ( cacheUpdateEvent ) ;
@@ -64,7 +64,10 @@ public Repository(NPath localPath, ICacheContainer container)
6464
6565 cacheContainer = container ;
6666 cacheContainer . CacheInvalidated += CacheHasBeenInvalidated ;
67- cacheContainer . CacheUpdated += ( cacheType , offset ) => cacheUpdateEvents [ cacheType ] ( new CacheUpdateEvent ( cacheType , offset ) ) ;
67+ cacheContainer . CacheUpdated += ( cacheType , offset ) =>
68+ {
69+ cacheUpdateEvents [ cacheType ] ( new CacheUpdateEvent ( cacheType , offset ) ) ;
70+ } ;
6871 }
6972
7073 public void Initialize ( IRepositoryManager repositoryManager , ITaskManager taskManager )
@@ -117,7 +120,7 @@ public ITask SetupRemote(string remote, string remoteUrl)
117120 public ITask ReleaseLock ( string file , bool force ) => repositoryManager . UnlockFile ( file , force ) ;
118121 public ITask DiscardChanges ( GitStatusEntry [ ] gitStatusEntry ) => repositoryManager . DiscardChanges ( gitStatusEntry ) ;
119122
120- public void CheckAndRaiseEventsIfCacheNewer ( CacheUpdateEvent cacheUpdateEvent ) => cacheContainer . CheckAndRaiseEventsIfCacheNewer ( cacheUpdateEvent ) ;
123+ public void CheckAndRaiseEventsIfCacheNewer ( CacheType cacheType , CacheUpdateEvent cacheUpdateEvent ) => cacheContainer . CheckAndRaiseEventsIfCacheNewer ( cacheType , cacheUpdateEvent ) ;
121124
122125
123126 /// <summary>
@@ -154,11 +157,14 @@ public bool Equals(IRepository other)
154157
155158 private void RefreshCache ( CacheType cacheType )
156159 {
157- var cache = cacheContainer . GetCache ( cacheType ) ;
158- // if the cache has valid data, we need to force an invalidation to refresh it
159- // if it doesn't have valid data, it will trigger an invalidation automatically
160- if ( cache . ValidateData ( ) )
161- cache . InvalidateData ( ) ;
160+ taskManager . RunInUI ( ( ) =>
161+ {
162+ var cache = cacheContainer . GetCache ( cacheType ) ;
163+ // if the cache has valid data, we need to force an invalidation to refresh it
164+ // if it doesn't have valid data, it will trigger an invalidation automatically
165+ if ( cache . ValidateData ( ) )
166+ cache . InvalidateData ( ) ;
167+ } ) ;
162168 }
163169
164170 private void CacheHasBeenInvalidated ( CacheType cacheType )
@@ -362,6 +368,7 @@ public string Name
362368 public NPath LocalPath { get ; private set ; }
363369 public string Owner => CloneUrl ? . Owner ?? null ;
364370 public bool IsGitHub => HostAddress . IsGitHubDotCom ( CloneUrl ) ;
371+ public bool IsBusy => repositoryManager ? . IsBusy ?? false ;
365372
366373 internal string DebuggerDisplay => String . Format ( CultureInfo . InvariantCulture ,
367374 "{0} Owner: {1} Name: {2} CloneUrl: {3} LocalPath: {4} Branch: {5} Remote: {6}" , GetHashCode ( ) , Owner , Name ,
@@ -398,17 +405,7 @@ public User(ICacheContainer cacheContainer)
398405 cacheContainer . CacheUpdated += ( type , dt ) => { if ( type == CacheType . GitUser ) CacheHasBeenUpdated ( dt ) ; } ;
399406 }
400407
401- public void CheckUserChangedEvent ( CacheUpdateEvent cacheUpdateEvent )
402- {
403- var managedCache = cacheContainer . GitUserCache ;
404- var raiseEvent = managedCache . LastUpdatedAt != cacheUpdateEvent . UpdatedTime ;
405-
406- Logger . Trace ( "Check GitUserCache CacheUpdateEvent Current:{0} Check:{1} Result:{2}" , managedCache . LastUpdatedAt ,
407- cacheUpdateEvent . UpdatedTime , raiseEvent ) ;
408-
409- if ( raiseEvent )
410- CacheHasBeenUpdated ( managedCache . LastUpdatedAt ) ;
411- }
408+ public void CheckUserChangedEvent ( CacheUpdateEvent cacheUpdateEvent ) => cacheContainer . CheckAndRaiseEventsIfCacheNewer ( CacheType . GitUser , cacheUpdateEvent ) ;
412409
413410 public void Initialize ( IGitClient client )
414411 {
@@ -486,89 +483,4 @@ public string Email
486483
487484 protected static ILogging Logger { get ; } = LogHelper . GetLogger < User > ( ) ;
488485 }
489-
490- [ Serializable ]
491- public struct CacheUpdateEvent
492- {
493- [ NonSerialized ] private DateTimeOffset ? updatedTimeValue ;
494- public string updatedTimeString ;
495- public CacheType cacheType ;
496-
497- public CacheUpdateEvent ( CacheType type , DateTimeOffset when )
498- {
499- cacheType = type ;
500- updatedTimeValue = when ;
501- updatedTimeString = when . ToString ( Constants . Iso8601Format ) ;
502- }
503-
504- public override int GetHashCode ( )
505- {
506- int hash = 17 ;
507- hash = hash * 23 + cacheType . GetHashCode ( ) ;
508- hash = hash * 23 + ( updatedTimeString ? . GetHashCode ( ) ?? 0 ) ;
509- return hash ;
510- }
511-
512- public override bool Equals ( object other )
513- {
514- if ( other is CacheUpdateEvent )
515- return Equals ( ( CacheUpdateEvent ) other ) ;
516- return false ;
517- }
518-
519- public bool Equals ( CacheUpdateEvent other )
520- {
521- return
522- cacheType == other . cacheType &&
523- String . Equals ( updatedTimeString , other . updatedTimeString )
524- ;
525- }
526-
527- public static bool operator == ( CacheUpdateEvent lhs , CacheUpdateEvent rhs )
528- {
529- // If both are null, or both are same instance, return true.
530- if ( ReferenceEquals ( lhs , rhs ) )
531- return true ;
532-
533- // If one is null, but not both, return false.
534- if ( ( ( object ) lhs == null ) || ( ( object ) rhs == null ) )
535- return false ;
536-
537- // Return true if the fields match:
538- return lhs . Equals ( rhs ) ;
539- }
540-
541- public static bool operator != ( CacheUpdateEvent lhs , CacheUpdateEvent rhs )
542- {
543- return ! ( lhs == rhs ) ;
544- }
545-
546- public DateTimeOffset UpdatedTime
547- {
548- get
549- {
550- if ( ! updatedTimeValue . HasValue )
551- {
552- DateTimeOffset result ;
553- if ( DateTimeOffset . TryParseExact ( updatedTimeString , Constants . Iso8601Format , CultureInfo . InvariantCulture , DateTimeStyles . None , out result ) )
554- {
555- updatedTimeValue = result ;
556- }
557- else
558- {
559- UpdatedTime = DateTimeOffset . MinValue ;
560- }
561- }
562-
563- return updatedTimeValue . Value ;
564- }
565- set
566- {
567- updatedTimeValue = value ;
568- updatedTimeString = value . ToString ( Constants . Iso8601Format ) ;
569- }
570- }
571-
572- public string UpdatedTimeString => updatedTimeString ;
573- }
574486}
0 commit comments