/// <summary> /// save a redirection. If redirection.Id equals Null.NullInteger(-1), that means need to add a new redirection; /// otherwise will update the redirection by redirection.Id. /// </summary> /// <param name="redirection">redirection object.</param> public void Save(IRedirection redirection) { if (redirection.Id == Null.NullInteger || redirection.SortOrder == 0) { redirection.SortOrder = GetRedirectionsByPortal(redirection.PortalId).Count + 1; } int id = DataProvider.Instance().SaveRedirection(redirection.Id, redirection.PortalId, redirection.Name, (int)redirection.Type, redirection.SortOrder, redirection.SourceTabId, redirection.IncludeChildTabs, (int)redirection.TargetType, redirection.TargetValue, redirection.Enabled, UserController.GetCurrentUserInfo().UserID); foreach (IMatchRule rule in redirection.MatchRules) { DataProvider.Instance().SaveRedirectionRule(rule.Id, id, rule.Capability, rule.Expression); } var logContent = string.Format("'{0}' {1}", redirection.Name, redirection.Id == Null.NullInteger ? "Added" : "Updated"); AddLog(logContent); ClearCache(redirection.PortalId); }
/// <summary> /// returns a target URL for the specific redirection /// </summary> /// <param name="redirection"></param> /// <param name="portalId"></param> /// <param name="currentTabId"></param> /// <returns></returns> public string GetRedirectUrlFromRule(IRedirection redirection, int portalId, int currentTabId) { string redirectUrl = string.Empty; if (redirection.TargetType == TargetType.Url) //independent url base { redirectUrl = redirection.TargetValue.ToString(); } else if (redirection.TargetType == TargetType.Tab) //page within same site { int targetTabId = int.Parse(redirection.TargetValue.ToString()); if (targetTabId != currentTabId) //ensure it's not redirecting to itself { var tabController = new TabController(); var tab = tabController.GetTab(targetTabId, portalId, false); if (tab != null && !tab.IsDeleted) { redirectUrl = Globals.NavigateURL(targetTabId); } } } else if (redirection.TargetType == TargetType.Portal) //home page of another portal { int targetPortalId = int.Parse(redirection.TargetValue.ToString()); if (targetPortalId != portalId) //ensure it's not redirecting to itself { //check whethter the target portal still exists var portalController = new PortalController(); if (portalController.GetPortals().Cast <PortalInfo>().Any(p => p.PortalID == targetPortalId)) { var portalSettings = new PortalSettings(targetPortalId); if (portalSettings.HomeTabId != Null.NullInteger && portalSettings.HomeTabId != currentTabId) //ensure it's not redirecting to itself { redirectUrl = GetPortalHomePageUrl(portalSettings); } } } } return(redirectUrl); }
private bool DoesCapabilityMatchWithRule(IClientCapability clientCapability, IRedirection redirection) { bool match = false; if (redirection.Type == RedirectionType.Tablet && clientCapability.IsTablet) { match = true; } else if (redirection.Type == RedirectionType.MobilePhone && clientCapability.IsMobile) { match = true; } else if (redirection.Type == RedirectionType.AllMobile && (clientCapability.IsMobile || clientCapability.IsTablet)) { match = true; } else if (redirection.Type == RedirectionType.Other) { // match all the capabilities defined in the rule int matchCount = 0; foreach (IMatchRule rule in redirection.MatchRules) { if (!string.IsNullOrEmpty(clientCapability[rule.Capability])) { if (clientCapability[rule.Capability].Equals(rule.Expression, StringComparison.InvariantCultureIgnoreCase)) { matchCount++; } } } if (matchCount > 0 && matchCount == redirection.MatchRules.Count) { match = true; } } return(match); }
private void SaveCallback(IRedirection profile) { }
private bool IsSmartPhoneRedirect(IRedirection redirect) { return(redirect.Type == RedirectionType.Other && redirect.MatchRules.Count == 1 && redirect.MatchRules[0].Capability == "IsSmartPhone"); }
private bool DoesCapabilityMatchWithRule(IClientCapability clientCapability, IRedirection redirection) { bool match = false; if (redirection.Type == RedirectionType.Tablet && clientCapability.IsTablet) { match = true; } else if (redirection.Type == RedirectionType.MobilePhone && clientCapability.IsMobile) { match = true; } else if (redirection.Type == RedirectionType.AllMobile && (clientCapability.IsMobile || clientCapability.IsTablet)) { match = true; } else if (redirection.Type == RedirectionType.Other) { //match all the capabilities defined in the rule int matchCount = 0; foreach (IMatchRule rule in redirection.MatchRules) { if (clientCapability.Capabilities != null && clientCapability.Capabilities.ContainsKey(rule.Capability)) { if (clientCapability.Capabilities[rule.Capability].Equals(rule.Expression, StringComparison.InvariantCultureIgnoreCase)) { matchCount++; } } } if(matchCount > 0 && matchCount == redirection.MatchRules.Count) { match = true; } } return match; }
/// <summary> /// returns a target URL for the specific redirection /// </summary> /// <param name="redirection"></param> /// <param name="portalId"></param> /// <param name="currentTabId"></param> /// <returns></returns> public string GetRedirectUrlFromRule(IRedirection redirection, int portalId, int currentTabId) { string redirectUrl = string.Empty; if (redirection.TargetType == TargetType.Url) //independent url base { redirectUrl = redirection.TargetValue.ToString(); } else if (redirection.TargetType == TargetType.Tab) //page within same site { int targetTabId = int.Parse(redirection.TargetValue.ToString()); if (targetTabId != currentTabId) //ensure it's not redirecting to itself { var tabController = new TabController(); var tab = tabController.GetTab(targetTabId, portalId, false); if (tab != null && !tab.IsDeleted) { redirectUrl = Globals.NavigateURL(targetTabId); } } } else if (redirection.TargetType == TargetType.Portal) //home page of another portal { int targetPortalId = int.Parse(redirection.TargetValue.ToString()); if (targetPortalId != portalId) //ensure it's not redirecting to itself { //check whethter the target portal still exists var portalController = new PortalController(); if (portalController.GetPortals().Cast<PortalInfo>().Any(p => p.PortalID == targetPortalId)) { var portalSettings = new PortalSettings(targetPortalId); if (portalSettings.HomeTabId != Null.NullInteger && portalSettings.HomeTabId != currentTabId) //ensure it's not redirecting to itself { redirectUrl = GetPortalHomePageUrl(portalSettings); } } } } return redirectUrl; }
/// <summary> /// save a redirection. If redirection.Id equals Null.NullInteger(-1), that means need to add a new redirection; /// otherwise will update the redirection by redirection.Id. /// </summary> /// <param name="redirection">redirection object.</param> public void Save(IRedirection redirection) { if(redirection.Id == Null.NullInteger || redirection.SortOrder == 0) { redirection.SortOrder = GetRedirectionsByPortal(redirection.PortalId).Count + 1; } int id = DataProvider.Instance().SaveRedirection(redirection.Id, redirection.PortalId, redirection.Name, (int) redirection.Type, redirection.SortOrder, redirection.SourceTabId, redirection.IncludeChildTabs, (int) redirection.TargetType, redirection.TargetValue, redirection.Enabled, UserController.GetCurrentUserInfo().UserID); foreach (IMatchRule rule in redirection.MatchRules) { DataProvider.Instance().SaveRedirectionRule(rule.Id, id, rule.Capability, rule.Expression); } var logContent = string.Format("'{0}' {1}", redirection.Name, redirection.Id == Null.NullInteger ? "Added" : "Updated"); AddLog(logContent); ClearCache(redirection.PortalId); }
private bool IsSmartPhoneRedirect(IRedirection redirect) { return SupportsSmartPhoneDetection && redirect.Type == RedirectionType.Other && redirect.MatchRules.Count == 1 && redirect.MatchRules[0].Capability == "IsSmartPhone"; }