TextCotent 在Kooboo.CMS.Content下面,在View中有使用到这个模型层。

  TextContent继承了ContentBase,而ContentBase是由2个部分类组成的,一个是内容对象基类的子类,另一个是实现了持久化.那。。。我们该如何去理解呢,这里我用PS画一幅图大家就懂了。TextContent有3个构造函数,其中这2个构造函数都和基类(ContentBase)有关系。这3个构造函数分别如下:

        /// <summary>/// Initializes a new instance of the <see cref="TextContent"/> class./// </summary>/// <param name="dictionary">The dictionary.</param>public TextContent(IDictionary<string, object> dictionary): base(dictionary){}/// <summary>/// Initializes a new instance of the <see cref="TextContent"/> class./// </summary>public TextContent(): base(){this.Id = string.Empty;}/// <summary>/// Initializes a new instance of the <see cref="TextContent"/> class./// </summary>/// <param name="repository">The repository.</param>/// <param name="schemaName">Name of the schema.</param>/// <param name="folderName">Name of the folder.</param>public TextContent(string repository, string schemaName, string folderName): base(repository, folderName){this.Id = string.Empty;this.SchemaName = schemaName;}

  大家也许会疑惑这个TextContent有什么用处,看看视图里面的ViewBag.XXX你就明白了,其实ViewBag.XXX得到的是一个弱类型,可以强制转换成TextContent,为什么我这么自信它可以转换为TextContent呢?因为其实在数据库里建立的这张表和TextContent是一一对应的,字段的名称都是相同的。

下面的是TextContent的全部代码,大家有兴趣的可以对比一下,都是一样的。

#region License
//
// Copyright (c) 2013, Kooboo team
//
// Licensed under the BSD License
// See the file LICENSE.txt for details.
//
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;using Kooboo.CMS.Common.Persistence.Non_Relational;namespace Kooboo.CMS.Content.Models
{/// <summary>/// 文本内容/// </summary>public class TextContent : ContentBase{/// <summary>/// Initializes a new instance of the <see cref="TextContent"/> class./// </summary>/// <param name="dictionary">The dictionary.</param>public TextContent(IDictionary<string, object> dictionary): base(dictionary){}/// <summary>/// Initializes a new instance of the <see cref="TextContent"/> class./// </summary>public TextContent(): base(){this.Id = string.Empty;}/// <summary>/// Initializes a new instance of the <see cref="TextContent"/> class./// </summary>/// <param name="repository">The repository.</param>/// <param name="schemaName">Name of the schema.</param>/// <param name="folderName">Name of the folder.</param>public TextContent(string repository, string schemaName, string folderName): base(repository, folderName){this.Id = string.Empty;this.SchemaName = schemaName;}/// <summary>/// 内容对应的Schema(Content type)/// </summary>/// <value>/// The name of the schema./// </value>public string SchemaName{get{if (this.ContainsKey("SchemaName") && base["SchemaName"] != null){return base["SchemaName"].ToString();}return null;}set{base["SchemaName"] = value;}}/// <summary>/// 内嵌内容的父目录/// </summary>public string ParentFolder{get{if (this.ContainsKey("ParentFolder") && base["ParentFolder"] != null){return base["ParentFolder"].ToString();}return null;}set{base["ParentFolder"] = value;}}/// <summary>///内嵌内容的父内容的UUID/// </summary>public string ParentUUID{get{if (this.ContainsKey("ParentUUID") && base["ParentUUID"] != null){return base["ParentUUID"].ToString();}return null;}set{base["ParentUUID"] = value;}}/// <summary>/// Gets the type of the content./// </summary>/// <value>/// The type of the content./// </value>public override ContentType ContentType{get{return ContentType.Text;}}/// <summary>/// 内容被广播过来的源UUID/// </summary>public string OriginalUUID{get{if (this.ContainsKey("OriginalUUID") && base["OriginalUUID"] != null){return base["OriginalUUID"].ToString();}return null;}set{base["OriginalUUID"] = value;}}/// <summary>/// 内容被广播过来的源仓库/// </summary>public string OriginalRepository{get{if (this.ContainsKey("OriginalRepository") && base["OriginalRepository"] != null){return base["OriginalRepository"].ToString();}return null;}set{base["OriginalRepository"] = value;}}/// <summary>/// 内容被广播过来的源目录/// </summary>public string OriginalFolder{get{if (this.ContainsKey("OriginalFolder") && base["OriginalFolder"] != null){return base["OriginalFolder"].ToString();}return null;}set{base["OriginalFolder"] = value;}}/// <summary>///内容被广播过来后是否本地化了/// </summary>public bool? IsLocalized{get{if (this.ContainsKey("IsLocalized") && base["IsLocalized"] != null){return (bool)base["IsLocalized"];}return true;}set{base["IsLocalized"] = value;}}/// <summary>/// 内容的排序顺序/// </summary>public int Sequence{get{if (this.ContainsKey("Sequence") && base["Sequence"] != null){return Convert.ToInt32(base["Sequence"]);}return 0;}set{base["Sequence"] = value;}}/// <summary>/// 内容是否有附件/// </summary>/// <returns>///   <c>true</c> if this instance has attachment; otherwise, <c>false</c>./// </returns>public bool HasAttachment(){var schema = this.GetSchema();foreach (var column in schema.AsActual().Columns.Where(it => string.Compare(it.ControlType, "File", true) == 0)){var value = this[column.Name];if (value != null && !string.IsNullOrEmpty(value.ToString())){return true;}}return false;}/// <summary>/// 保存时,要存储的附件/// </summary>public IEnumerable<ContentFile> ContentFiles { get; set; }/// <summary>/// Called when [saving]./// </summary>protected override void OnSaving(){base.OnSaving();this.UserKey = UserKeyGenerator.DefaultGenerator.Generate(this);}#region override objectpublic override bool Equals(object obj){if (!(obj is ContentBase)){return false;}var c = (ContentBase)obj;if (this.UUID.EqualsOrNullEmpty(c.UUID, StringComparison.CurrentCultureIgnoreCase)){return true;}return base.Equals(obj);}public override int GetHashCode(){return base.GetHashCode();}#endregionpublic bool ___EnableVersion___{get{if (this.ContainsKey("___EnableVersion___") && base["___EnableVersion___"] != null){return (bool)base["___EnableVersion___"];}return true;}set{base["___EnableVersion___"] = value;}}#region MoreOptionsOnBroadcastingpublic int OriginalUpdateTimes{get{if (this.ContainsKey("OriginalUpdateTimes") && base["OriginalUpdateTimes"] != null){return (int)(base["OriginalUpdateTimes"]);}return 0;}set{base["OriginalUpdateTimes"] = value;}}public int OriginalLastestVisitedVersionId{get{if (this.ContainsKey("OriginalLastestVisitedVersionId") && base["OriginalLastestVisitedVersionId"] != null){return Convert.ToInt32(base["OriginalLastestVisitedVersionId"]);}return 0;}set{base["OriginalLastestVisitedVersionId"] = value;}}#endregion}
}

View Code

大家有没有发现,代码里面没有Title,Photo和Description这3个字段,那么这3个字段又是从哪里来的呢?看下面的图,原来是我们在内容类型里面自定义的。

我们可以查看一下这3个字段在数据库中的类型:

这里证明了一点,至少证明了一点,Kooboo CMS在对于String 类型的字符串,只要你没有设置长度的话,默认是到最长,这里补充一点,长度在Kooboo CMS中是可以去设置的,在这里设置。

  好了,下面来讲解一下各个字段的用途。

  • UUID:类似于Guid码,Kooboo CMS自己定义的一套生成编码的规则方法所生成的不定字符串。
  • Repository:仓库,一个网站就是一个仓库,你可以把仓库理解为网站的名称,但是不是显示名称,这个名称是建立了就不可修改的。
  • FolderName:文件夹名称。
  • UserKey:下面的是这么解释的。。。。。这个主要是用在条件过滤的时候
        /// <summary>/// 根据Summary字段生成的一个友好的唯一主键值,一般用于在URL中传递。/// </summary>public string UserKey{get{if (this.ContainsKey("UserKey") && base["UserKey"] != null){return base["UserKey"] == null ? "" : base["UserKey"].ToString();}return null;}set{base["UserKey"] = value;}}

下面的图将会为你解释UserKey的作用,当然前提是你需要一个Summary 概述字段,Summary字段是自己去勾选的,在CMS的后台里面。

而配置UserKey的地方在View里面的数据查询可以配置。

看到了吗,其实这里可以进行内容过滤,如果是UserKey的话,那么就是下面这么一种写法。

UserKey=={UserKey} 这里的{UserKey}就是一个不定的参数,我个人感觉类似于string.Format()里面的{0}{1}这种形式的参数表示法。

我们再来想一下一个问题,为什么ContentBase要继承DynamicDictionary呢?我们先来看一下DynamicDictionary的结构,我这里为了简化只放出属性。

  public class DynamicDictionary : DynamicObject, IDictionary<string, object>{#region FieldsIDictionary<string, object> dictionary;#endregion#region Properties/// <summary>/// Gets the count./// </summary>/// <value>/// The count./// </value>int ICollection<KeyValuePair<string, object>>.Count{get{return dictionary.Count;}}#endregion}

  其实说白了就是字典的扩展嘛。其实说简单一点,就是基类对象里面如果有UserKey的话,那么就会用get方法得到其值其余的就不多说了,大多是描述字段。

这里最后在介绍一下ContentBase对于IPersistable的支持。

本来想说一下的,但是太晚了,而且这个太难,做个记号,以后懂了再讲解。

    /// <summary>/// ContentBase对IPersistable的实现/// </summary>public partial class ContentBase : IPersistable{/// <summary>/// The content integrate id composite of Repository, FolderName and UUID. example: Repository#FolderName#UUID/// </summary>public string IntegrateId{get{return new ContentIntegrateId(this).ToString();}}#region IPersistable Membersprivate bool isDummy = true;bool IPersistable.IsDummy{get { return isDummy; }}void IPersistable.Init(IPersistable source){isDummy = false;}void IPersistable.OnSaved(){isDummy = false;}void IPersistable.OnSaving(){OnSaving();}protected virtual void OnSaving(){if (string.IsNullOrEmpty(this.UUID)){this.UUID = UUIDGenerator.DefaultGenerator.Generate(this);}}#endregion}

Kooboo CMS 之TextContent详解相关推荐

  1. CMS垃圾收集器详解

    概述 CMS垃圾收集器是一款优秀的老年代并发垃圾收集器,通过与用户线程并发执行的方式减少GC停顿的时间.本文主要聊一下CMS设计到的相关的数据结构.具体的执行过程.运行中会出现的异常情况. 在CMS之 ...

  2. g1垃圾回收器与cms垃圾回收器详解及最佳实践

    2019独角兽企业重金招聘Python工程师标准>>> G1垃圾收集器入门 说明 concurrent: 并发, 多个线程协同做同一件事情(有状态) parallel: 并行, 多个 ...

  3. CMS垃圾回收器详解

    垃圾回收器组合 young Tenured JVM options Serial Serial -XX:+UseSerialGC Parallel Scavenge Serial -XX:+UsePa ...

  4. CMS垃圾收集器详解(转载)

    文章目录 概念 CMS的GC过程 初始标记 并发标记 并发预处理 重新标记 并发清除 CMS的缺点 总结: 概念 CMS全称为Concurrent Mark Sweep,即 并发标记清除,对比其他的收 ...

  5. 在linux上gc日志详解,JVM CMS GC日志详解

    # JDK8 -Xms20M -Xmx20M -XX:+PrintGCDetails -XX:+UseConcMarkSweepGC CMS 日志格式: [GC (Allocation Failure ...

  6. JVM GC 日志详解

    本文采用的JDK版本: java version "1.8.0_144" Java(TM) SE Runtime Environment (build 1.8.0_144-b01) ...

  7. Kooboo CMS - Html.FrontHtml[Helper.cs] 各个方法详解

    下面罗列了方法详解,每一个方法一篇文章. Kooboo CMS - @Html.FrontHtml().HtmlTitle() 详解 Kooboo CMS - Html.FrontHtml.Posit ...

  8. Kooboo CMS - Html.FrontHtml.Position 详解

    DataContract 数据契约 http://www.cnblogs.com/Gavinzhao/archive/2010/06/01/1748736.html https://msdn.micr ...

  9. 中英文 php cms,phpcms v9英语语言包应用详解

    phpcms英文二次开发之语言包详解 phpcms英文的语言包使其成为国际化的cms,从PHPCMS v9.1开始,发布了英文版.但很遇憾的是,到目前为止,PHPCMS还没有实现语言切换的功能,比如中 ...

最新文章

  1. Python提取数字图片特征向量
  2. jetty 配置jndi_使用Jetty设置JNDI(嵌入式)
  3. 【蓝桥杯每日一练】 巴斯卡三角形(杨辉三角形)
  4. 复数基础——数组_1
  5. struts读常量顺序
  6. 完整的企业机房设计(上)
  7. 在麒麟桌面操作系统编译安装postgresql的经历
  8. Python实现输出手写体图片
  9. python 下如何播放mp3
  10. django框架全解
  11. linux下添加JAVA_HOME环境变量
  12. 武汉云数时代网络科技有限公司代运营具体需要做好哪些方面?
  13. 画质超高的仙侠java游戏_画质超高的游戏有哪些?顶级画质大型游戏盘点
  14. NB-IoT技术的未来发展,主要面临哪些挑战?
  15. 模具设计师该如何报价?模具报价该如何计算?一起学起来
  16. 嵌入式系统基础概念(一)二进制和十六进制
  17. OpenCV-图像着色(采用DNN模块导入深度学习模型)
  18. 如何制作带图片的中药标签
  19. Windows10系统升级1903后护眼模式无效
  20. MySQL学习(二)【MySQL数据库对象与应用】

热门文章

  1. 微博评论点赞mysql设计_关于微博评论功能的设计与思考
  2. 双链表及其他链式结构:双循环链表的创建算法(尾插法)
  3. 玖红天下系统开发功能介绍--玖红天下APP开发源码分享
  4. 【SSH项目实战】国税协同平台-20.异步信息发布
  5. ppt怎么让人耳目一新_免费下载:160种令人耳目一新的通知声音,使您的手机不再那么烦人...
  6. 占豪收评--天然气荒
  7. 基于windows和linux下的各种操作命令
  8. 我爱IT(52IT)
  9. java复制屏幕文本内容_java实现文本复制功能
  10. Transformer进行底层图像处理任务