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));
        }
Esempio n. 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);
        }
        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));
        }
Esempio n. 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));
        }
Esempio n. 9
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/");
        }
Esempio n. 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));
        }