コード例 #1
0
        public static IHtmlControl GetArticleListView(SiteState state, LightObject currentUser, int pageNumber)
        {
            int[] allArticleIds = context.Articles.AllObjectIds;
            int   pageCount     = BinaryHlp.RoundUp(allArticleIds.Length, articleCountOnPage);
            int   curPos        = pageNumber * articleCountOnPage;

            if (curPos < 0 || curPos >= allArticleIds.Length)
            {
                return(new HPanel());
            }

            int[] articleIds = ArrayHlp.GetRange(allArticleIds, curPos,
                                                 Math.Min(articleCountOnPage, allArticleIds.Length - curPos)
                                                 );
            LightObject[] articleList = ArrayHlp.Convert(articleIds, delegate(int id)
                                                         { return(new LightObject(context.Articles, id)); }
                                                         );

            IHtmlControl[] items = GetArticleItems(state, articleList);

            return(new HPanel(
                       Decor.Title("Статьи").MarginBottom(15),
                       new HPanel(
                           new HPanel(
                               items
                               ),
                           ViewJumpHlp.JumpBar("/stati", context.Articles.AllObjectIds.Length, articleCountOnPage, pageNumber)
                           )
                       ));
        }
コード例 #2
0
        public static T[] GetPageItems <T>(T[] allItems, int itemCountOnPage, int pageNumber)
        {
            int pageCount = BinaryHlp.RoundUp(allItems.Length, itemCountOnPage);
            int curPos    = pageNumber * itemCountOnPage;

            if (curPos < 0 || curPos >= allItems.Length)
            {
                return(null);
            }

            return(ArrayHlp.GetRange(allItems, curPos, Math.Min(itemCountOnPage, allItems.Length - curPos)));
        }
コード例 #3
0
ファイル: ViewNewsHlp.cs プロジェクト: undyings/Basketball
        static IHtmlControl[] GetNewsItems(SiteState state, int[] allNewsIds, int pageNumber)
        {
            //int pageCount = BinaryHlp.RoundUp(allNewsIds.Length, newsCountOnPage);
            //int curPos = pageNumber * newsCountOnPage;
            //if (curPos < 0 || curPos >= allNewsIds.Length)
            //  return null;

            //int[] newsIds = ArrayHlp.GetRange(allNewsIds, curPos, Math.Min(newsCountOnPage, allNewsIds.Length - curPos));

            int[] newsIds = ViewJumpHlp.GetPageItems(allNewsIds, newsCountOnPage, pageNumber);
            if (newsIds == null)
            {
                return(null);
            }

            LightHead[] newsList = ArrayHlp.Convert(newsIds, delegate(int id)
                                                    { return(new LightHead(context.News, id)); }
                                                    );

            return(GetNewsItems(state, newsList));
        }
コード例 #4
0
        public ForumSectionStorage(IDataLayer fabricConnection, int sectionId)
        {
            this.fabricConnection = fabricConnection;
            this.SectionId        = sectionId;

            this.topicsCache = new Cache <LightHead[], long>(
                delegate
            {
                ObjectHeadBox topicBox = new ObjectHeadBox(fabricConnection,
                                                           "obj_id in (Select child_id from light_link Where parent_id = @parentId and type_id = @linkTypeId) order by act_till desc",
                                                           new DbParameter("parentId", sectionId),
                                                           new DbParameter("linkTypeId", ForumSectionType.TopicLinks.Kind)
                                                           );

                return(ArrayHlp.Convert(topicBox.AllObjectIds, delegate(int topicId)
                                        { return new LightHead(topicBox, topicId); }
                                        ));
            },
                delegate { return(dataChangeTick); }
                );
        }
コード例 #5
0
        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());
            }
                                                       )
                           );
        }