Пример #1
0
        public static ValuePathSource GetValuePathSource(IValueSetter setter)
        {
            var valueKind = setter.ValueKind & ValueKind.Unspecified;

            switch (valueKind)
            {
            case ValueKind.TemplateExpandoPath:
                return(ValuePathSource.TemplateExpando);

            case ValueKind.SelfExpandoPath:
                return(ValuePathSource.Expando);

            case ValueKind.SkinPath:
                return(ValuePathSource.Skin);

            case ValueKind.TemplateSkinPath:
                return(ValuePathSource.TemplateSkin);

            case ValueKind.ThemeResourcePath:
                return(ValuePathSource.ThemeResource);

            default:
                return(ValuePathSource.ThemeResource);
            }
        }
Пример #2
0
        protected override object DoUpdate(UpdateContext context, UpdateConfig config, IEnumerable <object> datas, object complexData)
        {
            var          sql         = config.Sql;
            var          cols        = GetCols(config);
            var          key         = GetKeyName(config, cols);
            IValueSetter valueSetter = ValueSetterCreater.Create(datas.First());

            //1.自定义SQl一条条插入
            if (!string.IsNullOrEmpty(sql) || !string.IsNullOrEmpty(config.Filter))
            {
                if (string.IsNullOrEmpty(sql))
                {
                    config.Sql = DBHelper.BuildUpdateSql(cols, config, key, SqlKeyWorld.ComplexDataObjectStart);
                }

                config.ReturnId = true;
                var keys = valueSetter.GetFields(datas.First());
                foreach (var data in datas)
                {
                    context.ContentParams.ReplaceOrInsert(SqlKeyWorld.ComplexData, data);
                    UpdateTrigger.TriggeValuesChecked(context, data, config, cols, ActionType.Update, valueSetter, keys);
                    SqlExcuter.ExcuteTrann(context);
                    ExcuteSubUpdate(context, config, data);
                }

                return(datas.Count());
            }

            return(UpdateOnOneTime(context, config, cols, datas, valueSetter, key));
        }
Пример #3
0
        public static void SetValuePathSource(IValueSetter setter, ValuePathSource value)
        {
            UnresolveValueProvider(setter);

            if (value == ValuePathSource.ThemeResource)
            {
                setter.ValueKind = ValueKind.ThemeResourcePath;
            }
            else if (value == ValuePathSource.Expando)
            {
                setter.ValueKind = ValueKind.SelfExpandoPath;
            }
            else if (value == ValuePathSource.TemplateExpando)
            {
                setter.ValueKind = ValueKind.TemplateExpandoPath;
            }
            else if (value == ValuePathSource.Skin)
            {
                setter.ValueKind = ValueKind.SkinPath;
            }
            else if (value == ValuePathSource.TemplateSkin)
            {
                setter.ValueKind = ValueKind.TemplateSkinPath;
            }
            else
            {
                setter.ValueKind = ValueKind.ThemeResourcePath;
            }
        }
        protected override object DoQuery(Context context)
        {
            var          handlerConfig = context.HandlerConfig;
            var          queryConfigs  = context.Configs;
            var          queryParam    = context.Params;
            IValueSetter valueSetter   = handlerConfig.Create();

            object outData = valueSetter.CreateInstance();

            context.Data = outData;

            IDictionary <string, object> contentData = new ExpandoObject();
            IValueSetter contentSetter = ValueSetterCreater.Create(contentData);

            foreach (var queryConfig in queryConfigs)
            {
                IQueryHandler          queryHandler          = QueryHandlerFactory.GetQueryHandler(queryConfig.QueryType);
                IConditionQueryHandler conditionQueryHandler = queryHandler as IConditionQueryHandler;
                var subContext = new Context(context)
                {
                    Data    = contentData,
                    Configs = new QueryConfig[] { queryConfig }
                };

                if (conditionQueryHandler != null)
                {
                    var isContinue = conditionQueryHandler.Continue(subContext);
                    if (isContinue == false)
                    {
                        if (conditionQueryHandler.WhetheStop(subContext))
                        {
                            return(outData);
                        }

                        continue;
                    }
                }

                context.Childs.Add(subContext);
                var data = queryHandler.Query(subContext);
                contentSetter.SetFieldByConfig(contentData, data, queryConfig);
                if (conditionQueryHandler != null)
                {
                    var result = conditionQueryHandler.WhetheResultStop(subContext, data);
                    if (result == true)
                    {
                        return(outData);
                    }
                }

                if (queryConfig.IngoreFill == true)
                {
                    continue;
                }

                valueSetter.SetField(queryConfig.Filed, data);
            }

            return(outData);
        }
Пример #5
0
        public static void SetValue(IValueSetter setter, object value)
        {
            UnresolveValueProvider(setter);

            setter.ValueStore = value;
            setter.ValueKind  = ValueKind.Explicit;
        }
 public DecoratedSetter(IValueSetter setter, GetInstanceDelegate <TInnerSubject> getTargetHandler, SetInstanceDelegate <TInnerSubject> newInstanceSetter, Func <TInnerSubject, TInnerSubject> cloner)
 {
     this.setter            = setter;
     this.cloner            = cloner;
     this.getTargetHandler  = getTargetHandler;
     this.newInstanceSetter = newInstanceSetter;
 }
Пример #7
0
        protected override object DoQuery(Context context)
        {
            var queryConfig   = context.Config;
            var handlerConfig = context.HandlerConfig;

            if (string.IsNullOrEmpty(queryConfig.Connection))
            {
                queryConfig.Connection = handlerConfig.Connection;
            }

            IValueSetter valueSetter = queryConfig.Create();
            var          datas       = SqlExcuter.ExcuteQuery(context, valueSetter);

            context.Data = datas;
            ExcuteSubQueries(context, queryConfig, valueSetter, datas);
            if (!queryConfig.OnlyOne)
            {
                return(datas);
            }

            if (datas.Any())
            {
                return(datas.First());
            }

            return(new object());
        }
Пример #8
0
        public void UpdateSelection(OptionValueChangedEventArgs e)
        {
            if (e == null)
            {
                return;
            }
            if (inUpdate)
            {
                return;
            }
//      if (!optionItem.IsAlive) {
//        return;
//      }

//      IOptionItem oi = (IOptionItem)optionItem.Target;
            object value = e.NewValue;

            if (value == OptionItem.VALUE_UNDEFINED)
            {
                //no change
                return;
            }
            try {
                inUpdate = true;
                //lock selection for the duration of our update
                selection.BeginValueUpdate();

                ICollection <IPropertyItemDescriptor <T> > descriptors;
                descriptors = selection.Selection;

                bool hasChanged = false;
                foreach (IPropertyItemDescriptor <T> descriptor in descriptors)
                {
                    //get the propertyItem from the current lookup
                    IPropertyMap map = descriptor.Properties;
                    if (map == null)
                    {
                        continue;
                    }

                    //get value from current selection item
                    IPropertyItem item   = map.GetEntry(virtualPropertyName);
                    IValueSetter  setter = item != null ? item.Setter : null;
                    if (setter == null || !setter.CanSet())
                    {
                        continue;
                    }
                    setter.SetValue(value);
                    hasChanged = true;
                }

                if (hasChanged)
                {
                    selection.UpdateSelectedItems();
                }
            } finally {
                selection.EndValueUpdate();
                inUpdate = false;
            }
        }
        protected override void ApplyRules(UpdateContext updateContext, UpdateConfig config, IDictionary <string, string> cols)
        {
            var          uParams     = updateContext.Params;
            IValueSetter valueSetter = ValueSetterCreater.Create(uParams);

            UpdateTrigger.TriggeValuesChecked(updateContext, uParams, config, cols, ActionType.Update, valueSetter, uParams.Keys);
        }
        /// <inheritdoc/>
        public IPropertyItem AddEntry(string virtualPropertyName, IValueGetter getter,
                                      IValueSetter setter, IEqualityComparer comparer)
        {
            DefaultPropertyItem item = new DefaultPropertyItem(getter, setter, comparer);

            internalMap[virtualPropertyName] = item;
            return(item);
        }
Пример #11
0
        public static IValueSetter GetPropertySetter(PropertyInfo propertyInfo)
        {
            if (!m_SetterDict.ContainsKey(propertyInfo)){
                IValueSetter setter = CreatePropertySetter(propertyInfo);
                m_SetterDict.Add(propertyInfo, setter);
                return setter;
            }

            return m_SetterDict[propertyInfo];
        }
Пример #12
0
        public static ISetterValueProvider ResolveValueProvider(IValueSetter setter)
        {
            var valueProvider = setter.ValueStore as ISetterValueProvider;

            if (valueProvider != null)
            {
                return(valueProvider);
            }

            var valueKind = setter.ValueKind;

            if (IsResolvedValueProvider(valueKind))
            {
                return(null);
            }

            try
            {
                if (valueKind == ValueKind.ThemeResourcePath)
                {
                    var actualValuePath = GetValuePath(setter);

                    if (string.IsNullOrEmpty(actualValuePath) == false)
                    {
                        valueProvider     = ThemeManager.GetThemeReference(actualValuePath);
                        setter.ValueStore = valueProvider;

                        return(valueProvider);
                    }
                }

                if (valueKind == ValueKind.Explicit)
                {
                    var actualValue = GetValue(setter);
                    var value       = actualValue;

                    if (value is ThemeResourceExtension themeResourceExtension)
                    {
                        valueProvider = themeResourceExtension;
                    }
                }
            }
            finally
            {
                if (valueProvider != null)
                {
                    setter.ValueStore = valueProvider;
                }

                setter.ValueKind |= ValueKind.Resolved;
            }

            return(valueProvider);
        }
Пример #13
0
 internal static IEnumerable <object> ExcuteQuery(IContext context, IValueSetter valueSetter, string querySql = "")
 {
     return(Excute <IEnumerable <object> >(context, (cmd) =>
     {
         using (var dataReader = cmd.ExecuteReader())
         {
             var columns = GetColumns(dataReader);
             return valueSetter.SetterDatas(context.GetConfig(), dataReader, columns);
         }
     }, querySql));
 }
Пример #14
0
        private static object GetOriginalValue(IValueSetter setter)
        {
            var valueStore = setter.ValueStore;

            if (IsResolvedValueProvider(setter.ValueKind) == false)
            {
                return(valueStore);
            }

            return(valueStore is ISetterValueProvider valueProvider ? valueProvider.OriginalValue : valueStore);
        }
Пример #15
0
        public static string GetValuePath(IValueSetter setter)
        {
            var valueKind = setter.ValueKind & ValueKind.Unspecified;

            if (valueKind != ValueKind.Explicit)
            {
                return((string)GetOriginalValue(setter));
            }

            return(null);
        }
 /// <summary>
 /// Decorates the setters to seemlessly perform the cloning on a set operation.
 /// </summary>
 internal IValueSetter decorate(IValueSetter setter)
 {
     if (parent.useClone && this.context.Policy == AssignmentPolicy.CreateNewInstance)
     {
         return(new CloneValueSetter(this, setter));
     }
     else
     {
         return(setter);
     }
 }
Пример #17
0
    private void AddPanel(string name, float initValue, IValueSetter valueSetter, Transform content)
    {
        GameObject gameObject = GameObject.Instantiate(panel, content);
        var        text       = gameObject.GetComponentInChildren <TextMeshProUGUI>();

        text.text = name + " - " + initValue;
        valueSetter.SetInitValue(initValue);
        GameObject value = valueSetter.MakeGameObject();

        valueSetter.AddAction((float val) => text.text = name + " - " + val);
        value.transform.SetParent(gameObject.transform);
    }
Пример #18
0
        public virtual object CreateInstance(IDataReader reader)
        {
            if (this._checkNullOrdinal != null)
            {
                if (reader.IsDBNull(this._checkNullOrdinal.Value))
                {
                    return(null);
                }
            }

            this._readerOrdinalEnumerator.Reset();
            this._objectActivatorEnumerator.Reset();

            object obj = null;

            try
            {
                obj = this._instanceCreator(reader, this._readerOrdinalEnumerator, this._objectActivatorEnumerator);
            }
            catch (Exception ex)
            {
                if (this._readerOrdinalEnumerator.CurrentOrdinal >= 0)
                {
                    throw new DataException(AppendErrorMsg(reader, this._readerOrdinalEnumerator.CurrentOrdinal), ex);
                }

                throw;
            }

            IValueSetter memberSetter = null;

            try
            {
                int count = this._memberSetters.Count;
                for (int i = 0; i < count; i++)
                {
                    memberSetter = this._memberSetters[i];
                    memberSetter.SetValue(obj, reader);
                }
            }
            catch (Exception ex)
            {
                MappingMemberBinder binder = memberSetter as MappingMemberBinder;
                if (binder != null)
                {
                    throw new DataException(AppendErrorMsg(reader, binder.Ordinal), ex);
                }

                throw;
            }

            return(obj);
        }
Пример #19
0
        } // End of ImplBoundValueAlign (...)

        private Boolean _BoundValueSetterAlign()
        {
            IValueSetter setter = ValueBinder.BoundObjectValue as IValueSetter;

            if (setter == null)
            {
                return(false);
            }

            setter.SetValue(Value);

            return(true);
        } // End of ImplBoundValueAlign (...)
Пример #20
0
        public static string BuildColVal(KeyValuePair <string, string> col, IValueSetter valueSetter, object data, IEnumerable <Column> columns)
        {
            var v = col.Value;

            if (v.StartsWith(SqlKeyWorld.ParamStart))
            {
                return(v);
            }

            var val = valueSetter.GetValue(data, v);

            return(DBHelper.GetDBValue(val, columns));
        }
Пример #21
0
        public static void SetValuePath(IValueSetter setter, string value)
        {
            UnresolveValueProvider(setter);

            var valueKind = setter.ValueKind & ValueKind.Unspecified;

            if (valueKind != ValueKind.SelfExpandoPath &&
                valueKind != ValueKind.TemplateExpandoPath &&
                valueKind != ValueKind.ThemeResourcePath &&
                valueKind != ValueKind.SkinPath &&
                valueKind != ValueKind.TemplateSkinPath)
            {
                setter.ValueKind = ValueKind.ValuePath;
            }

            setter.ValueStore = value;
        }
Пример #22
0
        public static void UnresolveValueProvider(IValueSetter setter)
        {
            var valueKind = setter.ValueKind;

            if (IsResolvedValueProvider(valueKind) == false)
            {
                return;
            }

            setter.ValueKind = valueKind & ValueKind.Unspecified;

            var valueStore = setter.ValueStore;

            if (valueStore is ISetterValueProvider valueProvider)
            {
                setter.ValueStore = valueProvider.OriginalValue;
            }
        }
Пример #23
0
        public static bool TryParse(string value, DependencyProperty property, out IValueSetter setter)
        {
            bool isLiteral = true;  // TODO: binding
            bool isBinding = false; // TODO: binding

            if (isLiteral && ValueConverter.TryConvert(value, property.PropertyType, out var result))
            {
                setter = new LiteralSetter(property, result);
                return(true);
            }
            else if (isBinding)
            {
                // TODO: binding
            }

            setter = null;
            return(false);
        }
Пример #24
0
        private void SetSubQueryValue(ReleatedQuery config, IValueSetter valueSetter, IEnumerable <object> parents, IEnumerable <object> datas)
        {
            var compareFields = config.CompareFields ?? new string[] { };
            Dictionary <string, string> mf = compareFields.Select(cf => cf.Split(SqlKeyWorld.Split)).ToDictionary(c => c[0], c => c[1]);
            var matchOneTime = config.MatchOneTime;

            foreach (var parent in parents)
            {
                IEnumerable <object> matchDatas = ValueGetter.GetFilterValues(mf, parent, datas);
                var handler = ReleatedFillHandlerFactory.Create(config);
                var data    = handler.Fill(config, parent, matchDatas, valueSetter);
                if (matchOneTime == false)
                {
                    continue;
                }

                datas = datas.Except(matchDatas).ToArray();
            }
        }
        ///<inheritdoc/>
        public virtual OptionItemValidities CheckValidity(ISelectionProvider <T> selection)
        {
            if (selection.Selection.Count == 0)
            {
                return(OptionItemValidities.Invalid);
            }
            OptionItemValidities retval = OptionItemValidities.ReadWrite;

            foreach (IPropertyItemDescriptor <T> descriptor in selection.Selection)
            {
                IPropertyMap map = descriptor.Properties;
                if (map == null)
                {
                    return(OptionItemValidities.Invalid);
                }
                IPropertyItem item = map.GetEntry(virtualPropertyName);
                if (item != null)
                {
                    IValueGetter getter = item.Getter;
                    IValueSetter setter = item.Setter;

                    if (getter != null && getter.CanGet())
                    {
                        if (setter == null || !setter.CanSet())
                        {
                            //readonly item...
                            retval = OptionItemValidities.ReadOnly;
                        }
                    }
                    else
                    {
                        //we can't even get the values :-(
                        return(OptionItemValidities.Invalid);
                    }
                }
                else
                {
                    return(OptionItemValidities.Invalid);
                }
            }
            return(retval);
        }
        protected override void ApplyRules(UpdateContext updateContext, UpdateConfig config, IDictionary <string, string> cols)
        {
            var          cParams     = updateContext.Params;
            IValueSetter valueSetter = ValueSetterCreater.Create(cParams);
            var          keys        = cParams.Keys;

            UpdateTrigger.TriggeDefaultValues(updateContext, cParams, config, cols, valueSetter, keys);
            UpdateTrigger.TriggeValuesChecked(updateContext, cParams, config, cols, ActionType.Insert, valueSetter, keys);
            config.ReturnId = true;

            var    key = GetKeyName(config, cols);
            object id;

            if (updateContext.Params.TryGetValue(key, out id) == false)
            {
                return;
            }

            updateContext.ContentParams.Add(SqlKeyWorld.ReturnKey, id);
        }
Пример #27
0
        protected override object DoUpdate(UpdateContext context, UpdateConfig config, IEnumerable <object> datas, object complexData)
        {
            var          sql         = config.Sql;
            var          ingoreKey   = config.Config[IngoreKey].ToSingleData <bool>();
            var          cols        = GetCols(config);
            var          key         = GetKeyName(config, cols);
            IValueSetter valueSetter = ValueSetterCreater.Create(datas.First());

            //1.自定义SQl一条条插入
            //2.未包含Key又没有忽略产生Key说明是要数据库自动生成
            if (!string.IsNullOrEmpty(sql) || (!cols.ContainsKey(key) && !ingoreKey))
            {
                if (string.IsNullOrEmpty(sql))
                {
                    config.Sql = DBHelper.BuildInsertSql(cols, config.Table, SqlKeyWorld.ComplexDataObjectStart);
                }

                config.ReturnId = true;
                var keys = valueSetter.GetFields(datas.First());
                foreach (var data in datas)
                {
                    context.ContentParams.ReplaceOrInsert(SqlKeyWorld.ComplexData, data);
                    UpdateTrigger.TriggeDefaultValues(context, data, config, cols, valueSetter, keys);
                    UpdateTrigger.TriggeValuesChecked(context, data, config, cols, ActionType.Insert, valueSetter, keys);
                    var  result = SqlExcuter.ExcuteTrann(context);
                    long id     = 0;
                    if (result is long || result is int)
                    {
                        id = long.Parse(result.ToString());
                        valueSetter.SetField(data, id, key);
                    }

                    ExcuteSubUpdate(context, config, data);
                }

                return(datas.Count());
            }

            return(InsertOnOneTime(context, config, cols, datas, valueSetter));
        }
Пример #28
0
        protected override object DoUpdate(UpdateContext context)
        {
            context.Submit();
            var queryConfig   = context.Config;
            var handlerConfig = context.HandlerConfig;

            if (string.IsNullOrEmpty(queryConfig.Connection))
            {
                queryConfig.Connection = handlerConfig.Connection;
            }

            IValueSetter valueSetter = queryConfig.Create();
            var          querySql    = queryConfig.Config["query_sql"].ToSingleData <string>(string.Empty);
            var          datas       = SqlExcuter.ExcuteQuery(context, valueSetter, querySql);

            foreach (var data in datas)
            {
                context.ContentParams.ReplaceOrInsert(SqlKeyWorld.ComplexData, data);
                SqlExcuter.ExcuteTrann(context);
            }

            return(true);
        }
 public IPropertyItem AddEntry(string virtualPropertyName, IValueGetter getter, IValueSetter setter)
 {
     return(childContext.AddEntry(virtualPropertyName, getter, wrapper.decorate(setter)));
 }
 public CloneValueSetter(WrappingBuildContext <T1, T2> parent, IValueSetter setter)
 {
     this.parent = parent;
     this.setter = setter;
 }