public MvcHtmlString Render()
        {
            ContextEngine context = new ContextEngine();

            StringBuilder sb     = new StringBuilder();
            StringWriter  writer = new StringWriter(sb);

            bool isFamilyFound = false;

            for (IEnumerator <ContextFamily> e = FamilyCollection.Families.GetEnumerator(); e.MoveNext();)
            {
                ContextFamily family = e.Current;
                if (!string.IsNullOrEmpty(context.DeviceFamily) && family.Name == context.DeviceFamily)
                {
                    isFamilyFound = true;
                    family.Predicate(Model).WriteTo(writer);
                }
            }

            if (!isFamilyFound && FamilyCollection.DefaultResult != null)
            {
                FamilyCollection.DefaultResult.WriteTo(writer);
            }

            return(new MvcHtmlString(sb.ToString()));
        }
Пример #2
0
        protected static ScreenWidth CalculateScreenWidth()
        {
            int width = IsContextCookiePresent ? ContextEngine.GetClaims <BrowserClaims>().DisplayWidth : 1024;

            if (width < SiteConfiguration.MediaHelper.SmallScreenBreakpoint)
            {
                return(ScreenWidth.ExtraSmall);
            }
            if (width < SiteConfiguration.MediaHelper.MediumScreenBreakpoint)
            {
                return(ScreenWidth.Small);
            }
            if (width < SiteConfiguration.MediaHelper.LargeScreenBreakpoint)
            {
                return(ScreenWidth.Medium);
            }
            return(ScreenWidth.Large);
        }
        public MvcHtmlString Render()
        {
            ContextEngine context = new ContextEngine();

            StringBuilder sb = new StringBuilder();
            StringWriter writer = new StringWriter(sb);

            bool isFamilyFound = false;
            for (IEnumerator<ContextFamily> e = FamilyCollection.Families.GetEnumerator(); e.MoveNext(); ) {
                ContextFamily family = e.Current;
                if (!string.IsNullOrEmpty(context.DeviceFamily) && family.Name == context.DeviceFamily) {
                    isFamilyFound = true;
                    family.Predicate(Model).WriteTo(writer);
                }
            }

            if (!isFamilyFound && FamilyCollection.DefaultResult != null) {
                FamilyCollection.DefaultResult.WriteTo(writer);
            }

            return new MvcHtmlString(sb.ToString());
        }
        protected static ScreenWidth CalculateScreenWidth()
        {
            int width = IsContextCookiePresent ? ContextEngine.GetClaims <BrowserClaims>().DisplayWidth : MaxWidth;

            // zero width is not valid and probably means the context engine was not correctly initialized so
            // again default to 1024
            if (width == 0)
            {
                width = MaxWidth;
            }
            if (width < SiteConfiguration.MediaHelper.SmallScreenBreakpoint)
            {
                return(ScreenWidth.ExtraSmall);
            }
            if (width < SiteConfiguration.MediaHelper.MediumScreenBreakpoint)
            {
                return(ScreenWidth.Small);
            }
            if (width < SiteConfiguration.MediaHelper.LargeScreenBreakpoint)
            {
                return(ScreenWidth.Medium);
            }
            return(ScreenWidth.Large);
        }