/// <summary> /// Registers the user into the database /// </summary> /// <param name="user">Required registration info.</param> /// <returns>The user's user token.</returns> public UserInfo Register(RegisterInfo user, out HttpStatusCode status) { if (user.Nickname == null || user.Nickname.Trim().Length == 0) { SetStatus(Forbidden, out status); return(null); } UserInfo t = new UserInfo(); t.UserToken = Guid.NewGuid().ToString(); users.TryAdd(t.UserToken, user.Nickname); SetStatus(Created, out status); return(t); }
/// <summary> /// Registers the user into the database /// </summary> /// <param name="user">Required registration info.</param> /// <returns>The user's user token.</returns> public UserInfo Register(RegisterInfo user) { if (user.Nickname == null || user.Nickname.Trim().Length == 0) { SetStatus(Forbidden); return(null); } UserInfo t = new UserInfo(); t.UserToken = Guid.NewGuid().ToString(); Console.WriteLine(t.UserToken); users.TryAdd(t.UserToken, user.Nickname); SetStatus(Created); return(t); }
/// <summary> /// receive the data from the http which seted by the users /// choose the right arguemnet and work on it /// </summary> /// <param name="httpRequestData"></param> /// <param name="status"></param> /// <returns></returns> private dynamic RunServiceMethod(dynamic httpRequestData, out HttpStatusCode status) { dynamic infoOut = null; status = HttpStatusCode.NotFound; // find the right arguement and do it switch ((string)httpRequestData.serviceMethod) { case "POST": switch ((string)httpRequestData.directory) { case "users": RegisterInfo registerInfoIn = JsonConvert.DeserializeObject <RegisterInfo>(httpRequestData.contentIn); infoOut = Register(registerInfoIn, out status); break; case "games": JoinInfo joinInfoIn = JsonConvert.DeserializeObject <JoinInfo>(httpRequestData.contentIn); infoOut = Join(joinInfoIn, out status); break; default: break; } break; case "PUT": switch ((string)httpRequestData.directory) { case "games": if (Regex.IsMatch((string)httpRequestData.parameters, @"^.+$")) { PlayInfo playInfoIn = JsonConvert.DeserializeObject <PlayInfo>(httpRequestData.contentIn); infoOut = PlayWord((string)httpRequestData.parameters, playInfoIn, out status); } else if (Regex.IsMatch((string)httpRequestData.parameters, @"^$")) { UserInfo userInfoIn = JsonConvert.DeserializeObject <UserInfo>(httpRequestData.contentIn); CancelJoin(userInfoIn, out status); } break; default: break; } break; case "GET": switch ((string)httpRequestData.directory) { case "games": if (Regex.IsMatch((string)httpRequestData.parameters, @"^.+(\?)(brief|Brief)(=)(yes|no)$")) { string[] theParameters = httpRequestData.parameters.Split('?'); infoOut = GameStatus(theParameters[0], theParameters[1].Split('=')[1], out status); } else if (Regex.IsMatch((string)httpRequestData.parameters, @"^.+$")) { infoOut = GameStatus(httpRequestData.parameters, null, out status); } break; default: break; } break; default: break; } return(infoOut); }