Example #1
0
        public async Task <UserStateInfo> SetUserStateToGame(string userId, long gameId)
        {
            await Task.CompletedTask;

            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (gameId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(gameId));
            }

            UserStateInfo userStateInfo = await userStateInfoRepository.GetByUserId(userId);

            if (userStateInfo == null)
            {
                throw new ArgumentException(nameof(userId));
            }

            userStateInfo.UserState = Interface.UserState.Game;
            userStateInfo.RoomId    = default;
            userStateInfo.GameId    = gameId;
            UserStateInfo result = await userStateInfoRepository.Update(userStateInfo);

            await SendEntityChangedMessage(result);

            return(result);
        }
Example #2
0
        public async Task <IActionResult> GetOrCreate()
        {
            string        userId        = callContextService.UserId;
            UserStateInfo userStateInfo = await userStateInfoService.GetOrCreate(userId);

            return(new ObjectResult(userStateInfo));
        }
Example #3
0
        /// <summary>
        /// Activate/Deactivate a given user.
        /// </summary>
        /// <param name="userId">The user identifier, as returned by the user creation API or retrieved from the API to fetch users. To update the details for the token owner, UserId can be replaced by \&quot;me\&quot; without quotes.</param>
        /// <param name="userStateInfo"></param>
        /// <param name="xApiUser">The userId or email of API caller using the account or group token in the format &lt;b&gt;userid:{userId} OR email:{email}.&lt;/b&gt; If it is not specified, then the caller is inferred from the token.</param>
        /// <returns>UserStatusUpdateResponse</returns>
        public UserStatusUpdateResponse ModifyUserState(string userId, UserStateInfo userStateInfo, string xApiUser = null)
        {
            // verify the required parameter 'authorization' is set


            // verify the required parameter 'userId' is set
            if (userId == null)
            {
                throw new ApiException(400, "Missing required parameter 'userId' when calling ModifyUserState");
            }

            // verify the required parameter 'userStateInfo' is set
            if (userStateInfo == null)
            {
                throw new ApiException(400, "Missing required parameter 'userStateInfo' when calling ModifyUserState");
            }


            var path = "/users/{userId}/state";

            path = path.Replace("{format}", "json");
            path = path.Replace("{" + "userId" + "}", ApiClient.ParameterToString(userId));

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;


            if (xApiUser != null)
            {
                headerParams.Add("x-api-user", ApiClient.ParameterToString(xApiUser)); // header parameter
            }
            postBody = ApiClient.Serialize(userStateInfo);                             // http body (model) parameter

            // authentication setting, if any
            String[] authSettings = new String[] { };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling ModifyUserState: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling ModifyUserState: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((UserStatusUpdateResponse)ApiClient.Deserialize(response.Content, typeof(UserStatusUpdateResponse), response.Headers));
        }
Example #4
0
        public ServiceResult <UserStateInfo> Login(AuthParameterInfo parameter)
        {
            parameter.AppIp    = Context.Request.UserHostAddress;
            parameter.DeviceId = parameter.DeviceId ?? parameter.Ip;
            UserStateInfo state = UserAdapter.Login(parameter);

            if (state != null)
            {
                return(new ServiceResult <UserStateInfo>(state));
            }
            else
            {
                return(new ServiceResult <UserStateInfo>(ServiceState.InvalidUserCredentials));
            }
        }
Example #5
0
        public async Task <UserStateInfo> GetOrCreate(string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            UserStateInfo userStateInfo = await userStateInfoRepository.GetByUserId(userId);

            if (userStateInfo != null)
            {
                return(userStateInfo);
            }

            UserStateInfo newUserStateInfo = CreateNewUserStateInfo(userId);

            return(await userStateInfoRepository.Save(newUserStateInfo));
        }
Example #6
0
        public async Task <UserStateInfo> SetUserStateToWaiting(string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            UserStateInfo userStateInfo = await userStateInfoRepository.GetByUserId(userId);

            if (userStateInfo == null)
            {
                throw new ArgumentException(nameof(userId));
            }

            userStateInfo.UserState = Interface.UserState.Waiting;
            userStateInfo.RoomId    = default;
            userStateInfo.GameId    = default;
            UserStateInfo result = await userStateInfoRepository.Update(userStateInfo);

            await SendEntityChangedMessage(result);

            return(result);
        }
Example #7
0
 private async Task SendEntityChangedMessage(UserStateInfo userStateInfo)
 {
     await messageService.Publish(UserStateInfoChangedMessageTopic.Topic, null,
                                  new UserStateInfoChangedMessage(userStateInfo));
 }
Example #8
0
 /// <summary>
 /// This method drives the population of the web page from the stored data
 /// </summary>
 ActionResult MainApplicationHandler(UserStateInfo stateInfo, BasespaceActionInfo model)
 {
     return View("DisplayBasespaceData", model);
 }
Example #9
0
        /// <summary>
        /// A simple cache of information about each user. In a real application, this would be in 
        /// a real database
        /// </summary>
        UserStateInfo GetUserStateInfo(string userId)
        {
            Dictionary<string, UserStateInfo> stateCache;
            lock (typeof(HomeController))
            {
                stateCache = HttpRuntime.Cache.Get("user_cache") as Dictionary<string, UserStateInfo>;
                if (stateCache == null)
                {
                    stateCache = new Dictionary<string, UserStateInfo>();

                    HttpRuntime.Cache.Add("user_cache", stateCache, null,
                            System.Web.Caching.Cache.NoAbsoluteExpiration,
                            System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);
                }
            }
            lock (stateCache)
            {
                if (!stateCache.ContainsKey(userId))
                    stateCache[userId] = new UserStateInfo();
                return stateCache[userId];
            }
        }
Example #10
0
 public UserStateInfoChangedMessage(UserStateInfo userStateInfo)
 {
     UserStateInfo = userStateInfo;
 }