Beispiel #1
0
        public QueryTokenTS(QueryToken qt, bool recursive)
        {
            this.toStr           = qt.ToString();
            this.niceName        = qt.NiceName();
            this.key             = qt.Key;
            this.fullKey         = qt.FullKey();
            this.type            = new TypeReferenceTS(qt.Type, qt.GetImplementations());
            this.filterType      = QueryUtils.TryGetFilterType(qt.Type);
            this.format          = qt.Format;
            this.unit            = UnitAttribute.GetTranslation(qt.Unit);
            this.typeColor       = qt.TypeColor;
            this.niceTypeName    = qt.NiceTypeName;
            this.queryTokenType  = GetQueryTokenType(qt);
            this.isGroupable     = qt.IsGroupable;
            this.hasOrderAdapter = QueryUtils.OrderAdapters.ContainsKey(qt.Type);

            this.preferEquals = qt.Type == typeof(string) &&
                                qt.GetPropertyRoute() is PropertyRoute pr &&
                                typeof(Entity).IsAssignableFrom(pr.RootType) &&
                                Schema.Current.HasSomeIndex(pr);

            this.propertyRoute = qt.GetPropertyRoute()?.ToString();
            if (recursive && qt.Parent != null)
            {
                this.parent = new QueryTokenTS(qt.Parent, recursive);
            }
        }
Beispiel #2
0
        public static Dictionary <string, TypeInfoTS> GetEntities(IEnumerable <Type> allTypes)
        {
            var models = (from type in allTypes
                          where typeof(ModelEntity).IsAssignableFrom(type) && !type.IsAbstract
                          select type).ToList();

            var queries = QueryLogic.Queries;

            var schema   = Schema.Current;
            var settings = Schema.Current.Settings;

            var result = (from type in TypeLogic.TypeToEntity.Keys.Concat(models)
                          where !type.IsEnumEntity() && !ReflectionServer.ExcludeTypes.Contains(type)
                          let descOptions = LocalizedAssembly.GetDescriptionOptions(type)
                                            let allOperations = !type.IsEntity() ? null : OperationLogic.GetAllOperationInfos(type)
                                                                select KVP.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS
            {
                Kind = KindOfType.Entity,
                FullName = type.FullName,
                NiceName = descOptions.HasFlag(DescriptionOptions.Description) ? type.NiceName() : null,
                NicePluralName = descOptions.HasFlag(DescriptionOptions.PluralDescription) ? type.NicePluralName() : null,
                Gender = descOptions.HasFlag(DescriptionOptions.Gender) ? type.GetGender().ToString() : null,
                EntityKind = type.IsIEntity() ? EntityKindCache.GetEntityKind(type) : (EntityKind?)null,
                EntityData = type.IsIEntity() ? EntityKindCache.GetEntityData(type) : (EntityData?)null,
                IsLowPopulation = type.IsIEntity() ? EntityKindCache.IsLowPopulation(type) : false,
                IsSystemVersioned = type.IsIEntity() ? schema.Table(type).SystemVersioned != null : false,
                ToStringFunction = typeof(Symbol).IsAssignableFrom(type) ? null : LambdaToJavascriptConverter.ToJavascript(ExpressionCleaner.GetFieldExpansion(type, miToString)),
                QueryDefined = queries.QueryDefined(type),
                Members = PropertyRoute.GenerateRoutes(type).Where(pr => InTypeScript(pr))
                          .ToDictionary(p => p.PropertyString(), p =>
                {
                    var mi = new MemberInfoTS
                    {
                        NiceName = p.PropertyInfo?.NiceName(),
                        TypeNiceName = GetTypeNiceName(p.PropertyInfo?.PropertyType),
                        Format = p.PropertyRouteType == PropertyRouteType.FieldOrProperty ? Reflector.FormatString(p) : null,
                        IsReadOnly = !IsId(p) && (p.PropertyInfo?.IsReadOnly() ?? false),
                        Unit = UnitAttribute.GetTranslation(p.PropertyInfo?.GetCustomAttribute <UnitAttribute>()?.UnitName),
                        Type = new TypeReferenceTS(IsId(p) ? PrimaryKey.Type(type).Nullify() : p.PropertyInfo?.PropertyType, p.Type.IsMList() ? p.Add("Item").TryGetImplementations() : p.TryGetImplementations()),
                        IsMultiline = Validator.TryGetPropertyValidator(p)?.Validators.OfType <StringLengthValidatorAttribute>().FirstOrDefault()?.MultiLine ?? false,
                        MaxLength = Validator.TryGetPropertyValidator(p)?.Validators.OfType <StringLengthValidatorAttribute>().FirstOrDefault()?.Max.DefaultToNull(-1),
                        PreserveOrder = settings.FieldAttributes(p)?.OfType <PreserveOrderAttribute>().Any() ?? false,
                    };

                    return(OnAddPropertyRouteExtension(mi, p));
                }),

                Operations = allOperations == null ? null : allOperations.ToDictionary(oi => oi.OperationSymbol.Key, oi => OnAddOperationExtension(new OperationInfoTS(oi), oi, type)),

                RequiresEntityPack = allOperations != null && allOperations.Any(oi => oi.HasCanExecute != null),
            }, type))).ToDictionaryEx("entities");

            return(result);
        }
Beispiel #3
0
        public ColumnDescriptionTS(ColumnDescription a, object queryName)
        {
            var token = new ColumnToken(a, queryName);

            this.name            = a.Name;
            this.type            = new TypeReferenceTS(a.Type, a.Implementations);
            this.filterType      = QueryUtils.TryGetFilterType(a.Type);
            this.typeColor       = token.TypeColor;
            this.niceTypeName    = token.NiceTypeName;
            this.isGroupable     = token.IsGroupable;
            this.hasOrderAdapter = QueryUtils.OrderAdapters.ContainsKey(token.Type);
            this.preferEquals    = token.Type == typeof(string) &&
                                   token.GetPropertyRoute() is PropertyRoute pr &&
                                   typeof(Entity).IsAssignableFrom(pr.RootType) &&
                                   Schema.Current.HasSomeIndex(pr);
            this.unit          = UnitAttribute.GetTranslation(a.Unit);
            this.format        = a.Format;
            this.displayName   = a.DisplayName;
            this.propertyRoute = token.GetPropertyRoute()?.ToString();
        }