public static string GetPushpinImageUrl(OrganizationServiceContext context, Entity entity)
        {
            var serviceRequestType = entity.GetAttributeValue <EntityReference>("adx_servicerequesttype");

            if (serviceRequestType == null)
            {
                return(string.Empty);
            }

            var type = context.CreateQuery("adx_servicerequesttype").FirstOrDefault(s => s.GetAttributeValue <Guid>("adx_servicerequesttypeid") == serviceRequestType.Id);

            if (type == null)
            {
                return(string.Empty);
            }

            var url = type.GetAttributeValue <string>("adx_mapiconimageurl");

            if (string.IsNullOrWhiteSpace(url))
            {
                return(string.Empty);
            }

            if (url.StartsWith("http", true, CultureInfo.InvariantCulture))
            {
                return(url);
            }

            var portalContext = PortalCrmConfigurationManager.CreatePortalContext();

            return(WebsitePathUtility.ToAbsolute(portalContext.Website, url));
        }
예제 #2
0
        public ActionResult Search(double longitude, double latitude, int distance, string units, Guid id)
        {
            var originLatitude  = latitude;
            var originLongitude = longitude;
            var radius          = distance <= 0 ? 5 : distance;

            var uom = string.IsNullOrWhiteSpace(units)
                                                ? GeoHelpers.Units.Miles
                                                : units == "km" ? GeoHelpers.Units.Kilometers : GeoHelpers.Units.Miles;
            var context = PortalCrmConfigurationManager.CreateServiceContext();

            var entityList = context.CreateQuery("adx_entitylist").FirstOrDefault(e => e.GetAttributeValue <Guid>("adx_entitylistid") == id);

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

            var entityName           = entityList.GetAttributeValue <string>("adx_entityname");
            var latitudeFieldName    = entityList.GetAttributeValue <string>("adx_map_latitudefieldname");
            var longitudeFieldName   = entityList.GetAttributeValue <string>("adx_map_longitudefieldname");
            var titleFieldName       = entityList.GetAttributeValue <string>("adx_map_infoboxtitlefieldname");
            var descriptionFieldName = entityList.GetAttributeValue <string>("adx_map_infoboxdescriptionfieldname");
            var pushpinImageUrl      = entityList.GetAttributeValue <string>("adx_map_pushpinurl") ?? string.Empty;
            var pushpinImageWidth    = entityList.GetAttributeValue <int?>("adx_map_pushpinwidth").GetValueOrDefault(DefaultMapPushpinWidth);
            var pushpinImageHeight   = entityList.GetAttributeValue <int?>("adx_map_pushpinheight").GetValueOrDefault(DefaultMapPushpinHeight);

            if (!string.IsNullOrWhiteSpace(pushpinImageUrl) && !pushpinImageUrl.StartsWith("http", true, CultureInfo.InvariantCulture))
            {
                var portalContext = PortalCrmConfigurationManager.CreatePortalContext();
                pushpinImageUrl = WebsitePathUtility.ToAbsolute(portalContext.Website, pushpinImageUrl);
            }

            var entities = context.CreateQuery(entityName)
                           .Where(e => e.GetAttributeValue <double?>(latitudeFieldName) != null && e.GetAttributeValue <double?>(longitudeFieldName) != null)
                           .FilterByBoxDistance(originLatitude, originLongitude, longitudeFieldName, latitudeFieldName, "double", radius, uom);

            var nodes = entities.DistanceQueryWithResult(originLatitude, originLongitude, longitudeFieldName, latitudeFieldName, radius, uom).ToList();

            var mapNodes = new List <MapNode>();

            if (nodes.Any())
            {
                mapNodes = nodes.Select(s =>
                                        new MapNode(s.Item1.Id, string.Empty,
                                                    s.Item1.GetAttributeValue <string>(titleFieldName),
                                                    s.Item1.GetAttributeValue <string>(descriptionFieldName),
                                                    s.Item1.GetAttributeValue <Double?>(latitudeFieldName) ?? 0,
                                                    s.Item1.GetAttributeValue <Double?>(longitudeFieldName) ?? 0,
                                                    string.Format("{0},{1}", s.Item1.GetAttributeValue <Double?>(latitudeFieldName) ?? 0, s.Item1.GetAttributeValue <Double?>(longitudeFieldName) ?? 0),
                                                    Math.Round(s.Item2, 1), pushpinImageUrl, pushpinImageHeight, pushpinImageWidth)).ToList();
            }

            var json = Json(mapNodes);

            return(json);
        }
예제 #3
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);
        }
        public static string GetCheckStatusUrl(Entity serviceRequest)
        {
            var portalContext = PortalCrmConfigurationManager.CreatePortalContext();
            var context       = PortalCrmConfigurationManager.CreateServiceContext();
            var website       = context.CreateQuery("adx_website").FirstOrDefault(w => w.GetAttributeValue <Guid>("adx_websiteid") == portalContext.Website.Id);
            var statusPage    = context.GetPageBySiteMarkerName(website, "check-status");

            if (statusPage == null)
            {
                return(string.Empty);
            }

            var statusUrl = new UrlBuilder(context.GetUrl(statusPage));

            statusUrl.QueryString.Add("refnum", serviceRequest.GetAttributeValue <string>("adx_servicerequestnumber"));

            return(WebsitePathUtility.ToAbsolute(website, statusUrl.PathWithQueryString));
        }
        public static string GetAlertPushpinImageUrl()
        {
            var portalContext   = PortalCrmConfigurationManager.CreatePortalContext();
            var context         = PortalCrmConfigurationManager.CreateServiceContext();
            var website         = context.CreateQuery("adx_website").FirstOrDefault(w => w.GetAttributeValue <Guid>("adx_websiteid") == portalContext.Website.Id);
            var alertMapIconUrl = context.GetSiteSettingValueByName(website, "ServiceRequestMap/AlertMapIconUrl");

            if (string.IsNullOrWhiteSpace(alertMapIconUrl))
            {
                return(string.Empty);
            }

            if (alertMapIconUrl.StartsWith("http", true, CultureInfo.InvariantCulture))
            {
                return(alertMapIconUrl);
            }

            return(WebsitePathUtility.ToAbsolute(website, alertMapIconUrl));
        }
 /// <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);
     }
 }
        public static string GetServiceRequestTypeThumbnailImageUrl(OrganizationServiceContext context, Entity entity)
        {
            if (entity == null)
            {
                return(string.Empty);
            }

            var url = entity.GetAttributeValue <string>("adx_thumbnailimageurl");

            if (string.IsNullOrWhiteSpace(url))
            {
                return(string.Empty);
            }

            if (url.StartsWith("http", true, CultureInfo.InvariantCulture))
            {
                return(url);
            }

            var portalContext = PortalCrmConfigurationManager.CreatePortalContext();

            return(WebsitePathUtility.ToAbsolute(portalContext.Website, url));
        }
예제 #8
0
        protected string BuildOpenNewSupportRequestUrl(Guid id)
        {
            var portalContext = PortalCrmConfigurationManager.CreatePortalContext();

            var page = portalContext.ServiceContext.GetPageBySiteMarkerName(portalContext.Website, OpenNewSupportRequestSiteMarker);

            if (page == null)
            {
                throw new Exception("Please contact your System Administrator. Required Site Marker '{0}' is missing.".FormatWith(OpenNewSupportRequestSiteMarker));
            }

            var pageUrl = portalContext.ServiceContext.GetUrl(page);

            if (pageUrl == null)
            {
                throw new Exception("Please contact your System Administrator. Unable to build URL for Site Marker '{0}'.".FormatWith(OpenNewSupportRequestSiteMarker));
            }

            var url = new UrlBuilder(pageUrl);

            url.QueryString.Set("id", id.ToString());

            return(WebsitePathUtility.ToAbsolute(portalContext.Website, url.PathWithQueryString));
        }
예제 #9
0
        private static UrlMappingResult <Entity> LookupPageByUrlPath(OrganizationServiceContext context, Entity website, string urlPath, Func <Entity, bool> predicate)
        {
            website.AssertEntityName("adx_website");

            if (website.Id == Guid.Empty)
            {
                throw new ArgumentException(string.Format("Unable to retrieve the Id of the website. {0}", ""), "website");
            }

            var urlWithoutWebsitePath = WebsitePathUtility.ToRelative(website, urlPath);

            if (!context.IsAttached(website))
            {
                context.ReAttach(website);
            }

            var pages = website.GetRelatedEntities(context, "adx_website_webpage").Where(predicate).ToArray();

            // Use _pagePathRegex to extract the right-most path segment (child path), and the remaining left
            // part of the path (parent path), while enforcing that web page paths must end in a '/'.
            var pathMatch = _pagePathRegex.Match(urlWithoutWebsitePath);

            if (!pathMatch.Success)
            {
                // If we don't have a valid path match, still see if there is a page with the entire literal
                // path as its partial URL. (The previous iteration of this method has this behaviour, so we
                // maintain it here.)
                return(GetResultFromQuery(pages.Where(p => IsPartialUrlMatch(p, urlWithoutWebsitePath))));
            }

            var fullPath   = pathMatch.Groups["full"].Value;
            var parentPath = pathMatch.Groups["parent"].Value;
            var childPath  = pathMatch.Groups["child"].Value;

            // Check if we can find a page with the exact fullPath match. This may be a web page with a
            // partial URL that matches the entire path, but in the more common case, it will match the
            // root URL path "/".
            var fullPathMatchPageResult = GetResultFromQuery(pages.Where(p => IsPartialUrlMatch(p, fullPath)));

            if (fullPathMatchPageResult.Node != null)
            {
                return(fullPathMatchPageResult);
            }

            // If we don't have non-empty parentPath and childPath, lookup fails.
            if (string.IsNullOrEmpty(parentPath) || string.IsNullOrEmpty(childPath))
            {
                return(UrlMappingResult <Entity> .MatchResult(null));
            }

            // Look up the parent page, using the parent path. This will generally recurse until parentPath
            // is the root path "/", at which point fullPath will match the Home page and the recursion will
            // unwind.
            var parentPageFilterResult = LookupPageByUrlPath(context, website, parentPath, predicate);

            // If we can't find a parent page, lookup fails.
            if (parentPageFilterResult.Node == null)
            {
                return(parentPageFilterResult);
            }

            // Look for a partial URL match for childPath, among the children of the returned parent page.
            var query = context.GetChildPages(parentPageFilterResult.Node).Where(p => predicate(p) && IsPartialUrlMatch(p, childPath));

            return(GetResultFromQuery(query));
        }
예제 #10
0
        public MapConfiguration(IPortalContext portalContext, bool mapEnabled, OptionSetValue mapDistanceUnit,
                                string mapDistanceValues, int?mapInfoboxOffsetY, int?mapInfoboxOffsetX, int?mapPushpinWidth,
                                string mapPushpinUrl, int?mapZoom, double?mapLongitude, double?mapLatitude, string mapRestUrl,
                                string mapCredentials, int?mapPushpinHeight)
        {
            Enabled = mapEnabled;

            if (!string.IsNullOrWhiteSpace(mapCredentials))
            {
                Credentials = mapCredentials;
            }

            RestUrl = mapRestUrl;
            DefaultCenterLatitude  = mapLatitude ?? 0;
            DefaultCenterLongitude = mapLongitude ?? 0;
            DefaultZoom            = mapZoom ?? 12;
            PinImageUrl            = mapPushpinUrl;
            PinImageWidth          = mapPushpinWidth ?? 32;
            PinImageHeight         = mapPushpinHeight ?? 39;
            InfoboxOffsetX         = mapInfoboxOffsetX ?? 25;
            InfoboxOffsetY         = mapInfoboxOffsetY ?? 46;

            if (!string.IsNullOrWhiteSpace(mapDistanceValues))
            {
                var distanceItems = mapDistanceValues.Split(',');
                var distanceList  = new List <int>();

                if (distanceItems.Any())
                {
                    foreach (var distance in distanceItems)
                    {
                        int distanceValue;
                        if (int.TryParse(distance, out distanceValue))
                        {
                            distanceList.Add(distanceValue);
                        }
                    }
                }
                else
                {
                    distanceList = new List <int> {
                        5, 10, 25, 100
                    };
                }

                DistanceValues = distanceList;
            }

            if (mapDistanceUnit != null)
            {
                if (Enum.IsDefined(typeof(DistanceUnits), mapDistanceUnit.Value))
                {
                    DistanceUnit = (DistanceUnits)mapDistanceUnit.Value;
                }
                else
                {
                    ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Distance Unit value '{0}' is not a valid value defined by MapConfiguration.DistanceUnits class.",
                                                                                         mapDistanceUnit.Value));
                }
            }

            SearchUrl = WebsitePathUtility.ToAbsolute(portalContext.Website, "/EntityList/Map/Search/");
        }
예제 #11
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));
        }