public DissidiaModule(IBootstrapInjection injection) { Get[EndpointConfigurationEnum.GET_CHARACTERS] = p => { return(Response.AsJson(CharEnum.ToList())); }; Get["email"] = p => { injection.Services.Team.InvitePlayer("*****@*****.**", "teste"); return(""); }; }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { base.ApplicationStartup(container, pipelines); pipelines.BeforeRequest.AddItemToEndOfPipeline(ctx => { #if DEBUG #else /* * try * { * if (!(ctx.Request.Url.ToString().Contains("/login.html") || * ctx.Request.Url.ToString().Contains("dissidia/login") || * ctx.Request.Url.ToString().Contains("/canAccess") || * ctx.Request.Url.ToString().Contains("dissidia/user/register")) * ) * { * var logged = Convert.ToBoolean(ctx.Request.Session["logged"]); * if (logged) * { * return null; * } * } * } * catch (Exception) * { * return new RedirectResponse("http://*****:*****@"C:\temp\OCR\Dissidia", @"C:\Users\leonardo.kobus\Desktop\lobby\input"), "http://localhost", @"C:\temp\dissidia\tokenDir"); var i = new BoostrapInjection(configurationGlobal); i.Services.RegisterAuthentication(new AuthenticationService(i.Repositories.User)); Injection = i; container.Register <IBootstrapInjection, BoostrapInjection>(i); }
public static void RepairNames(IBootstrapInjection injection) { var allMAtches = injection.Repositories.Match.GetAll(); var allNames = allMAtches.Select(p => p.PlayersTeamWinner.Select(n => n.Name).Concat(p.PlayersTeamLooser.Select(n => n.Name))); IEnumerable <string> result = new List <string>(); foreach (var teamNAme in allNames) { result = result.Concat(teamNAme); } var distinctNames = result.DistinctBy(p => p); var playerDicts = GetPlayersDict(); var newMatches = new List <Match>(); allMAtches.ForEach(m => { _passou = false; var winners = new List <PlayerInfo>(); var loosers = new List <PlayerInfo>(); m.PlayersTeamWinner.ForEach(p => winners.Add(CorrectPlayerInfo(playerDicts, p))); m.PlayersTeamLooser.ForEach(p => loosers.Add(CorrectPlayerInfo(playerDicts, p))); if (_passou) { newMatches.Add(Match.Factory.From(m) .WithWinners(winners) .WithLoosers(loosers) .Instance); } }); newMatches.ForEach(m => { injection.Repositories.Match.Upsert(m); }); var oi = ""; }
public PontuationModule(IBootstrapInjection injection) { _playerPontuation = injection.Services.PlayerPontuation; Get[EndpointConfigurationEnum.GET_PLAYER_PONTUATION] = p => { var result = _playerPontuation.GetPlayersPontuations().Select(c => new PlayerPontuationDTO(c)) .OrderByDescending(c => c.TotalMatches) .ToList(); return(Response.AsJson(result)); }; Get[EndpointConfigurationEnum.GET_SOLO_TEAM_PONTUATION] = p => { int view = Convert.ToInt32(p.view.Value); int minMatches = Convert.ToInt32(p.minMatches.Value); var result = _playerPontuation.GetSoloTeamsPontuations(minMatches, view).Select(c => new PlayerPontuationDTO(c)) .OrderByDescending(c => c.TotalMatches) .ToList(); return(Response.AsJson(result)); }; Get[EndpointConfigurationEnum.GET_POSITION_PONTUATION] = p => { var id = p.id.Value.ToString(); var pontuation = injection.Services.PlayerPontuation.GetPlayerPositionPontuation(id); return(Response.AsJson(new PositionDTO(pontuation))); }; Get[EndpointConfigurationEnum.GET_DUO_TEAM_PONTUATION] = p => { int view = Convert.ToInt32(p.view.Value); int minMatches = Convert.ToInt32(p.minMatches.Value); var result = _playerPontuation.GetSoloBestDuosPontuation(minMatches, view).Select(c => new PlayerPontuationDTO(c)) .OrderByDescending(c => c.TotalMatches) .ToList(); return(Response.AsJson(result)); }; Get[EndpointConfigurationEnum.GET_PLAYER_PONTUATION_BY_ID] = p => { var id = p.userId; List <PlayerPontuationDTO> result = new List <PlayerPontuationDTO>(); List <ScorePontuation> oi = _playerPontuation.GetPlayerInfo(id); return(Response.AsJson(oi.Select(c => new PlayerPontuationDTO(c)).ToList())); }; Get[EndpointConfigurationEnum.GET_PLAYER_PONTUATION_BY_ID_AND_DATE] = p => { var id = p.userId; DateTime from = DateTime.ParseExact(p.from, "dd-MM-yyyy", CultureInfo.InvariantCulture); DateTime until = DateTime.ParseExact(p.until, "dd-MM-yyyy", CultureInfo.InvariantCulture); List <PlayerPontuationDTO> result = new List <PlayerPontuationDTO>(); List <ScorePontuation> oi = _playerPontuation.GetPlayerInfo(id, from, until); return(Response.AsJson(oi.Select(c => new PlayerPontuationDTO(c)).ToList())); }; Get[EndpointConfigurationEnum.GET_PLAYER_LINE_GRAPH] = p => { var id = p.userId; int type = 0; int.TryParse(p.typ.Value, out type); int period = 0; int.TryParse(p.period.Value, out period); LineGraph result = _playerPontuation.GetLineGraph(id, period, type); return(Response.AsJson(result)); }; }
public TeamModule(IBootstrapInjection injection) { _teamService = injection.Services.Team; _teamPontuationService = injection.Services.TeamPontuation; Get[EndpointConfigurationEnum.GET_TEAM] = p => { var teamId = p.teamId; return(Response.AsJson(new TeamDTO(_teamService.GetTeam(teamId)))); }; Post[EndpointConfigurationEnum.JOIN_TEAM] = p => { var token = p.token; var userId = p.userId; var teamid = p.teamId; _teamService.JoinTeam(userId, token, teamid); return(HttpStatusCode.OK); }; Get[EndpointConfigurationEnum.GET_TEAM_USER] = p => { var team = _teamService.GetTeamFromUser(p.userId); if (team == null) { return(HttpStatusCode.NotFound); } return(Response.AsJson(new TeamDTO(team))); }; Put[EndpointConfigurationEnum.GET_IMAGE_TEAM] = p => { var contentTypeRegex = new Regex("^multipart/form-data;\\s*boundary=(.*)$", RegexOptions.IgnoreCase); var boundary = contentTypeRegex.Match(Request.Headers.ContentType).Groups[1].Value; var multipart = new HttpMultipart(this.Request.Body, boundary); var bodyStream = multipart.GetBoundaries().First(b => b.Name == "image").Value; var teamId = p.teamId; _teamService.SubmitTeamImage(teamId, bodyStream); return(HttpStatusCode.OK); }; Get[EndpointConfigurationEnum.GET_IMAGE_TEAM] = p => { try { Stream imagem = _teamService.GetImage(p.teamId); if (imagem == null) { throw new ArgumentException("Não existe"); } return(Response.FromStream(imagem, "image/jpg")); } catch (ArgumentException) { return(HttpStatusCode.NotFound); } catch (Exception) { return(HttpStatusCode.InternalServerError); } }; Post[EndpointConfigurationEnum.CREATE_TEAM] = p => { try { var founderId = p.founderId.Value; var dto = JsonConvert.DeserializeObject <TeamDTO>(Request.Body.AsString()); _teamService.CreateTeam(founderId, dto.Id, dto.Alias); dto.Members.Where(c => c.Contains("@")).ToList() .ForEach(c => _teamService.InvitePlayer(c, dto.Id)); return(HttpStatusCode.OK); } catch (TeamAlreadyExistException ex) { return(Response.AsJson(new GenericErrorDTO(ex))); } catch (Exception ex) { return(Response.AsJson(new GenericErrorDTO(ex))); } }; Put[EndpointConfigurationEnum.INVITE_PLAYER_TEAM] = p => { if (p.email.ToString().Contains("@")) { _teamService.InvitePlayer(p.email.ToString(), p.teamId.ToString()); return(HttpStatusCode.Accepted); } else { return(HttpStatusCode.NotAcceptable); } }; Get[EndpointConfigurationEnum.GET_TEAM_PONTUATIONS] = p => { string id = p.teamId.ToString(); var result = _teamPontuationService.GetTeamPontuations(id).Select(c => new PlayerPontuationDTO(c)).ToList(); return(Response.AsJson(result)); }; }
public MatchModule(IBootstrapInjection injection) { JsonSettings.MaxJsonLength = int.MaxValue; _matcheService = injection.Services.Match; _matchRepository = injection.Repositories.Match; Get[EndpointConfigurationEnum.GET_ALL_MATCHES] = p => { var dtos = _matcheService.GetAll() .Select(m => new MatchDTO(m)); return(Response.AsJson(dtos)); }; Get[EndpointConfigurationEnum.GET_ALL_MATCHES] = p => { var dtos = _matcheService.GetAll() .Select(m => new MatchDTO(m)); return(Response.AsJson(dtos)); }; Get[EndpointConfigurationEnum.GET_IMAGE_MATCH] = p => { try { Stream imagem = _matcheService.GetImage(p.id); if (imagem == null) { throw new ArgumentException("Não existe"); } return(Response.FromStream(imagem, "image/jpg")); } catch (ArgumentException) { return(HttpStatusCode.NotFound); } catch (Exception) { return(HttpStatusCode.InternalServerError); } }; Get[EndpointConfigurationEnum.GET_MATCH] = p => { var match = _matcheService.GetMatch(p.id); return(Response.AsJson(new MatchDTO(match))); }; Put[EndpointConfigurationEnum.CHANGE_MATCH] = p => { var matchId = p.id; var userId = p.userId; var match = JsonConvert.DeserializeObject <MatchDTO>(Request.Body.AsString()); _matcheService.UpdateMatch(match.PlayersTeamWinner, match.PlayersTeamLooser, userId, matchId); return(HttpStatusCode.Accepted); }; Post[EndpointConfigurationEnum.UPLOAD_MATCH, true] = async(x, p) => { var bodyStream = GetImageBodyStream(); int type = Convert.ToInt32(x.matchType.Value); await _matcheService.RegisterMatchAsync(bodyStream, (MatchTypeEnum)type); return(HttpStatusCode.OK); }; Post[EndpointConfigurationEnum.UPLOAD_MATCH_DETAILS] = x => { var bodyStream = GetImageBodyStream(); int type = Convert.ToInt32(x.matchType.Value); string dateStr = x.dateTime.ToString(); DateTime date = DateTime.ParseExact(dateStr, "yyyy-MM-dd_HH-mm-ss", CultureInfo.InvariantCulture); var t = _matcheService.RegisterMatchAsync(bodyStream, (MatchTypeEnum)type, date); t.Wait(); return(HttpStatusCode.OK); }; Get["Import"] = p => { var toImport = JsonConvert.DeserializeObject <List <MatchDTO> >( System.IO.File.ReadAllText( @"C:\users\leonardo.kobus\desktop\matches.txt")); toImport.ForEach(m => { try { var file = GetImageFile(m.Date.AddHours(-3)); var result = Domain.Entities.Match.Factory.FromDTO( m.Id, m.Date, m.PlayersTeamWinner, m.PlayersTeamLooser, m.Status, m.Winners, m.Loosers, file, MatchTypeEnum.SOLO ); _matchRepository.Upsert(result.Instance); } catch (Exception ex) { var ops = ""; } }); return("ok"); }; }
public AuthenticationModule(IBootstrapInjection injection) { _authService = injection.Services.Authentication; #region utilities Get["JustdoIt"] = p => { HelperService.RepairNames(injection); return(""); }; Get["Repair"] = p => { var ms = injection.Repositories.Match.GetAll(); var toRelace = new List <Match>(); var toEnter = true; foreach (var m in ms) { if (m.Id == "5bb4556acab1201a6c6c954a") { toEnter = false; } if (!toEnter) { toRelace.Add(m); } if (m.Id == "5bb48214cab1201a6c6c97c3") { break; } } var i = 0; Parallel.ForEach(toRelace, m => { i++; injection.Services.Match.UpdateMatch(m.PlayersTeamWinner, m.PlayersTeamLooser, "Barreto", m.Id); }); var parou = ""; return("ok"); }; Get["MatchDate"] = p => { var options = new ParallelOptions(); options.MaxDegreeOfParallelism = 20; var regex = new System.Text.RegularExpressions.Regex(@"\d{4}:\d{2}:\d{2} \d{2}:\d{2}:\d{2}"); Parallel.ForEach( System.IO.Directory.GetFiles("C:\\temp\\match") .ToList(), options, f => { try { var date = DateTime.ParseExact(regex.Match(System.IO.File.ReadAllText(f)).Value, "yyyy:MM:dd HH:mm:ss", CultureInfo.InvariantCulture); var id = new FileInfo(f).Name.Split('.')[0]; injection.Repositories.Match.Upsert( Match.Factory.From(injection.Repositories.Match.GetById(id)) .WithDate(date) .Instance); } catch (Exception) { var cagou = ""; } }); return("ok"); }; #endregion Post[EndpointConfigurationEnum.LOGIN] = p => { var body = Request.Body.AsString(); var auth = JsonConvert.DeserializeObject <AuthDTO>(body); string id; if (_authService.AuthUser(auth.Username, auth.Password)) { id = _authService.GetUserIdByUsername(auth.Username); Request.Cookies["logged"] = "true"; } else { return(HttpStatusCode.Unauthorized); } return(Response.AsJson(id, HttpStatusCode.Accepted)); }; Post[EndpointConfigurationEnum.REGISTER_USER] = p => { try { var userRegister = JsonConvert.DeserializeObject <UserRegisterDTO>(Request.Body.AsString()); _authService.RegisterUser(userRegister.Username, userRegister.Password, userRegister.Email); return(HttpStatusCode.Created); } catch (UserAlreadyExistException ex) { return("User already exist"); } catch (Exception) { return("whoooops."); } }; Put[EndpointConfigurationEnum.GET_IMAGE_USER] = p => { var contentTypeRegex = new System.Text.RegularExpressions.Regex("^multipart/form-data;\\s*boundary=(.*)$", System.Text.RegularExpressions.RegexOptions.IgnoreCase); var boundary = contentTypeRegex.Match(Request.Headers.ContentType).Groups[1].Value; var multipart = new HttpMultipart(this.Request.Body, boundary); var bodyStream = multipart.GetBoundaries().First(b => b.Name == "image").Value; var teamId = p.userId; _authService.SubmitUserImage(teamId, bodyStream); return(HttpStatusCode.OK); }; Get[EndpointConfigurationEnum.GET_IMAGE_USER_BY_NICK] = p => { try { Stream imagem = _authService.GetImageFromNick(p.nickname); if (imagem == null) { throw new ArgumentException("Não existe"); } return(Response.FromStream(imagem, "image/jpg")); } catch (ArgumentException) { return(HttpStatusCode.NotFound); } catch (Exception) { return(HttpStatusCode.InternalServerError); } }; Get[EndpointConfigurationEnum.GET_IMAGE_USER] = p => { try { Stream imagem = _authService.GetImage(p.userId); if (imagem == null) { throw new ArgumentException("Não existe"); } return(Response.FromStream(imagem, "image/jpg")); } catch (ArgumentException) { return(HttpStatusCode.NotFound); } catch (Exception) { return(HttpStatusCode.InternalServerError); } }; Get["oi"] = p => { return(Thread.CurrentThread.ManagedThreadId); }; Get[EndpointConfigurationEnum.GET_NICKS_BY_ID] = p => { string result = _authService.GetNicknameById(p.userId.ToString()); return(Response.AsJson(result)); }; }