Пример #1
0
        public static OperationAllowed MaxTypePermission(OperationSymbol operationKey, TypeAllowedBasic minimum, Func <Type, TypeAllowedAndConditions> allowed)
        {
            Func <Type, OperationAllowed> operationAllowed = t =>
            {
                if (!TypeLogic.TypeToEntity.ContainsKey(t))
                {
                    return(OperationAllowed.Allow);
                }

                var ta = allowed(t);

                return(minimum <= ta.MaxUI() ? OperationAllowed.Allow :
                       minimum <= ta.MaxDB() ? OperationAllowed.DBOnly :
                       OperationAllowed.None);
            };

            return(OperationLogic.FindTypes(operationKey).Max(t =>
            {
                var operation = OperationLogic.FindOperation(t, operationKey);

                Type resultType = operation.OperationType == OperationType.ConstructorFrom ||
                                  operation.OperationType == OperationType.ConstructorFromMany ? operation.ReturnType : operation.OverridenType;

                var result = operationAllowed(resultType);

                if (result == OperationAllowed.None)
                {
                    return result;
                }

                Type fromType = operation.OperationType == OperationType.ConstructorFrom ||
                                operation.OperationType == OperationType.ConstructorFromMany ? operation.OverridenType : null;

                if (fromType == null)
                {
                    return result;
                }

                var fromTypeAllowed = operationAllowed(fromType);

                return result < fromTypeAllowed ? result : fromTypeAllowed;
            }));
        }