Example #1
0
        protected void Initialise(string connectionId, ActionEnum actionType, string gameId, string user, string parameters)
        {
            // Do any initialisation that is common to all user actions.

            // If there is any failure that only needs to be reported back to the player who attempted the action, notify
            // them by throwing a HubException with an appropriate message. The client treats a HubException as a deliberate
            // means of feeding back details of a mistake that does not affect the game state and the user can rectify.

            // The ProcessAction() method can use the same technique as long as the game state has not changed.

            G                = Game.FindOrCreateGame(gameId); // find our game or create a new one if required
            ActionType       = actionType;
            UserName         = user;
            Parameters       = parameters;
            PlayerIndex      = -1;
            ConnectionId     = connectionId;
            ResponseType     = ActionResponseTypeEnum.PlayerCentricGameState; // Default response type for actions
            ResponseAudience = ActionResponseAudienceEnum.AllPlayers;         // Default audience for action response

            if (G.IsRunningInTestMode())
            {
                ConnectionId = UserName; // Simulate a unique connection id as there won't be a separate connection for each player
            }

            // Ensure name is not blank
            if (this.UserName == "")
            {
                throw new HubException("You tried to " + ActionType.ToString().ToLower() + " but your user name was blank"); // client catches this as part of action method, i.e. no call to separate client method required
            }

            // Check that this connection is not being used by someone with a different user name
            Participant p = G.GetParticipantFromConnection(ConnectionId);

            if (p != null)
            {
                if (p.Name != this.UserName)
                {
                    // This connection is already being used by someone else
                    throw new HubException("You attempted to " + ActionType.ToString().ToLower() + " (as user " + this.UserName + ") from a connection that is already in use by " + p.Name); // client catches this as part of action method, i.e. no call to separate client method required
                }
            }

            // Check player has permission to trigger this action
            PlayerIndex = G.PlayerIndexFromName(user);
            if (!G.ActionIsAvailableToPlayer(ActionType, PlayerIndex))
            {
                throw new HubException("You attempted to " + ActionType.ToString().ToLower() + " (as user " + this.UserName + ") but this option is not available to you at this point"); // client catches this as part of action method, i.e. no call to separate client method required
            }

            if (p == null /* from above */ && PlayerIndex != -1 && G.Participants[PlayerIndex].IsLockedOutFollowingReplay == true)
            {
                // This is a new connection AND the player is currently locked out following a 'replay' action,
                // so do an implicit Rejoin by linking the new connection to the current player
                // (note the game will no longer be in test mode at this stage, so IsRunningInTestMode() will show false even though this is as a result of testing)
                G.Participants[PlayerIndex].NoteConnectionId(this.ConnectionId);
                G.Participants[PlayerIndex].IsLockedOutFollowingReplay = false;
                // Can continue processing the command now
            }
        }
Example #2
0
        public void GetPermissions_WhenActionTypeDependsOnIsBiddingLockedAndIsBiddingLockedIsTrue_ShouldIsEnabledAndIsVisibleIsEqualToFalse(
            ActionEnum action)
        {
            // Arrange
            this.property.IsBiddingLocked = true;

            // Act
            var smartSearchPermissions = this.sut.GetPermissions(this.callContext);

            // Assert
            var smartSearchPermission = smartSearchPermissions.First(x => x.Action == action);

            Assert.That(smartSearchPermission.IsVisible, Is.False, $"{action.ToString()} IsVisible is not correct");
            Assert.That(smartSearchPermission.IsEnabled, Is.False, $"{action.ToString()} IsEnabled is not correct ");
        }
 /**
  * <summary>Serializes the specified PDF file.</summary>
  * <param name="file">File to serialize.</param>
  * <param name="action">Generator.</param>
  * <param name="index">File index.</param>
  */
 private void Serialize(
     File file,
     ActionEnum action,
     int?index
     )
 {
     Serialize(
         file,
         GetType().Name + "_" + action.ToString() + (index.HasValue ? "." + index.Value : ""),
         null,
         action.ToString(),
         "managing document pages",
         action.ToString()
         );
 }
Example #4
0
        /// <summary>
        ///     角色行動
        /// </summary>
        /// <param name="input">要汁妹還是做啥來著</param>
        /// <returns>結果</returns>
        public async Task <bool> DoAction(ActionEnum input)
        {
            Console.WriteLine($"DoAction {input} Result:");
            var request = new HttpRequestMessage(HttpMethod.Post, "my-kirito/doaction")
            {
                Content = new StringContent($"{{\"action\":\"{input.ToString().ToLower()}{Const.DoActionVersion}\"}}",
                                            Encoding.UTF8,
                                            "application/json")
            };
            //var client = _clientFactory.CreateClient("kiritoAPI");
            // 送出行動請求
            var response = await _clientkiritoAPI.SendAsync(request);

            // 結果
            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                Console.WriteLine(result);
            }
            else
            {
                Console.WriteLine($"DoAction {response.StatusCode}");
            }

            return(response.IsSuccessStatusCode);
        }
Example #5
0
        GetPermission_WhenActionTypeDependsOnPropertyStatusIs5_ShouldIsEnabledEqualToFalseAndIsVisibleIsTrue(
            ActionEnum action)
        {
            // Arrange
            this.property.StatusId     = 5;
            this.callContext.IsPrivate = false;

            // Act
            var smartSearchPermissions = this.sut.GetPermissions(this.callContext);

            // Assert
            var permission = smartSearchPermissions.FirstOrDefault(x => x.Action == action);

            Assert.That(permission.IsEnabled, Is.False, $"{action.ToString()} IsEnable is not false");
            Assert.That(permission.IsVisible, Is.True, $"{action.ToString()} IsVisible is not true");
        }
Example #6
0
        private static void Init()
        {
            // 更新授權Token
            Console.WriteLine("[Required] Input your token:");
            string newInput;

            while (true)
            {
                newInput = Console.ReadLine();
                if (!string.IsNullOrWhiteSpace(newInput))
                {
                    _token = newInput;
                    Console.WriteLine($"Token is update to: {newInput}");
                    break;
                }

                Console.WriteLine("[Required] Input your token, know?");
            }

            // 更新預設動作
            Console.Write("[Optional] Input your action from:");
            foreach (var name in Enum.GetNames(typeof(ActionEnum)))
            {
                Console.Write($" {name} ");
            }
            Console.WriteLine();
            newInput = Console.ReadLine();
            if (!string.IsNullOrWhiteSpace(newInput))
            {
                _defaultAct = (ActionEnum)Enum.Parse(typeof(ActionEnum), newInput);
                Console.WriteLine($"Action is update to: {_defaultAct.ToString()}");
            }
        }
Example #7
0
        public XmlNode asXML(XmlDocument doc)
        {
            XmlElement element = doc.CreateElement("actionStruct");

            XMLUtil.addElementValue(doc, element, "action", action.ToString());
            XMLUtil.addElementValue(doc, element, "time", time.ToString());
            XMLUtil.addElementValue(doc, element, "intensity", intensity.ToString());
            return(element);
        }
Example #8
0
        public void GetPermissions_WhenActionTypeDependsOnCustomer_ShouldIsEnabledAndIsVisibleIsEqualToIsAuthorized(
            ActionEnum action, bool isAuthorized)
        {
            // Arrange
            this.permissionAuthorizer
            .IsAuthorized(Arg.Any <CallContext>(), Arg.Any <IList <PropertyUserPrivilege> >(), Arg.Any <int>())
            .Returns(isAuthorized);

            // Act
            var smartSearchPermissions = this.sut.GetPermissions(this.callContext);

            // Assert
            var smartSearchPermission = smartSearchPermissions.First(x => x.Action == action);

            Assert.That(smartSearchPermission.IsVisible, Is.EqualTo(isAuthorized),
                        $"{action.ToString()} IsVisible is not correct");
            Assert.That(smartSearchPermission.IsEnabled, Is.EqualTo(isAuthorized),
                        $"{action.ToString()} IsEnabled is not correct ");
        }
Example #9
0
        public async Task <ActionOutput> DoAction(ActionEnum input)
        {
            string act = string.Empty;

            switch (input)
            {
            case ActionEnum.H1:
                act = "1h";
                break;

            case ActionEnum.H2:
                act = "2h";
                break;

            case ActionEnum.H4:
                act = "4h";
                break;

            case ActionEnum.H8:
                act = "8h";
                break;

            case ActionEnum.FloorBonus:
                act = "floorBonus";
                break;

            default:
                act = input.ToString().ToLower() + Global.DoActionVersion;
                break;
            }
            var json = new ActionInput {
                Action = act
            };
            HttpContent contentPost = new StringContent(json.ToJsonString(), Encoding.UTF8, "application/json");
            var         response    = await Client.PostAsync("my-kirito/doaction", contentPost);

            Console.WriteLine("{0} {1} {2}", "開始行動", input.GetDescriptionText(), response.StatusCode);
            var content = response.Content;

            if (response.IsSuccessStatusCode)
            {
                var output = await content.ReadAsJsonAsync <ActionOutput>();

                Console.WriteLine(output.Message);
                if (output != null && output.Gained != null && output.Gained.Hp != null)
                {
                    await WriteJson(output.Gained, input);
                }
                return(output);
            }

            await OnErrorOccur(response.StatusCode, content, "行動", 1);

            return(null);
        }
        public void GetPermissionModel_WhenActionIsAlwaysVisibleAndEnable_ShouldPermissionTypeEqualToNoRestriction(ActionEnum actionType)
        {
            // Arrange
            this.permissionSettings.IsPrivate = false;
            this.permissionSettings.Action    = actionType;

            // Act
            var permission = this.sut.GetPermission(this.permissionSettings);

            // Assert
            Assert.That(permission, Is.InstanceOf <NoRestriction>(), $"{actionType.ToString()} action type is not NoRestriction type");
        }
        public void GetPermissionModel_WhenActionTypeIsRestricted_shouldPermissionTypeEqualToRestricted(ActionEnum actionType)
        {
            // Arrange
            this.permissionSettings.IsPrivate = true;
            this.permissionSettings.Action    = actionType;

            // Act
            var permission = this.sut.GetPermission(this.permissionSettings);

            // Assert
            Assert.That(permission, Is.InstanceOf <RestrictedPermission>(), $"{actionType.ToString()} action type is not RestrictedPermission type");
        }
Example #12
0
 void ISql.MultiAction(ActionEnum action, StringBuilder sb, Context dc)
 {
     if (action == ActionEnum.And)
     {
         Spacing(sb); sb.Append("&&"); Spacing(sb);
     }
     else if (action == ActionEnum.Or)
     {
         Spacing(sb); sb.Append("||"); Spacing(sb);
     }
     else
     {
         throw XConfig.EC.Exception(XConfig.EC._010, action.ToString());
     }
 }
Example #13
0
            /// <summary>
            ///     角色行動
            /// </summary>
            /// <param name="input">要汁妹還是做啥來著</param>
            /// <returns>結果</returns>
            public async Task <string> DoAction(ActionEnum input)
            {
                var request = new HttpRequestMessage(HttpMethod.Post, "my-kirito/doaction")
                {
                    Content = new StringContent($"{{\"action\":\"{input.ToString().ToLower()}\"}}", Encoding.UTF8,
                                                "application/json")
                };
                var client = _clientFactory.CreateClient("kiritoAPI");
                // 送出行動請求
                var response = await client.SendAsync(request);

                // 結果
                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsStringAsync());
                }
                return($"StatusCode: {response.StatusCode}");
            }
Example #14
0
        /****************************************************************************************************************/

        internal protected static void Action(ActionEnum action, StringBuilder sb, Context dc)
        {
            switch (action)
            {
            case ActionEnum.None:
            case ActionEnum.Insert:
            case ActionEnum.Update:
            case ActionEnum.Select:
            case ActionEnum.From:
            case ActionEnum.OrderBy:
                return;

            case ActionEnum.InnerJoin:
                Inner(sb); Spacing(sb); Join(sb);
                return;

            case ActionEnum.LeftJoin:
                Left(sb); Spacing(sb); Join(sb);
                return;

            case ActionEnum.On:
                On(sb);
                return;

            case ActionEnum.Where:
                Where(sb);
                return;

            case ActionEnum.And:
                Tab(sb); And(sb);
                return;

            case ActionEnum.Or:
                Tab(sb); Or(sb);
                return;

            default:
                throw XConfig.EC.Exception(XConfig.EC._014, action.ToString());
            }
        }
Example #15
0
        public async Task <ActionOutput> DoAction(ActionEnum input)
        {
            var json = new ActionInput {
                Action = input.ToString().ToLower() + Global.DoActionVersion
            };
            HttpContent contentPost = new StringContent(json.ToJsonString(), Encoding.UTF8, "application/json");
            var         response    = await Client.PostAsync("my-kirito/doaction", contentPost);

            Console.WriteLine("{0} {1} {2}", "開始行動", input.GetDescriptionText(), response.StatusCode);
            var content = response.Content;

            if (response.IsSuccessStatusCode)
            {
                var output = await content.ReadAsJsonAsync <ActionOutput>();

                Console.WriteLine(output.Message);
                return(output);
            }

            await OnErrorOccur(response.StatusCode, content, "行動", ConsoleColor.Yellow);

            return(null);
        }
Example #16
0
 /**
   <summary>Serializes the specified PDF file.</summary>
   <param name="file">File to serialize.</param>
   <param name="action">Generator.</param>
   <param name="index">File index.</param>
 */
 private void Serialize(
     File file,
     ActionEnum action,
     int? index
     )
 {
     Serialize(
     file,
     GetType().Name + "_" + action.ToString() + (index.HasValue ? "." + index.Value : ""),
     null,
     action.ToString(),
     "managing document pages",
     action.ToString()
     );
 }
        public void GetPermissionModel_WhenActionTypeHasBiddingLockedPermissionRule_ShouldPermissionRuleHasBiddingLockedPermissionRule(ActionEnum action)
        {
            // Arrange
            this.permissionSettings.Action = action;

            // Act
            var permissionModel = this.sut.GetPermission(this.permissionSettings);

            // Assert
            RestrictedPermission restrictedPermission = (RestrictedPermission)permissionModel;

            Assert.That(restrictedPermission.Rules, Has.Some.TypeOf <BiddingLockedPermissionRule>(), $"{action.ToString()} action type doesnt have BiddingLockedPermissionRule");
        }
        public void GetPermissionModel_WhenActionTypeIsRelatedWithPrivateProperty_ShouldHasPrivatePermissionRuleType(ActionEnum actionType)
        {
            // Arrange
            this.permissionSettings.Action = actionType;

            // Act
            var permission = this.sut.GetPermission(this.permissionSettings);

            // Assert
            RestrictedPermission restrictedPermission = (RestrictedPermission)permission;

            Assert.That(restrictedPermission.Rules, Has.Some.TypeOf <PrivatePermissionRule>(), $"{actionType.ToString()} action type doesnt have PermissionRuleModel");
        }
        public void GetPermissionModel_WhenActionTypeIsRelatedPropertyStatusRule_ShouldPermissionHasPropertyStatusRule(ActionEnum action)
        {
            // Arrange
            this.permissionSettings.Action = action;

            // Act
            var permission = this.sut.GetPermission(this.permissionSettings);

            // Assert
            RestrictedPermission restrictedPermission = (RestrictedPermission)permission;

            Assert.That(restrictedPermission.Rules, Has.Some.TypeOf <PropertyStatusPermissionRule>(), $"{action.ToString()} action type doesnt have RoomStatusPermissionRule");
        }
Example #20
0
        /// <summary>
        /// 获取请求API的URL路径
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        public static string GetRequestApiUrlPath(this ActionEnum action)
        {
            string filter = "Controller";
            var    desc   = action.ToEnumDiscription();

            if (desc.Contains(filter))
            {
                desc = desc.Replace(filter, "");
            }
            filter = " ";
            if (desc.Contains(filter))
            {
                desc = desc.Replace(filter, "");
            }
            return(string.Format("{0}/{1}/{2}", ConfigurationSettings.AppSettings["WebApiUrl"].ToString().Trim(), desc.Trim(), action.ToString().Trim()));
        }