public static ApplicationPath GetApplicationPath(
            this IEntityUrlProvider entityUrlProvider,
            OrganizationServiceContext context,
            Entity entity,
            string partialUrlLogicalName,
            Relationship parentEntityRelationship,
            string parentEntityName,
            Func <OrganizationServiceContext, Entity, ApplicationPath> getParentApplicationPath,
            string siteMarker = null)
        {
            var parentEntity = entity.GetRelatedEntity(context, parentEntityRelationship);

            var partialUrlAttributeValue = entity.GetAttributeValue <object>(partialUrlLogicalName);
            var partialUrl = partialUrlAttributeValue == null ? null : partialUrlAttributeValue.ToString();

            if (parentEntity == null)
            {
                if (siteMarker == null)
                {
                    return(ApplicationPath.FromPartialPath(partialUrl));
                }

                var siteMarkerPage = context.GetPageBySiteMarkerName(context.GetWebsite(entity), siteMarker);
                var siteMarkerUrl  = context.GetApplicationPath(siteMarkerPage);

                return(JoinApplicationPath(siteMarkerUrl.PartialPath, partialUrl));
            }

            var parentUrl = getParentApplicationPath(context, parentEntity);

            var url = JoinApplicationPath(parentUrl.PartialPath, partialUrl);

            return(url);
        }
Ejemplo n.º 2
0
        internal static ApplicationPath JoinApplicationPath(string basePath, string extendedPath)
        {
            if (basePath.Contains("?") ||
                basePath.Contains(":") ||
                basePath.Contains("//") ||
                basePath.Contains("&") ||
                basePath.Contains("%3f") ||
                basePath.Contains("%2f%2f") ||
                basePath.Contains("%26"))
            {
                throw new ApplicationException("Invalid base path");
            }

            if (extendedPath.Contains("?") ||
                extendedPath.Contains("&") ||
                extendedPath.Contains("//") ||
                extendedPath.Contains(":") ||
                extendedPath.Contains("%3f") ||
                extendedPath.Contains("%2f%2f") ||
                extendedPath.Contains("%26"))
            {
                throw new ApplicationException("Invalid extendedPath");
            }

            var path = "{0}/{1}".FormatWith(basePath.TrimEnd('/'), extendedPath.TrimStart('/'));

            return(ApplicationPath.FromPartialPath(path));
        }
        private ApplicationPath GetApplicationPath(WebFileNode file)
        {
            var websiteRelativeUrl = InternalGetApplicationPath(file);
            var path    = websiteRelativeUrl.PartialPath;
            var appPath = ApplicationPath.FromPartialPath(path);

            return(appPath);
        }
Ejemplo n.º 4
0
        internal static ApplicationPath GetApplicationPath(string rawUrl)
        {
            var appRelativePath = VirtualPathUtility.ToAppRelative(rawUrl);

            return(VirtualPathUtility.IsAppRelative(appRelativePath)
                                ? ApplicationPath.FromAppRelativePath(appRelativePath)
                                : ApplicationPath.FromPartialPath(appRelativePath));
        }
Ejemplo n.º 5
0
        public virtual ApplicationPath GetApplicationPath(OrganizationServiceContext context, Entity entity)
        {
            context.ThrowOnNull("context");

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

            if (entity.LogicalName == "adx_weblink")
            {
                return(GetWebLinkUrl(context, entity));
            }

            var lookup = new Dictionary <string, Tuple <string, Relationship, string> >
            {
                {
                    "adx_webpage",
                    new Tuple <string, Relationship, string> (
                        "adx_partialurl",
                        "adx_webpage_webpage".ToRelationship(EntityRole.Referencing),
                        "adx_webpage")
                },
                {
                    "adx_webfile",
                    new Tuple <string, Relationship, string> (
                        "adx_partialurl",
                        "adx_webpage_webfile".ToRelationship(),
                        "adx_webpage")
                },
            };

            Tuple <string, Relationship, string> urlData;

            if (lookup.TryGetValue(entity.LogicalName, out urlData))
            {
                var partialUrlLogicalName = urlData.Item1;
                var relationship          = urlData.Item2;
                var otherEntityName       = urlData.Item3;

                var websiteRelativeUrl = this.GetApplicationPath(context, entity, partialUrlLogicalName, relationship, otherEntityName, GetApplicationPath);

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

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

                return(ApplicationPath.FromPartialPath(path));
            }

            return(null);
        }
        /// <summary>
        /// Returns application path url by joining the partial url and partial path of parent url.
        /// </summary>
        /// <param name="parent">Contains Parent page of Webpage node.</param>
        /// <param name="partialUrl">Contains partial url of Webpage node.</param>
        private ApplicationPath InternalJoinApplicationPath(WebPageNode parent, string partialUrl)
        {
            var applicationPathUrl = ApplicationPath.FromPartialPath(string.Empty);
            var parentUrl          = InternalGetApplicationPath(parent);

            if (parentUrl == null)
            {
                ADXTrace.Instance.TraceWarning(TraceCategory.Application, string.Format("Parent is Null. PartialUrl = {0}", partialUrl));
                return(null);
            }

            applicationPathUrl = JoinApplicationPath(parentUrl.PartialPath, partialUrl);
            return(applicationPathUrl);
        }
        /// <summary>
        /// Gets the application path for the webpage.
        /// </summary>
        /// <param name="webPage">
        /// The web page.
        /// </param>
        /// <param name="additionalPartialUrl">
        /// Optional additional Partial Url to be added to the webpage url.
        /// </param>
        /// <returns>
        /// The <see cref="ApplicationPath"/>.
        /// </returns>
        private static ApplicationPath GetApplicationPath(WebPageNode webPage, string additionalPartialUrl = null)
        {
            var partialUrl = webPage.PartialUrl;

            if (!string.IsNullOrEmpty(additionalPartialUrl))
            {
                partialUrl = string.Format("{0}/{1}", partialUrl, additionalPartialUrl);
            }
            if (webPage.Parent != null)
            {
                return(AdxEntityUrlProvider.JoinApplicationPath(GetApplicationPath(webPage.Parent).PartialPath, partialUrl));
            }
            return(ApplicationPath.FromPartialPath(partialUrl));
        }
        private ApplicationPath GetApplicationPath(ContentMap map, Entity entity, string partialUrlAttribute, string parentReferenceAttribute, bool trailingSlash = false, bool prependLangCode = false)
        {
            var partialUrl = entity.GetAttributeValue <string>(partialUrlAttribute);

            if (string.IsNullOrEmpty(partialUrl))
            {
                return(null);
            }

            var parentReference = entity.GetAttributeValue <EntityReference>(parentReferenceAttribute);

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

            EntityNode parentNode;

            if (!map.TryGetValue(parentReference, out parentNode))
            {
                return(null);
            }

            var parentPath = GetApplicationPath(map, parentNode);

            if (parentPath == null || parentPath.PartialPath == null)
            {
                return(null);
            }

            partialUrl = trailingSlash && !partialUrl.EndsWith("/") ? partialUrl + "/" : partialUrl;

            var parentPartialPath = parentPath.PartialPath.EndsWith("/") ? parentPath.PartialPath : parentPath.PartialPath + "/";

            var resultAppPath = ApplicationPath.FromPartialPath(parentPartialPath + partialUrl);

            if (ContextLanguageInfo.DisplayLanguageCodeInUrl &&
                ContextLanguageInfo.IsCrmMultiLanguageEnabledInWebsite(PortalContext.Current.Website) &&
                prependLangCode)
            {
                resultAppPath = ContextLanguageInfo.PrependLanguageCode(resultAppPath);
            }

            return(resultAppPath);
        }
        private ApplicationPath InternalGetApplicationPath(WebPageNode page)
        {
            var parent     = page.Parent;
            var partialUrl = page.PartialUrl;
            var url        = ApplicationPath.FromPartialPath(string.Empty);

            if (parent == null || parent.IsReference)
            {
                // Home page (with partial url "/") are not expected to have a parent page.
                if (partialUrl == "/")
                {
                    return(ApplicationPath.FromPartialPath(partialUrl));
                }

                var traceMessage = parent == null?string.Format("Parent is Null. Page.Id = {0}", page.Id) : string.Format("Parent is Reference. Page.Id = {0}, ParentId = {1}", page.Id, parent.Id);

                ADXTrace.Instance.TraceWarning(TraceCategory.Application, traceMessage);
                return(null);
            }

            Version currentVersion   = page.Website.CurrentBaseSolutionCrmVersion;
            Version centaurusVersion = BaseSolutionVersions.CentaurusVersion;

            if (currentVersion.Major >= centaurusVersion.Major && currentVersion.Minor >= centaurusVersion.Minor)
            {
                url = InternalJoinApplicationPath(parent, partialUrl);
            }

            else
            {
                if (CircularReferenceCheck(page) == true)
                {
                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Circular reference with page {0}", page.Id));
                    return(url);
                }
                else
                {
                    url = InternalJoinApplicationPath(parent, partialUrl);
                }
            }

            return(url);
        }
 /// <summary>
 /// Is the web page url defined.
 /// </summary>
 /// <param name="webPage">
 /// The web page.
 /// </param>
 /// <param name="additionalPartialUrl">
 /// Optional additional Partial Url to be added to the webpage url.
 /// </param>
 /// <returns>
 /// If the webpage has a URL defined or not.
 /// </returns>
 private static bool IsWebPageUrlDefined(WebPageNode webPage, string additionalPartialUrl = null)
 {
     if (webPage == null)
     {
         ADXTrace.Instance.TraceWarning(TraceCategory.Monitoring, "Web Page url is not defined. Web Page is null");
         return(false);
     }
     try
     {
         var applicationPath = GetApplicationPath(webPage, additionalPartialUrl);
         var newPath         = ApplicationPath.FromPartialPath(WebsitePathUtility.ToAbsolute(new Entity("adx_website", webPage.Website.Id), applicationPath.PartialPath));
         return(newPath != null);
     }
     catch (Exception e)
     {
         // if the application path wasn't a real path then it will throw an exception so just return false
         ADXTrace.Instance.TraceWarning(TraceCategory.Monitoring, string.Format("IsWebPageUrlDefined caught exception, returning false - {0}", e));
         return(false);
     }
 }
        private new ApplicationPath JoinApplicationPath(string basePath, string extendedPath)
        {
            if (string.IsNullOrWhiteSpace(basePath) || basePath.Contains("?") || basePath.Contains(":") || basePath.Contains("//") || basePath.Contains("&") ||
                basePath.Contains("%3f") || basePath.Contains("%2f%2f") || basePath.Contains("%26"))
            {
                ADXTrace.Instance.TraceError(TraceCategory.Application, "The basePath is invalid.");

                return(null);
            }

            if (string.IsNullOrWhiteSpace(extendedPath) || extendedPath.Contains("?") || extendedPath.Contains("&") || extendedPath.Contains("//") ||
                extendedPath.Contains(":") || extendedPath.Contains("%3f") || extendedPath.Contains("%2f%2f") || extendedPath.Contains("%26"))
            {
                ADXTrace.Instance.TraceError(TraceCategory.Application, "The extendedPath is invalid.");

                return(null);
            }

            var path = "{0}/{1}".FormatWith(basePath.TrimEnd('/'), extendedPath.TrimStart('/'));

            return(ApplicationPath.FromPartialPath(path));
        }
        private ApplicationPath InternalGetApplicationPath(WebFileNode file)
        {
            var partialUrl = file.PartialUrl;

            if (file.Parent != null)
            {
                var parentUrl = InternalGetApplicationPath(file.Parent);

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

                return(JoinApplicationPath(parentUrl.PartialPath, partialUrl));
            }

            if (file.BlogPost != null)
            {
                var serviceContext = PortalCrmConfigurationManager.CreateServiceContext(PortalName);
                var blogPost       = serviceContext.CreateQuery("adx_blogpost")
                                     .FirstOrDefault(e => e.GetAttributeValue <Guid>("adx_blogpostid") == file.BlogPost.Id);

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

                var parentUrl = GetApplicationPath(serviceContext, blogPost);

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

                return(JoinApplicationPath(parentUrl.PartialPath, partialUrl));
            }

            return(ApplicationPath.FromPartialPath(partialUrl));
        }
        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);
        }
        public SyndicationFeed CreateFeed(IPortalContext portal, HttpContext context, string selfRouteName, int maximumItems)
        {
            if (portal == null)
            {
                throw new ArgumentNullException("portal");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var blog = _dataAdapter.Select();

            if (blog == null)
            {
                throw new InvalidOperationException("Blog not found.");
            }

            var posts = _dataAdapter.SelectPosts(0, maximumItems).ToArray();

            var feedLastUpdatedTime = posts.Any() ? new DateTimeOffset(posts.First().PublishDate) : DateTimeOffset.UtcNow;
            var blogHtmlUri         = new Uri(context.Request.Url, blog.ApplicationPath.AbsolutePath);

            var feed = new SyndicationFeed(posts.Select(p => GetFeedItem(p, context)))
            {
                Id              = "uuid:{0};{1}".FormatWith(blog.Id, feedLastUpdatedTime.Ticks),
                Title           = SyndicationContent.CreatePlaintextContent(blog.Title),
                Description     = SyndicationContent.CreateHtmlContent(blog.Summary.ToString()),
                LastUpdatedTime = feedLastUpdatedTime,
                BaseUri         = new Uri(context.Request.Url, "/")
            };

            var selfPath = RouteTable.Routes.GetVirtualPath(context.Request.RequestContext, selfRouteName, new RouteValueDictionary
            {
                { "__portalScopeId__", portal.Website.Id },
                { "id", blog.Id }
            });

            if (selfPath != null)
            {
                feed.Links.Add(SyndicationLink.CreateSelfLink(new Uri(context.Request.Url, ApplicationPath.FromPartialPath(selfPath.VirtualPath).AbsolutePath), "application/atom+xml"));
            }

            feed.Links.Add(SyndicationLink.CreateAlternateLink(blogHtmlUri, "text/html"));

            return(feed);
        }
Ejemplo n.º 15
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));
        }