public static IHtmlControl DeleteTopicPanel(SiteState state, TopicStorage topic) { return(new HPanel( Decor.Button("Удалить").Event("delete_topic", "", delegate { int messageCount = topic.MessageLink.AllRows.Length; if (!state.Operation.Validate(messageCount > 0, "Новость с комментариями не может быть удалена")) { return; } MessageHlp.DeleteTopicMessages(context.MessageConnection, topic.Topic.Id); BasketballHlp.DeleteTopic(context.FabricConnection, topic.TopicId); topic.UpdateTopic(); topic.UpdateMessages(); context.UpdateLastComments(false); context.UpdateNews(); context.UpdateArticles(); state.RedirectUrl = "/"; } ) ).Align(false)); }
public TopicStorage(IDataLayer topicConnection, IDataLayer messageConnection, int topicTypeId, int topicId) { this.TopicId = topicId; this.topicCache = new Cache <LightKin, long>( delegate { return(DataBox.LoadKin(topicConnection, topicTypeId, topicId)); }, delegate { return(topicChangeTick); } ); this.messageLinkCache = new Cache <Tuple <TableLink, Dictionary <int, string> >, long>( delegate { TableLink messageLink = MessageHlp.LoadMessageLink(messageConnection, topicId); Dictionary <int, string> htmlRepresentById = new Dictionary <int, string>(messageLink.AllRows.Length); foreach (RowLink message in messageLink.AllRows) { int messageId = message.Get(MessageType.Id); string content = message.Get(MessageType.Content); string htmlRepresent = BasketballHlp.PreViewComment(content); htmlRepresentById[messageId] = htmlRepresent; } return(_.Tuple(messageLink, htmlRepresentById)); }, delegate { return(messageChangeTick); } ); }
public static void InsertMessageAndUpdate(IDataLayer commentConnection, TopicStorage topic, LightObject currentUser, int?whomId, string content) { MessageHlp.InsertMessage(commentConnection, topic.TopicId, currentUser.Id, whomId, content); topic.UpdateMessages(); context.UpdateLastComments(commentConnection == context.ForumConnection); //hack if (commentConnection == context.ForumConnection) { context.FabricConnection.GetScalar("", "Update light_object Set act_till=@modifyTime Where obj_id=@topicId", new DbParameter("modifyTime", DateTime.UtcNow), new DbParameter("topicId", topic.TopicId) ); int?sectionId = topic.Topic.GetParentId(ForumSectionType.TopicLinks); if (sectionId != null) { context.Forum.ForSection(sectionId.Value).Update(); } } }
static IHtmlControl GetTopicRedoPanel(SiteState state, LightObject currentUser, LightSection forumSection, TopicStorage topic) { string blockHint = string.Format("topic_edit_{0}", topic.TopicId); IHtmlControl redoPanel = null; if (state.BlockHint == blockHint) { redoPanel = new HPanel( new HPanel( Decor.Button("Удалить тему").Event("delete_topic", "", delegate { int messageCount = topic.MessageLink.AllRows.Length; if (!state.Operation.Validate(messageCount > 1, "Тема с комментариями не может быть удалена")) { return; } MessageHlp.DeleteTopicMessages(context.ForumConnection, topic.Topic.Id); BasketballHlp.DeleteTopic(context.FabricConnection, topic.TopicId); topic.UpdateTopic(); topic.UpdateMessages(); context.UpdateLastComments(true); context.Forum.ForSection(forumSection.Id).Update(); state.RedirectUrl = "/"; } ) ).Align(false), Decor.PropertyEdit("editTopicTitle", "Заголовок темы", topic.Topic.Get(TopicType.Title)), Decor.Button("Переименовать тему") .Event("save_topic_edit", "editTopicData", delegate(JsonData json) { string title = json.GetText("editTopicTitle"); WebOperation operation = state.Operation; if (!operation.Validate(title, "Не задан заголовок")) { return; } LightObject editTopic = DataBox.LoadObject(context.FabricConnection, TopicType.Topic, topic.TopicId); editTopic.SetWithoutCheck(TopicType.Title, title); editTopic.Box.Update(); context.Forum.ForSection(forumSection.Id).Update(); topic.UpdateTopic(); state.BlockHint = ""; }, topic.TopicId ) ).EditContainer("editTopicData") .Padding(5, 10).MarginTop(5).Background(Decor.pageBackground); } return(new HPanel( Decor.Button("Редактировать") .Event("topic_edit", "", delegate { state.SetBlockHint(blockHint); } ), redoPanel ).MarginTop(5).MarginBottom(10)); }
static IHtmlControl GetTopicAddPanel(SiteState state, LightObject currentUser, LightSection section) { string blockHint = "topic_add"; IHtmlControl addPanel = null; if (state.BlockHint == blockHint) { addPanel = new HPanel( Decor.PropertyEdit("addTopicTitle", "Заголовок темы"), new HTextArea("addTopicText") .Width("100%").Height("6em").MarginBottom(5), Decor.Button("Сохранить").MarginTop(10) .Event("save_topic_add", "addTopicData", delegate(JsonData json) { string title = json.GetText("addTopicTitle"); string text = json.GetText("addTopicText"); WebOperation operation = state.Operation; if (!operation.Validate(title, "Не задан заголовок")) { return; } if (!operation.Validate(text, "Не задан текст")) { return; } KinBox editBox = new KinBox(context.FabricConnection, "1=0"); int addTopicId = editBox.CreateObject(TopicType.Topic, TopicType.Title.CreateXmlIds(title), DateTime.UtcNow); LightKin addTopic = new LightKin(editBox, addTopicId); addTopic.SetParentId(ForumSectionType.TopicLinks, section.Id); addTopic.Set(ObjectType.ActTill, DateTime.UtcNow); addTopic.Set(TopicType.PublisherId, currentUser.Id); editBox.Update(); MessageHlp.InsertMessage(context.ForumConnection, addTopic.Id, currentUser.Id, null, text); context.UpdateLastComments(true); context.Forum.ForSection(section.Id).Update(); state.BlockHint = ""; //context.Forum.TopicsStorages.ForTopic(addTopic.Id); } ) ).EditContainer("addTopicData").MarginTop(5); } return(new HPanel( Decor.Button("Создать тему") .Event("topic_add", "", delegate { state.SetBlockHint(blockHint); } ), addPanel ).MarginTop(5).MarginBottom(10)); }
protected void Application_Start(object sender, EventArgs e) { string appPath = HttpContext.Current.Server.MapPath(""); string logFolder = ApplicationHlp.CheckAndCreateFolderPath(appPath, "Logs"); try { Logger.EnableLogging(Path.Combine(logFolder, "site.log"), 2); GlobalConfiguration.Configure(WebApiConfig.Register); string databaseFolder = ApplicationHlp.CheckAndCreateFolderPath(appPath, "Data"); IDataLayer userConnection = new SQLiteDataLayer(string.Format( connectionStringFormat, Path.Combine(databaseFolder, "user.db3"))); IDataLayer fabricConnection = new SQLiteDataLayer(string.Format( connectionStringFormat, Path.Combine(databaseFolder, "fabric.db3"))); IDataLayer messageConnection = new SQLiteDataLayer(string.Format( connectionStringFormat, Path.Combine(databaseFolder, "message.db3"))); IDataLayer forumConnection = new SQLiteDataLayer(string.Format( connectionStringFormat, Path.Combine(databaseFolder, "forum.db3"))); Logger.AddMessage("Подключения к базам данных успешно созданы"); SQLiteDatabaseHlp.CheckAndCreateDataBoxTables(userConnection); SQLiteDatabaseHlp.CheckAndCreateDataBoxTables(fabricConnection); MessageHlp.CheckAndCreateMessageTables(messageConnection); MessageHlp.CheckAndCreateMessageTables(forumConnection); DialogueHlp.CheckAndCreateDialogueTables(forumConnection); MetaHlp.ReserveDiapasonForMetaProperty(fabricConnection); FabricHlp.CheckAndCreateMenu(fabricConnection, "main"); EditorSelector sectionEditorSelector = new EditorSelector( new SectionTunes("news", "Новости"), new SectionTunes("articles", "Статьи"), new SectionTunes("forum", "Форум"), new SectionTunes("rules", "Правила").Link(), new SectionTunes("forumSection", "Раздел форума") ); EditorSelector unitEditorSelector = new EditorSelector( new UnitTunes("reclame", "Рекламный блок").Tile().ImageAlt().Link().Annotation() ); Shop.Engine.Site.Novosti = "news"; Shop.Engine.Site.DirectPageLinks = true; //Shop.Engine.Site.AddFolderForNews = true; try { string fabricScriptPath = Path.Combine(appPath, "FabricScript.sql"); if (File.Exists(fabricScriptPath)) { string script = File.ReadAllText(fabricScriptPath); Logger.AddMessage("Выполняем стартовый скрипт для fabric.db3: {0}", script); fabricConnection.GetScalar("", script); } string userScriptPath = Path.Combine(appPath, "UserScript.sql"); if (File.Exists(userScriptPath)) { string script = File.ReadAllText(userScriptPath); Logger.AddMessage("Выполняем стартовый скрипт для user.db3: {0}", script); userConnection.GetScalar("", script); } } catch (Exception ex) { Logger.WriteException(ex, "Ошибка при выполнении стартового скрипта"); } SiteContext.Default = new BasketballContext( appPath, sectionEditorSelector, unitEditorSelector, userConnection, fabricConnection, messageConnection, forumConnection ); SiteContext.Default.Pull.StartTask(Labels.Service, MemoryChecker((BasketballContext)SiteContext.Default) ); SiteContext.Default.Pull.StartTask(Labels.Service, SiteTasks.CleaningSessions(SiteContext.Default, TimeSpan.FromHours(1), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(1) ) ); } catch (Exception ex) { Logger.WriteException(ex, "Ошибка создания подключения к базе данных:"); } }
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")); }