Beispiel #1
0
        public static IEnumerable <T> QueryList <T>(Site site, string viewName)
        {
            var bucket = site.GetClient();

            if (bucket != null)
            {
                var view = GetView(bucket, site.GetBucketName(), viewName, viewName);

                var idList = view.Select(it => it.ItemId).ToArray();

                return(bucket.ExecuteGet(idList).Select(it => ModelExtensions.JsonToObject <T>(it.Value.Value.ToString()))
                       .Select(it => { if (it is ISiteObject)
                                       {
                                           ((ISiteObject)it).Site = site;
                                       }
                                       return it; }));
            }
            else
            {
                return(new T[0]);
            }
        }
Beispiel #2
0
 private IEnumerable <Page> QueryBySite(Site site)
 {
     return(DataHelper.QueryList <Page>(site, ModelExtensions.GetQueryView(ModelExtensions.PageDataType), createModel)
            .Where(it => it.Parent == null));
 }
Beispiel #3
0
        public Models.Page Get(Models.Page dummy)
        {
            var bucketDocumentKey = ModelExtensions.GetBucketDocumentKey(ModelExtensions.PageDataType, dummy.FullName);

            return(DataHelper.QueryByKey <Page>(dummy.Site, bucketDocumentKey, createModel));
        }
Beispiel #4
0
 public void RemoveDraft(Page page)
 {
     DataHelper.DeleteItemByKey(page.Site, ModelExtensions.GetBucketDocumentKey(ModelExtensions.PageDraftDataType, page.FullName));
 }
Beispiel #5
0
        public Page GetDraft(Page page)
        {
            var bucketDocumentKey = ModelExtensions.GetBucketDocumentKey(ModelExtensions.PageDraftDataType, page.FullName);

            return(DataHelper.QueryByKey <Page>(page.Site, bucketDocumentKey, createModel));
        }
Beispiel #6
0
 private IEnumerable <Page> AllPagesNested(Site site)
 {
     return(DataHelper.QueryList <Page>(site, ModelExtensions.GetQueryView(ModelExtensions.PageDataType), createModel));
 }
Beispiel #7
0
 public IEnumerable <Page> ChildPages(Models.Page parentPage)
 {
     return(DataHelper.QueryList <Page>(parentPage.Site, ModelExtensions.GetQueryView(ModelExtensions.PageDataType), createModel)
            .Where(it => it.Parent == parentPage));
 }
Beispiel #8
0
 public static string GetViewBody(string dataType)
 {
     return(string.Format(DataHelper.ViewTemplate, ModelExtensions.GetQueryViewName(dataType), dataType));
 }
Beispiel #9
0
 public override void Remove(Site item)
 {
     DataHelper.DeleteItemByKey(item, ModelExtensions.GetBucketDocumentKey(ModelExtensions.SiteDataType, item.Name));
     base.Remove(item);
 }
Beispiel #10
0
 public virtual void Remove(T item)
 {
     DataHelper.DeleteItemByKey(item.Site, ModelExtensions.GetBucketDocumentKey(DataType, item.UUID));
 }
Beispiel #11
0
 public virtual IEnumerable <T> All(Models.Site site)
 {
     return(DataHelper.QueryList <T>(site, ModelExtensions.GetQueryView(DataType), CreateModel));
 }
Beispiel #12
0
        static SiteProvider()
        {
            //Create Kooboo_CMS global bucket
            var defaultBucket = DatabaseSettings.Instance.DefaultBucketName;

            if (!DatabaseHelper.ExistBucket(defaultBucket))
            {
                DatabaseHelper.CreateBucket(defaultBucket);
                System.Threading.Thread.Sleep(3000);
            }
            DatabaseHelper.CreateDesignDocument(defaultBucket, ModelExtensions.GetQueryView(ModelExtensions.ABRuleSettingDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.ABRuleSettingDataType), ModelExtensions.ABRuleSettingDataType));
            DatabaseHelper.CreateDesignDocument(defaultBucket, ModelExtensions.GetQueryView(ModelExtensions.ABSiteSettingDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.ABSiteSettingDataType), ModelExtensions.ABSiteSettingDataType));
            System.Threading.Thread.Sleep(3000);
        }
Beispiel #13
0
 public static bool CreateDefaultViews(this Site site)
 {
     return(CreateDesignDocument(site.GetBucketName(), ModelExtensions.DesignDocumentName, ModelExtensions.GetDesignDocumentBody()));
 }
Beispiel #14
0
        public static IView <IViewRow> GetView(CouchbaseClient bucket, string bucketName, string designName, string viewName)
        {
            var view = bucket.GetView(viewName, viewName).Stale(global::Couchbase.StaleMode.False).Reduce(false);

            if (!view.CheckExistsByCache(bucketName, viewName))
            {
                var created = DatabaseHelper.CreateDesignDocument(bucketName, viewName, string.Format(viewTemplate, viewName, ModelExtensions.GetDataType(viewName)));
                if (created)
                {
                    DatabaseHelper.ExistedView.Add(DatabaseHelper.GetViewCacheName(bucketName, viewName));
                    System.Threading.Thread.Sleep(3000);
                }
                else
                {
                    throw new Exception("Create view " + viewName + " faild");
                }
            }
            return(view);
        }
Beispiel #15
0
        public static void StoreObject(ISiteObject o, string key, string dataType)
        {
            var bucket = o.Site.GetClient();

            bucket.ExecuteStore(StoreMode.Set, ModelExtensions.GetBucketDocumentKey(dataType, key), o.ToJson(dataType), PersistTo.One);
        }
Beispiel #16
0
        public virtual void Initialize(Site site)
        {
            var bucketName = site.GetBucketName();

            if (!DatabaseHelper.ExistBucket(bucketName))
            {
                DatabaseHelper.CreateBucket(bucketName);
                System.Threading.Thread.Sleep(3000);
                //此处需暂停几秒钟,否则,通过选择模板创建站点的方式,在导入数据时,会出现数据未导入的情况
                //大致原因在于,Couchbae在数据库创建之后,需要几秒钟的初始化过程,在这个过程中插入任何数据都将失败
            }
            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.PageDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.PageDataType), ModelExtensions.PageDataType));
            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.PageDraftDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.PageDraftDataType), ModelExtensions.PageDraftDataType));
            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.HtmlBlockDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.HtmlBlockDataType), ModelExtensions.HtmlBlockDataType));
            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.LabelDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.LabelDataType), ModelExtensions.LabelDataType));
            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.LabelCategoryDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.LabelCategoryDataType), ModelExtensions.LabelCategoryDataType));
            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.UserDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.UserDataType), ModelExtensions.UserDataType));
            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.CustomErrorDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.CustomErrorDataType), ModelExtensions.CustomErrorDataType));
            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.UrlRedirectDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.UrlRedirectDataType), ModelExtensions.UrlRedirectDataType));

            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.ABPageSettingDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.ABPageSettingDataType), ModelExtensions.ABPageSettingDataType));
            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.ABPageTestResultDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.ABPageTestResultDataType), ModelExtensions.ABPageTestResultDataType));
            DatabaseHelper.CreateDesignDocument(bucketName, ModelExtensions.GetQueryView(ModelExtensions.ABRuleSettingDataType), string.Format(DataHelper.viewTemplate, ModelExtensions.GetQueryView(ModelExtensions.ABRuleSettingDataType), ModelExtensions.ABRuleSettingDataType));

            System.Threading.Thread.Sleep(3000);
        }