Example #1
0
        private PagedListViewModel <MediaFileViewModel> GetPagedFilesBy(SiteDb siteDb, string by, int PageSize, int PageNumber)
        {
            string baseurl = siteDb.WebSite.BaseUrl();
            // by = View, Page, Layout, TextContent, Style.
            byte consttype = ConstObjectType.GetByte(by);

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

            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> list = 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());
                }

                list.Add(model);
            }

            Result.List = list;
            return(Result);
        }
Example #2
0
        public List <PushItemViewModel> PushItems(ApiCall call)
        {
            List <PushItemViewModel> result = new List <PushItemViewModel>();

            var sitedb = call.WebSite.SiteDb();

            foreach (var item in sitedb.Synchronization.GetPushItems(call.ObjectId))
            {
                var siteojbect = ObjectService.GetSiteObject(sitedb, item);
                if (siteojbect == null)
                {
                    continue;
                }
                ChangeType changetype = ChangeType.Add;
                if (item.EditType == IndexedDB.EditType.Delete)
                {
                    changetype = ChangeType.Delete;
                }
                else if (item.EditType == IndexedDB.EditType.Update)
                {
                    changetype = ChangeType.Update;
                }

                PushItemViewModel viewmodel = new PushItemViewModel
                {
                    Id           = item.Id,
                    ObjectType   = ConstTypeService.GetModelType(siteojbect.ConstType).Name,
                    Name         = LogService.GetLogDisplayName(sitedb, item),
                    KoobooType   = siteojbect.ConstType,
                    ChangeType   = changetype,
                    LastModified = siteojbect.LastModified,
                    LogId        = item.Id
                };

                viewmodel.Size = CalculateUtility.GetSizeString(ObjectService.GetSize(siteojbect));

                if (siteojbect.ConstType == ConstObjectType.Image)
                {
                    viewmodel.Thumbnail = ThumbnailService.GenerateThumbnailUrl(siteojbect.Id, 50, 50, call.WebSite.Id);
                }

                result.Add(viewmodel);
            }

            return(result);
        }
Example #3
0
        private PageViewModel ToPageModel(SiteDb sitedb, Page item)
        {
            PageViewModel pagemodel = new PageViewModel()
            {
                Id           = item.Id,
                Name         = item.Name,
                Type         = item.Type,
                Online       = item.Online,
                Path         = Sites.Service.ObjectService.GetObjectRelativeUrl(sitedb, item),
                PreviewUrl   = PageService.GetPreviewUrl(sitedb, item),
                Linked       = sitedb.Relations.GetReferredBy(item).Count(),
                LayoutId     = GetLayoutId(item),
                PageView     = sitedb.VisitorLog.QueryDescending(o => o.ObjectId == item.Id).EndQueryCondition(o => o.Begin < DateTime.UtcNow.AddHours(-24)).Take(999999).Count(),
                LastModified = item.LastModified,
                StartPage    = item.DefaultStart,
                InlineUrl    = "/_api/redirect/inline?siteid=" + sitedb.WebSite.Id + "&pageid=" + item.Id
            };

            var relations = sitedb.Relations.GetRelations(item.Id);

            if (relations != null && relations.Count() > 0)
            {
                var relationresult = pagemodel.Relations;
                foreach (var onerelation in relations.Where(o => o.ConstTypeY == ConstObjectType.Layout || o.ConstTypeY == ConstObjectType.View || o.ConstTypeY == ConstObjectType.Form || o.ConstTypeY == ConstObjectType.HtmlBlock || o.ConstTypeY == ConstObjectType.Menu))
                {
                    var objecttypename = ConstTypeService.GetModelType(onerelation.ConstTypeY).Name;
                    if (relationresult.ContainsKey(objecttypename))
                    {
                        var value = relationresult[objecttypename];
                        value = value + 1;
                        relationresult[objecttypename] = value;
                    }
                    else
                    {
                        relationresult.Add(objecttypename, 1);
                    }
                }
            }

            return(pagemodel);
        }
Example #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);
        }
Example #5
0
        public static Dictionary <string, int> Sum(List <UsedByRelation> relations)
        {
            Dictionary <string, int> result = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);

            if (relations != null && relations.Any())
            {
                foreach (var item in relations.GroupBy(o => o.ConstType))
                {
                    var consttype = item.Key;

                    var type = ConstTypeService.GetModelType(consttype);

                    if (type != null)
                    {
                        var name  = type.Name;
                        var count = item.Count();
                        result[name] = count;
                    }
                }
            }

            return(result);
        }
Example #6
0
        public static void ComputeUrlRelation(SiteDb sitedb, Guid objectId, byte constType, List <string> urllist)
        {
            List <Guid> internalRoutes   = new List <Guid>();
            List <Guid> ExternalResource = new List <Guid>();

            var oldRouteRelations            = sitedb.Relations.GetRelationViaRoutes(objectId);
            var oldExternalResourceRelations = sitedb.Relations.GetExternalRelations(objectId, 0);

            byte FinalDestConstType = 0;

            foreach (var item in urllist.Distinct())
            {
                FinalDestConstType = ConstTypeService.GetConstTypeByUrl(item);;

                if (Service.DomUrlService.IsExternalLink(item))
                {
                    Guid externalid = Kooboo.Data.IDGenerator.Generate(item, ConstObjectType.ExternalResource);
                    ExternalResource.Add(externalid);
                    if (oldExternalResourceRelations.Find(o => o.objectYId == externalid) == null)
                    {
                        sitedb.ExternalResource.AddOrUpdate(item, FinalDestConstType);
                    }
                }
                else
                {
                    var routeids = DomRelation.GetRouteIds(sitedb, item);
                    internalRoutes.AddRange(routeids);
                    if (routeids.Count == 1 && oldRouteRelations.Find(o => o.objectYId == routeids[0]) == null)
                    {
                        sitedb.Routes.EnsureExists(item, FinalDestConstType);
                    }
                }
            }

            foreach (var item in oldRouteRelations)
            {
                if (!internalRoutes.Contains(item.objectYId))
                {
                    sitedb.Relations.Delete(item.Id);
                }
            }

            foreach (var item in internalRoutes)
            {
                if (oldRouteRelations.Find(o => o.objectYId == item) == null)
                {
                    sitedb.Relations.AddOrUpdate(objectId, item, constType, ConstObjectType.Route, FinalDestConstType);
                }
            }


            foreach (var item in oldExternalResourceRelations)
            {
                if (!ExternalResource.Contains(item.objectYId))
                {
                    sitedb.Relations.Delete(item.Id);
                }
            }

            foreach (var item in ExternalResource)
            {
                if (oldExternalResourceRelations.Find(o => o.objectYId == item) == null)
                {
                    sitedb.Relations.AddOrUpdate(objectId, item, constType, ConstObjectType.ExternalResource, FinalDestConstType);
                }
            }
        }
Example #7
0
        public List <PushItemViewModel> PushItems(ApiCall call)
        {
            List <PushItemViewModel> result = new List <PushItemViewModel>();

            var sitedb = call.WebSite.SiteDb();
            var kdb    = Kooboo.Data.DB.GetKDatabase(call.Context.WebSite);

            foreach (var item in sitedb.Synchronization.GetPushItems(call.ObjectId))
            {
                ChangeType changetype = ChangeType.Add;
                if (item.EditType == IndexedDB.EditType.Delete)
                {
                    changetype = ChangeType.Delete;
                }
                else if (item.EditType == IndexedDB.EditType.Update)
                {
                    changetype = ChangeType.Update;
                }

                if (item.IsTable)
                {
                    var table = Data.DB.GetTable(kdb, item.TableName);
                    if (table != null)
                    {
                        var logdata = table.GetLogData(item);
                        PushItemViewModel viewmodel = new PushItemViewModel
                        {
                            Id         = item.Id,
                            ObjectType = Kooboo.Data.Language.Hardcoded.GetValue("Table", call.Context),
                            Name       = LogService.GetTableDisplayName(sitedb, item, call.Context),
                            // KoobooType = siteojbect.ConstType,
                            ChangeType   = changetype,
                            LastModified = item.UpdateTime,
                            LogId        = item.Id
                        };
                        result.Add(viewmodel);
                    }
                }
                else
                {
                    var siteojbect = ObjectService.GetSiteObject(sitedb, item);
                    if (siteojbect == null)
                    {
                        continue;
                    }

                    PushItemViewModel viewmodel = new PushItemViewModel
                    {
                        Id           = item.Id,
                        ObjectType   = ConstTypeService.GetModelType(siteojbect.ConstType).Name,
                        Name         = LogService.GetLogDisplayName(sitedb, item),
                        KoobooType   = siteojbect.ConstType,
                        ChangeType   = changetype,
                        LastModified = siteojbect.LastModified,
                        LogId        = item.Id
                    };

                    viewmodel.Size = CalculateUtility.GetSizeString(ObjectService.GetSize(siteojbect));

                    if (siteojbect.ConstType == ConstObjectType.Image)
                    {
                        viewmodel.Thumbnail = ThumbnailService.GenerateThumbnailUrl(siteojbect.Id, 50, 50, call.WebSite.Id);
                    }

                    result.Add(viewmodel);
                }
            }

            return(result.OrderBy(o => o.LogId).ToList());
        }