Пример #1
0
        private static bool ValidateRedirectTypes(UserContractRedirect redirect, HttpBrowserCapabilitiesBase browser)
        {
            if (redirect.RedirectTypeValues.Count == 0) return true;

            foreach (var redirectTypeValue in redirect.RedirectTypeValues)
            {
                var name = redirectTypeValue.RedirectType.Name;
                var browserProperty = browser.GetType().GetProperty(name);
                if (browserProperty != null)
                {
                    var broserValue = browserProperty.GetValue(browser, null);
                    if (broserValue != null)
                    {
                        var stringValue = broserValue.ToString();
                        var value = redirectTypeValue.Name;
                        if (value != stringValue)
                        {
                            return false;
                        }
                    }
                }

            }
            return true;
        }
        private Dictionary<string, string> FillRedirectType(HttpBrowserCapabilitiesBase browser)
        {
            var result = new Dictionary<string, string>();
            if (browser.IsMobileDevice)
            {
                //can use also browser.MobileDeviceManufacturer
                var screenHeight = browser.ScreenPixelsHeight;
                var screenWidth = browser.ScreenPixelsWidth;

                //create the the scaling code for the html5 plugin accordingly, on $ready
            }
            var properties = db.RedirectTypes.ToList();
            foreach (var property in properties)
            {
                //find the browser property if any
                var browserProperty = browser.GetType().GetProperty(property.Name);
                if (browserProperty != null)
                {
                    var broserValue = browserProperty.GetValue(browser, null);
                    if (broserValue != null)
                    {
                        var stringValue = broserValue.ToString();
                        var value =
                            db.RedirectTypeValues.SingleOrDefault(
                                row => row.RedirectTypeId == property.Id && row.Name == stringValue);
                        if (value == null)
                        {
                            value = new RedirectTypeValue
                                {
                                    Id = Guid.NewGuid(),
                                    Name = stringValue,
                                    RedirectTypeId = property.Id
                                };
                            db.RedirectTypeValues.Add(value);
                            db.SaveChanges();
                        }
                        result.Add(property.Name, stringValue);
                    }
                }
            }
            return result;
        }