Example #1
0
        public async Task <ICollection <CustomEntityRoute> > ExecuteAsync(GetCustomEntityRoutesByDefinitionCodeQuery query, IExecutionContext executionContext)
        {
            return(await _customEntityCache.GetOrAddAsync(query.CustomEntityDefinitionCode, async() =>
            {
                var dbRoutes = await _dbContext
                               .CustomEntities
                               .Include(c => c.CustomEntityVersions)
                               .Include(c => c.Locale)
                               .AsNoTracking()
                               .Where(e => e.CustomEntityDefinitionCode == query.CustomEntityDefinitionCode && (e.LocaleId == null || e.Locale.IsActive))
                               .ToListAsync();

                var allLocales = await _queryExecutor.ExecuteAsync(new GetAllActiveLocalesQuery(), executionContext);
                var localesLookup = allLocales.ToDictionary(l => l.LocaleId);

                return await MapRoutesAsync(query, dbRoutes, localesLookup);;
            }));
        }
        private CustomEntityRoute[] MapRoutes(GetCustomEntityRoutesByDefinitionCodeQuery query, List <CustomEntity> dbRoutes)
        {
            var definition = _customEntityDefinitionRepository.GetByCode(query.CustomEntityDefinitionCode);

            EntityNotFoundException.ThrowIfNull(definition, query.CustomEntityDefinitionCode);

            var routingDataProperties = definition
                                        .GetDataModelType()
                                        .GetProperties()
                                        .Where(prop => prop.IsDefined(typeof(CustomEntityRouteDataAttribute), false));

            var routes = new List <CustomEntityRoute>(dbRoutes.Count);

            foreach (var dbRoute in dbRoutes)
            {
                var route    = Mapper.Map <CustomEntityRoute>(dbRoute);
                var versions = new List <CustomEntityVersionRoute>();
                route.Versions = versions;
                routes.Add(route);

                foreach (var dbVersion in dbRoute.CustomEntityVersions)
                {
                    var version = Mapper.Map <CustomEntityVersionRoute>(dbVersion);
                    versions.Add(version);

                    if (routingDataProperties.Any())
                    {
                        // Parse additional routing data properties
                        var model = _customEntityDataModelMapper.Map(query.CustomEntityDefinitionCode, dbVersion.SerializedData);
                        foreach (var routingDataProperty in routingDataProperties)
                        {
                            version.AdditionalRoutingData.Add(routingDataProperty.Name, Convert.ToString(routingDataProperty.GetValue(model)));
                        }
                    }
                }
            }

            return(routes.ToArray());
        }
Example #3
0
        private async Task <ICollection <CustomEntityRoute> > MapRoutesAsync(
            GetCustomEntityRoutesByDefinitionCodeQuery query,
            List <CustomEntity> dbEntities,
            Dictionary <int, ActiveLocale> allLocales
            )
        {
            var definition = _customEntityDefinitionRepository.GetByCode(query.CustomEntityDefinitionCode);

            EntityNotFoundException.ThrowIfNull(definition, query.CustomEntityDefinitionCode);

            var routes = dbEntities
                         .Select(r => MapRoute(r, allLocales))
                         .ToList();

            // Map additional parameters

            await(Task) _mapAdditionalRouteDataAsyncMethod
            .MakeGenericMethod(definition.GetType(), definition.GetDataModelType())
            .Invoke(this, new object[] { definition, routes, dbEntities });

            return(routes);
        }
Example #4
0
        /// <summary>
        /// Gets CustomEntityRoute data for all custom entities of a
        /// specific type. These route objects are small and cached which
        /// makes them good for quick lookups.
        /// </summary>
        /// <param name="customEntityDefinitionCode">
        /// The code identifier for the custom entity type
        /// to query for.
        /// </param>
        /// <param name="executionContext">Optional execution context to use when executing the query. Useful if you need to temporarily elevate your permission level.</param>
        public Task <ICollection <CustomEntityRoute> > GetCustomEntityRoutesByDefinitionCodeAsync(string customEntityDefinitionCode, IExecutionContext executionContext = null)
        {
            var query = new GetCustomEntityRoutesByDefinitionCodeQuery(customEntityDefinitionCode);

            return(_queryExecutor.ExecuteAsync(query, executionContext));
        }
        /// <summary>
        /// Gets CustomEntityRoute data for all custom entities of a
        /// specific type. These route objects are small and cached which
        /// makes them good for quick lookups.
        /// </summary>
        /// <param name="customEntityDefinitionCode">
        /// The code identifier for the custom entity type
        /// to query for.
        /// </param>
        /// <param name="executionContext">Optional execution context to use when executing the query. Useful if you need to temporarily elevate your permission level.</param>
        public IEnumerable <CustomEntityRoute> GetCustomEntityRoutesByDefinitionCode(string customEntityDefinitionCode, IExecutionContext executionContext = null)
        {
            var query = new GetCustomEntityRoutesByDefinitionCodeQuery(customEntityDefinitionCode);

            return(_queryExecutor.Execute(query, executionContext));
        }
Example #6
0
        public IContentRepositoryQueryContext <ICollection <CustomEntityRoute> > AsRoutes()
        {
            var query = new GetCustomEntityRoutesByDefinitionCodeQuery(_customEntityDefinitionCode);

            return(ContentRepositoryQueryContextFactory.Create(query, ExtendableContentRepository));
        }
        public Task <ICollection <CustomEntityRoute> > AsRoutesAsync()
        {
            var query = new GetCustomEntityRoutesByDefinitionCodeQuery(_customEntityDefinitionCode);

            return(ExtendableContentRepository.ExecuteQueryAsync(query));
        }