예제 #1
0
        public void Initialize()
        {
            foreach (var singleton in SingletonProvider.GetAll())
            {
                var content     = ContentGetter.Get <IContent>(singleton.Id, null);
                var contentType = ContentTypeProvider.Get(singleton.ContentTypeId);

                if (content != null)
                {
                    if (content.ContentTypeId != contentType.Id)
                    {
                        throw new SingletonWithIdIsOfWrongType(singleton.Id, contentType, content.GetType(), content.ContentTypeId);
                    }

                    continue;
                }

                content = (IContent)Activator.CreateInstance(contentType.Type);

                content.Id = singleton.Id;

                ContentInserter.Insert(content);
            }
        }
예제 #2
0
        public string Get(IContent content)
        {
            var routable = content as IRoutable;

            if (routable == null)
            {
                return(null);
            }

            var hierarchical = content as IHierarchical;

            if (hierarchical == null)
            {
                if (routable.UrlSegment == null)
                {
                    return("/");
                }

                return(routable.UrlSegment);
            }

            var languageSpecific = content as ILanguageSpecific;

            var allContent = AncestorsRepository.GetAncestorLinks(content.Id).Reverse().Select(id => ContentGetter.Get <IContent>(id, languageSpecific?.Language));

            if (allContent.Any(c => !(c is IRoutable)))
            {
                return(null);
            }

            var segments = allContent.Cast <IRoutable>().Select(c => c.UrlSegment).ToList();

            if (segments.Any() && segments.First() == null)
            {
                segments = segments.Skip(1).ToList();
            }

            if (segments.Contains(null))
            {
                return(null);
            }

            segments.Add(routable.UrlSegment);

            return("/" + string.Join("/", segments));
        }