Example #1
0
        private void Execute(bool isPaused, string buttonKey, Action <bool> handler)
        {
            var hasAppToggled = appState.Pause(isPaused);

            controller.IsPaused = isPaused;

            if (!hasAppToggled)
            {
                return;
            }

            if (isPaused)
            {
                var data = new DialogueData
                {
                    Message         = localization.Get(TextKeys.PAUSE_TEXT),
                    BackgroundAlpha = 1f
                };

                if (!string.IsNullOrEmpty(buttonKey))
                {
                    var buttonText = localization.Get(buttonKey);
                    data.AddAction(buttonText, handler);
                }

                onShowDialogue.Dispatch(data);
            }
            else
            {
                onHideDialogue.Dispatch();
            }
        }
        /// <summary>
        /// Invoke the specified context.
        /// </summary>
        /// <returns>The ınvoke.</returns>
        /// <param name="context">Context.</param>
        public async Task Invoke(HttpContext context)
        {
            var originBody = context.Response.Body;

            var newBody = new MemoryStream();

            context.Response.Body = newBody;

            await _next(context);

            newBody.Seek(0, SeekOrigin.Begin);

            var json = new StreamReader(newBody).ReadToEnd();

            if (json.ToObject <Response <dynamic> >().Data == null)
            {
                json = new Response <dynamic>
                {
                    ResponseCode         = ResponseCode.NoContent,
                    FriendlyErrorMessage = _localization.Get("NoContent")
                }.ToJson();
            }

            context.Language();

            context.Response.Body = originBody;
            await context.Response.WriteAsync(json);
        }
        private void OnOk()
        {
            hotKeys.KeyActions = new Dictionary <string, Action>
            {
                { GetHotKey(TextKeys.YES), OnYes },
                { GetHotKey(TextKeys.NO), OnNo },
                { "left", OnYes },
                { "right", OnNo },
            };

            var question = localization.Get(TextKeys.MF_QUESTION);
            var yes      = localization.Get(TextKeys.YES);
            var no       = localization.Get(TextKeys.NO);

            mediated.ShowRound(question, yes, no);
            onFinishInitialRound.Dispatch();
            controller.RoundCreated();
        }
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="context">http上下文</param>
        /// <returns>任务</returns>
        public async Task InvokeAsync(HttpContext context)
        {
            var path = context.Request.Path.Value.ToLower();

            if (path.StartsWith(options.PfxApiPath))
            {
                var routeValue = context.Request.RouteValues;
                var routes     = routeValue.GetControllerAction();
                if (routes.IsNullOrLength0())
                {
                    await next(context);

                    return;
                }

                var routePermisses = reader.Reader();
                if (routePermisses.IsNullOrLength0())
                {
                    await next(context);

                    return;
                }

                var controllerConfig = routePermisses.Where(p => p.Controller == routes[0]).FirstOrDefault();
                if (controllerConfig == null)
                {
                    await next(context);

                    return;
                }
                if (controllerConfig.Disabled)
                {
                    var tempReturn = new BasicReturnInfo();
                    tempReturn.SetFailureMsg(localize.Get(CommonCodeDefine.DISABLED_ACCESS_CULTURE_KEY, "此功能已禁用"));
                    await WriteContent(context, tempReturn);

                    return;
                }
                if (controllerConfig.Actions.IsNullOrLength0())
                {
                    await next(context);

                    return;
                }

                var actionConfig = controllerConfig.Actions.Where(p => p.Action == routes[1]).FirstOrDefault();
                if (actionConfig == null)
                {
                    await next(context);

                    return;
                }
                if (actionConfig.Disabled)
                {
                    var tempReturn = new BasicReturnInfo();
                    tempReturn.SetFailureMsg(localize.Get(CommonCodeDefine.DISABLED_ACCESS_CULTURE_KEY, "此功能已禁用"));
                    await WriteContent(context, tempReturn);

                    return;
                }

                var basicReturn = new BasicReturnInfo();
                var isPer       = IsHavePermission(context, controllerConfig, actionConfig, basicReturn);
                if (basicReturn.Failure())
                {
                    await WriteContent(context, basicReturn);

                    return;
                }
                if (isPer)
                {
                    await next(context);
                }
                else
                {
                    await NotPermissionHandle(context);
                }
            }
            else
            {
                await next(context);
            }
        }
Example #5
0
 protected void InitView(string textKey)
 {
     mediated.Init(localization.Get(textKey));
 }