/// <summary>
        ///   Returns ClientCapability based on HttpRequest.
        /// </summary>
        /// <returns></returns>
        public virtual IClientCapability GetClientCapability(HttpRequest httpRequest)
        {
            IClientCapability clientCapability = this.GetClientCapability(httpRequest.UserAgent);

            clientCapability.FacebookRequest = FacebookRequestController.GetFacebookDetailsFromRequest(httpRequest);

            return(clientCapability);
        }
Exemple #2
0
        void FormatGrid()
        {
            if (SearchGrid.Rows.Count == 0)
            {
                DataTable DT = Data2.Connection.D_Supplier.Get_AllShort(UserId);
                if (DT != null)
                {
                    SearchGrid.DataSource = DT;
                    SearchGrid.DataBind();
                }



                for (int a = 0; a < SearchGrid.Rows.Count; a++)
                {
                    HyperLink HLEdit = new HyperLink();
                    HLEdit.Text        = "Editar";
                    HLEdit.NavigateUrl = "/MyManager/Proveedores?edt=" + SearchGrid.Rows[a].Cells[0].Text.ToString();
                    HyperLink HLDelete = new HyperLink();
                    HLDelete.Text        = "Borrar";
                    HLDelete.NavigateUrl = "/MyManager/Proveedores?del=" + SearchGrid.Rows[a].Cells[0].Text.ToString();
                    HtmlGenericControl HTMLSeparator = new HtmlGenericControl("span");

                    SearchGrid.Rows[a].Cells[4].Controls.Add(HLEdit);
                    SearchGrid.Rows[a].Cells[4].Controls.Add(HLDelete);
                    SearchGrid.Rows[a].Cells[4].CssClass = "AtroxDarkLink";
                }

                IClientCapability MyCLient = ClientCapabilityProvider.CurrentClientCapability;
                if (MyCLient.IsMobile)
                {
                    SearchGrid.Columns[3].Visible = false;
                    SearchGrid.Columns[4].Visible = false;
                    for (int a = 0; a < SearchGrid.Rows.Count; a++)
                    {
                        string t_Telephone = SearchGrid.Rows[a].Cells[2].Text;
                        SearchGrid.Rows[a].Cells[2].Text = "";
                        HyperLink HLTelephone = new HyperLink();
                        HLTelephone.Text        = t_Telephone;
                        HLTelephone.NavigateUrl = "tel:" + t_Telephone;
                        SearchGrid.Rows[a].Cells[2].Controls.Add(HLTelephone);
                    }
                }
            }
        }
        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 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>
        /// Get Redirection Url based on Http Context and Portal Id.
        /// </summary>
        /// <returns>string - Empty if redirection rules are not defined or no match found</returns>
        /// <param name="userAgent">User Agent - used for client capability detection.</param>
        /// <param name="portalId">Portal Id from which Redirection Rules should be applied.</param>
        /// <param name="currentTabId">Current Tab Id that needs to be evaluated.</param>
        public string GetRedirectUrl(string userAgent, int portalId, int currentTabId)
        {
            Requires.NotNullOrEmpty("userAgent", userAgent);

            string redirectUrl = string.Empty;

            IList <IRedirection> redirections = GetRedirectionsByPortal(portalId);

            //check for redirect only when redirect rules are defined
            if (redirections == null || redirections.Count == 0)
            {
                return(redirectUrl);
            }

            //try to get content from cache
            var cacheKey = string.Format(RedirectionUrlCacheKey, userAgent, portalId, currentTabId);

            redirectUrl = GetUrlFromCache(cacheKey);
            if (!string.IsNullOrEmpty(redirectUrl))
            {
                return(redirectUrl);
            }

            IClientCapability clientCapability = null;

            foreach (var redirection in redirections)
            {
                if (redirection.Enabled)
                {
                    bool checkFurther = false;
                    //redirection is based on source tab
                    if (redirection.SourceTabId != Null.NullInteger)
                    {
                        //source tab matches current tab
                        if (currentTabId == redirection.SourceTabId)
                        {
                            checkFurther = true;
                        }
                        //is child tabs to be included as well
                        else if (redirection.IncludeChildTabs)
                        {
                            //Get all the descendents of the source tab and find out if current tab is in source tab's hierarchy or not.
                            foreach (var childTab in TabController.Instance.GetTabsByPortal(portalId).DescendentsOf(redirection.SourceTabId))
                            {
                                if (childTab.TabID == currentTabId)
                                {
                                    checkFurther = true;
                                    break;
                                }
                            }
                        }
                    }
                    //redirection is based on portal
                    else if (redirection.SourceTabId == Null.NullInteger)
                    {
                        checkFurther = true;
                    }

                    if (checkFurther)
                    {
                        if (clientCapability == null)
                        {
                            clientCapability = ClientCapabilityProvider.Instance().GetClientCapability(userAgent);
                        }
                        //check if client capability matches with this rule
                        if (DoesCapabilityMatchWithRule(clientCapability, redirection))
                        {
                            //find the redirect url
                            redirectUrl = GetRedirectUrlFromRule(redirection, portalId, currentTabId);

                            //update cache content
                            SetUrlInCache(cacheKey, redirectUrl);
                            break;
                        }
                    }
                }
            }

            return(redirectUrl);
        }