public override void Write(Utf8JsonWriter writer, Lite <T> value, JsonSerializerOptions options) { var lite = value; writer.WriteStartObject(); writer.WriteString("EntityType", TypeLogic.GetCleanName(lite.EntityType)); writer.WritePropertyName("id"); JsonSerializer.Serialize(writer, lite.IdOrNull?.Object, lite.IdOrNull?.Object.GetType() ?? typeof(object), options); writer.WriteString("toStr", lite.ToString()); if (lite.EntityOrNull != null) { writer.WritePropertyName("entity"); var pr = PropertyRoute.Root(lite.Entity.GetType()); var entity = (ModifiableEntity)(IEntity)lite.EntityOrNull; using (EntityJsonContext.SetCurrentPropertyRouteAndEntity((pr, entity, null))) JsonSerializer.Serialize(writer, lite.Entity, options); } writer.WriteEndObject(); }
public static LineLocator <S> LineLocator <T, S>(this ILineContainer <T> lineContainer, Expression <Func <T, S> > property) where T : IModifiableEntity { PropertyRoute route = lineContainer.Route ?? PropertyRoute.Root(typeof(T)); var element = lineContainer.Element; foreach (var mi in Reflector.GetMemberList(property)) { if (mi is MethodInfo && ((MethodInfo)mi).IsInstantiationOf(MixinDeclarations.miMixin)) { route = route.Add(((MethodInfo)mi).GetGenericArguments()[0]); } else { var newRoute = route.Add(mi); if (newRoute.Parent != route && route != lineContainer.Route) { element = element.FindElement(By.CssSelector("[data-property-path='" + route.PropertyString() + "']")); } route = newRoute; } } return(new LineLocator <S>( elementLocator: element.WithLocator(By.CssSelector("[data-property-path='" + route.PropertyString() + "']")), route: route )); }
public override PropertyRoute GetPropertyRoute() { if (Column.PropertyRoutes != null) { return(Column.PropertyRoutes[0]); //HACK: compatibility with IU entitiy elements } Type type = Lite.Extract(Type); // Useful? if (type != null && type.IsIEntity()) { var implementations = Column.Implementations; if (implementations != null && !implementations.Value.IsByAll) { var imp = implementations.Value.Types.Only(); if (imp == null) { return(null); } return(PropertyRoute.Root(imp)); } } return(null); }
public MultiOperationResponse DeleteMultiple([Required, FromBody] MultiOperationRequest request) { if (request.Setters.HasItems()) { var errors = ForeachMultiple(request.Lites, lite => { var entity = lite.RetrieveAndForget(); MultiSetter.SetSetters(entity, request.Setters, PropertyRoute.Root(entity.GetType())); var op = request.GetOperationSymbol(entity.GetType()); OperationLogic.ServiceDelete(entity, op, request.ParseArgs(op)); }); return(new MultiOperationResponse(errors)); } else { var errors = ForeachMultiple(request.Lites, lite => { var op = request.GetOperationSymbol(lite.EntityType); OperationLogic.ServiceDelete(lite, op, request.ParseArgs(op)); }); return(new MultiOperationResponse(errors)); } }
private static PropertyRoute GetCurrentPropertyRoute(object value) { var pr = JsonSerializerExtensions.CurrentPropertyRoute; if (value is IRootEntity) { pr = PropertyRoute.Root(value.GetType()); } if (pr == null) { var embedded = (EmbeddedEntity)value; var hpr = DefaultPropertyRoutes.TryGetC(embedded.GetType()); if (hpr == null) { throw new InvalidOperationException($"Impossible to determine PropertyRoute for {value.GetType().Name}. Consider adding a new value to {nameof(EntityJsonConverter)}.{nameof(EntityJsonConverter.DefaultPropertyRoutes)}."); } pr = hpr; } else if (pr.Type.ElementType() == value.GetType()) { pr = pr.Add("Item"); //We habe a custom MListConverter but not for other simple collections } return(pr); }
public ExtensionDictionaryInfo <T, KVP, K, V> RegisterDictionary <T, KVP, K, V>( Expression <Func <T, IEnumerable <KVP> > > collectionSelector, Expression <Func <KVP, K> > keySelector, Expression <Func <KVP, V> > valueSelector, Expression <Func <T, EmbeddedEntity> > forEmbedded = null, ResetLazy <HashSet <K> > allKeys = null) where T : Entity { var mei = new ExtensionDictionaryInfo <T, KVP, K, V> { CollectionSelector = collectionSelector, KeySelector = keySelector, ValueSelector = valueSelector, AllKeys = allKeys ?? GetAllKeysLazy <T, KVP, K>(collectionSelector, keySelector) }; var route = forEmbedded == null? PropertyRoute.Root(typeof(T)) : PropertyRoute.Construct(forEmbedded); RegisteredExtensionsDictionaries.Add(route, mei); return(mei); }
public FramePageProxy(RemoteWebDriver selenium) { this.Selenium = selenium; this.Element = selenium.WaitElementPresent(By.CssSelector(".normal-control")); this.Route = PropertyRoute.Root(typeof(T)); this.WaitLoaded(); }
public override T GetValue(MappingContext <T> ctx) { using (HeavyProfiler.LogNoStackTrace("GetValue", () => "AutoEntityMapping<{0}>".FormatWith(typeof(T).TypeName()))) { if (ctx.Empty()) { return(ctx.None()); } Type entityType; entityType = GetRuntimeType(ctx); if (entityType == null) { return((T)(object)null); } if (typeof(T) == entityType || typeof(T).IsEmbeddedEntity()) { return(GetRuntimeValue <T>(ctx, ctx.PropertyRoute)); } return(miGetRuntimeValue.GetInvoker(entityType)(this, ctx, PropertyRoute.Root(entityType))); } }
public static QueryToken IdProperty(QueryToken parent) { return(new EntityPropertyToken(parent, piId, PropertyRoute.Root(parent.Type.CleanType()).Add(piId)) { Priority = 10 }); }
public static PropertyRoute GetRoute <T, S>(this ILineContainer <T> container, Expression <Func <T, S> > property) where T : ModifiableEntity { PropertyRoute result = container.PreviousRoute ?? PropertyRoute.Root(typeof(T)); foreach (var mi in Reflector.GetMemberList(property)) { result = result.Add(mi); } return(result); }
void Complete(Table table) { Type type = table.Type; table.IdentityBehaviour = GetPrimaryKeyAttribute(type).IdentityBehaviour; table.Name = GenerateTableName(type, Settings.TypeAttribute <TableNameAttribute>(type)); table.CleanTypeName = GenerateCleanTypeName(type); table.Fields = GenerateFields(PropertyRoute.Root(type), table, NameSequence.Void, forceNull: false, inMList: false); table.Mixins = GenerateMixins(PropertyRoute.Root(type), table, NameSequence.Void); table.GenerateColumns(); }
public PropertyRoute AddDynamic(MemberInfo mi) { if (Value is Entity) { return(PropertyRoute.Root(value.GetType()).Add(mi)); } else { return(Route.Add(mi)); } }
public override PropertyRoute?GetPropertyRoute() { Type?type = Lite.Extract(parent.GetPropertyRoute()?.Type ?? parent.Type); if (type != null) { return(PropertyRoute.Root(type).Add(miToStringProperty)); } return(null); }
protected override Expression VisitUnary(UnaryExpression u) { if (u.NodeType == ExpressionType.TypeAs || u.NodeType == ExpressionType.Convert) { var tce = Cast(Visit(u.Operand)); return(new TypeContextExpression(tce.Properties, u.Type, PropertyRoute.Root(tce.Value == NonValue ? u.Type : tce.Value.GetType()), tce.Value == NonValue ? NonValue : tce.Value)); } return(base.VisitUnary(u)); }
public Table NewView(Type type) { Table table = new Table(type) { Name = GenerateTableName(type, Settings.TypeAttribute <TableNameAttribute>(type)), IsView = true }; table.Fields = GenerateFields(PropertyRoute.Root(type), table, NameSequence.Void, forceNull: false, inMList: false); table.GenerateColumns(); return(table); }
public ExtensionDictionaryInfo <T, KVP, K, V> RegisterDictionary <T, KVP, K, V>( Expression <Func <T, IEnumerable <KVP> > > collectionSelector, Expression <Func <KVP, K> > keySelector, Expression <Func <KVP, V> > valueSelector, ResetLazy <HashSet <K> >?allKeys = null) where T : Entity where K : notnull { var mei = new ExtensionDictionaryInfo <T, KVP, K, V>(collectionSelector, keySelector, valueSelector, allKeys ?? GetAllKeysLazy <T, KVP, K>(collectionSelector, keySelector)); RegisteredExtensionsDictionaries.Add(PropertyRoute.Root(typeof(T)), mei); return(mei); }
public FrameModalProxy <T> CreateModal <T>() where T : ModifiableEntity { string changes = GetChanges(); var popup = this.CreateButton.WaitVisible().CaptureOnClick(); popup = ChooseTypeCapture(popup, typeof(T)); var itemRoute = this.ItemRoute.Type == typeof(T) ? this.ItemRoute : PropertyRoute.Root(typeof(T)); return(new FrameModalProxy <T>(popup, itemRoute) { Disposing = okPressed => { WaitNewChanges(changes, "create dialog closed"); } }); }
public List <Index> GeneratAllIndexes() { IEnumerable <EntityField> fields = Fields.Values.AsEnumerable(); if (Mixins != null) { fields = fields.Concat(Mixins.Values.SelectMany(m => m.Fields.Values)); } var result = fields.SelectMany(f => f.Field.GenerateIndexes(this)).ToList(); if (MultiColumnIndexes != null) { result.AddRange(MultiColumnIndexes); } if (result.OfType <UniqueIndex>().Any()) { var s = Schema.Current.Settings; List <IColumn> attachedFields = fields.Where(f => s.FieldAttributes(PropertyRoute.Root(this.Type).Add(f.FieldInfo)).OfType <AttachToUniqueIndexesAttribute>().Any()) .SelectMany(f => Index.GetColumnsFromFields(f.Field)) .ToList(); if (attachedFields.Any()) { result = result.Select(ix => { var ui = ix as UniqueIndex; if (ui == null || ui.AvoidAttachToUniqueIndexes) { return(ix); } return(new UniqueIndex(ui.Table, ui.Columns.Concat(attachedFields).ToArray()) { Where = ui.Where }); }).ToList(); } } if (this.SystemVersioned != null) { result.Add(new Index(this, this.SystemVersioned.Columns().PreAnd(this.PrimaryKey).ToArray())); } return(result); }
public void SetFullMListGetter() { var root = PropertyRoute.Root(this.Type); foreach (var field in this.Fields.Values) { field.Field.SetFullMListGetter(root.Add(field.FieldInfo), field.Getter); } if (this.Mixins != null) { foreach (var kvp in this.Mixins) { kvp.Value.SetFullMListGetter(root.Add(kvp.Key), kvp.Value.Getter); } } }
public DynamicValidationTestResponse Test([Required, FromBody] DynamicValidationTestRequest request) { IDynamicValidationEvaluator evaluator; try { evaluator = request.dynamicValidation.Eval.Algorithm; } catch (Exception e) { return(new DynamicValidationTestResponse { compileError = e.Message }); } var pr = request.dynamicValidation.SubEntity?.ToPropertyRoute() ?? PropertyRoute.Root(TypeLogic.EntityToType.GetOrThrow(request.dynamicValidation.EntityType)); var candidates = GraphExplorer.FromRootEntity(request.exampleEntity) .Where(a => a is ModifiableEntity me && pr.MatchesEntity(me) == true) .Cast <ModifiableEntity>(); var properties = Entities.Validator.GetPropertyValidators(pr.Type).Values.Select(a => a.PropertyInfo).ToList(); try { return(new DynamicValidationTestResponse { validationResult = candidates .SelectMany(me => properties.Select(pi => new DynamicValidationResult { propertyName = pi.NiceName(), validationResult = evaluator.EvaluateUntyped(me, pi), })) .ToArray() }); } catch (Exception e) { return(new DynamicValidationTestResponse { validationException = e.Message }); } }
public override Control CreateView(ModifiableEntity entity, PropertyRoute typeContext) { if (View == null) { throw new InvalidOperationException("View not defined in EntitySettings"); } if (typeContext == null && !(entity is IRootEntity)) { throw new ArgumentException("An EmbeddedEntity neeed TypeContext"); } Control control = View((T)entity); Common.SetPropertyRoute(control, typeContext ?? PropertyRoute.Root(entity.GetType())); return(control); }
private static PropertyRoute GetCurrentPropertyRoute(object value) { var pr = JsonSerializerExtensions.CurrentPropertyRoute; if (value is IRootEntity) { pr = PropertyRoute.Root(value.GetType()); } if (pr == null) { var controller = ((ControllerActionDescriptor)SignumCurrentContextFilter.CurrentContext !.ActionDescriptor); var embedded = (EmbeddedEntity)value; var att = controller.MethodInfo.GetCustomAttribute <EmbeddedPropertyRouteAttribute>() ?? controller.MethodInfo.DeclaringType !.GetCustomAttribute <EmbeddedPropertyRouteAttribute>() ?? throw new InvalidOperationException(@$ "Impossible to determine PropertyRoute for {value.GetType().Name}. Consider adding someting like [EmbeddedPropertyRoute(typeof({embedded.GetType().Name}), typeof(SomeEntity), nameof(SomeEntity.SomeProperty))] to your action or controller.
public IEnumerable <QueryToken> GetExtensions(QueryToken parent) { var parentType = parent.Type.CleanType().UnNullify(); var dic = RegisteredExtensions.TryGetValue(parentType); IEnumerable <QueryToken> extensionsTokens = dic == null?Enumerable.Empty <QueryToken>() : dic.Values.Where(ei => ei.Inherit || ei.SourceType == parentType).Select(v => v.CreateToken(parent)); var pr = parentType.IsEntity() && !parentType.IsAbstract ? PropertyRoute.Root(parentType) : parentType.IsEmbeddedEntity() ? parent.GetPropertyRoute() : null; var edi = pr == null ? null : RegisteredExtensionsDictionaries.TryGetC(pr); IEnumerable <QueryToken> dicExtensionsTokens = edi == null?Enumerable.Empty <QueryToken>() : edi.GetAllTokens(parent); return(extensionsTokens.Concat(dicExtensionsTokens)); }
public virtual (PropertyRoute pr, ModifiableEntity?mod) GetCurrentPropertyRoute(ModifiableEntity mod) { var tup = EntityJsonContext.CurrentPropertyRouteAndEntity; if (mod is IRootEntity re) { tup = (PropertyRoute.Root(mod.GetType()), mod); } if (tup == null) { var embedded = (EmbeddedEntity)mod; var route = GetCurrentPropertyRouteEmbedded(embedded); return(route, embedded); } else if (tup.Value.pr.Type.ElementType() == mod.GetType()) { tup = (tup.Value.pr.Add("Item"), null); //We have a custom MListConverter but not for other simple collections } return(tup.Value); }
void Complete(Table table) { using (HeavyProfiler.LogNoStackTrace("Complete", () => table.Type.Name)) using (var tr = HeavyProfiler.LogNoStackTrace("GetPrimaryKeyAttribute", () => table.Type.Name)) { Type type = table.Type; table.IdentityBehaviour = GetPrimaryKeyAttribute(type).IdentityBehaviour; tr.Switch("GenerateTableName"); table.Name = GenerateTableName(type, Settings.TypeAttribute <TableNameAttribute>(type)); tr.Switch("GenerateCleanTypeName"); table.CleanTypeName = GenerateCleanTypeName(type); tr.Switch("GenerateFields"); table.Fields = GenerateFields(PropertyRoute.Root(type), table, NameSequence.Void, forceNull: false, inMList: false); tr.Switch("GenerateMixins"); table.Mixins = GenerateMixins(PropertyRoute.Root(type), table, NameSequence.Void); tr.Switch("GenerateColumns"); table.GenerateColumns(); } }
public IEnumerable <QueryToken> GetExtensions(QueryToken parent) { var parentTypeClean = parent.Type.CleanType(); var compatibleTypes = CompatibleTypes(parent.Type); var dic = compatibleTypes .Select(t => RegisteredExtensions.TryGetValue(t)) .Aggregate((Dictionary <string, ExtensionInfo>?)null, (dic1, dic2) => { if (dic1 == null) { return(dic2); } if (dic2 == null) { return(dic1); } var dic = new Dictionary <string, ExtensionInfo>(); dic.SetRange(dic1); dic.DefaultRange(dic2); return(dic); }); IEnumerable <QueryToken> extensionsTokens = dic == null?Enumerable.Empty <QueryToken>() : dic.Values.Where(ei => ei.Inherit || compatibleTypes.Contains(ei.SourceType)) .Where(ei => ei.IsApplicable == null || ei.IsApplicable(parent)) .Select(v => v.CreateToken(parent)); var pr = parentTypeClean.IsEntity() && !parentTypeClean.IsAbstract ? PropertyRoute.Root(parentTypeClean) : parentTypeClean.IsEmbeddedEntity() ? parent.GetPropertyRoute() : null; var edi = pr == null ? null : RegisteredExtensionsDictionaries.TryGetC(pr); IEnumerable <QueryToken> dicExtensionsTokens = edi == null?Enumerable.Empty <QueryToken>() : edi.GetAllTokens(parent); return(extensionsTokens.Concat(dicExtensionsTokens)); }
public override PropertyRoute GetPropertyRoute() { PropertyRoute parent = Parent.GetPropertyRoute(); if (parent == null) { Type type = Lite.Extract(Parent.Type); //Because Parent.Type is always a lite if (type != null) { return(PropertyRoute.Root(type).Add(miToStringProperty)); } } else { Type type = Lite.Extract(parent.Type); //Because Add doesn't work with lites if (type != null) { return(PropertyRoute.Root(type).Add(miToStringProperty)); } } return(null); }
internal ReadOnlyCollection <FieldBinding> GenerateBindings(Alias tableAlias, QueryBinder binder, Expression id) { List <FieldBinding> result = new List <FieldBinding>(); result.Add(new FieldBinding(Table.fiId, id)); foreach (var ef in this.Fields.Values) { var fi = ef.FieldInfo; if (!ReflectionTools.FieldEquals(fi, fiId)) { result.Add(new FieldBinding(fi, ef.Field.GetExpression(tableAlias, binder, id))); } } if (this.Type.IsEntity()) { result.AddRange(Schema.Current.GetAdditionalQueryBindings(PropertyRoute.Root(this.Type), (PrimaryKeyExpression)id)); } return(result.ToReadOnly()); }
internal PropertyRoute AddPropertyRoute(PropertyInfo pi) { if (typeof(ModelEntity).IsAssignableFrom(Type)) { return(PropertyRoute.Root(Type).Add(pi)); } Type type = Lite.Extract(Type); //Because Add doesn't work with lites if (type != null) { return(PropertyRoute.Root(type).Add(pi)); } PropertyRoute pr = GetPropertyRoute(); if (pr == null) { return(null); } return(pr.Add(pi)); }
public static PropertyRoute GetRoute <T, S>(this ILineContainer <T> lineContainer, Expression <Func <T, S> > property, out string newPrefix) where T : ModifiableEntity { newPrefix = lineContainer.Prefix; PropertyRoute result = lineContainer.Route ?? PropertyRoute.Root(typeof(T)); foreach (var mi in Reflector.GetMemberList(property)) { if (mi is MethodInfo && ((MethodInfo)mi).IsInstantiationOf(MixinDeclarations.miMixin)) { result = result.Add(((MethodInfo)mi).GetGenericArguments()[0]); } else { result = result.Add(mi); if (newPrefix.HasText()) { newPrefix += "_"; } newPrefix += mi.Name; } } return(result); }