Ejemplo n.º 1
0
        public override async Task InvokeAsync(ServerActionContext context)
        {
            if (context.GetActionOrThrow().HasParameters)
            {
                try
                {
                    context.GetActionOrThrow().ValidateParameters(context.Parameters);
                }
                catch (Exception e)
                {
                    throw new BoltServerException(ServerErrorCode.DeserializeParameters, context.Action.Name, context.RequestUrl, e);
                }
            }

            if (context.ContractInstance == null)
            {
                throw new BoltServerException(
                          $"There is no contract instance assigned for action '{context.Action.Name}'.",
                          ServerErrorCode.NoContractInstance,
                          context.Action.Name,
                          context.RequestUrl);
            }

            /*
             * if (!(context.ContractInstance.GetType().GetTypeInfo().ImplementedInterfaces.Contains(context.Contract)))
             * {
             *  throw new BoltServerException(
             *      $"Contract instance of type {context.Contract.Name} is expected but {context.ContractInstance.GetType().Name} was provided.",
             *      ServerErrorCode.InvalidContractInstance,
             *      context.Action,
             *      context.RequestUrl);
             * }
             */

            if (context.Action.Action == BoltFramework.SessionMetadata.InitSessionDefault ||
                context.Action.Action == BoltFramework.SessionMetadata.DestroySessionDefault)
            {
                await Next(context);
            }
            else
            {
                ActionDescriptor result = _actions.GetOrAdd(context.Action, a => new ActionDescriptor(a));
                await result.ExecuteAsync(context);
                await Next(context);
            }
        }