/// <summary>
 /// 写入导航属性到实体(列表)
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="DbCon"></param>
 /// <returns></returns>
 private static List <T> SetNavigationList <T>(this List <T> data, IDbConnection dbCon, IProviderOption providerOption)
 {
     if (providerOption.NavigationList.Any())
     {
         var setListMethod = typeof(MapperExtension).GetMethod("SetListValue");
         foreach (var navigation in providerOption.NavigationList)
         {
             StringBuilder sqlBuilder           = new StringBuilder();
             var           navigationExpression = new NavigationExpression(navigation.MemberAssign.Expression);
             //参数数
             int paramCount = 0;
             //根据得知的映射列表获取条件值
             foreach (var mapp in providerOption.MappingList)
             {
                 //根据映射的键设置实际的值
                 if (navigationExpression.SqlCmd.IndexOf($"= {mapp.Key}") != -1)
                 {
                     foreach (var item in data)
                     {
                         string param = $"{providerOption.ParameterPrefix}{mapp.Value}_{paramCount++}";
                         sqlBuilder.Append(navigationExpression.SqlCmd.Replace($"= {mapp.Key}", $"= {param}") + $";{Environment.NewLine}");
                         //获取实体类的值
                         object paramValue = EntityCache.QueryEntity(typeof(T)).Properties.FirstOrDefault(x => x.Name == mapp.Value).GetValue(item);
                         navigationExpression.Param.Add(param, paramValue);
                     }
                 }
             }
             setListMethod
             .MakeGenericMethod(new Type[] { typeof(T), navigationExpression.ReturnType })
             .Invoke(null, new object[] { data, dbCon, sqlBuilder.ToString(), navigationExpression.Param,
                                          navigation.MemberAssignName });
         }
     }
     return(data);
 }
 /// <summary>
 /// 写入导航属性到实体(单条)
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="dbCon"></param>
 /// <returns></returns>
 private static T SetNavigation <T>(this T data, IDbConnection dbCon, IProviderOption providerOption)
 {
     if (providerOption.NavigationList.Any())
     {
         //写入值方法
         var setValueMethod = typeof(MapperExtension).GetMethod("SetValue");
         foreach (var navigation in providerOption.NavigationList)
         {
             var navigationExpression = new NavigationExpression(navigation.MemberAssign.Expression);
             //根据得知的映射列表获取条件值
             foreach (var mapp in providerOption.MappingList)
             {
                 //根据映射的键设置实际的值
                 if (navigationExpression.SqlCmd.IndexOf($"= {mapp.Key}") != -1)
                 {
                     string param = $"{providerOption.ParameterPrefix}{mapp.Value}";
                     navigationExpression.SqlCmd = navigationExpression.SqlCmd.Replace($"= {mapp.Key}", $"= {param}");
                     //获取实体类的值
                     object paramValue = EntityCache.QueryEntity(typeof(T)).Properties.FirstOrDefault(x => x.Name == mapp.Value).GetValue(data);
                     navigationExpression.Param.Add(param, paramValue);
                 }
             }
             setValueMethod
             .MakeGenericMethod(new Type[] { typeof(T), navigationExpression.ReturnType })
             .Invoke(null, new object[] { data, dbCon, navigationExpression.SqlCmd, navigationExpression.Param, navigation.MemberAssignName });
         }
     }
     return(data);
 }
        /// <summary>
        /// Adds a trigger to the prioritizer.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="selector">The selector which caused this style to be considered.</param>
        /// <param name="navigationExpression">The navigation expression associated with the style.</param>
        /// <param name="trigger">The trigger to add to the prioritizer.</param>
        public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression? navigationExpression, Trigger trigger)
        {
            Contract.Require(uv, "uv");

            var key = new StyleKey(trigger.CanonicalName, navigationExpression);
            var priority = CalculatePriorityFromSelector(selector, false);

            PrioritizedTrigger existing;
            if (!triggers.TryGetValue(key, out existing) || selector.IsHigherPriorityThan(existing.Selector))
            {
                triggers[key] = new PrioritizedTrigger(trigger, selector, priority);
            }
        }
        /// <summary>
        /// Adds a style to the prioritizer.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="selector">The selector which caused this style to be considered.</param>
        /// <param name="navigationExpression">The navigation expression associated with the style.</param>
        /// <param name="style">The style to add to the prioritizer.</param>
        public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression? navigationExpression, UvssStyle style)
        {
            Contract.Require(uv, "uv");

            var key = new StyleKey(style.CanonicalName, navigationExpression);
            var priority = CalculatePriorityFromSelector(selector, style.IsImportant);

            PrioritizedStyle existing;
            if (!styles.TryGetValue(key, out existing))
            {
                styles[key] = new PrioritizedStyle(style, selector, priority);
            }
            else
            {
                if (selector.IsHigherPriorityThan(existing.Selector) && (style.IsImportant || !existing.Style.IsImportant))
                {
                    styles[key] = new PrioritizedStyle(style, selector, priority);
                }
            }
        }
Example #5
0
        /// <inheritdoc/>
        protected internal sealed override void ApplyStyles(UvssDocument document)
        {
            var rule = document.RuleSets.Where(x => x.IsViewResourceRule()).LastOrDefault();

            if (rule != null)
            {
                foreach (var style in rule.Rules)
                {
                    var dp = DependencyProperty.FindByStylingName(style.Name, GetType());
                    if (dp != null)
                    {
                        var selector = rule.Selectors[0];
                        var navexp   = NavigationExpression.FromUvssNavigationExpression(
                            view.Ultraviolet, selector.NavigationExpression);
                        base.ApplyStyle(style, selector, navexp, dp);
                    }
                }
            }
            base.ApplyStyles(document);
        }
        /// <summary>
        /// Adds a trigger to the prioritizer.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="selector">The selector which caused this style to be considered.</param>
        /// <param name="navigationExpression">The navigation expression associated with the style.</param>
        /// <param name="trigger">The trigger to add to the prioritizer.</param>
        /// <param name="index">The index of the trigger's rule set within the style sheet.</param>
        public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression? navigationExpression, UvssTrigger trigger, Int32 index)
        {
            Contract.Require(uv, nameof(uv));

            var key = new StyleKey(trigger.CanonicalName, navigationExpression);
            var priority = CalculatePriorityFromSelector(selector, false);

            PrioritizedTrigger existing;
            if (!triggers.TryGetValue(key, out existing))
            {
                triggers[key] = new PrioritizedTrigger(trigger, selector, priority, index);
            }
            else
            {
                var comparison = selector.ComparePriority(existing.Selector);
                if (comparison == 0 && index > existing.Index)
                    comparison = 1;

                if (comparison > 0 && (trigger.IsImportant || !existing.Trigger.IsImportant))
                {
                    triggers[key] = new PrioritizedTrigger(trigger, selector, priority, index);
                }
            }
        }
 /// <inheritdoc/>
 protected internal sealed override void ApplyStyle(UvssStyle style, UvssSelector selector, NavigationExpression? navigationExpression, DependencyProperty dp)
 {
     base.ApplyStyle(style, selector, navigationExpression, dp);
 }