示例#1
0
        /// <summary>
        /// Standardises a page path ensuring it
        /// - starts with a slash
        /// - doesn't end with a trailing slash
        /// - (optionally) does not contain the locale.
        /// </summary>
        /// <param name="path">Path to standadise</param>
        /// <param name="currentLocale">Locale of the path to remove if present.</param>
        public string StandardisePathWithoutLocale(string path, ActiveLocale currentLocale)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return(PATH_DELIMITER);
            }
            if (!path.StartsWith(PATH_DELIMITER))
            {
                path = PATH_DELIMITER + path;
            }

            // Remove the current locale if it's included in the path
            if (currentLocale != null && path.StartsWith(PATH_DELIMITER + currentLocale.IETFLanguageTag, StringComparison.OrdinalIgnoreCase))
            {
                path = path.Remove(0, currentLocale.IETFLanguageTag.Length + 1);

                // If we accidently removed the starting slash in the above operation, add it again.
                // Example case: path = "en-ca"
                if (!path.StartsWith(PATH_DELIMITER))
                {
                    path = PATH_DELIMITER + path;
                }
            }

            if (path == PATH_DELIMITER)
            {
                return(path);
            }

            // Remove trailing slash
            return(path.TrimEnd(PATH_DELIMITER[0]));
        }
        private string CreateFullPath(string path1, string path2, ActiveLocale locale)
        {
            string fullPath = null;

            if (string.IsNullOrWhiteSpace(path2))
            {
                fullPath = path1;
            }
            else if (path1.EndsWith("/"))
            {
                fullPath = path1 + path2;
            }
            else
            {
                fullPath = path1 + "/" + path2;
            }

            if (locale == null)
            {
                return(fullPath);
            }

            var localePath = "/" + locale.IETFLanguageTag.ToLowerInvariant();

            if (fullPath == "/")
            {
                return(localePath);
            }

            fullPath = localePath + fullPath;

            return(fullPath);
        }
示例#3
0
        /// <summary>
        /// Maps an EF CustomEntity record from the db into a CustomEntityRoute object. If the
        /// db record is null then null is returned.
        /// </summary>
        /// <param name="dbCustomEntity">CustomEntity record from the database.</param>
        /// <param name="locale">Locale to map to the object.</param>
        public CustomEntityRoute Map(
            CustomEntity dbCustomEntity,
            ActiveLocale locale
            )
        {
            if (dbCustomEntity == null)
            {
                throw new ArgumentNullException(nameof(dbCustomEntity));
            }
            if (dbCustomEntity.CustomEntityVersions == null)
            {
                throw new ArgumentNullException(nameof(dbCustomEntity.CustomEntityVersions));
            }

            var route = new CustomEntityRoute()
            {
                CustomEntityDefinitionCode = dbCustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbCustomEntity.CustomEntityId,
                UrlSlug       = dbCustomEntity.UrlSlug,
                Locale        = locale,
                PublishDate   = DbDateTimeMapper.AsUtc(dbCustomEntity.PublishDate),
                PublishStatus = dbCustomEntity.PublishStatusCode == PublishStatusCode.Published ? PublishStatus.Published : PublishStatus.Unpublished,
                Ordering      = dbCustomEntity.Ordering
            };

            bool hasLatestPublishVersion = false;

            route.Versions = new List <CustomEntityVersionRoute>();

            foreach (var dbVersion in dbCustomEntity
                     .CustomEntityVersions
                     .OrderByLatest())
            {
                var version = new CustomEntityVersionRoute()
                {
                    CreateDate     = DbDateTimeMapper.AsUtc(dbVersion.CreateDate),
                    Title          = dbVersion.Title,
                    VersionId      = dbVersion.CustomEntityVersionId,
                    WorkFlowStatus = (WorkFlowStatus)dbVersion.WorkFlowStatusId
                };

                if (!hasLatestPublishVersion && version.WorkFlowStatus == WorkFlowStatus.Published)
                {
                    version.IsLatestPublishedVersion = true;
                    hasLatestPublishVersion          = true;
                }
                route.Versions.Add(version);
            }

            route.HasDraftVersion     = route.Versions.Any(v => v.WorkFlowStatus == WorkFlowStatus.Draft);
            route.HasPublishedVersion = route.Versions.Any(v => v.WorkFlowStatus == WorkFlowStatus.Published);

            return(route);
        }
        private CustomEntityRenderSummary MapSingle(
            CustomEntityVersion dbResult,
            ICollection <PageRoutingInfo> allRoutings,
            ActiveLocale locale
            )
        {
            var entity = MapCore(dbResult);

            entity.Locale   = locale;
            entity.PageUrls = MapPageRoutings(allRoutings, dbResult);

            return(entity);
        }
示例#5
0
        private CustomEntityRenderSummary MapSingle(
            CustomEntityVersion dbResult,
            IEnumerable <PageRoutingInfo> allRoutings,
            ActiveLocale locale
            )
        {
            var entity = Mapper.Map <CustomEntityRenderSummary>(dbResult);

            entity.Locale          = locale;
            entity.Model           = _customEntityDataModelMapper.Map(dbResult.CustomEntity.CustomEntityDefinitionCode, dbResult.SerializedData);
            entity.DetailsPageUrls = MapPageRoutings(allRoutings, dbResult);

            return(entity);
        }
示例#6
0
        public CustomEntityRoute MapRoute(
            CustomEntity dbCustomEntity,
            Dictionary <int, ActiveLocale> allLocales
            )
        {
            ActiveLocale locale = null;

            if (dbCustomEntity.LocaleId.HasValue)
            {
                locale = allLocales.GetOrDefault(dbCustomEntity.LocaleId.Value);
            }

            return(_customEntityRouteMapper.Map(dbCustomEntity, locale));
        }
        /// <summary>
        /// Maps an EF Locale record from the db into an ActiveLocale
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="dbLocale">Locale record from the database.</param>
        public ActiveLocale Map(Locale dbLocale)
        {
            if (dbLocale == null)
            {
                return(null);
            }

            var locale = new ActiveLocale()
            {
                IETFLanguageTag = dbLocale.IETFLanguageTag,
                LocaleId        = dbLocale.LocaleId,
                Name            = dbLocale.LocaleName
            };

            return(locale);
        }
示例#8
0
        public async Task <CustomEntityRenderSummary> MapSummaryAsync(
            CustomEntityVersion dbResult,
            IExecutionContext executionContext
            )
        {
            var routingQuery = GetPageRoutingQuery(dbResult);
            var routing      = await _queryExecutor.ExecuteAsync(routingQuery, executionContext);

            ActiveLocale locale = null;

            if (dbResult.CustomEntity.LocaleId.HasValue)
            {
                locale = await _queryExecutor.GetByIdAsync <ActiveLocale>(dbResult.CustomEntity.LocaleId.Value, executionContext);
            }

            return(MapSingle(dbResult, routing, locale));
        }
示例#9
0
        /// <summary>
        /// Maps an EF CustomEntity record from the db into a CustomEntityRoute object. If the
        /// db record is null then null is returned.
        /// </summary>
        /// <param name="dbCustomEntity">CustomEntity record from the database.</param>
        /// <param name="locale">Locale to map to the object.</param>
        /// <param name="routingDataProperties">Collection of data properties to map to the routing parameters collection.</param>
        public CustomEntityRoute Map(
            CustomEntity dbCustomEntity,
            ActiveLocale locale
            )
        {
            if (dbCustomEntity == null)
            {
                throw new ArgumentNullException(nameof(dbCustomEntity));
            }

            var route = new CustomEntityRoute()
            {
                CustomEntityDefinitionCode = dbCustomEntity.CustomEntityDefinitionCode,
                CustomEntityId             = dbCustomEntity.CustomEntityId,
                UrlSlug       = dbCustomEntity.UrlSlug,
                Locale        = locale,
                PublishDate   = DbDateTimeMapper.AsUtc(dbCustomEntity.PublishDate),
                PublishStatus = dbCustomEntity.PublishStatusCode == PublishStatusCode.Published ? PublishStatus.Published : PublishStatus.Unpublished,
                Ordering      = dbCustomEntity.Ordering
            };

            var versions = new List <CustomEntityVersionRoute>();

            route.Versions = versions;

            foreach (var dbVersion in dbCustomEntity.CustomEntityVersions)
            {
                var version = new CustomEntityVersionRoute()
                {
                    CreateDate     = DbDateTimeMapper.AsUtc(dbVersion.CreateDate),
                    Title          = dbVersion.Title,
                    VersionId      = dbVersion.CustomEntityVersionId,
                    WorkFlowStatus = (WorkFlowStatus)dbVersion.WorkFlowStatusId
                };
                versions.Add(version);
            }

            return(route);
        }
        /// <summary>
        /// Maps an EF CustomEntityVersion record from the db into a CustomEntityRenderSummary
        /// object. If the db record is null then null is returned.
        /// </summary>
        /// <param name="dbResult">CustomEntityVersion record from the database.</param>
        /// <param name="executionContext">Context to run any sub queries under.</param>
        public async Task <CustomEntityRenderSummary> MapAsync(
            CustomEntityVersion dbResult,
            IExecutionContext executionContext
            )
        {
            if (dbResult == null)
            {
                return(null);
            }

            var routingQuery = GetPageRoutingQuery(dbResult);
            var routing      = await _queryExecutor.ExecuteAsync(routingQuery, executionContext);

            ActiveLocale locale = null;

            if (dbResult.CustomEntity.LocaleId.HasValue)
            {
                var getLocaleQuery = new GetActiveLocaleByIdQuery(dbResult.CustomEntity.LocaleId.Value);
                locale = await _queryExecutor.ExecuteAsync(getLocaleQuery, executionContext);
            }

            return(MapSingle(dbResult, routing, locale));
        }
示例#11
0
        private bool MatchesLocale(ActiveLocale locale, int?localeId)
        {
            var localeIdToCheck = locale == null ? (int?)null : locale.LocaleId;

            return(localeId == localeIdToCheck);
        }