public static IHtmlControl GetFoundTagListView(SiteState state, out string title) { title = string.Format("Найденные теги по запросу: {0}", state.Option.Get(OptionType.SearchQuery)); List <IHtmlControl> elements = new List <IHtmlControl>(); int[] foundTagIds = state.Option.Get(OptionType.FoundTagIds); if (foundTagIds != null) { foreach (int tagId in foundTagIds) { RowLink tagRow = context.Tags.TagBox.ObjectById.AnyRow(tagId); if (tagRow == null) { continue; } string tagDisplay = TagType.DisplayName.Get(tagRow); elements.Add( new HPanel( new HLink(ViewTagHlp.TagUrl(tagId, 0), tagDisplay) ).MarginBottom(4) ); } } return(new HPanel( Decor.Title(title), new HPanel( elements.ToArray() ) )); }
/// <summary> /// Открыть страницу с информацией о рейсе /// </summary> /// <param name="trainNumber">номер строки</param> public TrainDetailsPage OpenTrainDetails(string trainNumber) { CustomTestContext.WriteLine($"Открыть страницу с информацией о рейсе №{trainNumber}"); RowLink = Driver.FindElement(By.XPath(ROW_LINK.Replace("*#*", trainNumber))); RowLink.Click(); return(new TrainDetailsPage(Driver).LoadPage()); }
public SourceTableProvider(TableLink sourceTableLink, RowLink[] sourceRows) { this.sourceTableLink = sourceTableLink; //this.table = sourceTableLink.Table.Copy(); this.table = sourceTableLink.Table.Clone(); foreach (RowLink sourceRow in sourceRows) { table.ImportRow(sourceRow.DataRow); } }
static LightObject FindUserForMessage(RowLink message) { if (message == null) { return(null); } int lastUserId = message.Get(MessageType.UserId); return(context.UserStorage.FindUser(lastUserId)); }
public void Cover() { RowLink.Unlink(); foreach (var one in Ones) { foreach (var r in one.RowLink.Elements().Skip(1)) { r.ColLink.Unlink(); r.Header.Size--; } } }
static IHtmlControl GetDialogBlock(IDataLayer forumConnection, UserStorage userStorage, LightObject user, RowLink dialog, int messageIndex) { LightObject collocutor = userStorage.FindUser(dialog.Get(DialogueType.CollocutorId)); if (collocutor == null) { return(null); } bool read = dialog.Get(DialogueType.Unread); bool inbox = dialog.Get(DialogueType.Inbox); LightObject author = inbox ? collocutor : user; DateTime localTime = dialog.Get(DialogueType.ModifyTime).ToLocalTime(); HBefore before = null; if (!inbox) { before = std.BeforeAwesome(@"\f112", 8); } IHtmlControl messageBlock = new HPanel("", new IHtmlControl[] { new HPanel( ViewUserHlp.AvatarBlock(collocutor) ).PositionAbsolute().Left(0).Top(0).Padding(7, 5, 10, 5), new HPanel( new HPanel( new HLabel(collocutor.Get(UserType.Login)).FontBold(), new HLabel(collocutor.Get(UserType.FirstName)).MarginLeft(5), new HLabel(localTime.ToString("dd.MM.yyyy HH:mm")).PositionAbsolute().Right(5) .FontSize("90%").Color(Decor.minorColor) ).PositionRelative().MarginBottom(6), new HLabel( //BasketballHlp.PreViewComment(dialog.Get(DialogueType.Content)), dialog.Get(DialogueType.Content), before ).Block().PaddingBottom(15).BorderBottom("1px solid silver").MarginBottom(5) .FontBold(read).Color(read ? Decor.textColor : Decor.minorColor) .Width("100%").NoWrap().Overflow("hidden").CssAttribute("text-overflow", "ellipsis") ).BoxSizing().Width("100%").BorderLeft(Decor.columnBorder).Padding(7, 5, 5, 5) }, new HHover().Background(Decor.pageBackground) ).PositionRelative().PaddingLeft(64).BorderTop("2px solid #fff").Color(Decor.textColor); //if (messageIndex % 2 != 0) // messageBlock.Background(Decor.evenBackground); return(new HLink(string.Format("{0}", UrlHlp.ShopUrl("dialog", collocutor.Id)), messageBlock, new HHover().Background(Decor.pageBackground) ).TextDecoration("none")); }
public void Uncover() { foreach (var one in OnesRev) { foreach (var r in one.RowLink.Elements(false).Skip(1)) { r.Header.Size++; r.ColLink.Relink(); } } RowLink.Relink(); }
static IHtmlControl GetWhomBlock(SiteState state, UserStorage userStorage, TopicStorage topic, Dictionary <int, string> htmlRepresentByMessageId, RowLink comment) { int commentId = comment.Get(MessageType.Id); int?whomId = comment.Get(MessageType.WhomId); if (whomId == null) { return(null); } RowLink whom = topic.MessageLink.FindRow(MessageType.MessageById, whomId.Value); if (whom == null) { return(null); } LightObject whomUser = userStorage.FindUser(whom.Get(MessageType.UserId)); DateTime whomTime = whom.Get(MessageType.CreateTime).ToLocalTime(); string whomHint = string.Format("whom_{0}", commentId); IHtmlControl whomTextBlock = null; if (state.BlockHint == whomHint) { //string whomDisplay = BasketballHlp.PreViewComment(whom.Get(MessageType.Content)); string whomDisplay = DictionaryHlp.GetValueOrDefault(htmlRepresentByMessageId, whomId.Value); whomTextBlock = new HPanel( new HTextView(whomDisplay).FontSize(12) ).Padding(5); } return(new HPanel( new HPanel( new HButton( whomUser?.Get(UserType.Login), new HHover().TextDecoration("none") ).Color(Decor.linkColor).TextDecoration("underline").MarginRight(5) .Event("whom_display", "", delegate { state.SetBlockHint(whomHint); }, commentId ), new HLabel(string.Format("({0})", whomTime.ToString(Decor.timeFormat))) ), whomTextBlock ).Color(Decor.minorColor).FontSize("90%")); }
static RowLink[] GetTagRows(ObjectHeadBox tagBox, int[] tagIds) { List <RowLink> tagRows = new List <RowLink>(tagIds.Length); foreach (int tagId in tagIds) { RowLink tagRow = tagBox.ObjectById.AnyRow(tagId); if (tagRow != null) { tagRows.Add(tagRow); } } return(tagRows.ToArray()); }
public static bool IsDuplicate(TopicStorage topic, int currentUserId, string content) { RowLink[] messageRows = topic.MessageLink.AllRows; if (messageRows.Length == 0) { return(false); } RowLink lastMessage = _.Last(messageRows); if (lastMessage.Get(MessageType.UserId) == currentUserId && lastMessage.Get(MessageType.Content) == content) { return(true); } return(false); }
public static IHtmlControl GetForumView(SiteState state, LightObject currentUser, LightSection forum) { return(new HPanel( Decor.Title("Форумы").MarginBottom(15), new HGrid <LightSection>(forum.Subsections, delegate(LightSection subSection) { TopicStorage lastTopic = GetLastTopicForForumSection(subSection); RowLink lastMessage = lastTopic == null ? null : _.Last(lastTopic.MessageLink.AllRows); LightObject lastUser = FindUserForMessage(lastMessage); return new HPanel( new HPanel( new HLink(UrlHlp.ShopUrl("page", subSection.Id), subSection.Get(SectionType.Title) ).FontBold() ).RelativeWidth(50).PaddingLeft(5).VAlign(true).PaddingTop(15) .MediaTablet(new HStyle().Block().Width("auto")), new HPanel( new HPanel( new HLink(UrlHlp.ShopUrl("topic", lastTopic?.TopicId), lastTopic?.Topic.Get(TopicType.Title) ) ).MarginTop(7).MarginBottom(3), new HPanel( new HLink(UrlHlp.ShopUrl("user", lastUser?.Id), lastUser?.Get(UserType.Login) ), new HLabel( lastMessage?.Get(MessageType.CreateTime).ToLocalTime().ToString(Decor.timeFormat) ).MarginLeft(7).MarginRight(7), new HLink( string.Format("{0}?page=last#bottom", UrlHlp.ShopUrl("topic", lastTopic?.TopicId)), new HImage("/images/full.gif") ).Hide(lastMessage == null) ).MarginBottom(7) ).RelativeWidth(50).Padding(0, 5).Height(45).BorderLeft(Decor.columnBorder) .MediaTablet(new HStyle().Width("auto").Border("none")) ); }, new HRowStyle().Even(new HTone().Background(Decor.evenBackground)) ).BorderBottom(Decor.bottomBorder).MarginBottom(10), DecorEdit.AdminGroupPanel(state.EditMode, forum.Id) )); }
public static IHtmlControl GetTagView(SiteState state, LightObject currentUser, int?tagId, int pageNumber, out string title, out string description) { title = ""; description = ""; if (tagId == null) { return(null); } RowLink tagRow = context.Tags.TagBox.ObjectById.AnyRow(tagId.Value); if (tagRow == null) { return(null); } string tagDisplay = TagType.DisplayName.Get(tagRow); title = string.Format("{0} - все новости на basketball.ru.com", tagDisplay); description = string.Format("{0} - все новости. Живое обсуждение баскетбольных событий на basketball.ru.com", tagDisplay); int[] newsIds = ViewTagHlp.GetNewsIdsForTag(context.FabricConnection, tagId.Value); IHtmlControl[] items = GetNewsItems(state, newsIds, pageNumber); if (items == null) { return(null); } string urlWithoutPageIndex = string.Format("/tags?tag={0}", tagId.Value); return(new HPanel( Decor.Title(tagDisplay), //.Color(Decor.subtitleColor), //Decor.Subtitle(string.Format("Тег — {0}", tagDisplay)).MarginTop(5), new HPanel( new HPanel( items ), ViewJumpHlp.JumpBar(urlWithoutPageIndex, newsIds.Length, newsCountOnPage, pageNumber) ) )); }
static IHtmlControl GetDialogItem(SiteState state, LightObject currentUser, string kind) { if (currentUser == null) { return(null); } RowLink unreadRow = context.UnreadDialogLink.FindRow(DialogReadType.UnreadByUserId, currentUser.Id); HAfter after = null; if (unreadRow != null) { after = new HAfter().Content(unreadRow.Get(DialogReadType.Count).ToString()) .Align(null).MarginLeft(8).FontBold().TextDecoration("none") .InlineBlock().BoxSizing().Size(20, 20).LineHeight(18) .BorderRadius("50%").Background(Decor.redColor); } HPanel labelPanel = new HPanel( new HLabel("Личные сообщения", after, new HHover().TextDecoration("none")) .Padding(7, 17, 8, 17).LineHeight(20).TextDecoration("underline") .Media(600, new HStyle().Display("none")), new HLabel("", std.BeforeAwesome(@"\f086", 0).FontSize(20).VAlign(-2), after) .Padding(7, 17, 8, 17).LineHeight(20) .Display("none").Media(600, new HStyle().InlineBlock()) ).InlineBlock(); if (kind != "dialog") { labelPanel.Color(Decor.menuColor); } else { labelPanel.Color(Decor.menuSelectedColor).FontBold().Background(Decor.menuSelectedBackground); } return(new HPanel( new HLink(UrlHlp.ShopUrl("dialog", null), labelPanel ) ).InlineBlock().PositionAbsolute().Right(2).Top(3)); }
public TopicStorage ForTopic(int topicId) { lock (lockObj) { TopicStorage storage; if (!topicStorageById.TryGetValue(topicId, out storage)) { storage = new TopicStorage(topicConnection, messageConnection, topicTypeId, topicId); DateTime refTime = DateTime.UtcNow.AddDays(-7); RowLink lastMessage = _.Last(storage.MessageLink.AllRows); DateTime?topicTime = storage.Topic.Get(ObjectType.ActFrom); if ((topicTime != null && topicTime.Value > refTime) || (lastMessage != null && lastMessage.Get(CorrespondenceType.CreateTime) > refTime)) { topicStorageById[topicId] = storage; } } return(storage); } }
public static IHtmlControl GetCommentsPanel(IDataLayer commentConnection, SiteState state, LightObject currentUser, TopicStorage topic, RowLink[] pageMessages) { HPanel addPanel = null; if (currentUser != null) { HPanel editPanel = null; if (state.BlockHint == "commentAdd") { string commentValue = BasketballHlp.AddCommentFromCookie(); editPanel = new HPanel( new HTextArea("commentContent", commentValue).Width("100%").Height("10em").MarginTop(5).MarginBottom(5), Decor.Button("отправить") .OnClick(BasketballHlp.AddCommentToCookieScript("commentContent")) .Event("comment_add_save", "commentData", delegate(JsonData json) { lock (lockObj) { string content = json.GetText("commentContent"); if (StringHlp.IsEmpty(content)) { return; } if (BasketballHlp.IsDuplicate(topic, currentUser.Id, content)) { return; } InsertMessageAndUpdate(commentConnection, topic, currentUser, null, content); state.BlockHint = ""; BasketballHlp.ResetAddComment(); } } ), new HElementControl( h.Script(h.type("text/javascript"), "$('.commentContent').focus();"), "" ) ).EditContainer("commentData"); } addPanel = new HPanel( Decor.ButtonMini("оставить комментарий").FontBold().FontSize(12).Padding(2, 7). Event("comment_add", "", delegate { state.SetBlockHint("commentAdd"); } ), new HButton("", new HBefore().ContentIcon(11, 11).BackgroundImage(UrlHlp.ImageUrl("refresh.png")) ).Color("#9c9c9c").MarginLeft(10).Title("Загрузить новые комментарии") .Event("comments_refresh", "", delegate { }), editPanel ); } Dictionary <int, string> htmlRepresentByMessageId = topic.HtmlRepresentByMessageId; //RowLink[] allMessages = topic.MessageLink.AllRows; RowLink bottomMessage = null; if (pageMessages.Length > 0) { bottomMessage = pageMessages[Math.Max(0, pageMessages.Length - 2)]; } return(new HPanel( new HAnchor("comments"), new HLabel("Комментарии:").MarginTop(30).MarginBottom(20).FontSize("160%") .Hide(commentConnection == context.ForumConnection), new HPanel( new HLabel("Автор").PositionAbsolute().Top(0).Left(0) .BoxSizing().Width(100).Padding(7, 5, 5, 5), new HLabel("Сообщение").Block().Padding(7, 5, 5, 5).BorderLeft(Decor.columnBorder) ).PositionRelative().Align(null).PaddingLeft(100).Background("#dddddd").FontBold(), new HGrid <RowLink>(pageMessages, delegate(RowLink comment) { IHtmlControl commentBlock = ViewCommentHlp.GetCommentBlock( commentConnection, state, currentUser, topic, htmlRepresentByMessageId, comment ); if (bottomMessage == comment) { return new HPanel(new HAnchor("bottom"), commentBlock); } return commentBlock; }, new HRowStyle().Even(new HTone().Background(Decor.evenBackground)) ).BorderBottom(Decor.bottomBorder).MarginBottom(10), //new HAnchor("bottom"), addPanel )); }
public void RemoveRow(RowLink row) { rowListChangeTick++; RemoveIndexForRow(row); row.DataRow.Delete(); }
public void AddRow(RowLink row) { rowListChangeTick++; tableProvider.Table.Rows.Add(row.DataRow); CreateIndexForRow(row); }
public RowLink NewRow() { DataRow dataRow = tableProvider.Table.NewRow(); RowLink row = new RowLink(this, dataRow); foreach (FieldLink field in fieldsByName.Values) field.FieldBlank.SetDefaultValue(row); if (primaryKeyCreator != null) primaryKeyCreator.SetPrimaryKey(row); return row; }
public void RemoveIndexForRow(RowLink row) { foreach (IndexBlank index in indicies) { UniversalKey key = index.CreateKey(this, row); if (index.IsMultiIndex) multiIndicesByName[index.IndexName][key].Remove(row); else singleIndicesByName[index.IndexName].Remove(key); } }
public void CreateIndexForRow(RowLink row) { foreach (IndexBlank index in indicies) { UniversalKey key = index.CreateKey(this, row); if (index.IsMultiIndex) { Dictionary<UniversalKey, List<RowLink>> rowsForKey = multiIndicesByName[index.IndexName]; List<RowLink> rows; if (!rowsForKey.TryGetValue(key, out rows)) { rows = new List<RowLink>(); rowsForKey[key] = rows; } rows.Add(row); } else { Dictionary<UniversalKey, RowLink> singleIndex = singleIndicesByName[index.IndexName]; if (singleIndex.ContainsKey(key)) Logger.AddMessage("Дубль значения '{0}' по индексу '{1}'", key, index.IndexName); singleIndex[key] = row; } } }
public TableLink Clone(RowLink[] sourceRows) { List<FieldBlank> fieldBlanks = new List<FieldBlank>(); foreach (FieldLink fieldLink in Fields) fieldBlanks.Add(fieldLink.FieldBlank); return new TableLink(new SourceTableProvider(this, sourceRows), primaryKeyCreator, fieldBlanks.ToArray(), indicies, constraints); }
public static IHtmlControl GetForumSectionView(SiteState state, LightObject currentUser, LightSection section) { LightHead[] topics = context.Forum.ForSection(section.Id).Topics; IHtmlControl addPanel = null; if (currentUser != null) { addPanel = GetTopicAddPanel(state, currentUser, section); } return(new HPanel( Decor.Title(section.Get(SectionType.Title)).MarginBottom(15), new HPanel( new HLink("/forum", "Форумы") ).MarginBottom(25), //new HPanel( // new HLink("/forum", "Форумы"), // ArrowElement(), // new HLabel(section.Get(SectionType.Title)) //).MarginBottom(10), addPanel, new HGrid <LightHead>(topics, delegate(LightHead topic) { TopicStorage topicStorage = context.Forum.TopicsStorages.ForTopic(topic.Id); //int publisherId = topicStorage.Topic.Get(TopicType.PublisherId); //LightObject user = context.UserStorage.FindUser(publisherId); RowLink lastMessage = _.Last(topicStorage.MessageLink.AllRows); LightObject lastUser = FindUserForMessage(lastMessage); return new HPanel( new HPanel( new HLink(string.Format("{0}?page=last", UrlHlp.ShopUrl("topic", topic.Id)), topic.Get(TopicType.Title) ).FontBold() ).RelativeWidth(55).Padding(8, 5, 9, 5).BorderRight(Decor.columnBorder) .MediaTablet(new HStyle().Block().Width("auto")), //new HPanel( // new HLink(UrlHlp.ShopUrl("user", publisherId), // user?.Get(UserType.Login) // ).FontBold() //).Align(null), new HPanel( new HLabel(topicStorage.MessageLink.AllRows.Length) ).Align(null).RelativeWidth(10).PaddingTop(8).PaddingBottom(9).BorderRight(Decor.columnBorder) .MediaTablet(new HStyle().Width(50).PaddingTop(0)), new HPanel( new HLink(UrlHlp.ShopUrl("user", lastUser?.Id), lastUser?.Get(UserType.Login) ), new HLabel( lastMessage?.Get(MessageType.CreateTime).ToLocalTime().ToString(Decor.timeFormat) ).MarginLeft(7).MarginRight(7), new HLink( string.Format("{0}?page=last#bottom", UrlHlp.ShopUrl("topic", topic.Id)), new HImage("/images/full.gif") ) ).RelativeWidth(35).Padding(0, 5) .MediaTablet(new HStyle().Width("auto")) ); }, new HRowStyle().Even(new HTone().Background(Decor.evenBackground)) ).BorderBottom(Decor.bottomBorder).MarginBottom(10) )); }
public static IHtmlControl GetCommentBlock(IDataLayer commentConnection, SiteState state, LightObject currentUser, TopicStorage topic, Dictionary <int, string> htmlRepresentByMessageId, RowLink comment) { LightObject user = context.UserStorage.FindUser(comment.Get(MessageType.UserId)); DateTime localTime = comment.Get(MessageType.CreateTime).ToLocalTime(); IHtmlControl whomBlock = GetWhomBlock(state, context.UserStorage, topic, htmlRepresentByMessageId, comment); int commentId = comment.Get(MessageType.Id); string answerHint = string.Format("answer_{0}", commentId); IHtmlControl answerBlock = null; if (currentUser != null && state.BlockHint == answerHint) { string commentValue = BasketballHlp.AddCommentFromCookie(); answerBlock = new HPanel( new HTextArea("answerContent", commentValue).Width("100%").Height("10em").MarginTop(5).MarginBottom(5), Decor.Button("отправить") .OnClick(BasketballHlp.AddCommentToCookieScript("answerContent")) .Event("save_answer", "answerContainer", delegate(JsonData json) { lock (lockObj) { string content = json.GetText("answerContent"); if (StringHlp.IsEmpty(content)) { return; } if (BasketballHlp.IsDuplicate(topic, currentUser.Id, content)) { return; } InsertMessageAndUpdate(commentConnection, topic, currentUser, commentId, content); state.BlockHint = ""; BasketballHlp.ResetAddComment(); } }, commentId ), new HElementControl( h.Script(h.type("text/javascript"), "$('.answerContent').focus();"), "" ) ).EditContainer("answerContainer"); } IHtmlControl editBlock = null; if (currentUser != null && currentUser.Id == user?.Id) { editBlock = new HPanel( ); } string redoHint = string.Format("redo_{0}", commentId); HButton redoButton = null; if (currentUser != null && currentUser.Id == user?.Id) { redoButton = Decor.ButtonMini("редактировать").Event("comment_redo", "", delegate(JsonData json) { state.SetBlockHint(redoHint); }, commentId ); } IHtmlControl redoBlock = null; if (currentUser != null && state.BlockHint == redoHint) { redoBlock = new HPanel( new HTextArea("redoContent", comment.Get(MessageType.Content)) .Width("100%").Height("10em").MarginTop(5).MarginBottom(5), Decor.Button("изменить").Event("save_redo", "redoContainer", delegate(JsonData json) { string content = json.GetText("redoContent"); if (StringHlp.IsEmpty(content)) { return; } //content = BasketballHlp.PreSaveComment(content); commentConnection.GetScalar("", "Update message Set content=@content, modify_time=@time Where id=@id", new DbParameter("content", content), new DbParameter("time", DateTime.UtcNow), new DbParameter("id", commentId) ); topic.UpdateMessages(); state.BlockHint = ""; }, commentId ), new HElementControl( h.Script(h.type("text/javascript"), "$('.redoContent').focus();"), "" ) ).EditContainer("redoContainer"); } IHtmlControl deleteElement = null; if (state.ModeratorMode) { deleteElement = new HButton("", std.BeforeAwesome(@"\f00d", 0) ).MarginLeft(5).Color(Decor.redColor).Title("удалить комментарий") .Event("delete_comment", "", delegate { MessageHlp.DeleteMessage(commentConnection, commentId); topic.UpdateMessages(); context.UpdateLastComments(commentConnection == context.ForumConnection); }, commentId ); } string topicType = topic.Topic.Get(ObjectType.TypeId) == NewsType.News ? "news" : "article"; string anchor = string.Format("reply{0}", commentId); return(new HXPanel( new HAnchor(anchor), new HPanel( new HLink(UrlHlp.ShopUrl("user", user?.Id), user?.Get(UserType.Login) ).FontBold(), new HLabel(user?.Get(UserType.FirstName)).Block() .MediaTablet(new HStyle().InlineBlock().MarginLeft(5)), new HPanel( ViewUserHlp.AvatarBlock(user) ).MarginTop(5) .MediaTablet(new HStyle().Display("none")) ).BoxSizing().WidthLimit("100px", "").Padding(7, 5, 10, 5) .MediaTablet(new HStyle().Block().PaddingBottom(0).PaddingRight(110)), new HPanel( new HPanel( new HLabel(localTime.ToString("dd.MM.yyyy HH:mm")).MarginRight(5) .MediaTablet(new HStyle().MarginBottom(5)), new HLink(string.Format("/{0}/{1}#{2}", topicType, topic.TopicId, anchor), "#").TextDecoration("none") .Hide(commentConnection == context.ForumConnection), deleteElement ).Align(false).FontSize("90%").Color(Decor.minorColor), whomBlock, new HTextView( DictionaryHlp.GetValueOrDefault(htmlRepresentByMessageId, commentId) ).PaddingBottom(15).MarginBottom(5).BorderBottom("1px solid silver"), new HPanel( Decor.ButtonMini("ответить").Event("comment_answer", "", delegate { state.SetBlockHint(answerHint); }, commentId ), redoButton ).Hide(currentUser == null), answerBlock, redoBlock ).BoxSizing().Width("100%").BorderLeft(Decor.columnBorder).Padding(7, 5, 5, 5) .MediaTablet(new HStyle().Block().MarginTop(-19)) ).BorderTop("2px solid #fff")); }
public BasketballContext(string rootPath, EditorSelector sectionEditorSelector, EditorSelector unitEditorSelector, IDataLayer userConnection, IDataLayer fabricConnection, IDataLayer messageConnection, IDataLayer forumConnection) { this.rootPath = rootPath; this.imagesPath = Path.Combine(RootPath, "Images"); this.userConnection = userConnection; this.fabricConnection = fabricConnection; this.messageConnection = messageConnection; this.forumConnection = forumConnection; this.sectionEditorSelector = sectionEditorSelector; this.unitEditorSelector = unitEditorSelector; this.userStorage = new UserStorage(userConnection); this.NewsStorages = new TopicStorageCache(fabricConnection, messageConnection, NewsType.News); this.ArticleStorages = new TopicStorageCache(fabricConnection, messageConnection, ArticleType.Article); this.Forum = new ForumStorageCache(fabricConnection, forumConnection); string settingsPath = Path.Combine(rootPath, "SiteSettings.config"); if (!File.Exists(settingsPath)) { this.siteSettings = new SiteSettings(); } else { this.siteSettings = XmlSerialization.Load <SiteSettings>(settingsPath); } this.pull = new TaskPull( new ThreadLabel[] { Labels.Service }, TimeSpan.FromMinutes(15) ); this.newsCache = new Cache <Tuple <ObjectHeadBox, LightHead[]>, long>( delegate { ObjectHeadBox newsBox = new ObjectHeadBox(fabricConnection, string.Format("{0} order by act_from desc", DataCondition.ForTypes(NewsType.News)) ); int[] allNewsIds = newsBox.AllObjectIds; List <LightHead> actualNews = new List <LightHead>(); for (int i = 0; i < Math.Min(22, allNewsIds.Length); ++i) { int newsId = allNewsIds[i]; actualNews.Add(new LightHead(newsBox, newsId)); } return(_.Tuple(newsBox, actualNews.ToArray())); }, delegate { return(newsChangeTick); } ); this.articlesCache = new Cache <Tuple <ObjectBox, LightObject[]>, long>( delegate { ObjectBox articleBox = new ObjectBox(fabricConnection, string.Format("{0} order by act_from desc", DataCondition.ForTypes(ArticleType.Article)) ); int[] allArticleIds = articleBox.AllObjectIds; ObjectBox actualBox = new ObjectBox(FabricConnection, string.Format("{0} order by act_from desc limit 5", DataCondition.ForTypes(ArticleType.Article)) ); List <LightObject> actualArticles = new List <LightObject>(); foreach (int articleId in actualBox.AllObjectIds) { actualArticles.Add(new LightObject(actualBox, articleId)); } return(_.Tuple(articleBox, actualArticles.ToArray())); }, delegate { return(articleChangeTick); } ); this.lightStoreCache = new Cache <IStore, long>( delegate { LightObject contacts = DataBox.LoadOrCreateObject(fabricConnection, ContactsType.Contacts, ContactsType.Kind.CreateXmlIds, "main"); LightObject seo = DataBox.LoadOrCreateObject(fabricConnection, SEOType.SEO, SEOType.Kind.CreateXmlIds, "main"); SectionStorage sections = SectionStorage.Load(fabricConnection); WidgetStorage widgets = WidgetStorage.Load(fabricConnection, siteSettings.DisableScripts); RedirectStorage redirects = RedirectStorage.Load(fabricConnection); SiteStore store = new SiteStore(sections, null, widgets, redirects, contacts, seo); store.Links.AddLink("register", null); store.Links.AddLink("passwordreset", null); return(store); }, delegate { return(dataChangeTick); } ); this.lastPublicationCommentsCache = new Cache <RowLink[], long>( delegate { DataTable table = messageConnection.GetTable("", "Select Distinct article_id From message order by create_time desc limit 10" ); List <RowLink> lastComments = new List <RowLink>(10); foreach (DataRow row in table.Rows) { int topicId = ConvertHlp.ToInt(row[0]) ?? -1; if (News.ObjectById.Exist(topicId)) { TopicStorage topic = NewsStorages.ForTopic(topicId); RowLink lastMessage = _.Last(topic.MessageLink.AllRows); if (lastMessage != null) { lastComments.Add(lastMessage); } } else if (Articles.ObjectById.Exist(topicId)) { TopicStorage topic = ArticleStorages.ForTopic(topicId); RowLink lastMessage = _.Last(topic.MessageLink.AllRows); if (lastMessage != null) { lastComments.Add(lastMessage); } } } return(lastComments.ToArray()); }, delegate { return(publicationCommentChangeTick); } ); this.lastForumCommentsCache = new Cache <RowLink[], long>( delegate { DataTable table = forumConnection.GetTable("", "Select Distinct article_id From message order by create_time desc limit 7" ); List <RowLink> lastComments = new List <RowLink>(7); foreach (DataRow row in table.Rows) { int topicId = ConvertHlp.ToInt(row[0]) ?? -1; TopicStorage topic = Forum.TopicsStorages.ForTopic(topicId); RowLink lastMessage = _.Last(topic.MessageLink.AllRows); if (lastMessage != null) { lastComments.Add(lastMessage); } } return(lastComments.ToArray()); }, delegate { return(forumCommentChangeTick); } ); this.tagsCache = new Cache <TagStore, long>( delegate { ObjectHeadBox tagBox = new ObjectHeadBox(fabricConnection, DataCondition.ForTypes(TagType.Tag) + " order by xml_ids asc"); return(new TagStore(tagBox)); }, delegate { return(tagChangeTick); } ); //this.tagsCache = new Cache<Tuple<ObjectHeadBox, Dictionary<string, int>>, long>( // delegate // { // ObjectHeadBox tagBox = new ObjectHeadBox(fabricConnection, DataCondition.ForTypes(TagType.Tag) + " order by xml_ids asc"); // Dictionary<string, int> tagIdByKey = new Dictionary<string, int>(); // foreach (int tagId in tagBox.AllObjectIds) // { // string tagName = TagType.DisplayName.Get(tagBox, tagId); // if (StringHlp.IsEmpty(tagName)) // continue; // string tagKey = tagName.ToLower(); // tagIdByKey[tagKey] = tagId; // } // return _.Tuple(tagBox, tagIdByKey); // }, // delegate { return tagChangeTick; } //); this.unreadDialogCache = new Cache <TableLink, long>( delegate { return(DialogueHlp.LoadUnreadLink(forumConnection)); }, delegate { return(unreadChangeTick); } ); Pull.StartTask(Labels.Service, SiteTasks.SitemapXmlChecker(this, rootPath, delegate(LinkInfo[] sectionlinks) { List <LightLink> allLinks = new List <LightLink>(); allLinks.AddRange( ArrayHlp.Convert(sectionlinks, delegate(LinkInfo link) { return(new LightLink(link.Directory, null)); }) ); foreach (int articleId in Articles.AllObjectIds) { LightHead article = new LightHead(Articles, articleId); allLinks.Add( new LightLink(UrlHlp.ShopUrl("article", articleId), article.Get(ObjectType.ActTill) ?? article.Get(ObjectType.ActFrom) ) ); } foreach (int newsId in News.AllObjectIds) { LightHead news = new LightHead(News, newsId); allLinks.Add( new LightLink(UrlHlp.ShopUrl("news", newsId), news.Get(ObjectType.ActTill) ?? news.Get(ObjectType.ActFrom) ) ); } //foreach (int tagId in Tags.AllObjectIds) //{ // LightHead tag = new LightHead(Tags, tagId); // allLinks.Add( // new LightLink(string.Format("/tags?tag={0}", tagId) // ) // ); //} return(allLinks.ToArray()); } ) ); }
static IHtmlControl GetMessageBlock(IDataLayer forumConnection, SiteState state, LightObject user, LightObject collocutor, RowLink message, int messageIndex) { int messageId = message.Get(CorrespondenceType.Id); LightObject author = message.Get(CorrespondenceType.Inbox) ? collocutor : user; DateTime localTime = message.Get(CorrespondenceType.CreateTime).ToLocalTime(); IHtmlControl deleteElement = null; if (state.BlockHint == "correspondence_moderation") { deleteElement = new HButton("", std.BeforeAwesome(@"\f00d", 0) ).MarginLeft(5).Color(Decor.redColor).Title("удалить комментарий") .Event("delete_message", "", delegate { forumConnection.GetScalar("", "Delete From correspondence Where id = @messageId", new DbParameter("messageId", messageId) ); }, messageId ); } IHtmlControl messageBlock = new HPanel("", new IHtmlControl[] { new HPanel( ViewUserHlp.AvatarBlock(author) ).PositionAbsolute().Left(0).Top(0).Padding(7, 5, 10, 5), new HPanel( new HPanel( //new HLabel(author.Get(UserType.Login)).FontBold(), new HLink(UrlHlp.ShopUrl("user", author.Id), author.Get(UserType.FirstName) ).FontBold(), //new HLabel(author.Get(UserType.FirstName)).MarginLeft(5), new HPanel( new HLabel(localTime.ToString("dd.MM.yyyy HH:mm")).FontSize("90%").Color(Decor.minorColor), deleteElement ).InlineBlock().PositionAbsolute().Right(5) ).PositionRelative().MarginBottom(6), new HTextView( BasketballHlp.PreViewComment(message.Get(CorrespondenceType.Content)) ).Block().PaddingBottom(15).BorderBottom("1px solid silver").MarginBottom(5) ).BoxSizing().Width("100%").BorderLeft(Decor.columnBorder).Padding(7, 5, 5, 5) } ).PositionRelative().PaddingLeft(64).BorderTop("2px solid #fff").Color(Decor.textColor); //IHtmlControl messageBlock = new HXPanel( // new HPanel( // new HLink(UrlHlp.ShopUrl("user", author.Id), // author.Get(UserType.Login) // ).FontBold(), // new HLabel(author.Get(UserType.FirstName)).Block() // .MediaTablet(new HStyle().InlineBlock().MarginLeft(5)), // new HPanel( // ViewUserHlp.AvatarBlock(author) // ).MarginTop(5) // .MediaTablet(new HStyle().Display("none")) // ).BoxSizing().WidthLimit("100px", "").Padding(7, 5, 10, 5) // .MediaTablet(new HStyle().Block().PaddingBottom(0).PaddingRight(110)), // new HPanel( // new HPanel( // new HLabel(localTime.ToString("dd.MM.yyyy HH:mm")).MarginRight(5) // .MediaTablet(new HStyle().MarginBottom(5)), // deleteElement // ).Align(false).FontSize("90%").Color(Decor.minorColor), // new HTextView( // BasketballHlp.PreViewComment(message.Get(CorrespondenceType.Content)) // ).PaddingBottom(15).MarginBottom(5).BorderBottom("1px solid silver") // ).BoxSizing().Width("100%").BorderLeft(Decor.columnBorder).Padding(7, 5, 5, 5) // .MediaTablet(new HStyle().Block().MarginTop(-19)) //).BorderTop("2px solid #fff"); if (messageIndex % 2 != 0) { messageBlock.Background(Decor.evenBackground); } return(messageBlock); }