static IEnumerable <Step> MemoryChecker(BasketballContext context) { while (!context.Pull.IsFinishing) { Process process = Process.GetCurrentProcess(); Logger.AddMessage("Process: {0}", ProcessInfoToString(process, context)); yield return(new WaitStep(TimeSpan.FromMinutes(5))); } }
static string ProcessInfoToString(Process process, BasketballContext context) { //PerformanceCounter counter = new PerformanceCounter("ASP.NET Applications", "Sessions Active", "__Total__"); //PerformanceCounter counter = new PerformanceCounter("ASP.NET", "Application Restarts"); return(string.Format( "id = {0} cpu = {1}, session = {2}, work = {3}mb, virtual = {4}mb, requests = {5}, topics = {6}, forum = {7}", process.Id, process.UserProcessorTime, HWebApiSynchronizeHandler.Frames.Count, process.WorkingSet64 / 1000000, process.VirtualMemorySize64 / 1000000, requestCount, context.NewsStorages.TopicCount, context.Forum.TopicsStorages.TopicCount )); }
private void LoginButton_Click(object sender, EventArgs e) { if (loginTextBox.TextLength > 0 && passwordTextBox.TextLength > 0) { bool flag = false; using (BasketballContext db = new BasketballContext()) { if (teamRadioButton.Checked) { var teams = db.Team.ToList(); foreach (var t in teams) { if (t.Login == loginTextBox.Text && t.Password == passwordTextBox.Text) { TeamForm tF = new TeamForm(t.Id); tF.ShowDialog(); flag = true; Hide(); break; } } } else if (judgeRadioButton.Checked) { var judges = db.Judge.ToList(); foreach (var j in judges) { if (j.Login == loginTextBox.Text && j.Password == passwordTextBox.Text) { JudgeForm jF = new JudgeForm(j.Id); jF.ShowDialog(); flag = true; Hide(); break; } } } } if (flag) { Close(); } else { MessageBox.Show("Неверный логин или пароль"); } } else { MessageBox.Show("Данные введены некорректно"); } }
private void RequestButton_Click(object sender, EventArgs e) { if (requestComboBox.SelectedIndex == -1) { MessageBox.Show("Выберите соревнование"); } else { using (BasketballContext db = new BasketballContext()) { bool flag = true; var requests = db.Request.ToList(); foreach (var r in requests) { if (r.TeamId == id && r.CompetitionId == requestCompIds[requestComboBox.SelectedIndex]) { flag = false; break; } } if (flag) { int ind = requestCompIds[requestComboBox.SelectedIndex]; if (db.Request.Count(r => r.CompetitionId == ind) < 8) { Request req = new Request { CompetitionId = ind, TeamId = id }; db.Request.Add(req); db.SaveChanges(); MessageBox.Show("Заявка успешно подана!"); } else { MessageBox.Show("Заявки на это соревнование больше не принимаются"); } } else { MessageBox.Show("Вы уже участвуете в этом соревновании"); } } } }
private void TabControl_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl.SelectedTab.Text == "Подать заявку") { requestCompIds.Clear(); requestComboBox.Items.Clear(); using (BasketballContext db = new BasketballContext()) { var competitions = db.Competition.ToList(); foreach (var comp in competitions) { requestComboBox.Items.Add(comp.Name + "-" + comp.Year + "-" + comp.Country); requestCompIds.Add(comp.Id); } } } }
private void CreateCompButton_Click(object sender, EventArgs e) { if (compTextBox.TextLength > 0 && countryTextBox.TextLength > 0) { bool flag = true; using (BasketballContext db = new BasketballContext()) { var comppetitions = db.Competition.ToList(); foreach (var comp in comppetitions) { if (comp.Name == compTextBox.Text && comp.Country == countryTextBox.Text && comp.Year == yearNumericUpDown.Value) { flag = false; break; } } } if (flag) { using (BasketballContext db = new BasketballContext()) { Competition comp = new Competition { Name = compTextBox.Text, Country = countryTextBox.Text, Year = yearNumericUpDown.Value }; db.Competition.Add(comp); db.SaveChanges(); } MessageBox.Show("Соревнование успешно добавлено!"); } else { MessageBox.Show("Соревнование уже существует"); } } else { MessageBox.Show("Данные введены некорректно"); } }
private void RegisterButton_Click(object sender, EventArgs e) { string[] playerNames = playerNameTextBox.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); string[] playerSurnames = playerSurnameTextBox.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); if (playerNames.Length == 5 && playerSurnames.Length == 5) { using (BasketballContext db = new BasketballContext()) { Team t = new Team { Login = regLogin, Password = regPassword, Name = teamName, Сountry = countryName, Rating = 0, TrainerName = trainerName, TrainerSurname = trainerSurname }; db.Team.Add(t); db.SaveChanges(); for (int i = 0; i < 5; i++) { Player p = new Player { Name = playerNames[i], Surname = playerSurnames[i], Rating = 0, TeamId = t.Id }; db.Player.Add(p); } db.SaveChanges(); registerPanel.BringToFront(); } } else { MessageBox.Show("Данные введены некорректно"); } }
public static void SendMessage(BasketballContext context, int senderId, int recipientId, string content) { IDataLayer forumConnection = context.ForumConnection; DateTime createTime = DateTime.UtcNow; if (senderId != recipientId) { DialogueHlp.InsertMessage(forumConnection, recipientId, senderId, true, content, createTime); } DialogueHlp.InsertMessage(forumConnection, senderId, recipientId, false, content, createTime); if (senderId != recipientId) { DialogueHlp.UpdateDialog(forumConnection, recipientId, senderId, true, content, createTime); } DialogueHlp.UpdateDialog(forumConnection, senderId, recipientId, false, content, createTime); context.UpdateUnreadDialogs(); }
private void NextTeamButton_Click(object sender, EventArgs e) { if (teamTextBox.TextLength > 0 && countryTextBox.TextLength > 0 && trainerNameTextBox.TextLength > 0 && trainerSurnameTextBox.TextLength > 0) { bool flag = true; using (BasketballContext db = new BasketballContext()) { var teams = db.Team.ToList(); foreach (var t in teams) { if (t.Name == teamTextBox.Text) { flag = false; break; } } } if (flag) { teamName = teamTextBox.Text; countryName = countryTextBox.Text; trainerName = trainerNameTextBox.Text; trainerSurname = trainerSurnameTextBox.Text; playerPanel.BringToFront(); } else { MessageBox.Show("Такая команда уже существует"); } } else { MessageBox.Show("Данные введены некорректно"); } }
private void NextRegButton_Click(object sender, EventArgs e) { if (regLoginTextBox.TextLength > 0 && regPasswordTextBox.TextLength > 0 && confPasswordextBox.Text == regPasswordTextBox.Text) { bool flag = true; using (BasketballContext db = new BasketballContext()) { var teams = db.Team.ToList(); foreach (var t in teams) { if (t.Login == regLoginTextBox.Text) { flag = false; break; } } } if (flag) { regLogin = regLoginTextBox.Text; regPassword = regPasswordTextBox.Text; teamPanel.BringToFront(); } else { MessageBox.Show("Логин занят"); } } else { MessageBox.Show("Данные введены некорректно"); } }
public static void SaveTags(BasketballContext context, SiteState state, LightParent editTopic) { List <string> tags = state.Tag as List <string>; if (tags == null) { return; } ObjectHeadBox editBox = null; List <int> tagIds = new List <int>(); foreach (string tag in tags) { if (StringHlp.IsEmpty(tag)) { continue; } string tagKey = tag.ToLower(); { int tagId; if (context.TagIdByKey.TryGetValue(tagKey, out tagId)) { tagIds.Add(tagId); continue; } } string xmlIds = TagType.DisplayName.CreateXmlIds(tag); //RowLink tagRow = context.Tags.ObjectByXmlIds.AnyRow(xmlIds); //if (tagRow != null) //{ // tagIds.Add(tagRow.Get(ObjectType.ObjectId)); // continue; //} if (editBox == null) { editBox = new ObjectHeadBox(context.FabricConnection, "1=0"); } int?newTagId = editBox.CreateUniqueObject(TagType.Tag, xmlIds, null); if (newTagId == null) { continue; } tagIds.Add(newTagId.Value); } if (editBox != null) { editBox.Update(); context.UpdateTags(); } for (int i = 0; i < tagIds.Count; ++i) { int tagId = tagIds[i]; if (tagId != editTopic.GetChildId(TopicType.TagLinks, i)) { editTopic.SetChildId(TopicType.TagLinks, i, tagId); } } RowLink[] allTagRows = editTopic.AllChildRows(TopicType.TagLinks); for (int i = allTagRows.Length - 1; i >= tagIds.Count; --i) { editTopic.RemoveChildLink(TopicType.TagLinks, i); } }
public static IHtmlControl GetAddPanel(BasketballContext context, SiteState state, LightObject user, LightObject collocutor, bool sendFromUserView) { if (user == null) { return(null); } if (user.Id == collocutor.Id) { return(null); } IHtmlControl editPanel = null; if (state.BlockHint == "messageAdd") { string commentValue = BasketballHlp.AddCommentFromCookie(); editPanel = new HPanel( new HTextArea("messageContent", commentValue).BoxSizing().Width("100%") .Height("10em").MarginTop(5).MarginBottom(5), Decor.Button("отправить") .OnClick(BasketballHlp.AddCommentToCookieScript("messageContent")) .Event("message_add_save", "messageData", delegate(JsonData json) { string content = json.GetText("messageContent"); if (StringHlp.IsEmpty(content)) { return; } DialogueHlp.SendMessage(context, user.Id, collocutor.Id, content); state.BlockHint = ""; BasketballHlp.ResetAddComment(); if (sendFromUserView) { state.Operation.Message = "Сообщение успешно отправлено"; } } ), new HElementControl( h.Script(h.type("text/javascript"), "$('.messageContent').focus();"), "" ) ).EditContainer("messageData"); } HButton moderatorButton = null; HPanel moderatorPanel = null; if (!sendFromUserView) { moderatorButton = new HButton("", std.BeforeAwesome(@"\f1e2", 0) ).PositionAbsolute().Right(5).Top(0) .Title("Модерирование личных сообщений").FontSize(14) .Color(state.BlockHint == correspondenceModeration ? Decor.redColor : Decor.disabledColor) .Event("correspondence_moderation_set", "", delegate { state.SetBlockHint(correspondenceModeration); }); if (state.BlockHint == correspondenceModeration) { bool lockedCollocutor = user.Get(BasketballUserType.LockedUserIds, collocutor.Id); moderatorPanel = new HPanel( Decor.ButtonMidi(!lockedCollocutor ? "Заблокировать собеседника" : "Разблокировать собеседника") .Event("collocutor_locked", "", delegate { LightObject editUser = DataBox.LoadObject(context.UserConnection, UserType.User, user.Id); editUser.Set(BasketballUserType.LockedUserIds, collocutor.Id, !lockedCollocutor); editUser.Box.Update(); context.UserStorage.Update(); }), new HSpoiler(Decor.ButtonMidi("Удаление переписки").Block().FontBold(false), new HPanel( Decor.ButtonMidi("Удалить? (без подтверждения)") .MarginTop(5).MarginLeft(10) .Event("correspondence_delete", "", delegate { context.ForumConnection.GetScalar("", "Delete From correspondence Where user_id = @userId and collocutor_id = @collocutorId", new DbParameter("userId", user.Id), new DbParameter("collocutorId", collocutor.Id) ); context.ForumConnection.GetScalar("", "Delete From dialogue Where user_id = @userId and collocutor_id = @collocutorId", new DbParameter("userId", user.Id), new DbParameter("collocutorId", collocutor.Id) ); context.UpdateUnreadDialogs(); }) ) ).MarginTop(10) ).MarginTop(10); } } bool locked = user.Get(BasketballUserType.LockedUserIds, collocutor.Id) || collocutor.Get(BasketballUserType.LockedUserIds, user.Id); return(new HPanel( new HPanel( Decor.ButtonMidi("Написать сообщение") .Hide(locked) .Event("message_add", "", delegate { state.SetBlockHint("messageAdd"); } ), new HLabel("Вы не можете отправить сообщение этому пользователю").Hide(!locked) .MarginLeft(10).Color(Decor.subtitleColor), moderatorButton ).PositionRelative(), editPanel, moderatorPanel ).MarginTop(10).MarginBottom(10)); }
static HElement Page(HttpContext httpContext, SiteState state, string kind, int?id) { UserHlp.DirectAuthorization(httpContext, SiteContext.Default.SiteSettings); LightObject currentUser = UserHlp.GetCurrentUser(httpContext, SiteContext.Default.UserStorage); if (currentUser != null && (BasketballHlp.IsBanned(currentUser) || currentUser.Get(UserType.NotConfirmed))) { currentUser = null; httpContext.Logout(); } state.EditMode = httpContext.IsInRole("edit"); state.SeoMode = httpContext.IsInRole("seo"); state.UserMode = currentUser != null; int[] foundTagIds = state.Option.Get(OptionType.FoundTagIds); if (foundTagIds != null && foundTagIds.Length > 0) { kind = "search"; id = null; } IHtmlControl adminSectionPanel = null; if (kind == "page") { LightSection section = store.Sections.FindSection(id); adminSectionPanel = DecorEdit.AdminSectionPanel( state.EditMode, state.SeoMode, kind, section, false ); } IHtmlControl dialogBox = null; if (!StringHlp.IsEmpty(state.Operation.Message)) { dialogBox = DecorEdit.GetDialogBox(state); } bool isForum = kind == "topic"; if (kind == "page") { LightSection pageSection = store.Sections.FindSection(id); string designKind = pageSection.Get(SectionType.DesignKind); if (pageSection != null && (designKind == "forum" || designKind == "forumSection")) { isForum = true; } } string title = ""; string description = ""; SchemaOrg schema = null; bool wideContent; IHtmlControl centerView = ViewHlp.GetCenter(httpContext, state, currentUser, kind, id, out title, out description, out schema, out wideContent ); if (centerView == null && StringHlp.IsEmpty(state.RedirectUrl)) { return(null); } BasketballContext context = (BasketballContext)SiteContext.Default; try { if (currentUser != null && kind == "dialog" && id != null) { if (context.UnreadDialogLink.FindRow(DialogReadType.UnreadByUserId, currentUser.Id) != null) { DialogueHlp.MarkReadCorrespondence(context.ForumConnection, currentUser.Id, id.Value); context.UpdateUnreadDialogs(); } } } catch (Exception ex) { Logger.WriteException(ex); } HEventPanel mainPanel = new HEventPanel( new HPanel( new HAnchor("top"), DecorEdit.AdminMainPanel(SiteContext.Default.SiteSettings, httpContext), ViewHeaderHlp.GetHeader(httpContext, state, currentUser, kind, id, isForum), adminSectionPanel, new HPanel( new HPanel( centerView, new HPanel( ViewRightColumnHlp.GetRightColumnView(state, isForum).InlineBlock().MarginRight(15) .MediaLaptop(new HStyle().Block().MarginRight(0)) .MediaTablet(new HStyle().InlineBlock().MarginRight(15)) .MediaSmartfon(new HStyle().Width("100%").MarginRight(0)), ViewRightColumnHlp.GetReclameColumnView(state).InlineBlock().VAlign(true) ).Hide(wideContent).PositionAbsolute().Top(13).Right(15) .MediaTablet(new HStyle().Position("static").MarginTop(15)) //.MediaSmartfon(new HStyle().Width("100%")) ).PositionRelative().Align(true) .Padding(15).PaddingRight(485) .WidthLimit("", kind == "" ? "727px" : "892px") .MediaLaptop(new HStyle().PaddingRight(250)) .MediaTablet(new HStyle().PaddingRight(15)) .MediaSmartfon(new HStyle().PaddingLeft(5).PaddingRight(5)) ).MarginLeft(12).MarginRight(12).PaddingBottom(160).Background(Decor.panelBackground) .BoxSizing().HeightLimit("900px", "") .MediaTablet(new HStyle().MarginLeft(0).MarginRight(0)) ), ViewHlp.GetFooterView(kind == ""), dialogBox //popupPanel ).Width("100%").BoxSizing().Align(null).Background(Decor.pageBackground) .Padding(1) .FontFamily("Tahoma").FontSize(12); //.Color(Decor.textColor); if (!StringHlp.IsEmpty(state.PopupHint) || dialogBox != null) { mainPanel.OnClick(";"); mainPanel.Event("popup_reset", "", delegate { state.PopupHint = ""; state.Operation.Reset(); }); } StringBuilder css = new StringBuilder(); std.AddStyleForFileUploaderButtons(css); HElement mainElement = mainPanel.ToHtml("main", css); SiteSettings settings = SiteContext.Default.SiteSettings; //string blockHint = state.BlockHint; //bool withCkeditor = false; //if (!StringHlp.IsEmpty(blockHint)) //{ // withCkeditor = blockHint == "news_add" || blockHint.StartsWith("article_edit_") || // blockHint.StartsWith("news_edit_"); //} //bool withFileuploader = kind == "user" || withCkeditor; return(h.Html ( h.Head( h.Element("title", title), h.MetaDescription(description), h.LinkCss(UrlHlp.FileUrl("/css/static.css")), h.LinkShortcutIcon("/images/favicon.ico"), h.Meta("viewport", "width=device-width"), //h.LinkCss("/css/font-awesome.css"), //h.LinkCss("/css/fileuploader.css"), h.LinkScript("/scripts/fileuploader.js"), h.LinkScript("/ckeditor/ckeditor.js?v=4113"), HtmlHlp.CKEditorUpdateAll(), h.Raw(store.SeoWidgets.WidgetsCode), HtmlHlp.SchemaOrg(schema), h.OpenGraph("type", "website"), h.OpenGraph("title", title), h.OpenGraph("url", description), h.OpenGraph("site_name", settings.Organization), h.OpenGraph("image", settings.FullUrl("/images/logo_mini.jpg")) ), h.Body( h.Css(h.Raw(css.ToString())), h.Div( HtmlHlp.RedirectScript(state.RedirectUrl) ), //h.Div( // withFileuploader ? h.LinkScript("/scripts/fileuploader.js") : null, // withCkeditor ? h.LinkScript("/ckeditor/ckeditor.js") : null, // withCkeditor ? HtmlHlp.CKEditorUpdateAll() : null //), mainElement //withEditor ? h.Script(h.type("text/javascript"), "console.log('withScript');") : null, //!withFileuploader && withEditor ? h.LinkScript("/scripts/fileuploader.js") : null, //withEditor ? h.LinkScript("/ckeditor/ckeditor.js") : null, //withEditor ? HtmlHlp.CKEditorUpdateAll() : null //HtmlHlp.SchemaOrg(schema), ) )); }
private void CreateMatchButton_Click(object sender, EventArgs e) { if (matchCompComboBox.SelectedIndex == -1) { MessageBox.Show("Выберите соревнование"); } else { using (BasketballContext db = new BasketballContext()) { int ind = matchCompIds[matchCompComboBox.SelectedIndex]; int requestCount = db.Request.Count(r => r.CompetitionId == ind); if (requestCount == 8) { var matches = db.Match.Where(m => m.Request1.CompetitionId == ind); int count = matches.Count(); MessageBox.Show(count.ToString()); if (count < 7) { var finishedMatches = matches.Where(m => m.IsFinished == false); if (finishedMatches.Count() > 0 && (count == 4 || count == 6)) { MessageBox.Show("Не все команды закончили раунд"); } else { int round; if (count < 4) { round = 1; } else if (count < 6) { round = 2; } else { round = 3; } var freeRequest = db.Request.Where(r => r.Match.Count(m => m.Round == round) == 0 && r.Match1.Count(m => m.Round == round) == 0 && (r.Match.Count(m => m.Score1 > m.Score2) == round - 1 || r.Match1.Count(m => m.Score2 > m.Score1) == round - 1)); if (freeRequest.Count() > 0) { IList <Request> requestIds = freeRequest.ToList(); Random rnd = new Random(); int id1 = rnd.Next(requestIds.Count() - 1); var req1 = requestIds[id1]; requestIds.RemoveAt(id1); int id2 = rnd.Next(requestIds.Count() - 1); var req2 = requestIds[id2]; Match match = new Match { Round = round, Date = matchDatePicker.Value.Date + matchTimePicker.Value.TimeOfDay, IsFinished = false, RequestId1 = req1.Id, RequestId2 = req2.Id, Score1 = 0, Score2 = 0 }; db.Match.Add(match); db.SaveChanges(); roundLabel.Text = "Раунд:\n" + round; team1Label.Text = "Команда №1:\n" + req1.Team.Name; team2Label.Text = "Команда №2:\n" + req2.Team.Name; MessageBox.Show("Матч создан!"); } else { MessageBox.Show("Нет команд для распределения"); } } } else { MessageBox.Show("Турнирная сетка уже заполнена"); } } else { MessageBox.Show("Недостаточно заявок на соревнование"); } } } }