public ActionResult SayStatus(string password, bool isOnline) { if (password != WebConstants.WebPassword) { return new ContentResult { Content = "password fail" } } ; var context = new UnityContext(); var status = context.UnityStatus.First(); if (status.Online == isOnline) { return new ContentResult { Content = "already know!" } } ; status.Online = isOnline; if (isOnline) { status.UpTime = WebConstants.GetCurrentTime(); } context.SaveChanges(); return(new ContentResult { Content = "successful" }); }
public ActionResult DeleteGamesByFilter(FormCollection collection) { var gameContext = new UnityContext(); var contextChanged = false; double minutesToDelete; if (double.TryParse(collection["Time"], out minutesToDelete)) { var timeToDeleteFrom = WebConstants.GetCurrentTime() - TimeSpan.FromMinutes(minutesToDelete); var gamesToDeleteByTime = gameContext.GameResults.Where(r => r.Time > timeToDeleteFrom).ToArray(); contextChanged = gamesToDeleteByTime.Length > 0; foreach (var game in gamesToDeleteByTime) { gameContext.GameResults.Remove(game); } } string tag = collection["Tag"]; string subtag = collection["Subtag"]; var gamesToDelete = string.IsNullOrEmpty(subtag) ? gameContext.GameResults.Where(r => r.Type == tag).ToArray() : gameContext.GameResults.Where(r => r.Type == tag && r.Subtype == subtag).ToArray(); contextChanged = contextChanged || gamesToDelete.Length > 0; foreach (var game in gamesToDelete) { gameContext.GameResults.Remove(game); } if (contextChanged) { gameContext.SaveChanges(); } return(View()); }
public ActionResult UnityStatus() { var context = new UnityContext(); var hourAgo = WebConstants.GetCurrentTime() - TimeSpan.FromHours(1); var lastHoursGames = context.GameResults.Where(r => r.Time > hourAgo); var gamesCount = lastHoursGames.Count(); var uniquePlayersCount = lastHoursGames.Select(r => r.LeftPlayerUserName) .Union(lastHoursGames.Select(r => r.RightPlayerUserName)) .Count(); var status = context.UnityStatus.First(); var model = new UnityStatistics { IsOnline = status.Online, GamePlayed = gamesCount, UniquePlayers = uniquePlayersCount, UpTime = status.Online ? status.UpTime : null }; return(PartialView("_UnityStatusPartial", model)); }
public void CreatetSignatureTable() { HtmlTableCell cell; CssPostfix = WebConstants.GetCssPostfix(Page.Theme); tbSignature.Rows.Clear(); tbSignature.SetTableStyle(CssPostfix); tbCtrl_Signature.SetTableControlStyle(CssPostfix); tbCtrl_Signature.Attributes["border"] = "1"; int count = 0; if (PersonList != null) { count = PersonList.Count; } HtmlTableRow trHeader = null; if (showHeader) { cell = new HtmlTableCell() { InnerHtml = HeaderText }; cell.SetHeaderCellStyle(CssPostfix); cell.Attributes["style"] = "text-align:center"; trHeader = new HtmlTableRow(); trHeader.SetRowStyle(CssPostfix); trHeader.Cells.Add(cell); tbSignature.Rows.Add(trHeader); } HtmlTableRow trSignature = new HtmlTableRow(); HtmlTableRow trPartyName = new HtmlTableRow(); HtmlTableRow trEffectivePeriod = null; HtmlTableRow trEditPerson = new HtmlTableRow(); trSignature.SetRowStyle(CssPostfix); trPartyName.SetRowStyle(CssPostfix); trEditPerson.SetRowStyle(CssPostfix); tbSignature.Rows.Add(trSignature); tbSignature.Rows.Add(trPartyName); tbSignature.Rows.Add(trEditPerson); if (count > 0) { ASPxBinaryImage signature; switch (DirectionAlign) { case TableDirection.Vertical: break; default: count = PersonList.Count; if (showHeaderLeft) { cell = new HtmlTableCell() { Align = "Center", InnerHtml = Resource_Person.Signature }; cell.SetHeaderCellStyle(CssPostfix); trSignature.Cells.Add(cell); cell = new HtmlTableCell() { Align = "Center", InnerHtml = Resource_Person.FullName }; cell.SetHeaderCellStyle(CssPostfix); trPartyName.Cells.Add(cell); // Edit Person Button cell = new HtmlTableCell() { Align = "Center", InnerHtml = "แก้ไขข้อมูล" }; cell.SetHeaderCellStyle(CssPostfix); trEditPerson.Cells.Add(cell); if (showEffective) { trEffectivePeriod = new HtmlTableRow(); cell = new HtmlTableCell(TH_TAGNAME) { Align = "Center", InnerHtml = Resource_Global.EffectivePeriod }; cell.SetHeaderCellStyle(CssPostfix); trEffectivePeriod.Cells.Add(cell); } } for (int i = 0; i < PersonList.Count; i++) { // Signature Row System.Drawing.Image sig = PersonList[i].GetSignature(DateTime.Now); cell = new HtmlTableCell() { ID = string.Format("sig{0}", i), Align = "Center" }; cell.SetDataCellStyle(); cell.NoWrap = true; trSignature.Cells.Add(cell); if (sig != null) { signature = new ASPxBinaryImage(); signature.ContentBytes = WebHelper.ImageUtil.ImageToBytes(sig); cell.Controls.Add(signature); } else { cell.InnerHtml = " "; } // Party Name Row cell = new HtmlTableCell() { ID = string.Format("signame{0}", i), Align = "Center" }; cell.SetDataCellStyle(); cell.NoWrap = true; cell.InnerHtml = PersonList[i].FullName; trPartyName.Cells.Add(cell); // Edit Person cell = new HtmlTableCell() { ID = string.Format("editPers{0}", i), Align = "Center" }; cell.SetDataCellStyle(); cell.NoWrap = true; editPerson = new ASPxButton() { AutoPostBack = false }; editPerson.SetEditButton(); editPerson.ClientInstanceName = this.ClientID + editPerson.ID; editPerson.ClientSideEvents.Click = @"function(s, e) { cbpEditPerson.PerformCallback('" + PersonList[i].PartyID + @"'); }"; cbpEditPerson.ClientSideEvents.EndCallback = @"function(s, e) { popupEditPerson.Show(); }" ; cell.Controls.Add(editPerson); trEditPerson.Cells.Add(cell); // Effective Period Row if (showEffective) { cell = new HtmlTableCell() { ID = string.Format("sigeff{0}", i), Align = "Center" }; cell.SetDataCellStyle(); cell.NoWrap = true; TimeInterval effectivePeriod = PersonList[i].EffectivePeriod; if (effectivePeriod != null) { cell.InnerHtml = PersonList[i].EffectivePeriod.ToString(base.DateOutputFormat, base.LanguageCode); } else { cell.InnerHtml = "N/A"; } trEffectivePeriod.Cells.Add(cell); } } break; } if (trEffectivePeriod != null) { trEffectivePeriod.SetRowStyle(CssPostfix); tbSignature.Rows.Add(trEffectivePeriod); } } else { HtmlTableRow trNoData = new HtmlTableRow(); trNoData.SetRowStyle(CssPostfix); cell = new HtmlTableCell() { ID = "sigNoData", Align = "Center", InnerHtml = "No Person Data" }; cell.SetDataCellStyle(); trNoData.Cells.Add(cell); tbSignature.Rows.Add(trNoData); } if (trHeader != null) { if (trPartyName.Cells.Count > 1) { trHeader.Cells[0].ColSpan = trPartyName.Cells.Count; } } }
public ActionResult PushResult(GameResultInfo result) { if (result.PushPassword != WebConstants.WebPassword) { return new ContentResult { Content = "Password fail" } } ; var context = new UnityContext(); var users = context.UserProfiles.ToArray(); var tags = users.Select(u => u.CvarcTag).ToArray(); if (result.Players.Length == 2) { if (!tags.Contains(result.Players[0].CvarcTag) || !tags.Contains(result.Players[1].CvarcTag)) { return new ContentResult { Content = "tag fail" } } ; context.GameResults.Add(new GameResults { Time = WebConstants.GetCurrentTime(), LeftPlayerUserName = users.First(u => u.CvarcTag == result.Players[0].CvarcTag).UserName, RightPlayerUserName = users.First(u => u.CvarcTag == result.Players[1].CvarcTag).UserName, LeftPlayerScores = result.Players[0].Score, RightPlayerScores = result.Players[1].Score, LogFileName = result.LogFileName, Type = result.Tag, Subtype = result.Subtag }); context.SaveChanges(); return(new ContentResult { Content = "successful" }); } var player = result.Players[0]; if (!tags.Contains(player.CvarcTag)) { return new ContentResult { Content = "tag fail" } } ; context.GameResults.Add(new GameResults { Time = WebConstants.GetCurrentTime(), LeftPlayerUserName = users.First(u => u.CvarcTag == player.CvarcTag).UserName, LeftPlayerScores = player.Score, LogFileName = result.LogFileName, Type = result.Tag, Subtype = result.Subtag }); context.SaveChanges(); return(new ContentResult { Content = "successful" }); }
public ActionResult UploadSolution(SimpleFileView simpleFileView) { if (!Directory.Exists(WebConstants.BasePath + WebConstants.RelativeSolutionsPath)) { Directory.CreateDirectory(WebConstants.BasePath + WebConstants.RelativeSolutionsPath); } if (simpleFileView.UploadedFile == null) { ViewBag.Message = "Ошибка: Выберете файл для загрузки!"; return(View(simpleFileView)); } if (simpleFileView.UploadedFile.ContentLength > 7 * 512 * 1024) // 3.5 MB { ViewBag.Message = "Ошибка: Файл слишком большой! Максимальный размер 3.5 МБ. Попробуйте удалить все бинарные файлы из архива."; return(View(simpleFileView)); } var path = WebConstants.BasePath + WebConstants.RelativeSolutionsPath; var extention = simpleFileView.UploadedFile.FileName.Split('.').Last(); if (extention != "zip") { ViewBag.Message = "Ошибка: вы должны предоставить архив с решением в формате *.zip"; return(View(simpleFileView)); } var expectedFileName = User.Identity.Name + "." + extention; simpleFileView.UploadedFile.SaveAs(path + expectedFileName); var context = new UnityContext(); context.UserProfiles.First(u => u.UserName == User.Identity.Name).SolutionLoaded = WebConstants.GetCurrentTime(); context.SaveChanges(); ViewBag.Message = "Решение было загружено успешно!"; return(View(simpleFileView)); }
protected override void OnInit(EventArgs e) { base.OnInit(e); Page.RegisterRequiresControlState(this); this.CssPostfix = WebConstants.GetCssPostfix(Page.Theme); }