public IEnumerable <EntityContainer> GetContainers(int[] containerIds)
    {
        using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
        scope.ReadLock(ReadLockIds); // also for containers

        return(_containerRepository.GetMany(containerIds));
    }
    public IEnumerable <EntityContainer> GetContainers(string name, int level)
    {
        using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
        scope.ReadLock(ReadLockIds); // also for containers

        return(_containerRepository.Get(name, level));
    }
    public EntityContainer?GetContainer(Guid containerId)
    {
        using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
        scope.ReadLock(ReadLockIds); // also for containers

        return(_containerRepository.Get(containerId));
    }
    public IEnumerable <TItem> GetChildren(int id)
    {
        using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
        scope.ReadLock(ReadLockIds);
        IQuery <TItem> query = Query <TItem>().Where(x => x.ParentId == id);

        return(Repository.Get(query));
    }
    public bool HasChildren(int id)
    {
        using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
        scope.ReadLock(ReadLockIds);
        IQuery <TItem> query = Query <TItem>().Where(x => x.ParentId == id);
        var            count = Repository.Count(query);

        return(count > 0);
    }
    /// <inheritdoc />
    public void Rebuild(
        IReadOnlyCollection <int>?contentTypeIds = null,
        IReadOnlyCollection <int>?mediaTypeIds   = null,
        IReadOnlyCollection <int>?memberTypeIds  = null)
    {
        using (ICoreScope scope = ScopeProvider.CreateCoreScope(repositoryCacheMode: RepositoryCacheMode.Scoped))
        {
            scope.ReadLock(Constants.Locks.ContentTree);
            scope.ReadLock(Constants.Locks.MediaTree);
            scope.ReadLock(Constants.Locks.MemberTree);

            _repository.Rebuild(contentTypeIds, mediaTypeIds, memberTypeIds);

            // Save a key/value of the serialized type. This is used during startup to see
            // if the serialized type changed and if so it will rebuild with the correct type.
            _keyValueService.SetValue(NuCacheSerializerKey, _nucacheSettings.Value.NuCacheSerializerType.ToString());

            scope.Complete();
        }
    }
Exemple #7
0
    /// <summary>
    ///     Return all servers (active and inactive).
    /// </summary>
    /// <param name="refresh">A value indicating whether to force-refresh the cache.</param>
    /// <returns>All servers.</returns>
    /// <remarks>
    ///     By default this method will rely on the repository's cache, which is updated each
    ///     time the current server is touched, and the period depends on the configuration. Use the
    ///     <paramref name="refresh" /> parameter to force a cache refresh and reload all servers
    ///     from the database.
    /// </remarks>
    public IEnumerable <IServerRegistration> GetServers(bool refresh = false)
    {
        using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
        {
            scope.ReadLock(Constants.Locks.Servers);
            if (refresh)
            {
                _serverRegistrationRepository.ClearCache();
            }

            return(_serverRegistrationRepository.GetMany().ToArray()); // fast, cached // fast, cached
        }
    }
        public IEnumerable <TItem> GetAll(IEnumerable <Guid>?ids)
        {
            if (ids is null)
            {
                return(Enumerable.Empty <TItem>());
            }

            using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))

            {
                scope.ReadLock(ReadLockIds);
                return(Repository.GetMany(ids.ToArray()));
            }
        }
    public IEnumerable <TItem> GetChildren(Guid id)
    {
        using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
        scope.ReadLock(ReadLockIds);
        TItem?found = Get(id);

        if (found == null)
        {
            return(Enumerable.Empty <TItem>());
        }

        IQuery <TItem> query = Query <TItem>().Where(x => x.ParentId == found.Id);

        return(Repository.Get(query));
    }
    public bool HasChildren(Guid id)
    {
        using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
        {
            scope.ReadLock(ReadLockIds);
            TItem?found = Get(id);
            if (found == null)
            {
                return(false);
            }

            IQuery <TItem> query = Query <TItem>().Where(x => x.ParentId == found.Id);
            var            count = Repository.Count(query);
            return(count > 0);
        }
    }
    public Attempt <string[]?> ValidateComposition(TItem?compo)
    {
        try
        {
            using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
            {
                scope.ReadLock(ReadLockIds);
                ValidateLocked(compo !);
            }

            return(Attempt <string[]?> .Succeed());
        }
        catch (InvalidCompositionException ex)
        {
            return(Attempt.Fail(ex.PropertyTypeAliases, ex));
        }
    }
Exemple #12
0
        /// <inheritdoc />
        public IEnumerable <ContentVersionMeta>?GetPagedContentVersions(int contentId, long pageIndex, int pageSize, out long totalRecords, string?culture = null)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pageIndex));
            }

            if (pageSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pageSize));
            }

            using (ICoreScope scope = _scopeProvider.CreateCoreScope(autoComplete: true))
            {
                var languageId = _languageRepository.GetIdByIsoCode(culture, throwOnNotFound: true);
                scope.ReadLock(Constants.Locks.ContentTree);
                return(_documentVersionRepository.GetPagedItemsByContentId(contentId, pageIndex, pageSize, out totalRecords, languageId));
            }
        }
    public IEnumerable <TItem> GetDescendants(int id, bool andSelf)
    {
        using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
        scope.ReadLock(ReadLockIds);

        var descendants = new List <TItem>();

        if (andSelf)
        {
            TItem?self = Repository.Get(id);
            if (self is not null)
            {
                descendants.Add(self);
            }
        }

        var ids = new Stack <int>();

        ids.Push(id);

        while (ids.Count > 0)
        {
            var            i     = ids.Pop();
            IQuery <TItem> query = Query <TItem>().Where(x => x.ParentId == i);
            TItem[]? result = Repository.Get(query).ToArray();

            if (result is not null)
            {
                foreach (TItem c in result)
                {
                    descendants.Add(c);
                    ids.Push(c.Id);
                }
            }
        }

        return(descendants.ToArray());
    }
    public string GetDefault()
    {
        using (ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true))
        {
            scope.ReadLock(ReadLockIds);

            using (IEnumerator <IMemberType> e = _memberTypeRepository.GetMany(new int[0]).GetEnumerator())
            {
                if (e.MoveNext() == false)
                {
                    throw new InvalidOperationException("No member types could be resolved");
                }

                var first   = e.Current.Alias;
                var current = true;
                while (e.Current.Alias.InvariantEquals("Member") == false && (current = e.MoveNext()))
                {
                }

                return(current ? e.Current.Alias : first);
            }
        }
    }
 /// <inheritdoc />
 public bool VerifyMemberDbCache()
 {
     using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
     scope.ReadLock(Constants.Locks.MemberTree);
     return(_repository.VerifyMemberDbCache());
 }
 public TItem?Get(Guid id)
 {
     using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
     scope.ReadLock(ReadLockIds);
     return(Repository.Get(id));
 }
 public bool HasContentNodes(int id)
 {
     using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
     scope.ReadLock(ReadLockIds);
     return(Repository.HasContentNodes(id));
 }
 public int Count()
 {
     using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
     scope.ReadLock(ReadLockIds);
     return(Repository.Count(Query <TItem>()));
 }
 public IEnumerable <TItem> GetAll(params int[] ids)
 {
     using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);
     scope.ReadLock(ReadLockIds);
     return(Repository.GetMany(ids));
 }