コード例 #1
0
        ///<summary>
        /// Run the configEntity Crud operation with respect to the Context type.
        ///  Returns an OperationResult of Type ConfigEntity
        ///</summary>
        public static async Task <OperationResult> RunOperationAsync(ConfigurationContext context)
        {
            string methName = nameof(RunOperationAsync);

            SanityChecks.CheckNull(context, methName);
            if (context is QueryContext queryContext)
            {
                if (_queries.TryGetValue(queryContext.QueryType, out Func <QueryContext, Task <OperationResult> > query))
                {
                    return(await query(queryContext));
                }
                else
                {
                    return(OperationResult.Failure
                           (
                               ResultType.BadRequest,
                               $"did not find query type: {queryContext.QueryType}"
                           ));
                }
            }
            else if (context is CommandContext commandContext)
            {
                if (_cmds.TryGetValue(commandContext.CommandType, out Func <CommandContext, Task <OperationResult> > command))
                {
                    return(await command(commandContext));
                }
                else
                {
                    return(OperationResult.Failure
                           (
                               ResultType.BadRequest,
                               $"Did not find CommandType: {commandContext.CommandType}"
                           ));
                }
            }
            else if (context is UserContext userContext)
            {
                var commandType = userContext.Type;
                if (commandType.HasValue == false)
                {
                    return(await _userActions["query"](userContext));
                }
                else
                {
                    return(await _userActions[commandType.Value.ToString()](userContext));
                }
            }
            else
            {
                return(OperationResult.Failure
                       (
                           ResultType.BadRequest,
                           $"Type {context.GetType()} is not supported"
                       ));
            }
        }
コード例 #2
0
        }                                       // null means Query
        public UserContext(AuthModel user, IStorageModel model, CommandTypes?type, IAuthStorageModel authStorage, params ApplicationClaim[] claims)
            : base(model)
        {
            string msg = $"ctor of UserContext for [{type.ToString()}]";

            SanityChecks.CheckNull(model, msg);
            SanityChecks.CheckNull(user, msg);
            SanityChecks.CheckNull(authStorage, msg);

            Type        = type;
            Claims      = claims;
            AuthModel   = user;
            AuthStorage = authStorage;
        }
コード例 #3
0
 protected void Check <T>(T item, string paramName)
     where T : class
 {
     SanityChecks.CheckNull(item, $"ctor + [{nameof(ConfigurationContext)}]", paramName);
 }