Esempio n. 1
0
        private void RefreshMediaTypesLocked(List <int> removedIds, List <int> refreshedIds, List <int> otherIds, List <int> newIds)
        {
            if (removedIds.IsCollectionEmpty() && refreshedIds.IsCollectionEmpty() && otherIds.IsCollectionEmpty() && newIds.IsCollectionEmpty())
            {
                return;
            }

            // locks:
            // media (and content types) are read-locked while reading media
            // mediaStore is wlocked (so readable, only no new views)
            // and it can be wlocked by 1 thread only at a time
            using (var scope = _scopeProvider.CreateScope())
            {
                scope.ReadLock(Constants.Locks.MediaTypes);

                var typesA = refreshedIds == null
                    ? Array.Empty <IPublishedContentType>()
                    : CreateContentTypes(PublishedItemType.Media, refreshedIds.ToArray()).ToArray();

                var kits = refreshedIds == null
                    ? Array.Empty <ContentNodeKit>()
                    : _publishedContentService.GetTypeMediaSources(refreshedIds).ToArray();

                _mediaStore.UpdateContentTypesLocked(removedIds, typesA, kits);
                if (!otherIds.IsCollectionEmpty())
                {
                    _mediaStore.UpdateContentTypesLocked(CreateContentTypes(PublishedItemType.Media, otherIds.ToArray()).ToArray());
                }

                if (!newIds.IsCollectionEmpty())
                {
                    _mediaStore.NewContentTypesLocked(CreateContentTypes(PublishedItemType.Media, newIds.ToArray()).ToArray());
                }

                scope.Complete();
            }
        }