#pragma warning restore CS8618 // Non-nullable field is uninitialized. public TypeReferenceTS(Type type, Implementations?implementations) { this.IsCollection = type != typeof(string) && type != typeof(byte[]) && type.ElementType() != null; var clean = type == typeof(string) ? type : (type.ElementType() ?? type); this.IsLite = clean.IsLite(); this.IsNotNullable = clean.IsValueType && !clean.IsNullable(); this.IsEmbedded = clean.IsEmbeddedEntity(); if (this.IsEmbedded && !this.IsCollection) { this.TypeNiceName = type.NiceName(); } if (implementations != null) { try { this.Name = implementations.Value.Key(); } catch (Exception) when(StartParameters.IgnoredCodeErrors != null) { this.Name = "ERROR"; } } else { this.Name = TypeScriptType(type); } }
public DirtyMeta(Implementations?implementations, Meta[] properties) : base(implementations) { CleanMetas = properties.OfType <CleanMeta>().Concat( properties.OfType <DirtyMeta>().SelectMany(d => d.CleanMetas)) .ToReadOnly(); }
public Implementations FindImplementations(PropertyRoute route) { if (route.PropertyRouteType == PropertyRouteType.LiteEntity) { route = route.Parent; } Type type = route.RootType; if (!Tables.ContainsKey(type)) { return(Schema.Current.Settings.GetImplementations(route)); } Field field = TryFindField(Table(type), route.Members); //if (field == null) // return Implementations.ByAll; FieldReference refField = field as FieldReference; if (refField != null) { return(Implementations.By(refField.FieldType.CleanType())); } FieldImplementedBy ibField = field as FieldImplementedBy; if (ibField != null) { return(Implementations.By(ibField.ImplementationColumns.Keys.ToArray())); } FieldImplementedByAll ibaField = field as FieldImplementedByAll; if (ibaField != null) { return(Implementations.ByAll); } Implementations?implementations = CalculateExpressionImplementations(route); if (implementations != null) { return(implementations.Value); } var ss = Schema.Current.Settings; if (route.Follow(r => r.Parent) .TakeWhile(t => t.PropertyRouteType != PropertyRouteType.Root) .Any(r => ss.FieldAttribute <IgnoreAttribute>(r) != null)) { var ib = ss.FieldAttribute <ImplementedByAttribute>(route); var iba = ss.FieldAttribute <ImplementedByAllAttribute>(route); return(Implementations.TryFromAttributes(route.Type.CleanType(), route, ib, iba) ?? Implementations.By()); } throw new InvalidOperationException("Impossible to determine implementations for {0}".FormatWith(route, typeof(IEntity).Name)); }
public ExtensionDictionaryToken(QueryToken parent, K key, string unit, string format, Implementations?implementations, PropertyRoute propertyRoute) : base(parent) { this.keyValue = key; this.unit = unit; this.format = format; this.implementations = implementations; this.propertyRoute = propertyRoute; this.Priority = -10; }
public virtual void SetSearchViewableAndCreable(FindOptions findOptions, QueryDescription description) { var entityColumn = description.Columns.SingleEx(a => a.IsEntity); Type entitiesType = Lite.Extract(entityColumn.Type); Implementations?implementations = entityColumn.Implementations; if (findOptions.Navigate) { findOptions.Navigate = implementations.Value.IsByAll ? true : implementations.Value.Types.Any(t => Navigator.IsNavigable(t, null, true)); } if (findOptions.Create) { findOptions.Create = (implementations.Value.IsByAll ? true : implementations.Value.Types.Any(t => Navigator.IsCreable(t, true))); } }
public ExtensionDictionaryToken(QueryToken parent, K key, string?unit, string?format, Implementations?implementations, PropertyRoute?propertyRoute, Expression <Func <T, V> > lambda) { this.keyValue = key; this.unit = unit; this.format = format; this.implementations = implementations; this.propertyRoute = propertyRoute; this.Priority = -10; this.Lambda = lambda; this.parent = parent; }
public TypeReferenceTS(Type type, Implementations?implementations) { this.IsCollection = type != typeof(string) && type != typeof(byte[]) && type.ElementType() != null; var clean = type == typeof(string) ? type : (type.ElementType() ?? type); this.IsLite = clean.IsLite(); this.IsNotNullable = clean.IsValueType && !clean.IsNullable(); this.IsEmbedded = clean.IsEmbeddedEntity(); if (this.IsEmbedded && !this.IsCollection) { this.TypeNiceName = type.NiceName(); } this.Name = implementations?.Key() ?? TypeScriptType(type); }
public static Implementations FromAttributes(Type t, PropertyRoute route, ImplementedByAttribute ib, ImplementedByAllAttribute iba) { Implementations?imp = TryFromAttributes(t, route, ib, iba); if (imp == null) { var message = Error(t) + @". Set implementations for {0}.".FormatWith(route); if (t.IsInterface || t.IsAbstract) { message += @"\r\n" + ConsiderMessage(route, "typeof(YourConcrete" + t.TypeName() + ")"); } throw new InvalidOperationException(message); } return(imp.Value); }
protected override Expression VisitBinary(BinaryExpression b) { var right = Visit(b.Right); var left = Visit(b.Left); var mRight = right as MetaExpression; var mLeft = left as MetaExpression; Implementations?imps = mRight != null && mRight.Meta.Implementations != null && mLeft != null && mLeft.Meta.Implementations != null? AggregateImplementations(new[] { mRight.Meta.Implementations.Value, mLeft.Meta.Implementations.Value }) : (Implementations?)null; return(MakeDirtyMeta(b.Type, imps, left, right)); }
protected override Expression VisitConditional(ConditionalExpression c) { var ifTrue = Visit(c.IfTrue); var ifFalse = Visit(c.IfFalse); var mIfTrue = ifTrue as MetaExpression; var mIfFalse = ifFalse as MetaExpression; Implementations?imps = mIfTrue != null && mIfTrue.Meta.Implementations != null && mIfFalse != null && mIfFalse.Meta.Implementations != null? AggregateImplementations(new[] { mIfTrue.Meta.Implementations.Value, mIfFalse.Meta.Implementations.Value }) : (Implementations?)null; return(MakeDirtyMeta(c.Type, imps, Visit(c.Test), ifTrue, ifFalse)); }
public static Implementations FromAttributes(Type t, PropertyRoute route, ImplementedByAttribute ib, ImplementedByAllAttribute iba) { Implementations?imp = TryFromAttributes(t, route, ib, iba); if (imp == null) { var message = Error(t) + @". Set implementations for {0}.".FormatWith(route); if (t.IsInterface || t.IsAbstract) { message += @"\r\nConsider writing something like this in your Starter class: sb.Schema.Settings.FieldAttributes(({0} a) => a.{1}).Replace(new ImplementedByAttribute(typeof(YourConcrete{2})));" .FormatWith(route.RootType.TypeName(), route.PropertyString().Replace("/", ".First()."), t.TypeName()); } throw new InvalidOperationException(message); } return(imp.Value); }
private static bool Compatible(Implementations?multiImplementations, Implementations mainQueryImplementations) { if (multiImplementations == null) { return(false); } if (multiImplementations.Value.IsByAll || mainQueryImplementations.IsByAll) { return(false); } if (multiImplementations.Value.Types.Count() != 1 || mainQueryImplementations.Types.Count() != 1) { return(false); } return(multiImplementations.Value.Types.SingleEx().Equals(mainQueryImplementations.Types.SingleEx())); }
public ExtensionToken(QueryToken parent, string key, Type type, bool isProjection, string unit, string format, Implementations?implementations, string isAllowed, PropertyRoute propertyRoute) : base(parent) { var shouldHaveImplementations = typeof(IEntity).IsAssignableFrom((isProjection ? type.ElementType() : type).CleanType()); if (shouldHaveImplementations && implementations == null) { throw new ArgumentException("Extension token '{0}' (of type {1}) registered on type {2} has no implementations".FormatWith(key, type.TypeName(), parent.Type.CleanType().TypeName())); } this.key = key; this.type = type; this.isProjection = isProjection; this.unit = unit; this.format = format; this.implementations = implementations; this.isAllowed = isAllowed; this.propertyRoute = propertyRoute; }
public ExtensionToken(QueryToken parent, string key, Type type, bool isProjection, string unit, string format, Implementations?implementations, string isAllowed, PropertyRoute propertyRoute) : base(parent) { var shouldHaveImplementations = typeof(IEntity).IsAssignableFrom((isProjection ? type.ElementType() : type).CleanType()); if (shouldHaveImplementations && implementations == null) { throw new ArgumentException(@"Impossible to determine automatically the implementations for extension token '{0}' (of type {1}) registered on type {2}. Consider using dqm.RegisterExpression(({2} e) => e.{0}).ForceImplementations = Implementations.By(typeof({1}));".FormatWith(key, type.TypeName(), parent.Type.CleanType().TypeName())); } this.key = key; this.type = type; this.isProjection = isProjection; this.unit = unit; this.format = format; this.implementations = implementations; this.isAllowed = isAllowed; this.propertyRoute = propertyRoute; }
ColumnDescription(SerializationInfo info, StreamingContext context) { foreach (SerializationEntry entry in info) { switch (entry.Name) { case "name": name = (string)entry.Value; break; case "type": type = Type.GetType((string)entry.Value); break; case "unit": unit = (string)entry.Value; break; case "format": format = (string)entry.Value; break; case "implementations": implementations = (Implementations)entry.Value; break; case "propertyRoutes": propertyRoutes = (PropertyRoute[])entry.Value; break; case "propertyRoute": propertyRoutes = new[] { (PropertyRoute)entry.Value }; break; case "displayName": displayName = (string)entry.Value; break; } } }
static MetaExpression MakeDirtyMeta(Type type, Implementations?implementations, params Expression[] expression) { var metas = expression.OfType <MetaExpression>().Select(a => a.Meta).NotNull().ToArray(); return(new MetaExpression(type, new DirtyMeta(implementations, metas))); }
ColumnDescription(SerializationInfo info, StreamingContext context) { foreach (SerializationEntry entry in info) { switch (entry.Name) { case "name": name = (string)entry.Value; break; case "type": type = Type.GetType((string)entry.Value); break; case "unit": unit = (string)entry.Value; break; case "format": format = (string)entry.Value; break; case "implementations": implementations = (Implementations)entry.Value; break; case "propertyRoutes": propertyRoutes = (PropertyRoute[])entry.Value; break; case "propertyRoute": propertyRoutes = new[] { (PropertyRoute)entry.Value }; break; case "displayName": displayName = (string)entry.Value; break; } } }
protected Meta(Implementations? implementations) { this.Implementations = implementations; }
protected List <QueryToken> SubTokensBase(Type type, SubTokensOptions options, Implementations?implementations) { var ut = type.UnNullify(); if (ut == typeof(DateTime)) { return(DateTimeProperties(this, DateTimePrecision.Milliseconds)); } if (ut == typeof(float) || ut == typeof(double) || ut == typeof(decimal)) { return(StepTokens(this, 4)); } if (ut == typeof(int) || ut == typeof(long) || ut == typeof(short)) { return(StepTokens(this, 0)); } Type cleanType = type.CleanType(); if (cleanType.IsIEntity()) { if (implementations.Value.IsByAll) { return(new List <QueryToken>()); // new[] { EntityPropertyToken.IdProperty(this) }; } var onlyType = implementations.Value.Types.Only(); if (onlyType != null && onlyType == cleanType) { return new[] { EntityPropertyToken.IdProperty(this), new EntityToStringToken(this) } }
public void Register <T>(object queryName, Func <DynamicQueryCore <T> > lazyQueryCore, Implementations?entityImplementations = null) { queries[queryName] = new DynamicQueryBucket(queryName, lazyQueryCore, entityImplementations ?? DefaultImplementations(typeof(T), queryName)); }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <SendEmailTaskEntity>() .WithQuery(() => e => new { Entity = e, e.Id, e.Name, e.EmailTemplate, e.UniqueTarget, }); Validator.PropertyValidator((SendEmailTaskEntity er) => er.UniqueTarget).StaticPropertyValidation += (er, pi) => { if (er.UniqueTarget != null && er.TargetsFromUserQuery != null) { return(ValidationMessage._0And1CanNotBeSetAtTheSameTime.NiceToString(pi.NiceName(), ReflectionTools.GetPropertyInfo(() => er.TargetsFromUserQuery).NiceName())); } Implementations?implementations = er.EmailTemplate == null ? null : GetImplementations(er.EmailTemplate.InDB(a => a.Query)); if (implementations != null && er.UniqueTarget == null && er.TargetsFromUserQuery == null) { return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName())); } if (er.UniqueTarget != null) { if (!implementations.Value.Types.Contains(er.UniqueTarget.EntityType)) { return(ValidationMessage._0ShouldBeOfType1.NiceToString(pi.NiceName(), implementations.Value.Types.CommaOr(t => t.NiceName()))); } } return(null); }; Validator.PropertyValidator((SendEmailTaskEntity er) => er.TargetsFromUserQuery).StaticPropertyValidation += (SendEmailTaskEntity er, PropertyInfo pi) => { Implementations?implementations = er.EmailTemplate == null ? null : GetImplementations(er.EmailTemplate.InDB(a => a.Query)); if (implementations != null && er.TargetsFromUserQuery == null && er.UniqueTarget == null) { return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName())); } if (er.TargetsFromUserQuery != null) { var uqImplementations = GetImplementations(er.TargetsFromUserQuery.InDB(a => a.Query)); if (!implementations.Value.Types.Intersect(uqImplementations.Value.Types).Any()) { return(ValidationMessage._0ShouldBeOfType1.NiceToString(pi.NiceName(), implementations.Value.Types.CommaOr(t => t.NiceName()))); } } return(null); }; new Graph <SendEmailTaskEntity> .Execute(SendEmailTaskOperation.Save) { CanBeNew = true, CanBeModified = true, Execute = (e, _) => { } } .Register(); SchedulerLogic.ExecuteTask.Register((SendEmailTaskEntity er, ScheduledTaskContext ctx) => { if (er.UniqueTarget != null) { ModifiableEntity entity = er.UniqueTarget.RetrieveAndRemember(); if (er.ModelConverter != null) { entity = er.ModelConverter.Convert(entity); } Lite <EmailMessageEntity>?last = null; foreach (var email in er.EmailTemplate.CreateEmailMessage(entity)) { email.SendMailAsync(); last = email.ToLite(); } return(last); } else { var qr = er.TargetsFromUserQuery !.RetrieveAndRemember().ToQueryRequest(); qr.Columns.Clear(); var result = QueryLogic.Queries.ExecuteQuery(qr); var entities = result.Rows.Select(a => a.Entity).ToList(); if (entities.IsEmpty()) { return(null); } return(EmailPackageLogic.SendMultipleEmailsAsync(er.EmailTemplate, entities, er.ModelConverter).Execute(ProcessOperation.Execute).ToLite()); } }); } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <SendEmailTaskEntity>() .WithQuery(() => e => new { Entity = e, e.Id, e.Name, e.EmailTemplate, e.UniqueTarget, }); Validator.PropertyValidator((SendEmailTaskEntity er) => er.UniqueTarget).StaticPropertyValidation += (er, pi) => { if (er.UniqueTarget != null && er.EmailTemplate != null) { Implementations?implementations = GetImplementations(er.EmailTemplate.InDB(a => a.Query)); if (!implementations !.Value.Types.Contains(er.UniqueTarget.EntityType)) { return(ValidationMessage._0ShouldBeOfType1.NiceToString(pi.NiceName(), implementations.Value.Types.CommaOr(t => t.NiceName()))); } } return(null); }; Validator.PropertyValidator((SendEmailTaskEntity er) => er.TargetsFromUserQuery).StaticPropertyValidation += (SendEmailTaskEntity er, PropertyInfo pi) => { if (er.TargetsFromUserQuery != null && er.EmailTemplate != null) { Implementations?emailImplementations = GetImplementations(er.EmailTemplate.InDB(a => a.Query)); var uqImplementations = GetImplementations(er.TargetsFromUserQuery.InDB(a => a.Query)); if (!emailImplementations !.Value.Types.Intersect(uqImplementations !.Value.Types).Any()) { return(ValidationMessage._0ShouldBeOfType1.NiceToString(pi.NiceName(), emailImplementations.Value.Types.CommaOr(t => t.NiceName()))); } } return(null); }; new Graph <SendEmailTaskEntity> .Execute(SendEmailTaskOperation.Save) { CanBeNew = true, CanBeModified = true, Execute = (e, _) => { } } .Register(); SchedulerLogic.ExecuteTask.Register((SendEmailTaskEntity er, ScheduledTaskContext ctx) => { if (er.UniqueTarget != null) { ModifiableEntity entity = er.UniqueTarget.RetrieveAndRemember(); if (er.ModelConverter != null) { entity = er.ModelConverter.Convert(entity); } Lite <EmailMessageEntity>?last = null; foreach (var email in er.EmailTemplate.CreateEmailMessage(entity)) { email.SendMailAsync(); last = email.ToLite(); } return(last); } else { var qr = er.TargetsFromUserQuery !.RetrieveAndRemember().ToQueryRequest(); List <Lite <Entity> > entities; if (!qr.GroupResults) { qr.Columns.Clear(); var result = QueryLogic.Queries.ExecuteQuery(qr); entities = result.Rows.Select(a => a.Entity).Distinct().NotNull().ToList(); } else { var result = QueryLogic.Queries.ExecuteQuery(qr); var col = result.Columns.FirstOrDefault(); if (col == null || !col.Column.Type.IsLite()) { throw new InvalidOperationException("Grouping UserQueries should have the target entity as first column"); } entities = result.Rows.Select(row => (Lite <Entity>?)row[col]).Distinct().NotNull().ToList(); } if (entities.IsEmpty()) { return(null); } return(EmailPackageLogic.SendMultipleEmailsAsync(er.EmailTemplate, entities, er.ModelConverter).Execute(ProcessOperation.Execute).ToLite()); } }); } }
public CleanMeta(Implementations?implementations, params PropertyRoute[] propertyRoutes) : base(implementations) { this.PropertyRoutes = propertyRoutes; }
public void Register <T>(object queryName, Func <IQueryable <T> > lazyQuery, Implementations?entityImplementations = null) { queries[queryName] = new DynamicQueryBucket(queryName, () => DynamicQueryCore.Auto(lazyQuery()), entityImplementations ?? DefaultImplementations(typeof(T), queryName)); }
protected Meta(Implementations?implementations) { this.Implementations = implementations; }