Esempio n. 1
0
        // public PagedListViewModel<MediaFileViewModel> Files { get; set; }

        private PagedListViewModel <MediaFileViewModel> GetPagedFiles(SiteDb siteDb, string path, int PageSize, int PageNumber)
        {
            string baseurl = siteDb.WebSite.BaseUrl();

            List <Image> images = siteDb.Folders.GetFolderObjects <Image>(path, true);

            int totalskip = 0;

            if (PageNumber > 1)
            {
                totalskip = (PageNumber - 1) * PageSize;
            }

            PagedListViewModel <MediaFileViewModel> Result = new PagedListViewModel <MediaFileViewModel>();

            Result.TotalCount = images.Count();
            Result.TotalPages = ApiHelper.GetPageCount(Result.TotalCount, PageSize);
            Result.PageSize   = PageSize;
            Result.PageNr     = PageNumber;


            List <MediaFileViewModel> pagedlist = new List <MediaFileViewModel>();

            foreach (var item in images.Skip(totalskip).Take(PageSize))
            {
                MediaFileViewModel model = new MediaFileViewModel();
                model.Id           = item.Id;
                model.Height       = item.Height;
                model.Width        = item.Width;
                model.Size         = item.Size;
                model.Name         = item.Name;
                model.LastModified = item.LastModified;
                model.Thumbnail    = ThumbnailService.GenerateThumbnailUrl(item.Id, 90, 0, siteDb.Id);
                model.Url          = ObjectService.GetObjectRelativeUrl(siteDb, item);
                model.IsImage      = true;
                model.PreviewUrl   = Lib.Helper.UrlHelper.Combine(baseurl, model.Url);

                var usedby = siteDb.Images.GetUsedBy(item.Id);

                if (usedby != null)
                {
                    model.References = usedby.GroupBy(it => it.ConstType).ToDictionary(
                        key =>
                    {
                        return(ConstTypeService.GetModelType(key.Key).Name);
                    }, value => value.Count());
                }

                pagedlist.Add(model);
            }
            Result.List = pagedlist;
            return(Result);
        }
Esempio n. 2
0
 internal static PageViewModel ToPageViewModel(SiteDb SiteDb, Page page)
 {
     return(new PageViewModel()
     {
         Id = page.Id,
         Name = page.Name,
         Online = page.Online,
         Path = ObjectService.GetObjectRelativeUrl(SiteDb, page),
         PreviewUrl = PageService.GetPreviewUrl(SiteDb, page),
         Linked = SiteDb.Relations.GetReferredBy(page).Count(),
         PageView = SiteDb.VisitorLog.QueryDescending(o => o.ObjectId == page.Id).EndQueryCondition(o => o.Begin < DateTime.UtcNow.AddHours(-24)).Take(999999).Count(),
         LastModified = page.LastModified,
         InlineUrl = "/_api/redirect/inline?siteid=" + SiteDb.WebSite.Id + "&pageid=" + page.Id
     });
 }
Esempio n. 3
0
        public List <ResourceCount> getTopPages(RenderContext Context)
        {
            var sitedb = Context.WebSite.SiteDb();

            List <ResourceCount> pagecountes = new List <ResourceCount>();

            List <TempCounter> temp = new List <TempCounter>();

            var logs = DashBoardHelper.GetLogs(Context);

            foreach (var item in logs.GroupBy(o => o.ObjectId))
            {
                TempCounter one = new TempCounter();
                one.Item     = item.First();
                one.Count    = item.Count();
                one.ObjectId = item.Key;

                temp.Add(one);
            }

            int counter = 0;

            foreach (var item in temp.OrderByDescending(o => o.Count))
            {
                var page = sitedb.Pages.Get(item.ObjectId, true);
                if (page != null)
                {
                    ResourceCount count   = new ResourceCount();
                    var           pageurl = ObjectService.GetObjectRelativeUrl(sitedb, item.ObjectId, ConstObjectType.Page);
                    count.Name  = pageurl;
                    count.Count = item.Count;
                    count.Size  = item.Size;
                    pagecountes.Add(count);

                    counter += 1;
                    if (counter >= 3)
                    {
                        return(pagecountes);
                    }
                }
            }

            return(pagecountes);
        }
Esempio n. 4
0
        private List <MediaFileViewModel> GetFilesBy(SiteDb siteDb, string by)
        {
            string baseurl = siteDb.WebSite.BaseUrl();
            // by = View, Page, Layout, TextContent, Style.
            byte consttype = ConstObjectType.GetByte(by);

            var images = siteDb.Images.ListUsedBy(consttype);

            List <MediaFileViewModel> Result = new List <MediaFileViewModel>();

            foreach (var item in images)
            {
                MediaFileViewModel model = new MediaFileViewModel();
                model.Id           = item.Id;
                model.Height       = item.Height;
                model.Width        = item.Width;
                model.Size         = item.Size;
                model.Name         = item.Name;
                model.LastModified = item.LastModified;
                model.Thumbnail    = ThumbnailService.GenerateThumbnailUrl(item.Id, 90, 0, siteDb.Id);
                model.Url          = ObjectService.GetObjectRelativeUrl(siteDb, item);
                model.IsImage      = true;
                model.PreviewUrl   = Lib.Helper.UrlHelper.Combine(baseurl, model.Url);

                var usedby = siteDb.Images.GetUsedBy(item.Id);

                if (usedby != null)
                {
                    model.References = usedby.GroupBy(it => it.ConstType).ToDictionary(
                        key =>
                    {
                        return(ConstTypeService.GetModelType(key.Key).Name);
                    }, value => value.Count());
                }

                Result.Add(model);
            }
            return(Result);
        }
Esempio n. 5
0
        private List <FileItemViewModel> GetFiles(SiteDb siteDb, string path)
        {
            string baseurl = siteDb.WebSite.BaseUrl();

            List <CmsFile> files = siteDb.Folders.GetFolderObjects <CmsFile>(path, true);

            List <FileItemViewModel> Result = new List <FileItemViewModel>();

            foreach (var item in files)
            {
                FileItemViewModel model = new FileItemViewModel();
                model.Id           = item.Id;
                model.Size         = item.Size;
                model.Name         = item.Name;
                model.LastModified = item.LastModified;
                model.Url          = ObjectService.GetObjectRelativeUrl(siteDb, item);
                model.PreviewUrl   = Lib.Helper.UrlHelper.Combine(baseurl, model.Url);

                model.Relations = Sites.Helper.RelationHelper.Sum(siteDb.Files.GetUsedBy(item.Id));

                Result.Add(model);
            }
            return(Result);
        }
Esempio n. 6
0
        /// <summary>
        /// Calculate or reclculate the relation to css rule.
        /// </summary>
        /// <param name="style"></param>
        /// <param name="sitedb"></param>
        public static void Compute(Style style, Repository.SiteDb sitedb)
        {
            var body = style.Body;

            var covnerted = Kooboo.Sites.Service.CssService.ConvertCss(body, style.Id);

            if (style.OwnerObjectId != default(Guid))
            {
                foreach (var item in covnerted)
                {
                    item.CmsRule.OwnerObjectId        = style.OwnerObjectId;
                    item.CmsRule.OwnerObjectConstType = style.OwnerConstType;
                }
            }

            // remove not any more valid rules.
            RemoveOldRules(style, sitedb, covnerted);

            string baseurl = ObjectService.GetObjectRelativeUrl(sitedb, style);

            foreach (var item in covnerted)
            {
                ///compute import relation or the style image/font definition...
                if (item.CmsRule.ruleType == RuleType.ImportRule)
                {
                    var importrule = item.CssRule as Kooboo.Dom.CSS.CSSImportRule;
                    if (importrule != null)
                    {
                        string url = importrule.href;

                        if (!string.IsNullOrEmpty(url))
                        {
                            string objecturl = Kooboo.Lib.Helper.UrlHelper.Combine(baseurl, url);

                            Route temprouteid = new Route()
                            {
                                Name = objecturl
                            };
                            Guid routeid = temprouteid.Id;

                            List <ObjectRelation> oldrelations = sitedb.Relations.GetRelations(item.RuleId);

                            if (oldrelations.Count == 1 && oldrelations[0].objectYId == routeid && oldrelations[0].ConstTypeY == ConstObjectType.Route)
                            {
                                // the relation already there.
                                continue;
                            }

                            foreach (var relation in oldrelations)
                            {
                                sitedb.Relations.Delete(relation.Id);
                            }

                            sitedb.Relations.AddOrUpdate(item.CmsRule.Id, routeid, item.CmsRule.ConstType, ConstObjectType.Route, ConstObjectType.Style);
                        }
                    }
                }
                else if (item.CmsRule.ruleType == RuleType.StyleRule)
                {
                    Relation.CmsCssRuleRelation.ComputeUrl(item.CmsRule, baseurl, sitedb);
                }
                sitedb.CssRules.AddOrUpdate(item.CmsRule);
            }
        }