Exemplo n.º 1
0
 private bool LockAndLoadMedia(Func <bool> action)
 {
     // see note in LockAndLoadContent
     using (_mediaStore.GetScopedWriteLock(_scopeProvider))
         using (var scope = _scopeProvider.CreateScope())
         {
             scope.ReadLock(Constants.Locks.MediaTree);
             var ok = action();
             scope.Complete();
             return(ok);
         }
 }
Exemplo n.º 2
0
 // sudden panic... but in RepeatableRead can a content that I haven't already read, be removed
 // before I read it? NO! because the WHOLE content tree is read-locked using WithReadLocked.
 // don't panic.
 private bool LockAndLoadContent(Func <bool> action)
 {
     // first get a writer, then a scope
     // if there already is a scope, the writer will attach to it
     // otherwise, it will only exist here - cheap
     using (_contentStore.GetScopedWriteLock(_scopeProvider))
         using (var scope = _scopeProvider.CreateScope())
         {
             scope.ReadLock(Constants.Locks.ContentTree);
             var ok = action();
             scope.Complete();
             return(ok);
         }
 }
Exemplo n.º 3
0
        private void Notify <T>(ContentStore store, ContentTypeCacheRefresher.JsonPayload[] payloads, Action <List <int>, List <int>, List <int>, List <int> > action)
            where T : IContentTypeComposition
        {
            if (payloads.Length == 0)
            {
                return; // nothing to do
            }

            var nameOfT = typeof(T).Name;

            List <int> removedIds = null, refreshedIds = null, otherIds = null, newIds = null;

            foreach (var payload in payloads)
            {
                if (payload.ItemType != nameOfT)
                {
                    continue;
                }

                if (payload.ChangeTypes.HasType(ContentTypeChangeTypes.Remove))
                {
                    AddToList(ref removedIds, payload.Id);
                }
                else if (payload.ChangeTypes.HasType(ContentTypeChangeTypes.RefreshMain))
                {
                    AddToList(ref refreshedIds, payload.Id);
                }
                else if (payload.ChangeTypes.HasType(ContentTypeChangeTypes.RefreshOther))
                {
                    AddToList(ref otherIds, payload.Id);
                }
                else if (payload.ChangeTypes.HasType(ContentTypeChangeTypes.Create))
                {
                    AddToList(ref newIds, payload.Id);
                }
            }

            if (removedIds.IsCollectionEmpty() && refreshedIds.IsCollectionEmpty() && otherIds.IsCollectionEmpty() && newIds.IsCollectionEmpty())
            {
                return;
            }

            using (store.GetScopedWriteLock(_scopeProvider))
            {
                action(removedIds, refreshedIds, otherIds, newIds);
            }
        }