public ActionResult ProcessTournamentFile(int tournamentFileId) { if (!(isAdmin || isMod)) { var notAdminJson = new { response = "Unauthorized" }; return(Json(notAdminJson)); } TioParser tioParser; try { tioParser = new TioParser(tournamentFileId); } catch (FileAlreadyParsedException e) { var errorJson = new { response = "Already parsed" }; return(Json(errorJson)); } catch (Exception) { var errorJson = new { response = "Something went wrong. Please try again later." }; return(Json(errorJson)); } tioParser.ParseTournament(); var json = new { response = "Success!" }; return(Json(json)); }
public ActionResult TioFile(string tournamentGuid) { CultureInfo toCi = new CultureInfo("en-us"); if (Request["cultureCode"] != null) { try { toCi = new CultureInfo(Request["cultureCode"]); } catch (CultureNotFoundException e) { } } var tournamentFile = (from tf in db.TournamentFiles where tf.TournamentGuid.Equals(new Guid(tournamentGuid)) select tf).FirstOrDefault(); if (tournamentFile == null) { return(null); } XDocument safeXML = TioParser.getReadableXML(tournamentFile.XML); string returnXML = setDatesForTimeZoneInXML(safeXML, toCi); byte[] xmlBytes = System.Text.Encoding.UTF8.GetBytes(returnXML); FileContentResult outFile = File(xmlBytes, "text/xml"); outFile.FileDownloadName = tournamentFile.OriginalFileName; return(outFile); }
private void processFileAndElo(int tournamentFileId) { TioParser tioparser = new TioParser(tournamentFileId); try { int tournamentId = tioparser.ParseTournament(); ELOProcessor eloProcessor = new ELOProcessor(); eloProcessor.adjustEloScoresForTournament(tournamentId); } catch (Exception) { return; } }
public ActionResult SeedTournament(HttpPostedFileBase file) { if (file == null || file.ContentLength == 0) { ViewBag.UploadMessage = "Please select a file for upload."; return(View("Index")); } string xml; using (StreamReader sr = new StreamReader(file.InputStream)) { xml = sr.ReadToEnd(); } XmlDocument doc = new XmlDocument(); try { doc.LoadXml(xml); } catch { ViewBag.UploadMessage = "Error: The TIO file you uploaded was not well-formed xml."; return(View("Index")); } TioParser tioParser = new TioParser(xml); XDocument returnXML; if (Request["bracketType"].Equals("pools")) { returnXML = tioParser.SeedTournamentForPools(); } else { returnXML = tioParser.SeedTournamentForBracket(); } byte[] xmlBytes = System.Text.Encoding.UTF8.GetBytes(returnXML.ToString()); FileContentResult outFile = File(xmlBytes, "text/xml"); outFile.FileDownloadName = file.FileName; return(outFile); }