예제 #1
0
파일: Publish.cs 프로젝트: outputlog/Kooboo
        private PagedListViewModel <SyncLogItemViewModel> GetLogItem(ApiCall call, bool initem)
        {
            var sitedb = call.WebSite.SiteDb();

            int pagesize = ApiHelper.GetPageSize(call);
            int pagenr   = ApiHelper.GetPageNr(call);

            PagedListViewModel <SyncLogItemViewModel> model = new PagedListViewModel <SyncLogItemViewModel>();

            model.PageNr   = pagenr;
            model.PageSize = pagesize;

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

            Guid settingid = call.GetGuidValue("SyncSettingId");

            var items = sitedb.Synchronization.Query.Where(o => o.SyncSettingId == settingid && o.In == initem).SelectAll().OrderByDescending(o => o.LastModifyTick);

            model.TotalCount = items.Count();
            model.TotalPages = ApiHelper.GetPageCount(model.TotalCount, model.PageSize);

            foreach (var item in items.Skip(model.PageNr * model.PageSize - model.PageSize).Take(model.PageSize))
            {
                var repo = sitedb.GetRepository(item.StoreName);

                if (repo != null)
                {
                    var log = sitedb.Log.Get(item.Version);
                    if (log != null)
                    {
                        var siteobject = repo.GetByLog(log);

                        SyncLogItemViewModel logitem = new SyncLogItemViewModel();
                        var info = ObjectService.GetObjectInfo(sitedb, siteobject as ISiteObject);
                        logitem.Name         = info.Name;
                        logitem.Size         = Lib.Utilities.CalculateUtility.GetSizeString(info.Size);
                        logitem.ObjectType   = repo.StoreName;
                        logitem.LastModified = log.UpdateTime;
                        logitem.LogId        = log.Id;

                        if (log.EditType == IndexedDB.EditType.Add)
                        {
                            logitem.ChangeType = ChangeType.Add;
                        }
                        else if (log.EditType == IndexedDB.EditType.Update)
                        {
                            logitem.ChangeType = ChangeType.Update;
                        }
                        else
                        {
                            logitem.ChangeType = ChangeType.Delete;
                        }

                        result.Add(logitem);
                    }
                }
            }

            model.List = result;
            return(model);
        }
예제 #2
0
        private PagedListViewModel <SyncLogItemViewModel> GetLogItem(ApiCall call, bool initem)
        {
            var sitedb = call.WebSite.SiteDb();

            int pagesize = ApiHelper.GetPageSize(call);
            int pagenr   = ApiHelper.GetPageNr(call);

            PagedListViewModel <SyncLogItemViewModel> model = new PagedListViewModel <SyncLogItemViewModel>();

            model.PageNr   = pagenr;
            model.PageSize = pagesize;

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

            Guid settingid = call.GetGuidValue("SyncSettingId");

            var items = sitedb.Synchronization.Query.Where(o => o.SyncSettingId == settingid && o.In == initem).SelectAll().OrderByDescending(o => o.LastModifyTick);

            model.TotalCount = items.Count();
            model.TotalPages = ApiHelper.GetPageCount(model.TotalCount, model.PageSize);

            foreach (var item in items.Skip(model.PageNr * model.PageSize - model.PageSize).Take(model.PageSize))
            {
                var log = sitedb.Log.Get(item.Version);
                if (log != null)
                {
                    ChangeType changetype;
                    if (log.EditType == IndexedDB.EditType.Add)
                    {
                        changetype = ChangeType.Add;
                    }
                    else if (log.EditType == IndexedDB.EditType.Update)
                    {
                        changetype = ChangeType.Update;
                    }
                    else
                    {
                        changetype = ChangeType.Delete;
                    }

                    if (log.IsTable)
                    {
                        var kdb   = Kooboo.Data.DB.GetKDatabase(sitedb.WebSite);
                        var table = Data.DB.GetTable(kdb, log.TableName);

                        if (table != null)
                        {
                            var logdata = table.GetLogData(log);

                            string size = null;
                            if (logdata != null)
                            {
                                var json = Lib.Helper.JsonHelper.Serialize(logdata);
                                size = CalculateUtility.GetSizeString(json.Length);
                            }

                            var name = Kooboo.Sites.Service.LogService.GetTableDisplayName(sitedb, log, call.Context, logdata);

                            SyncLogItemViewModel logitem = new SyncLogItemViewModel();
                            logitem.Name = name;

                            logitem.ObjectType   = Data.Language.Hardcoded.GetValue("Table", call.Context);
                            logitem.LastModified = log.UpdateTime;
                            logitem.LogId        = log.Id;
                            logitem.ChangeType   = changetype;

                            result.Add(logitem);
                        }
                    }

                    else
                    {
                        var repo = sitedb.GetRepository(item.StoreName);

                        if (repo != null)
                        {
                            var siteobject = repo.GetByLog(log);

                            SyncLogItemViewModel logitem = new SyncLogItemViewModel();
                            var info = ObjectService.GetObjectInfo(sitedb, siteobject as ISiteObject);
                            logitem.Name         = info.Name;
                            logitem.Size         = Lib.Utilities.CalculateUtility.GetSizeString(info.Size);
                            logitem.ObjectType   = repo.StoreName;
                            logitem.LastModified = log.UpdateTime;
                            logitem.LogId        = log.Id;
                            logitem.ChangeType   = changetype;

                            result.Add(logitem);
                        }
                    }
                }
            }
            model.List = result;
            return(model);
        }