string TypeAuthCache_StaticPropertyValidation(ModifiableEntity sender, PropertyInfo pi)
        {
            RuleTypeEntity rt = (RuleTypeEntity)sender;

            if (rt.Resource == null)
            {
                if (rt.Conditions.Any())
                {
                    return("Default {0} should not have conditions".FormatWith(typeof(RuleTypeEntity).NiceName()));
                }

                return(null);
            }

            Type type       = TypeLogic.EntityToType[rt.Resource];
            var  conditions = rt.Conditions.Where(a =>
                                                  a.Condition.FieldInfo != null && /*Not 100% Sync*/
                                                  !TypeConditionLogic.IsDefined(type, a.Condition));

            if (conditions.IsEmpty())
            {
                return(null);
            }

            return("Type {0} has no definitions for the conditions: {1}".FormatWith(type.Name, conditions.CommaAnd(a => a.Condition.Key)));
        }
Exemple #2
0
        string?TypeAuthCache_StaticPropertyValidation(ModifiableEntity sender, PropertyInfo pi)
        {
            RuleTypeEntity rt = (RuleTypeEntity)sender;

            if (rt.Resource == null)
            {
                if (rt.Conditions.Any())
                {
                    return("Default {0} should not have conditions".FormatWith(typeof(RuleTypeEntity).NiceName()));
                }

                return(null);
            }

            try
            {
                Type type       = TypeLogic.EntityToType.GetOrThrow(rt.Resource);
                var  conditions = rt.Conditions.Where(a =>
                                                      a.Condition.FieldInfo != null && /*Not 100% Sync*/
                                                      !TypeConditionLogic.IsDefined(type, a.Condition));

                if (conditions.IsEmpty())
                {
                    return(null);
                }

                return("Type {0} has no definitions for the conditions: {1}".FormatWith(type.Name, conditions.CommaAnd(a => a.Condition.Key)));
            }
            catch (Exception ex) when(StartParameters.IgnoredDatabaseMismatches != null)
            {
                //This try { throw } catch is here to alert developers.
                //In production, in some cases its OK to attempt starting an application with a slightly different schema (dynamic entities, green-blue deployments).
                //In development, consider synchronize.
                StartParameters.IgnoredDatabaseMismatches.Add(ex);
                return(null);
            }
        }
        static SqlPreCommand Schema_Synchronizing(Replacements rep)
        {
            var conds = (from rt in Database.Query <RuleTypeEntity>()
                         from c in rt.Conditions
                         select new { rt.Resource, c.Condition, rt.Role }).ToList();

            var errors = conds.GroupBy(a => new { a.Resource, a.Condition }, a => a.Role)
                         .Where(gr =>
            {
                if (gr.Key.Condition.FieldInfo == null)
                {
                    return(rep.TryGetC(typeof(TypeConditionSymbol).Name)?.TryGetC(gr.Key.Condition.Key) == null);
                }

                return(!TypeConditionLogic.IsDefined(gr.Key.Resource.ToType(), gr.Key.Condition));
            })
                         .ToList();

            using (rep.WithReplacedDatabaseName())
                return(errors.Select(a => Administrator.UnsafeDeletePreCommand((RuleTypeEntity rt) => rt.Conditions, Database.MListQuery((RuleTypeEntity rt) => rt.Conditions)
                                                                               .Where(mle => mle.Element.Condition.Is(a.Key.Condition) && mle.Parent.Resource.Is(a.Key.Resource)))
                                     .AddComment("TypeCondition {0} not defined for {1} (roles {2})".FormatWith(a.Key.Condition, a.Key.Resource, a.ToString(", "))))
                       .Combine(Spacing.Double));
        }