Beispiel #1
0
        internal static ApplicationPath GetApplicationPath(string rawUrl)
        {
            var appRelativePath = VirtualPathUtility.ToAppRelative(rawUrl);

            return(VirtualPathUtility.IsAppRelative(appRelativePath)
                                ? ApplicationPath.FromAppRelativePath(appRelativePath)
                                : ApplicationPath.FromPartialPath(appRelativePath));
        }
Beispiel #2
0
        private ApplicationPath GetForumPostApplicationPath(OrganizationServiceContext context, Entity post, Entity thread)
        {
            var threadPath = GetApplicationPath(context, thread);

            if (threadPath == null || threadPath.AppRelativePath == null || threadPath.AppRelativePath.Contains("#"))
            {
                return(threadPath);
            }

            return(ApplicationPath.FromAppRelativePath("{0}#{1}".FormatWith(threadPath.AppRelativePath, post.Id)));
        }
Beispiel #3
0
        private ApplicationPath GetBlogPostCommentApplicationPath(OrganizationServiceContext context, Entity comment, Entity post)
        {
            var postPath = GetApplicationPath(context, post);

            if (postPath == null || postPath.AppRelativePath == null || postPath.AppRelativePath.Contains("#"))
            {
                return(postPath);
            }

            return(ApplicationPath.FromAppRelativePath("{0}#{1}".FormatWith(postPath.AppRelativePath, BlogPostComment.GetAnchorName(comment.Id))));
        }
        public ApplicationPath GetTagPath(string tag, EntityReference blog = null)
        {
            var archivePath = GetAggregationArchiveApplicationPath();

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

            return(ApplicationPath.FromAppRelativePath(
                       "{0}{1}tags/{2}".FormatWith(
                           archivePath.AppRelativePath,
                           archivePath.AppRelativePath.EndsWith("/") ? string.Empty : "/",
                           HttpUtility.UrlPathEncode(tag))));
        }
        public ApplicationPath GetMonthPath(DateTime month, EntityReference blog = null)
        {
            var archivePath = GetAggregationArchiveApplicationPath();

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

            return(ApplicationPath.FromAppRelativePath(
                       "{0}{1}{2:yyyy}/{2:MM}/".FormatWith(
                           archivePath.AppRelativePath,
                           archivePath.AppRelativePath.EndsWith("/") ? string.Empty : "/",
                           month)));
        }
        public ApplicationPath GetAuthorPath(Guid authorId, EntityReference blog = null)
        {
            var archivePath = GetAggregationArchiveApplicationPath();

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

            return(ApplicationPath.FromAppRelativePath(
                       "{0}{1}author/{2}/".FormatWith(
                           archivePath.AppRelativePath,
                           archivePath.AppRelativePath.EndsWith("/") ? string.Empty : "/",
                           authorId)));
        }
Beispiel #7
0
        public ApplicationPath GetMonthPath(DateTime month, EntityReference blog)
        {
            var blogPath = GetBlogApplicationPath(blog);

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

            return(ApplicationPath.FromAppRelativePath(
                       "{0}{1}{2:yyyy}/{2:MM}/".FormatWith(
                           blogPath.AppRelativePath,
                           blogPath.AppRelativePath.EndsWith("/") ? string.Empty : "/",
                           month)));
        }
Beispiel #8
0
        public ApplicationPath GetAuthorPath(Guid authorId, EntityReference blog)
        {
            var blogPath = GetBlogApplicationPath(blog);

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

            return(ApplicationPath.FromAppRelativePath(
                       "{0}{1}author/{2}/".FormatWith(
                           blogPath.AppRelativePath,
                           blogPath.AppRelativePath.EndsWith("/") ? string.Empty : "/",
                           authorId)));
        }
        private ApplicationPath GetApplicationPath(WebPageNode page)
        {
            var websiteRelativeUrl = InternalGetApplicationPath(page);

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

            var path    = websiteRelativeUrl.PartialPath;
            var appPath = ApplicationPath.FromPartialPath(path);

            if (appPath.ExternalUrl != null)
            {
                return(appPath);
            }

            var canonicalPath = appPath.AppRelativePath.EndsWith("/")
                                ? appPath
                                : ApplicationPath.FromAppRelativePath("{0}/".FormatWith(appPath.AppRelativePath));

            return(canonicalPath);
        }
Beispiel #10
0
        public override ApplicationPath GetApplicationPath(OrganizationServiceContext context, Entity entity)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

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

            if (entity.LogicalName == "adx_communityforumpost")
            {
                var thread = entity.GetRelatedEntity(context, "adx_communityforumthread_communityforumpost".ToRelationship());

                if (thread != null)
                {
                    return(GetForumPostApplicationPath(context, entity, thread));
                }
            }

            if (entity.LogicalName == "adx_blogpostcomment")
            {
                var post = entity.GetRelatedEntity(context, "adx_blogpost_blogpostcomment".ToRelationship());

                if (post != null)
                {
                    return(GetBlogPostCommentApplicationPath(context, entity, post));
                }
            }

            if (entity.LogicalName == "adx_shortcut")
            {
                return(GetShortcutApplicationPath(context, entity));
            }

            if (entity.LogicalName == "adx_ideaforum")
            {
                return(GetIdeaForumApplicationPath(context, entity));
            }

            if (entity.LogicalName == "adx_idea")
            {
                return(GetIdeaApplicationPath(context, entity));
            }

            if (entity.LogicalName == "adx_issue")
            {
                return(GetIssueApplicationPath(context, entity));
            }

            if (entity.LogicalName == "incident")
            {
                return(GetIncidentApplicationPath(context, entity));
            }

            if (entity.LogicalName == "kbarticle")
            {
                return(GetKbArticleApplicationPath(context, entity));
            }

            if (entity.LogicalName == "knowledgearticle")
            {
                return(GetKnowledgeArticleApplicationPath(context, entity));
            }

            if (entity.LogicalName == "category")
            {
                return(GetCategoryApplicationPath(context, entity));
            }

            // We want new behaviour for adx_webpages -- paths for this entity will now have a trailing slash ('/').
            if (entity.LogicalName == "adx_webpage")
            {
                var path = base.GetApplicationPath(context, entity);

                // If the path is an external URL (it shouldn't be, but just in case), return the original path untouched.
                if (path.ExternalUrl != null)
                {
                    return(path);
                }

                // If the path does not already have a trailing slash (it shouldn't), append one.
                return(path.AppRelativePath.EndsWith("/")
                                        ? path
                                        : ApplicationPath.FromAppRelativePath("{0}/".FormatWith(path.AppRelativePath)));
            }

            // Support adx_webfiles with a parent adx_blogpost, instead of adx_webpage.
            if (entity.LogicalName == "adx_webfile" && entity.GetAttributeValue <EntityReference>("adx_blogpostid") != null)
            {
                var post = entity.GetRelatedEntity(context, "adx_blogpost_webfile".ToRelationship());

                if (post != null)
                {
                    var postPath       = GetApplicationPath(context, post);
                    var filePartialUrl = entity.GetAttributeValue <string>("adx_partialurl");

                    if (postPath != null && filePartialUrl != null)
                    {
                        return(ApplicationPath.FromAppRelativePath("{0}/{1}".FormatWith(postPath.AppRelativePath.TrimEnd('/'), filePartialUrl)));
                    }
                }
            }

            var lookup = new Dictionary <string, Tuple <string[], Relationship, string, string, bool> >
            {
                {
                    "adx_communityforumthread",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_communityforumthreadid" },
                        "adx_communityforum_communityforumthread".ToRelationship(),
                        "adx_communityforum",
                        null,
                        false)
                },
                {
                    "adx_communityforum",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_partialurl" },
                        "adx_webpage_communityforum".ToRelationship(),
                        "adx_webpage",
                        "Forums",
                        false)
                },
                {
                    "adx_event",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_partialurl" },
                        "adx_webpage_event".ToRelationship(),
                        "adx_webpage",
                        "Events",
                        false)
                },
                {
                    "adx_survey",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_partialurl" },
                        "adx_webpage_survey".ToRelationship(),
                        "adx_webpage",
                        "Surveys",
                        false)
                },
                {
                    "adx_blog",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_partialurl" },
                        "adx_webpage_blog".ToRelationship(),
                        "adx_webpage",
                        null,
                        true)
                },
                {
                    "adx_blogpost",
                    new Tuple <string[], Relationship, string, string, bool>(
                        new[] { "adx_partialurl", "adx_blogpostid" },
                        "adx_blog_blogpost".ToRelationship(),
                        "adx_blog",
                        null,
                        true)
                },
            };

            Tuple <string[], Relationship, string, string, bool> urlData;

            if (lookup.TryGetValue(entity.LogicalName, out urlData))
            {
                var partialUrlLogicalName = urlData.Item1.FirstOrDefault(logicalName =>
                {
                    var partialUrlValue = entity.GetAttributeValue(logicalName);

                    return(partialUrlValue != null && !string.IsNullOrWhiteSpace(partialUrlValue.ToString()));
                });

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

                var relationship     = urlData.Item2;
                var siteMarker       = urlData.Item4;
                var addTrailingSlash = urlData.Item5;

                var websiteRelativeUrl = GetApplicationPath(context, entity, partialUrlLogicalName, relationship, GetApplicationPath, siteMarker);

                if (websiteRelativeUrl != null)
                {
                    if (addTrailingSlash && websiteRelativeUrl.PartialPath != null && !websiteRelativeUrl.PartialPath.EndsWith("/"))
                    {
                        websiteRelativeUrl = ApplicationPath.FromPartialPath("{0}/".FormatWith(websiteRelativeUrl.PartialPath));
                    }

                    var website = WebsiteProvider.GetWebsite(context, entity);

                    var path = WebsitePathUtility.ToAbsolute(website, websiteRelativeUrl.PartialPath);

                    return(ApplicationPath.FromPartialPath(path));
                }
            }

            return(base.GetApplicationPath(context, entity));
        }