Пример #1
0
        public static Sync.SyncObject GetSyncObject(SiteDb SiteDb, LogEntry log, bool GenerateClusterInfo = true)
        {
            var key = Kooboo.IndexedDB.ByteConverter.GuidConverter.ConvertFromByte(log.KeyBytes);

            Sync.SyncObject item = new Sync.SyncObject();

            var repo = SiteDb.GetRepository(log.StoreName);

            var siteobject = repo.GetByLog(log) as ISiteObject;

            if (log.EditType == EditType.Delete)
            {
                item.IsDelete        = true;
                item.ObjectConstType = ConstTypeContainer.GetConstType(repo.ModelType);
                item.ObjectId        = key;
            }
            else
            {
                if (siteobject != null)
                {
                    item = Sync.SyncObjectConvertor.ToSyncObject(siteobject);
                }
            }

            if (GenerateClusterInfo)
            {
                Sync.Cluster.Integrity.Generate(SiteDb, item, log.Id);
            }

            item.SenderVersion = log.Id;

            return(item);
        }
Пример #2
0
        public List <UsedByRelation> Relation(ApiCall call)
        {
            var sitedb = call.WebSite.SiteDb();

            string type = call.GetValue("type", "by");

            if (string.IsNullOrEmpty(type))
            {
                return(null);
            }
            byte consttype = ConstTypeContainer.GetConstType(type);

            if (call.ObjectId != default(Guid))
            {
                return(sitedb.Styles.GetUsedBy(call.ObjectId)
                       .Where(it => it.ConstType == consttype)
                       .Select(it =>
                {
                    it.Url = sitedb.WebSite.BaseUrl(it.Url);
                    return it;
                }).ToList());
            }

            return(null);
        }
Пример #3
0
        private List <UsedByRelation> PageRelation(SiteDb sitedb, string by, Guid PageId)
        {
            string baseurl = sitedb.WebSite.BaseUrl();

            byte consttype = ConstTypeContainer.GetConstType(by);

            List <UsedByRelation> result = new List <UsedByRelation>();

            var relations = sitedb.Relations.GetRelations(PageId, consttype);

            foreach (var item in relations)
            {
                var objectinfo = ObjectService.GetObjectInfo(sitedb, item.objectYId, item.ConstTypeY);

                if (objectinfo != null)
                {
                    UsedByRelation relation = new UsedByRelation();
                    relation.Name = objectinfo.DisplayName;
                    relation.Url  = objectinfo.Url;
                    if (!string.IsNullOrEmpty(relation.Url))
                    {
                        relation.Url = Lib.Helper.UrlHelper.Combine(baseurl, relation.Url);
                    }
                    relation.ModelType = objectinfo.ModelType;
                    relation.ObjectId  = objectinfo.ObjectId;
                    relation.ConstType = objectinfo.ConstType;
                    result.Add(relation);
                }
            }
            return(result);
        }
Пример #4
0
        public string RenderSystemLink(RenderContext context, Routing.Route route)
        {
            Render.FrontContext frontContext = context.GetItem <Render.FrontContext>();

            route.Parameters = ObjectRoute.ParseParameters(route, this.Url);

            var  constTypeString = route.Parameters.GetValue("objecttype");
            byte constType       = ConstObjectType.Unknown;

            if (!byte.TryParse(constTypeString, out constType))
            {
                constType = ConstTypeContainer.GetConstType(constTypeString);
            }
            var id = route.Parameters.GetValue("nameorid");

            if (constType == ConstObjectType.View)
            {
                var view = context.WebSite.SiteDb().Views.GetByNameOrId(id);

                if (view != null)
                {
                    var relation = context.WebSite.SiteDb().Relations.GetReferredBy(view, ConstObjectType.Page);

                    if (relation != null && relation.Count > 0)
                    {
                        var pageid = relation[0].objectXId;

                        var pageroute = context.WebSite.SiteDb().Routes.GetByObjectId(pageid);

                        if (pageroute != null)
                        {
                            return(RenderPageRoute(context, pageroute));
                        }
                    }
                    /// if view was not rendered within and by the page... try to render with rendercode.
                    if (frontContext.Page != null && frontContext.ExecutingView != null)
                    {
                        string currenturl = context.Request.RelativeUrl;

                        var values = PageRoute.GetViewParameterValues(context.WebSite.SiteDb(), view, frontContext);

                        var alternativeviewcode = Cache.ViewInSamePosition.GetAlternativeCode(frontContext.ExecutingView.Id, view.Id);

                        values.Add(SiteConstants.AlternativeViewQueryName, alternativeviewcode.ToString());
                        return(Kooboo.Lib.Helper.UrlHelper.AppendQueryString(currenturl, values));
                    }

                    else if (frontContext.Page == null)
                    {
                        var values = PageRoute.GetViewParameterValues(context.WebSite.SiteDb(), view, frontContext);

                        return(Kooboo.Lib.Helper.UrlHelper.AppendQueryString(this.Url, values));
                    }
                }
            }
            return(null);
        }
Пример #5
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 = ConstTypeContainer.GetConstType(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);
        }
Пример #6
0
        public static TValue Get(SiteDb SiteDb, string NameOrId)
        {
            Guid id;

            if (!System.Guid.TryParse(NameOrId, out id))
            {
                var consttype = ConstTypeContainer.GetConstType(typeof(TValue));
                id = Kooboo.Data.IDGenerator.Generate(NameOrId, consttype);
            }
            return(Get(SiteDb, id));
        }
Пример #7
0
        public static async Task Render(FrontContext context)
        {
            //systemroute.Name = "__kb/{objecttype}/{nameorid}"; defined in Routes.
            var  paras         = context.Route.Parameters;
            var  strObjectType = paras.GetValue("objecttype");
            byte constType     = ConstObjectType.Unknown;

            if (!byte.TryParse(strObjectType, out constType))
            {
                constType = ConstTypeContainer.GetConstType(strObjectType);
            }
            var id = paras.GetValue("nameorid");

            switch (constType)
            {
            case ConstObjectType.ResourceGroup:
                ResourceGroupRender(context, id);
                return;

            case ConstObjectType.View:
                await ViewRender(context, id, paras);

                return;

            case ConstObjectType.Image:
            {
                ImageRender(context, id, paras);
                return;
            }

            case ConstObjectType.CmsFile:
            {
                FileRender(context, id, paras);
                return;
            }

            case ConstObjectType.kfile:
            {
                KFileRender(context, paras);
                return;
            }

            //case ConstObjectType.TextContent:
            //    {
            //        TextContentRender(context, id, paras);
            //        return;
            //    }
            default:
                DefaultRender(context, constType, strObjectType, id, paras);
                break;
            }
        }
Пример #8
0
        public virtual TValue GetByNameOrId(string NameOrGuid)
        {
            Guid key;
            bool parseok = Guid.TryParse(NameOrGuid, out key);

            if (!parseok)
            {
                byte consttype = ConstTypeContainer.GetConstType(typeof(TValue));

                key = Data.IDGenerator.Generate(NameOrGuid, consttype);
            }
            return(Get(key));
        }
Пример #9
0
        public override RolePermission GetByNameOrId(string NameOrGuid)
        {
            Guid key;
            bool parseok = Guid.TryParse(NameOrGuid, out key);

            if (!parseok)
            {
                byte consttype = ConstTypeContainer.GetConstType(typeof(RolePermission));

                key = Data.IDGenerator.Generate(NameOrGuid, consttype);
            }
            return(Get(key, false));
        }
Пример #10
0
        public List <T> GetFolderObjects <T>(string FolderPath, bool UseColumnDataOnly = false, bool Recursive = false) where T : SiteObject
        {
            List <T> list = new List <T>();

            byte consttype = ConstTypeContainer.GetConstType(typeof(T));

            var siteobjectlist = GetFolderObjects(FolderPath, consttype, UseColumnDataOnly, Recursive);

            foreach (var item in siteobjectlist)
            {
                var tvalue = (T)item;
                if (tvalue != null)
                {
                    list.Add(tvalue);
                }
            }

            return(list);
        }
Пример #11
0
        private List <MediaFileViewModel> GetFilesBy(SiteDb siteDb, string by)
        {
            string baseurl = siteDb.WebSite.BaseUrl();
            // by = View, Page, Layout, TextContent, Style.
            byte consttype = ConstTypeContainer.GetConstType(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);
        }
Пример #12
0
        public List <UsedByRelation> ShowBy(ApiCall call)
        {
            var sitedb = call.WebSite.SiteDb();

            string type = call.GetValue("type");
            string by   = call.GetValue("by");

            if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(by))
            {
                return(null);
            }

            if (type.ToLower() == "page")
            {
                return(PageRelation(sitedb, by, call.ObjectId));
            }

            var repo       = sitedb.GetRepository(type);
            var siteobject = repo?.Get(call.ObjectId);

            if (repo == null || siteobject == null)
            {
                return(null);
            }

            string baseurl = call.WebSite.BaseUrl();

            byte consttype = ConstTypeContainer.GetConstType(by);

            List <UsedByRelation> result = new List <UsedByRelation>();

            var usedby = repo.GetUsedBy(call.ObjectId).Where(o => o.ConstType == consttype).ToList();

            foreach (var item in usedby)
            {
                item.Url = sitedb.WebSite.BaseUrl(item.Url);
            }
            return(usedby);
        }
Пример #13
0
        public List <UsedByRelation> ShowRelation(ApiCall call)
        {
            var viewdatamethod = call.WebSite.SiteDb().ViewDataMethods.Query.Where(o => o.MethodId == call.ObjectId).SelectAll();


            string by = call.GetValue("by");

            if (string.IsNullOrEmpty(by))
            {
                return(null);
            }

            byte consttype = ConstTypeContainer.GetConstType(by);

            var usedby = call.WebSite.SiteDb().Images.GetUsedBy(call.ObjectId).Where(o => o.ConstType == consttype).ToList();

            foreach (var item in usedby)
            {
                item.Url = call.WebSite.SiteDb().WebSite.BaseUrl(item.Url);
            }

            return(usedby);
        }
Пример #14
0
        public object Relation(ApiCall call)
        {
            string type = call.GetValue("type", "by");

            if (string.IsNullOrEmpty(type))
            {
                return(null);
            }
            byte consttype = ConstTypeContainer.GetConstType(type);

            if (call.ObjectId != default(Guid))
            {
                return(call.WebSite.SiteDb().Scripts.GetUsedBy(call.ObjectId)
                       .Where(it => it.ConstType == consttype)
                       .Select(it =>
                {
                    it.Url = call.WebSite.BaseUrl(it.Url);
                    return it;
                }));
            }

            return(null);
        }
Пример #15
0
        public static async Task Render(FrontContext context)
        {
            //systemroute.Name = "__kb/{objecttype}/{nameorid}"; defined in Routes.
            var paras         = context.Route.Parameters;
            var strObjectType = paras.GetValue("objecttype");

            if (strObjectType == null)
            {
                return;
            }
            byte constType = ConstObjectType.Unknown;

            if (!byte.TryParse(strObjectType, out constType))
            {
                constType = ConstTypeContainer.GetConstType(strObjectType);

                if (constType == 0 && strObjectType == "custom")
                {
                    //   sysRoute.Name = "/__kb/{objecttype}/{nameorid}/{action}";
                    var type = paras.GetValue("nameorid");
                    var para = paras.GetValue("action");
                    await Kooboo.Sites.Render.Renderers.Custom.CustomRenderManager.RenderAsync(type, para, context);

                    return;
                }
            }


            var id = paras.GetValue("nameorid");

            switch (constType)
            {
            case ConstObjectType.ResourceGroup:
                ResourceGroupRender(context, id);
                return;

            case ConstObjectType.View:
                await ViewRender(context, id, paras);

                return;

            case ConstObjectType.Image:
            {
                ImageRender(context, id, paras);
                return;
            }

            case ConstObjectType.CmsFile:
            {
                FileRender(context, id, paras);
                return;
            }

            case ConstObjectType.kfile:
            {
                KFileRender(context, paras);
                return;
            }

            //case ConstObjectType.TextContent:
            //    {
            //        TextContentRender(context, id, paras);
            //        return;
            //    }
            default:
                DefaultRender(context, constType, strObjectType, id, paras);
                break;
            }
        }