コード例 #1
0
        /// <summary>
        /// Occurs when a no actions are matched by the route policy.
        /// </summary>
        /// <param name="context">The current <see cref="RouteContext">route context</see>.</param>
        /// <param name="selectionResult">The current <see cref="ActionSelectionResult">action selection result</see>.</param>
        protected virtual void OnUnmatched(RouteContext context, ActionSelectionResult selectionResult)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (selectionResult == null)
            {
                throw new ArgumentNullException(nameof(selectionResult));
            }

            const RequestHandler?NotFound = default;
            var candidates = selectionResult.CandidateActions;
            var handler    = NotFound;

            if (candidates.Count > 0)
            {
                var builder = new ClientErrorBuilder()
                {
                    Options            = Options,
                    ApiVersionReporter = ApiVersionReporter,
                    HttpContext        = context.HttpContext,
                    Candidates         = candidates,
                    Logger             = Logger,
                };

                handler = builder.Build();
            }

            context.Handler = handler !;
        }
コード例 #2
0
        /// <summary>
        /// Executes the API versioning route policy.
        /// </summary>
        /// <param name="context">The <see cref="RouteContext">route context</see> to evaluate against.</param>
        /// <param name="selectionResult">The <see cref="ActionSelectionResult">result</see> of action selection.</param>
        /// <returns>The <see cref="ActionDescriptor">action</see> conforming to the policy or <c>null</c>.</returns>
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
        public virtual ActionDescriptor?Evaluate(RouteContext context, ActionSelectionResult selectionResult)
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
        {
            if (selectionResult == null)
            {
                throw new ArgumentNullException(nameof(selectionResult));
            }

#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
            const ActionDescriptor?NoMatch = default;
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

            switch (selectionResult.MatchingActions.Count)
            {
            case 0:
                OnUnmatched(context, selectionResult);
                return(NoMatch);

            case 1:
                return(OnSingleMatch(context, selectionResult));
            }

            OnMultipleMatches(context, selectionResult);
            return(NoMatch);
        }
コード例 #3
0
        /// <summary>
        /// Occurs when a no actions are matched by the route policy.
        /// </summary>
        /// <param name="context">The current <see cref="RouteContext">route context</see>.</param>
        /// <param name="selectionResult">The current <see cref="ActionSelectionResult">action selection result</see>.</param>
        protected virtual void OnUnmatched(RouteContext context, ActionSelectionResult selectionResult)
        {
            Arg.NotNull(context, nameof(context));
            Arg.NotNull(selectionResult, nameof(selectionResult));

            context.Handler = ClientError(context.HttpContext, selectionResult);
        }
コード例 #4
0
        /// <summary>
        /// Occurs when a no actions are matched by the route policy.
        /// </summary>
        /// <param name="context">The current <see cref="RouteContext">route context</see>.</param>
        /// <param name="selectionResult">The current <see cref="ActionSelectionResult">action selection result</see>.</param>
        protected virtual void OnUnmatched(RouteContext context, ActionSelectionResult selectionResult)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (selectionResult == null)
            {
                throw new ArgumentNullException(nameof(selectionResult));
            }

#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
            const RequestHandler?NotFound = default;
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
            var candidates = selectionResult.CandidateActions;
            var handler    = NotFound;

            if (candidates.Count > 0)
            {
                var builder = new ClientErrorBuilder()
                {
                    Options            = Options,
                    ApiVersionReporter = ApiVersionReporter,
                    HttpContext        = context.HttpContext,
                    Candidates         = candidates,
                    Logger             = Logger,
                };

                handler = builder.Build();
            }

            context.Handler = handler !;
        }
コード例 #5
0
        /// <summary>
        /// Occurs when a single action is matched to the route policy.
        /// </summary>
        /// <param name="context">The current <see cref="RouteContext">route context</see>.</param>
        /// <param name="selectionResult">The current <see cref="ActionSelectionResult">action selection result</see>.</param>
        /// <returns>The single, matching <see cref="ActionDescriptor">action</see> conforming to the policy.</returns>
        protected virtual ActionDescriptor OnSingleMatch(RouteContext context, ActionSelectionResult selectionResult)
        {
            if (selectionResult == null)
            {
                throw new ArgumentNullException(nameof(selectionResult));
            }

            return(selectionResult.BestMatch);
        }
コード例 #6
0
        /// <summary>
        /// Occurs when a single action is matched to the route policy.
        /// </summary>
        /// <param name="context">The current <see cref="RouteContext">route context</see>.</param>
        /// <param name="selectionResult">The current <see cref="ActionSelectionResult">action selection result</see>.</param>
        /// <param name="match">The <see cref="ActionDescriptorMatch">matched</see> action.</param>
        protected virtual void OnSingleMatch(RouteContext context, ActionSelectionResult selectionResult, ActionDescriptorMatch match)
        {
            Arg.NotNull(context, nameof(context));
            Arg.NotNull(selectionResult, nameof(selectionResult));
            Arg.NotNull(match, nameof(match));

            var handler = new DefaultActionHandler(ActionInvokerFactory, ActionContextAccessor, selectionResult, match);

            context.RouteData = match.RouteData;
            context.Handler   = handler.Invoke;
        }
        /// <summary>
        /// Occurs when a single action is matched to the route policy.
        /// </summary>
        /// <param name="context">The current <see cref="RouteContext">route context</see>.</param>
        /// <param name="selectionResult">The current <see cref="ActionSelectionResult">action selection result</see>.</param>
        /// <param name="match">The <see cref="ActionDescriptorMatch">matched</see> action.</param>
        protected virtual void OnSingleMatch(RouteContext context, ActionSelectionResult selectionResult, ActionDescriptorMatch match)
        {
            Arg.NotNull(context, nameof(context));
            Arg.NotNull(selectionResult, nameof(selectionResult));
            Arg.NotNull(match, nameof(match));

            var handler = new DefaultActionHandler(ActionInvokerFactory, ActionContextAccessor, selectionResult, match);

            match.Action.AggregateAllVersions(selectionResult.CandidateActions);
            context.Handler = handler.Invoke;
        }
コード例 #8
0
 internal DefaultActionHandler(
     IActionInvokerFactory actionInvokerFactory,
     IActionContextAccessor actionContextAccessor,
     ActionSelectionResult selectionResult,
     ActionDescriptorMatch match)
 {
     this.actionContextAccessor = actionContextAccessor;
     this.actionInvokerFactory  = actionInvokerFactory;
     this.selectionResult       = selectionResult;
     this.match = match;
 }
コード例 #9
0
        RequestHandler ClientError(HttpContext httpContext, ActionSelectionResult selectionResult)
        {
            Contract.Requires(httpContext != null);
            Contract.Requires(selectionResult != null);

            const RequestHandler NotFound = default;
            var candidates = selectionResult.CandidateActions;

            if (candidates.Count == 0)
            {
                return(NotFound);
            }

            var feature          = httpContext.Features.Get <IApiVersioningFeature>();
            var method           = httpContext.Request.Method;
            var requestUrl       = new Lazy <string>(httpContext.Request.GetDisplayUrl);
            var requestedVersion = feature.RawRequestedApiVersion;
            var parsedVersion    = feature.RequestedApiVersion;
            var actionNames      = new Lazy <string>(() => Join(NewLine, candidates.Select(a => a.DisplayName)));
            var allowedMethods   = new Lazy <HashSet <string> >(() => AllowedMethodsFromCandidates(candidates, parsedVersion));
            var apiVersions      = new Lazy <ApiVersionModel>(candidates.Select(a => a.GetProperty <ApiVersionModel>()).Aggregate);
            var handlerContext   = new RequestHandlerContext(ErrorResponseProvider, ApiVersionReporter, apiVersions);
            var url     = new Uri(requestUrl.Value);
            var safeUrl = url.SafeFullPath();

            if (parsedVersion == null)
            {
                if (IsNullOrEmpty(requestedVersion))
                {
                    if (Options.AssumeDefaultVersionWhenUnspecified || candidates.Any(c => c.IsApiVersionNeutral()))
                    {
                        return(VersionNeutralUnmatched(handlerContext, safeUrl, method, allowedMethods.Value, actionNames.Value));
                    }

                    return(UnspecifiedApiVersion(handlerContext, actionNames.Value));
                }
                else if (!TryParse(requestedVersion, out parsedVersion))
                {
                    return(MalformedApiVersion(handlerContext, safeUrl, requestedVersion));
                }
            }
            else if (IsNullOrEmpty(requestedVersion))
            {
                return(VersionNeutralUnmatched(handlerContext, safeUrl, method, allowedMethods.Value, actionNames.Value));
            }
            else
            {
                requestedVersion = parsedVersion.ToString();
            }

            return(Unmatched(handlerContext, safeUrl, method, allowedMethods.Value, actionNames.Value, parsedVersion, requestedVersion));
        }
コード例 #10
0
        /// <summary>
        /// Occurs when a multiple actions are matched to the route policy.
        /// </summary>
        /// <param name="context">The current <see cref="RouteContext">route context</see>.</param>
        /// <param name="selectionResult">The current <see cref="ActionSelectionResult">action selection result</see>.</param>
        /// <remarks>The default implementation always throws an <see cref="AmbiguousActionException"/>.</remarks>
        protected virtual void OnMultipleMatches(RouteContext context, ActionSelectionResult selectionResult)
        {
            Arg.NotNull(context, nameof(context));
            Arg.NotNull(selectionResult, nameof(selectionResult));

            var actionNames = Join(NewLine, selectionResult.MatchingActions.Select(ExpandActionSignature));

            Logger.AmbiguousActions(actionNames);

            var message = SR.ActionSelector_AmbiguousActions.FormatDefault(NewLine, actionNames);

            throw new AmbiguousActionException(message);
        }
コード例 #11
0
    public ActionSelectionResult TrySelectAction(int totalActionPoints, ActionType compType)
    {
        ActionSelectionResult trySelectResult = HasEnoughActionPoints(totalActionPoints, compType);

        if (trySelectResult == ActionSelectionResult.EnoughActionPoints)
        {
            if (compType == ActionType.Throw)
            {
                if (DiscManager.Instance.GetPossessedDiscsCount == 0)
                {
                    trySelectResult = ActionSelectionResult.NotEnoughDiscs;
                }
            }
            else if (compType == ActionType.Recall)
            {
                List <DiscScript> inRange    = DiscManager.Instance.GetInRangeDiscs;
                List <DiscScript> throwed    = DiscManager.Instance.GetAllThrowedDiscs;
                List <DiscScript> recallable = DiscListingFactory.GetSortedRecallableDiscs(recallCompetence, throwed, inRange);
                if (recallable.Count == 0)
                {
                    trySelectResult = ActionSelectionResult.NoNearbyDisc;
                }
            }
            else if (compType == ActionType.Special)
            {
                bool usable = GetSpecialCompetenceUsable(totalActionPoints);
                if (!usable)
                {
                    trySelectResult = ActionSelectionResult.NoNearbyDisc;
                }
            }
            currentActionPoints = totalActionPoints;
        }

        switch (trySelectResult)
        {
        case ActionSelectionResult.EnoughActionPoints:
            ChangeUsabilityState(UsabilityState.Preparing, compType);
            UIManager.Instance.GetActionBar.UpdatePreConsommationPointBar(totalActionPoints, GetCurrentCompetenceCost());
            UIManager.Instance.ShowActionPointsCostText();
            UIManager.Instance.UpdateActionPointCostText(GetCurrentCompetenceCost(), totalActionPoints);
            SoundManager.Instance.PlaySound(Sound.SelectCompetence, Camera.main.transform.position);
            break;

        default:
            SoundManager.Instance.PlaySound(Sound.NotEnoughActionPoint, Camera.main.transform.position);
            break;
        }

        return(trySelectResult);
    }
コード例 #12
0
        /// <summary>
        /// Occurs when a multiple actions are matched to the route policy.
        /// </summary>
        /// <param name="context">The current <see cref="RouteContext">route context</see>.</param>
        /// <param name="selectionResult">The current <see cref="ActionSelectionResult">action selection result</see>.</param>
        /// <remarks>The default implementation always throws an <see cref="AmbiguousActionException"/>.</remarks>
        protected virtual void OnMultipleMatches(RouteContext context, ActionSelectionResult selectionResult)
        {
            Arg.NotNull(context, nameof(context));
            Arg.NotNull(selectionResult, nameof(selectionResult));

            var matchingActions = selectionResult.MatchingActions.OrderBy(kvp => kvp.Key).SelectMany(kvp => kvp.Value).Distinct();
            var actionNames     = Join(NewLine, matchingActions.Select(match => match.Action.DisplayName));

            Logger.AmbiguousActions(actionNames);

            var message = SR.ActionSelector_AmbiguousActions.FormatDefault(NewLine, actionNames);

            throw new AmbiguousActionException(message);
        }
コード例 #13
0
        RequestHandler ClientError(HttpContext httpContext, ActionSelectionResult selectionResult)
        {
            Contract.Requires(httpContext != null);
            Contract.Requires(selectionResult != null);

            const RequestHandler NotFound = default(RequestHandler);
            var candidates = selectionResult.CandidateActions.OrderBy(kvp => kvp.Key).SelectMany(kvp => kvp.Value).Distinct().ToArray();

            if (candidates.Length == 0)
            {
                return(NotFound);
            }

            var properties       = httpContext.ApiVersionProperties();
            var method           = httpContext.Request.Method;
            var requestUrl       = new Lazy <string>(httpContext.Request.GetDisplayUrl);
            var requestedVersion = properties.RawApiVersion;
            var parsedVersion    = properties.ApiVersion;
            var actionNames      = new Lazy <string>(() => Join(NewLine, candidates.Select(a => a.DisplayName)));
            var allowedMethods   = new Lazy <HashSet <string> >(() => AllowedMethodsFromCandidates(candidates));
            var apiVersions      = new Lazy <ApiVersionModel>(selectionResult.CandidateActions.SelectMany(l => l.Value.Select(a => a.GetProperty <ApiVersionModel>()).Where(m => m != null)).Aggregate);
            var handlerContext   = new RequestHandlerContext(ErrorResponseProvider, ApiVersionReporter, apiVersions);

            if (parsedVersion == null)
            {
                if (IsNullOrEmpty(requestedVersion))
                {
                    if (Options.AssumeDefaultVersionWhenUnspecified || candidates.Any(c => c.IsApiVersionNeutral()))
                    {
                        return(VersionNeutralUnmatched(handlerContext, requestUrl.Value, method, allowedMethods.Value, actionNames.Value));
                    }

                    return(UnspecifiedApiVersion(handlerContext, actionNames.Value));
                }
                else if (!TryParse(requestedVersion, out parsedVersion))
                {
                    return(MalformedApiVersion(handlerContext, requestUrl.Value, requestedVersion));
                }
            }
            else if (IsNullOrEmpty(requestedVersion))
            {
                return(VersionNeutralUnmatched(handlerContext, requestUrl.Value, method, allowedMethods.Value, actionNames.Value));
            }
            else
            {
                requestedVersion = parsedVersion.ToString();
            }

            return(Unmatched(handlerContext, requestUrl.Value, method, allowedMethods.Value, actionNames.Value, parsedVersion, requestedVersion));
        }
コード例 #14
0
        /// <summary>
        /// Occurs when a multiple actions are matched to the route policy.
        /// </summary>
        /// <param name="context">The current <see cref="RouteContext">route context</see>.</param>
        /// <param name="selectionResult">The current <see cref="ActionSelectionResult">action selection result</see>.</param>
        /// <remarks>The default implementation always throws an <see cref="AmbiguousActionException"/>.</remarks>
        protected virtual void OnMultipleMatches(RouteContext context, ActionSelectionResult selectionResult)
        {
            if (selectionResult == null)
            {
                throw new ArgumentNullException(nameof(selectionResult));
            }

            var actionNames = Join(NewLine, selectionResult.MatchingActions.Select(a => a.ExpandSignature()));

            Logger.AmbiguousActions(actionNames);

            var message = SR.ActionSelector_AmbiguousActions.FormatDefault(NewLine, actionNames);

            throw new AmbiguousActionException(message);
        }
コード例 #15
0
        /// <summary>
        /// Executes the API versioning route policy.
        /// </summary>
        /// <param name="context">The <see cref="RouteContext">route context</see> to evaluate against.</param>
        /// <param name="selectionResult">The <see cref="ActionSelectionResult">result</see> of action selection.</param>
        /// <returns>The <see cref="ActionDescriptor">action</see> conforming to the policy or <c>null</c>.</returns>
        public virtual ActionDescriptor Evaluate(RouteContext context, ActionSelectionResult selectionResult)
        {
            Arg.NotNull(context, nameof(context));
            Arg.NotNull(selectionResult, nameof(selectionResult));

            const ActionDescriptor NoMatch = default;

            switch (selectionResult.MatchingActions.Count)
            {
            case 0:
                OnUnmatched(context, selectionResult);
                return(NoMatch);

            case 1:
                return(OnSingleMatch(context, selectionResult));
            }

            OnMultipleMatches(context, selectionResult);
            return(NoMatch);
        }
コード例 #16
0
        /// <summary>
        /// Executes the API versioning route policy.
        /// </summary>
        /// <param name="context">The <see cref="RouteContext">route context</see> to evaluate against.</param>
        /// <param name="selectionResult">The <see cref="ActionSelectionResult">result</see> of action selection.</param>
        /// <returns>The <see cref="ActionDescriptor">action</see> conforming to the policy or <c>null</c>.</returns>
        public virtual ActionDescriptor?Evaluate(RouteContext context, ActionSelectionResult selectionResult)
        {
            if (selectionResult == null)
            {
                throw new ArgumentNullException(nameof(selectionResult));
            }

            const ActionDescriptor?NoMatch = default;

            switch (selectionResult.MatchingActions.Count)
            {
            case 0:
                OnUnmatched(context, selectionResult);
                return(NoMatch);

            case 1:
                return(OnSingleMatch(context, selectionResult));
            }

            OnMultipleMatches(context, selectionResult);
            return(NoMatch);
        }
コード例 #17
0
        RequestHandler ClientError(RouteContext context, ActionSelectionResult selectionResult)
        {
            Contract.Requires(context != null);
            Contract.Requires(selectionResult != null);

            const RequestHandler NotFound = default(RequestHandler);
            var candidates = selectionResult.CandidateActions.OrderBy(kvp => kvp.Key).SelectMany(kvp => kvp.Value).Distinct().ToArray();

            if (candidates.Length == 0)
            {
                return(NotFound);
            }

            var httpContext       = context.HttpContext;
            var properties        = httpContext.ApiVersionProperties();
            var code              = default(string);
            var requestedVersion  = default(string);
            var parsedVersion     = properties.ApiVersion;
            var actionNames       = new Lazy <string>(() => Join(NewLine, candidates.Select(a => a.DisplayName)));
            var allowedMethods    = new Lazy <HashSet <string> >(() => AllowedMethodsFromCandidates(candidates));
            var newRequestHandler = default(Func <IErrorResponseProvider, string, string, RequestHandler>);

            if (parsedVersion == null)
            {
                requestedVersion = properties.RawApiVersion;

                if (IsNullOrEmpty(requestedVersion))
                {
                    code = ApiVersionUnspecified;
                    Logger.ApiVersionUnspecified(actionNames.Value);
                    return(new BadRequestHandler(ErrorResponseProvider, code, SR.ApiVersionUnspecified));
                }
                else if (TryParse(requestedVersion, out parsedVersion))
                {
                    code = UnsupportedApiVersion;
                    Logger.ApiVersionUnmatched(parsedVersion, actionNames.Value);

                    if (allowedMethods.Value.Contains(httpContext.Request.Method))
                    {
                        newRequestHandler = (e, c, m) => new BadRequestHandler(e, c, m);
                    }
                    else
                    {
                        newRequestHandler = (e, c, m) => new MethodNotAllowedHandler(e, c, m, allowedMethods.Value.ToArray());
                    }
                }
                else
                {
                    code = InvalidApiVersion;
                    Logger.ApiVersionInvalid(requestedVersion);
                    newRequestHandler = (e, c, m) => new BadRequestHandler(e, c, m);
                }
            }
            else
            {
                requestedVersion = parsedVersion.ToString();
                code             = UnsupportedApiVersion;
                Logger.ApiVersionUnmatched(parsedVersion, actionNames.Value);

                if (allowedMethods.Value.Contains(httpContext.Request.Method))
                {
                    newRequestHandler = (e, c, m) => new BadRequestHandler(e, c, m);
                }
                else
                {
                    newRequestHandler = (e, c, m) => new MethodNotAllowedHandler(e, c, m, allowedMethods.Value.ToArray());
                }
            }

            var message = SR.VersionedResourceNotSupported.FormatDefault(httpContext.Request.GetDisplayUrl(), requestedVersion);

            return(newRequestHandler(ErrorResponseProvider, code, message));
        }
コード例 #18
0
 /// <summary>
 /// Occurs when a single action is matched to the route policy.
 /// </summary>
 /// <param name="context">The current <see cref="RouteContext">route context</see>.</param>
 /// <param name="selectionResult">The current <see cref="ActionSelectionResult">action selection result</see>.</param>
 /// <returns>The single, matching <see cref="ActionDescriptor">action</see> conforming to the policy.</returns>
 protected virtual ActionDescriptor OnSingleMatch(RouteContext context, ActionSelectionResult selectionResult)
 {
     Arg.NotNull(context, nameof(context));
     Arg.NotNull(selectionResult, nameof(selectionResult));
     return(selectionResult.BestMatch);
 }
コード例 #19
0
        RequestHandler ClientError(HttpContext httpContext, ActionSelectionResult selectionResult)
        {
            Contract.Requires(httpContext != null);
            Contract.Requires(selectionResult != null);

            const RequestHandler NotFound = default(RequestHandler);
            var candidates = selectionResult.CandidateActions.OrderBy(kvp => kvp.Key).SelectMany(kvp => kvp.Value).Distinct().ToArray();

            if (candidates.Length == 0)
            {
                return(NotFound);
            }

            var properties        = httpContext.ApiVersionProperties();
            var requestedVersion  = default(string);
            var parsedVersion     = properties.ApiVersion;
            var actionNames       = new Lazy <string>(() => Join(NewLine, candidates.Select(a => a.DisplayName)));
            var allowedMethods    = new Lazy <HashSet <string> >(() => AllowedMethodsFromCandidates(candidates));
            var newRequestHandler = default(Func <RequestHandlerContext, RequestHandler>);
            var apiVersions       = new Lazy <ApiVersionModel>(selectionResult.CandidateActions.SelectMany(l => l.Value.Select(a => a.GetProperty <ApiVersionModel>()).Where(m => m != null)).Aggregate);
            var handlerContext    = new RequestHandlerContext(ErrorResponseProvider, ApiVersionReporter, apiVersions);

            if (parsedVersion == null)
            {
                var versionNeutral = new Lazy <bool>(() => candidates.Any(c => c.IsApiVersionNeutral()));

                requestedVersion = properties.RawApiVersion;

                if (IsNullOrEmpty(requestedVersion) && !versionNeutral.Value)
                {
                    Logger.ApiVersionUnspecified(actionNames.Value);
                    handlerContext.Code    = ApiVersionUnspecified;
                    handlerContext.Message = SR.ApiVersionUnspecified;
                    return(new BadRequestHandler(handlerContext));
                }
                else if (TryParse(requestedVersion, out parsedVersion))
                {
                    Logger.ApiVersionUnmatched(parsedVersion, actionNames.Value);
                    handlerContext.Code = UnsupportedApiVersion;

                    if (allowedMethods.Value.Contains(httpContext.Request.Method))
                    {
                        newRequestHandler = c => new BadRequestHandler(c);
                    }
                    else
                    {
                        handlerContext.AllowedMethods = allowedMethods.Value.ToArray();
                        newRequestHandler             = c => new MethodNotAllowedHandler(c);
                    }
                }
                else if (versionNeutral.Value)
                {
                    Logger.ApiVersionUnspecified(actionNames.Value);
                    handlerContext.Code    = UnsupportedApiVersion;
                    handlerContext.Message = SR.VersionNeutralResourceNotSupported.FormatDefault(httpContext.Request.GetDisplayUrl());

                    if (allowedMethods.Value.Contains(httpContext.Request.Method))
                    {
                        return(new BadRequestHandler(handlerContext));
                    }

                    handlerContext.AllowedMethods = allowedMethods.Value.ToArray();
                    return(new MethodNotAllowedHandler(handlerContext));
                }
                else
                {
                    Logger.ApiVersionInvalid(requestedVersion);
                    handlerContext.Code = InvalidApiVersion;
                    newRequestHandler   = c => new BadRequestHandler(c);
                }
            }
            else
            {
                Logger.ApiVersionUnmatched(parsedVersion, actionNames.Value);
                requestedVersion    = parsedVersion.ToString();
                handlerContext.Code = UnsupportedApiVersion;

                if (allowedMethods.Value.Contains(httpContext.Request.Method))
                {
                    newRequestHandler = c => new BadRequestHandler(c);
                }
                else
                {
                    handlerContext.AllowedMethods = allowedMethods.Value.ToArray();
                    newRequestHandler             = c => new MethodNotAllowedHandler(c);
                }
            }

            handlerContext.Message = SR.VersionedResourceNotSupported.FormatDefault(httpContext.Request.GetDisplayUrl(), requestedVersion);
            return(newRequestHandler(handlerContext));
        }
コード例 #20
0
    public void SelectAction(ActionType actionType)
    {
        if (!GetPlayerCanAct)
        {
            return;
        }

        if (actionType == ActionType.None)
        {
            if (competencesUsabilityManager.IsPreparingCompetence)
            {
                CallUnselectActionEvent(competencesUsabilityManager.GetCurrentCompetenceType);
                competencesUsabilityManager.InterruptPreparation();
            }

            if (playerMovementsManager.IsWillingToMove)
            {
                CallUnselectActionEvent(ActionType.Move);
                playerMovementsManager.InterruptMovementPreparation();
            }
        }

        if (actionType == ActionType.Move)
        {
            if (competencesUsabilityManager.IsPreparingCompetence)
            {
                CallUnselectActionEvent(competencesUsabilityManager.GetCurrentCompetenceType);
                competencesUsabilityManager.InterruptPreparation();
            }

            if (!playerMovementsManager.IsWillingToMove)
            {
                if (currentActionPointsAmount == 0)
                {
                    Debug.Log("Not enough AP to move");
                    SoundManager.Instance.PlaySound(Sound.NotEnoughActionPoint, Camera.main.transform.position);
                    return;
                }

                SoundManager.Instance.PlaySound(Sound.SelectCompetence, Camera.main.transform.position);
                CallSelectActionEvent(ActionType.Move);
                playerMovementsManager.StartMovementPreparation(currentActionPointsAmount);
                SetActionPointsDebugTextVisibility(true);
            }
            else
            {
                CallUnselectActionEvent(ActionType.Move);
                playerMovementsManager.InterruptMovementPreparation();
                SetActionPointsDebugTextVisibility(false);
            }
        }
        else
        {
            ActionType previousActionType = competencesUsabilityManager.GetCurrentCompetenceType;

            if (playerMovementsManager.IsWillingToMove)
            {
                CallUnselectActionEvent(ActionType.Move);
                playerMovementsManager.InterruptMovementPreparation();
            }

            if (competencesUsabilityManager.IsPreparingCompetence)
            {
                CallUnselectActionEvent(previousActionType);
                competencesUsabilityManager.InterruptPreparation();
            }

            if (previousActionType != actionType)
            {
                ActionSelectionResult competenceSelectionResult = competencesUsabilityManager.TrySelectAction(currentActionPointsAmount, actionType);
                if (competenceSelectionResult == ActionSelectionResult.EnoughActionPoints)
                {
                    CallSelectActionEvent(actionType);
                }

                SetActionPointsDebugTextVisibility(competenceSelectionResult == ActionSelectionResult.EnoughActionPoints);
                UpdateActionPointsDebugTextAmount(competencesUsabilityManager.GetCurrentCompetenceCost());
            }
        }

        CheckForCompetencesUsability();
    }