public virtual MenuItemBlock ContextualItemsHelper_GetConstructorFromManyMenuItems(SelectedItemsMenuContext ctx) { if (ctx.Lites.IsNullOrEmpty()) { return(null); } var type = ctx.Lites.Select(a => a.EntityType).Distinct().Only(); if (type == null) { return(null); } List <IMenuItem> menuItems = (from oi in OperationInfos(type) where oi.OperationType == OperationType.ConstructorFromMany let os = GetSettings <ContextualOperationSettingsBase>(type, oi.OperationSymbol) let coc = newContextualOperationContext.GetInvoker(os?.OverridenType ?? oi.BaseType)(ctx, oi, os, null) where os == null || !os.HasIsVisible || os.OnIsVisible(coc) select CreateContextual(coc, _coc => JsModule.Operations["constructFromManyDefault"](_coc.Options(), JsFunction.Event))) .OrderBy(a => a.Order) .Cast <IMenuItem>() .ToList(); if (menuItems.IsEmpty()) { return(null); } return(new MenuItemBlock { Header = SearchMessage.Create.NiceToString(), Items = menuItems }); }
protected override Expression VisitConstant(ConstantExpression c) { if (disableQueryFilter) { return(base.VisitConstant(c)); } if (typeof(IQueryable).IsAssignableFrom(c.Type)) { IQueryable query = (IQueryable)c.Value; if (query.IsBase()) { Type queryType = c.Type.GetGenericArguments().SingleEx(); if (filter) { if (typeof(Entity).IsAssignableFrom(queryType)) { LambdaExpression?rawFilter = giFilter.GetInvoker(queryType)(Schema.Current); if (rawFilter != null) { Expression clean = ExpressionCleaner.Clean(rawFilter) !; var cleanFilter = (LambdaExpression)OverloadingSimplifier.Simplify(clean) !; return(Expression.Call(miWhere.MakeGenericMethod(queryType), query.Expression, cleanFilter)); } } else if (queryType.IsInstantiationOf(typeof(MListElement <,>))) { Type entityType = queryType.GetGenericArguments()[0]; LambdaExpression?rawFilter = giFilter.GetInvoker(entityType)(Schema.Current); if (rawFilter != null) { var param = Expression.Parameter(queryType, "mle"); var lambda = Expression.Lambda(Expression.Invoke(rawFilter, Expression.Property(param, "Parent")), param); Expression clean = ExpressionCleaner.Clean(lambda) !; var cleanFilter = (LambdaExpression)OverloadingSimplifier.Simplify(clean) !; return(Expression.Call(miWhere.MakeGenericMethod(queryType), query.Expression, cleanFilter)); } } } return(c); } else { /// <summary> /// Replaces every expression like ConstantExpression{ Type = IQueryable, Value = complexExpr } by complexExpr /// </summary> return(DbQueryProvider.Clean(query.Expression, filter, null) !); } } return(base.VisitConstant(c)); }
public static Mapping <T> New <T>() { var result = ForValue <T>(); if (result != null) { return(result); } if (typeof(T).IsModifiableEntity() || typeof(T).IsIEntity()) { return((Mapping <T>)giForAutoEntity.GetInvoker(typeof(T))()); } ; if (typeof(T).IsLite()) { return((Mapping <T>)giForLite.GetInvoker(Lite.Extract(typeof(T)))()); } if (Reflector.IsMList(typeof(T))) { return((Mapping <T>)giForMList.GetInvoker(typeof(T).ElementType())()); } return(ctx => { throw new InvalidOperationException("No mapping implemented for {0}".FormatWith(typeof(T).TypeName())); }); }
static IEnumerable <MenuItem> SearchControl_GetContextMenuItems(SearchControl sc) { if (!Navigator.IsViewable(typeof(PackageOperationEntity))) { return(Enumerable.Empty <MenuItem>()); } if (sc.SelectedItems.IsNullOrEmpty() || sc.SelectedItems.Count == 1) { return(null); } if (sc.Implementations.IsByAll) { return(null); } var type = sc.SelectedItems.Select(a => a.EntityType).Distinct().Only(); if (type == null) { return(null); } var result = (from oi in OperationClient.Manager.OperationInfos(type) where oi.IsEntityOperation let os = OperationClient.Manager.GetSettings <EntityOperationSettingsBase>(type, oi.OperationSymbol) let coc = newContextualOperationContext.GetInvoker(os?.OverridenType ?? type)(sc, oi, os?.ContextualFromManyUntyped) where os == null ? oi.Lite == true && oi.OperationType != OperationType.ConstructorFrom : !os.ContextualFromManyUntyped.HasIsVisible ? (oi.Lite == true && !os.HasIsVisible && oi.OperationType != OperationType.ConstructorFrom && (!os.HasClick || os.ContextualFromManyUntyped.HasClick)) : os.ContextualFromManyUntyped.OnIsVisible(coc) select coc).ToList(); if (result.IsEmpty()) { return(null); } var cleanKeys = result .Where(cod => cod.CanExecute == null && cod.OperationInfo.HasStates == true) .Select(cod => cod.OperationInfo.OperationSymbol).ToList(); if (cleanKeys.Any()) { Dictionary <OperationSymbol, string> canExecutes = Server.Return((IOperationServer os) => os.GetContextualCanExecute(sc.SelectedItems, cleanKeys)); foreach (var cod in result) { var ce = canExecutes.TryGetC(cod.OperationInfo.OperationSymbol); if (ce.HasText()) { cod.CanExecute = ce; } } } return(result.Select(coc => PackageOperationMenuItemConsturctor.Construct(coc))); }
protected internal virtual Entity Construct(ConstructorContext ctx) { var dic = (from oi in OperationInfos(ctx.Type) where oi.OperationType == OperationType.Constructor let os = GetSettings <ConstructorOperationSettingsBase>(ctx.Type, oi.OperationSymbol) let coc = newConstructorOperationContext.GetInvoker(ctx.Type)(oi, ctx, os) where os != null && os.HasIsVisible ? os.OnIsVisible(coc) : true select coc).ToDictionary(a => a.OperationInfo.OperationSymbol); if (dic.Count == 0) { return(null); } OperationSymbol selected = null; if (dic.Count == 1) { selected = dic.Keys.SingleEx(); } else { if (!SelectorWindow.ShowDialog(dic.Keys.ToArray(), out selected, elementIcon: k => OperationClient.GetImage(ctx.Type, k), elementText: k => OperationClient.GetText(ctx.Type, k), title: SelectorMessage.ConstructorSelector.NiceToString(), message: SelectorMessage.PleaseSelectAConstructor.NiceToString(), owner: Window.GetWindow(ctx.Element))) { return(null); } } var selCoc = dic[selected]; if (selCoc.Settings != null && selCoc.Settings.HasConstructor) { return(selCoc.Settings.OnConstructor(selCoc)); } else { return(Server.Return((IOperationServer s) => s.Construct(ctx.Type, selected, ctx.Args))); } }
public static List <Lite <Entity> > RetrieveListLite(Type type, List <PrimaryKey> ids) { if (type == null) { throw new ArgumentNullException("type"); } IList list = (IList)giRetrieveListLite.GetInvoker(type).Invoke(ids); return(list.Cast <Lite <Entity> >().ToList()); }
public static DEnumerable <T> GroupBy <T>(this DEnumerable <T> collection, HashSet <QueryToken> keyTokens, HashSet <AggregateToken> aggregateTokens) { var keySelector = KeySelector(collection.Context, keyTokens); BuildExpressionContext newContext; LambdaExpression resultSelector = ResultSelectSelectorAndContext(collection.Context, keyTokens, aggregateTokens, keySelector.Body.Type, out newContext); var resultCollection = giGroupByE.GetInvoker(typeof(object), keySelector.Body.Type, typeof(object))(collection.Collection, keySelector.Compile(), resultSelector.Compile()); return(new DEnumerable <T>(resultCollection, newContext)); }
public static List <Lite <Entity> > RetrieveAllLite(Type type) { if (type == null) { throw new ArgumentNullException("type"); } IList list = giRetrieveAllLite.GetInvoker(type)(); return(list.Cast <Lite <Entity> >().ToList()); }
public T RequestIBA <T>(PrimaryKey?typeId, string id) where T : class, IEntity { if (id == null) { return(null); } Type type = TypeLogic.IdToType[typeId.Value]; var parsedId = PrimaryKey.Parse(id, type); return((T)(IEntity)giRequest.GetInvoker(type)(this, parsedId)); }
protected internal virtual IEnumerable <MenuItem> SearchControl_GetConstructorFromManyMenuItems(SearchControl sc) { if (sc.SelectedItems.IsNullOrEmpty()) { return(null); } var type = sc.SelectedItems.Select(a => a.EntityType).Distinct().Only(); if (type == null) { return(null); } return((from oi in OperationInfos(type) where oi.OperationType == OperationType.ConstructorFromMany let os = GetSettings <ContextualOperationSettingsBase>(type, oi.OperationSymbol) let coc = newContextualOperationContext.GetInvoker(os?.OverridenType ?? oi.BaseType)(sc, oi, os) where os == null || !os.HasIsVisible || os.OnIsVisible(coc) select ConstructFromManyMenuItemConsturctor.Construct(coc)) .OrderBy(Common.GetOrder) .ToList()); }
protected internal JsFunction ClientConstruct(ClientConstructorContext ctx) { var dic = (from oi in OperationInfos(ctx.Type) where oi.OperationType == OperationType.Constructor let os = GetSettings <ConstructorOperationSettingsBase>(ctx.Type, oi.OperationSymbol) let coc = newClientConstructorOperationContext.GetInvoker(ctx.Type)(oi, ctx, os) where os != null && os.HasIsVisible ? os.OnIsVisible(coc) : true select coc).ToDictionary(a => a.OperationInfo.OperationSymbol); if (dic.Count == 0) { return(null); } return(JsModule.Navigator["chooseConstructor"](ClientConstructorManager.ExtraJsonParams, ctx.Prefix, SelectorMessage.PleaseSelectAConstructor.NiceToString(), dic.Select(kvp => new { value = kvp.Key.Key, toStr = kvp.Value.Settings?.Text ?? kvp.Key.NiceToString(), operationConstructor = kvp.Value.Settings == null || !kvp.Value.Settings.HasClientConstructor ? null : new JRaw(PromiseRequire(kvp.Value.Settings.OnClientConstructor(kvp.Value))) }))); }
private IList Split(string concatenated, Func <string, object> deserialize) { string[] splitted = concatenated.Split('|'); IList result = listBuilder.GetInvoker(column.Type)(splitted.Length); for (int i = 1; i < splitted.Length - 1; i++) { string str = splitted[i]; if (string.IsNullOrEmpty(str)) { result.Add(null); } else { result.Add(deserialize(str)); } } return(result); }
public Expression MaterializeField(Field field) { if (field is FieldValue) { var value = GetTupleProperty((IColumn)field); return(value.Type == field.FieldType ? value : Expression.Convert(value, field.FieldType)); } if (field is FieldEnum) { return(Expression.Convert(GetTupleProperty((IColumn)field), field.FieldType)); } if (field is IFieldReference) { var nullRef = Expression.Constant(null, field.FieldType); bool isLite = ((IFieldReference)field).IsLite; if (field is FieldReference) { IColumn column = (IColumn)field; return(GetEntity(isLite, column, field.FieldType.CleanType())); } if (field is FieldImplementedBy ib) { var call = ib.ImplementationColumns.Aggregate((Expression)nullRef, (acum, kvp) => { IColumn column = (IColumn)kvp.Value; Expression entity = GetEntity(isLite, column, kvp.Key); return(Expression.Condition(Expression.NotEqual(WrapPrimaryKey(GetTupleProperty(column)), NullId), Expression.Convert(entity, field.FieldType), acum)); }); return(call); } if (field is FieldImplementedByAll iba) { Expression id = GetTupleProperty(iba.Column); Expression typeId = GetTupleProperty(iba.ColumnType); if (isLite) { var liteCreate = Expression.Call(miGetIBALite.MakeGenericMethod(field.FieldType.CleanType()), Expression.Constant(Schema.Current), NewPrimaryKey(typeId.UnNullify()), id.UnNullify()); var liteRequest = Expression.Call(retriever, miRequestLite.MakeGenericMethod(Lite.Extract(field.FieldType) !), liteCreate); return(Expression.Condition(Expression.NotEqual(WrapPrimaryKey(id), NullId), liteRequest, nullRef)); } else { return(Expression.Call(retriever, miRequestIBA.MakeGenericMethod(field.FieldType), typeId, id)); } } } if (field is FieldEmbedded fe) { Expression ctor = Expression.MemberInit(Expression.New(fe.FieldType), fe.EmbeddedFields.Values.Select(f => Expression.Bind(f.FieldInfo, MaterializeField(f.Field)))); var result = Expression.Call(retriever, miModifiablePostRetrieving.MakeGenericMethod(ctor.Type), ctor); if (fe.HasValue == null) { return(result); } return(Expression.Condition( Expression.Equal(GetTupleProperty(fe.HasValue), Expression.Constant(true)), result, Expression.Constant(null, field.FieldType))); } if (field is FieldMList mListField) { var idColumn = table.Columns.Values.OfType <FieldPrimaryKey>().First(); string lastPartialJoin = CreatePartialInnerJoin(idColumn); Type elementType = field.FieldType.ElementType() !; CachedTableBase ctb = ciCachedTableMList.GetInvoker(elementType)(cachedTable.controller, mListField.TableMList, aliasGenerator, lastPartialJoin, remainingJoins); if (cachedTable.subTables == null) { cachedTable.subTables = new List <CachedTableBase>(); } cachedTable.subTables.Add(ctb); return(Expression.Call(Expression.Constant(ctb), ctb.GetType().GetMethod("GetMList"), NewPrimaryKey(GetTupleProperty(idColumn)), retriever)); } throw new InvalidOperationException("Unexpected {0}".FormatWith(field.GetType().Name)); }
public static bool Exists(Type type, PrimaryKey id) { return(giExist.GetInvoker(type)(id)); }
public static Entity Retrieve(Type type, PrimaryKey id) { return(giRetrieve.GetInvoker(type)(id)); }
protected internal virtual List <FrameworkElement> ButtonBar_GetButtonBarElement(object entity, EntityButtonContext ctx) { Entity ident = entity as Entity; if (ident == null) { return(null); } Type type = ident.GetType(); var operations = (from oi in OperationInfos(type) where oi.IsEntityOperation && (oi.AllowsNew.Value || !ident.IsNew) let os = GetSettings <EntityOperationSettingsBase>(type, oi.OperationSymbol) let eoc = newEntityOperationContext.GetInvoker(os?.OverridenType ?? type)(ident, oi, ctx, os) where (os != null && os.HasIsVisible) ? os.OnIsVisible(eoc) : ctx.ShowOperations select eoc).ToList(); if (operations.Any(eoc => eoc.OperationInfo.HasCanExecute == true)) { Dictionary <OperationSymbol, string> canExecutes = Server.Return((IOperationServer os) => os.GetCanExecuteAll(ident)); foreach (var eoc in operations) { var ce = canExecutes.TryGetC(eoc.OperationInfo.OperationSymbol); if (ce != null && ce.HasText()) { eoc.CanExecute = ce; } } } List <FrameworkElement> buttons = new List <FrameworkElement>(); Dictionary <EntityOperationGroup, ToolBarButton> groups = new Dictionary <EntityOperationGroup, ToolBarButton>(); Dictionary <EntityOperationGroup, List <FrameworkElement> > groupButtons = new Dictionary <EntityOperationGroup, List <FrameworkElement> >(); foreach (var eoc in operations) { if (eoc.OperationInfo.OperationType == OperationType.ConstructorFrom && (eoc.OperationSettings == null || !eoc.OperationSettings.AvoidMoveToSearchControl)) { if (EntityOperationToolBarButton.MoveToSearchControls(eoc)) { continue; } } EntityOperationGroup group = GetDefaultGroup(eoc); if (group != null) { var list = groupButtons.GetOrCreate(group, () => { var tbb = EntityOperationToolBarButton.CreateGroupContainer(group); groups.Add(group, tbb); buttons.Add(tbb); return(new List <FrameworkElement>()); }); list.Add(EntityOperationToolBarButton.NewMenuItem(eoc, group)); } else { buttons.Add(EntityOperationToolBarButton.NewToolbarButton(eoc)); } } foreach (var gr in groups) { var cm = gr.Value.ContextMenu; foreach (var b in groupButtons.GetOrThrow(gr.Key).OrderBy(Common.GetOrder)) { cm.Items.Add(b); } } return(buttons.ToList()); }
private Expression GetEntity(bool isLite, IColumn column, Type type) { Expression id = GetTupleProperty(column); if (isLite) { Expression lite; switch (CacheLogic.GetCacheType(type)) { case CacheType.Cached: { lite = Expression.Call(retriever, miRequestLite.MakeGenericMethod(type), Lite.NewExpression(type, NewPrimaryKey(id.UnNullify()), Expression.Constant(null, typeof(string)))); lite = Expression.Call(retriever, miModifiablePostRetrieving.MakeGenericMethod(typeof(LiteImp)), lite.TryConvert(typeof(LiteImp))).TryConvert(lite.Type); break; } case CacheType.Semi: { string lastPartialJoin = CreatePartialInnerJoin(column); CachedTableBase ctb = ciCachedSemiTable.GetInvoker(type)(cachedTable.controller, aliasGenerator !, lastPartialJoin, remainingJoins); if (cachedTable.subTables == null) { cachedTable.subTables = new List <CachedTableBase>(); } cachedTable.subTables.Add(ctb); ctb.ParentColumn = column; lite = Expression.Call(Expression.Constant(ctb), ctb.GetType().GetMethod("GetLite"), NewPrimaryKey(id.UnNullify()), retriever); break; } default: throw new InvalidOperationException("{0} should be cached at this stage".FormatWith(type)); } if (!id.Type.IsNullable()) { return(lite); } return(Expression.Condition(Expression.Equal(id, NullId), Expression.Constant(null, Lite.Generate(type)), lite)); } else { switch (CacheLogic.GetCacheType(type)) { case CacheType.Cached: return(Expression.Call(retriever, miRequest.MakeGenericMethod(type), WrapPrimaryKey(id.Nullify()))); case CacheType.Semi: { string lastPartialJoin = CreatePartialInnerJoin(column); CachedTableBase ctb = ciCachedTable.GetInvoker(type)(cachedTable.controller, aliasGenerator, lastPartialJoin, remainingJoins); if (cachedTable.subTables == null) { cachedTable.subTables = new List <CachedTableBase>(); } cachedTable.subTables.Add(ctb); ctb.ParentColumn = column; var entity = Expression.Parameter(type); LambdaExpression lambda = Expression.Lambda(typeof(Action <>).MakeGenericType(type), Expression.Call(Expression.Constant(ctb), ctb.GetType().GetMethod("Complete"), entity, retriever), entity); return(Expression.Call(retriever, miComplete.MakeGenericMethod(type), WrapPrimaryKey(id.Nullify()), lambda)); } default: throw new InvalidOperationException("{0} should be cached at this stage".FormatWith(type)); } } }
public virtual ToolBarButton[] ButtonBar_GetButtonBarElement(EntityButtonContext ctx, ModifiableEntity entity) { Entity ident = entity as Entity; if (ident == null) { return(null); } Type type = ident.GetType(); var operations = (from oi in OperationInfos(type) where oi.IsEntityOperation && (oi.AllowsNew.Value || !ident.IsNew) let os = GetSettings <EntityOperationSettingsBase>(type, oi.OperationSymbol) let eoc = newEntityOperationContext.GetInvoker(os?.OverridenType ?? type)(ident, oi, ctx, os) where (os != null && os.HasIsVisible) ? os.OnIsVisible(eoc) : ctx.ShowOperations select eoc).ToList(); if (operations.Any(eoc => eoc.OperationInfo.HasCanExecute == true)) { Dictionary <OperationSymbol, string> canExecutes = OperationLogic.ServiceCanExecute(ident); foreach (var eoc in operations) { var ce = canExecutes.TryGetC(eoc.OperationInfo.OperationSymbol); if (ce != null && ce.HasText()) { eoc.CanExecute = ce; } } } List <ToolBarButton> buttons = new List <ToolBarButton>(); Dictionary <EntityOperationGroup, ToolBarDropDown> groups = new Dictionary <EntityOperationGroup, ToolBarDropDown>(); foreach (var eoc in operations.Where(c => c.OperationSettings == null || !c.OperationSettings.HideOnCanExecute || c.CanExecute == null)) { EntityOperationGroup group = GetDefaultGroup(eoc); if (group != null) { var cm = groups.GetOrCreate(group, () => { var id = group == EntityOperationGroup.Create ? "tmConstructors" : ""; var tbm = new ToolBarDropDown(ctx.Prefix, id) { Title = group.Description(), Text = group.Description(), CssClass = group.CssClass, Items = new List <IMenuItem>(), Order = group.Order, }; buttons.Add(tbm); return(tbm); }); cm.Items.Add(CreateToolBarButton(eoc, group).ToMenuItem()); } else { buttons.Add(CreateToolBarButton(eoc, null)); } } foreach (var item in buttons.OfType <ToolBarDropDown>()) { item.Items = item.Items.OrderBy(a => ((MenuItem)a).Order).ToList(); } return(buttons.OrderBy(a => a.Order).ToArray()); }
protected internal virtual Entity Construct(ConstructorContext ctx) { OperationInfo constructor = GetConstructor(ctx); var settings = GetSettings <ConstructorOperationSettingsBase>(ctx.Type, constructor.OperationSymbol); var result = settings != null && settings.HasConstructor ? settings.OnConstructor(newConstructorOperationContext.GetInvoker(ctx.Type)(constructor, ctx, settings)) : OperationLogic.ServiceConstruct(ctx.Type, constructor.OperationSymbol); ctx.Controller.ViewData[ViewDataKeys.WriteEntityState] = true; return(result); }
public static ConstructorOperationSettingsBase Create(Type type, OperationSymbol symbol) { return(giCreate.GetInvoker(type)(symbol)); }