Пример #1
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 dqm = DynamicQueryManager.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)
                                            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,
                ToStringFunction = LambdaToJavascriptConverter.ToJavascript(ExpressionCleaner.GetFieldExpansion(type, miToString)),
                QueryDefined = dqm.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 = 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 = !type.IsEntity() ? null : OperationLogic.GetAllOperationInfos(type)
                             .ToDictionary(oi => oi.OperationSymbol.Key, oi => OnAddOperationExtension(new OperationInfoTS(oi), oi))
            }, type))).ToDictionaryEx("entities");

            return(result);
        }
Пример #2
0
        public static OperationRulePack GetOperationRules(Lite <RoleEntity> role, TypeEntity typeEntity)
        {
            var resources = OperationLogic.GetAllOperationInfos(TypeLogic.EntityToType[typeEntity]).Select(a => a.OperationSymbol);
            var result    = new OperationRulePack {
                Role = role, Type = typeEntity,
            };

            cache.GetRules(result, resources);

            var coercer = OperationCoercer.Instance.GetCoerceValue(role);

            result.Rules.ForEach(r => r.CoercedValues = EnumExtensions.GetValues <OperationAllowed>().Where(a => !coercer(r.Resource, a).Equals(a)).ToArray());

            return(result);
        }
Пример #3
0
        public static void AssignTranslatedFullEntity(this EntityHelpEntity entity, CultureInfoEntity fromCulture)
        {
            var fromEntity = Database.Query <EntityHelpEntity>().SingleOrDefaultEx(e => e.Type == entity.Type && e.Culture == fromCulture);

            if (fromEntity != null)
            {
                AssignTranslatedEntity(entity, fromEntity);
            }

            var queries = HelpLogic.TypeToQuery.Value.TryGetC(entity.Type.ToType()).EmptyIfNull().Select(QueryLogic.GetQueryEntity).ToList();

            foreach (var q in queries)
            {
                var fromQuery = Database.Query <QueryHelpEntity>().SingleOrDefaultEx(e => e.Query == q && e.Culture == fromCulture);

                if (fromQuery != null)
                {
                    var query = Database.Query <QueryHelpEntity>().SingleOrDefaultEx(e => e.Query == q && e.Culture == entity.Culture) ??
                                new QueryHelpEntity {
                        Culture = entity.Culture, Query = q
                    };

                    AsignTranslatedQuery(query, fromQuery);
                }
            }

            var operations = OperationLogic.GetAllOperationInfos(entity.Type.ToType()).Select(o => o.OperationSymbol).ToList();

            foreach (var oper in operations)
            {
                var fromOper = Database.Query <OperationHelpEntity>().SingleOrDefaultEx(e => e.Operation == oper && e.Culture == fromCulture);

                if (fromOper != null)
                {
                    var operation = Database.Query <OperationHelpEntity>().SingleOrDefaultEx(e => e.Operation == oper && e.Culture == entity.Culture) ??
                                    new OperationHelpEntity {
                        Culture = entity.Culture, Operation = oper
                    };

                    AsignTranslatedOperation(operation, fromOper);
                }
            }
        }
Пример #4
0
        public EntityHelp(Type type, CultureInfo culture, EntityHelpEntity entity)
        {
            Type    = type;
            Culture = culture;
            Info    = HelpGenerator.GetEntityHelp(type);

            Properties = PropertyRoute.GenerateRoutes(type)
                         .ToDictionary(
                pp => pp,
                pp => new PropertyHelp(pp, HelpGenerator.GetPropertyHelp(pp)));


            var allOperations = HelpLogic.CachedOperationsHelp();

            Operations = OperationLogic.GetAllOperationInfos(type).Select(oi => allOperations.GetOrThrow(oi.OperationSymbol)).ToDictionary(a => a.OperationSymbol);

            var allQueries = HelpLogic.CachedQueriesHelp();

            Queries = HelpLogic.TypeToQuery.Value.TryGetC(this.Type).EmptyIfNull().Select(a => allQueries.GetOrThrow(a)).ToDictionary(qh => qh.QueryName);

            if (entity != null)
            {
                HasEntity = true;

                Description = entity.Description;

                foreach (var tranProp in entity.Properties)
                {
                    Properties.GetOrThrow(tranProp.Property.ToPropertyRoute()).UserDescription = tranProp.Description;
                }

                foreach (var transOper in entity.Operations)
                {
                    Operations.GetOrThrow(transOper.Operation).UserDescription = transOper.Description;
                }
            }

            Entity = new Lazy <EntityHelpEntity>(() => HelpLogic.GlobalContext(() =>
            {
                if (entity == null)
                {
                    entity = new EntityHelpEntity
                    {
                        Culture = this.Culture.ToCultureInfoEntity(),
                        Type    = this.Type.ToTypeEntity(),
                    }
                }
                ;

                entity.Properties.AddRange(
                    PropertyRouteLogic.RetrieveOrGenerateProperties(this.Type.ToTypeEntity())
                    .Except(entity.Properties.Select(a => a.Property))
                    .Select(pr => new PropertyRouteHelpEmbedded
                {
                    Property    = pr,
                    Description = null,
                }));

                entity.Operations.AddRange(this.Operations.Values.Select(o => o.Entity.Value).ToList());

                entity.Queries.AddRange(this.Queries.Values.Select(a => a.Entity.Value).ToList());

                return(entity);
            }));
        }
Пример #5
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 KeyValuePair.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 validators = Validator.TryGetPropertyValidator(p)?.Validators;

                    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),
                        Required = !IsId(p) && ((p.Type.IsValueType && !p.Type.IsNullable()) || (validators?.Any(v => !v.DisabledInModelBinder && (!p.Type.IsMList() ? (v is NotNullValidatorAttribute) : (v is CountIsValidatorAttribute c && c.IsGreaterThanZero))) ?? 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 = validators?.OfType <StringLengthValidatorAttribute>().FirstOrDefault()?.MultiLine ?? false,
                        IsVirtualMList = p.IsVirtualMList(),
                        MaxLength = validators?.OfType <StringLengthValidatorAttribute>().FirstOrDefault()?.Max.DefaultToNull(-1),
                        PreserveOrder = settings.FieldAttributes(p)?.OfType <PreserveOrderAttribute>().Any() ?? false,
                    };

                    return(OnAddPropertyRouteExtension(mi, p));
                }),
Пример #6
0
 public static AuthThumbnail?GetAllowedThumbnail(Lite <RoleEntity> role, Type entityType)
 {
     return(OperationLogic.GetAllOperationInfos(entityType).Select(oi => cache.GetAllowed(role, oi.OperationSymbol)).Collapse());
 }