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是一一对应的,字段的名称都是相同的。

Kooboo CMS  之TextContent详解

Kooboo CMS  之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 object
        public 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();
        }
        #endregion

        public bool ___EnableVersion___
        {
            get
            {
                if (this.ContainsKey("___EnableVersion___") && base["___EnableVersion___"] != null)
                {
                    return (bool)base["___EnableVersion___"];
                }
                return true;
            }
            set
            {
                base["___EnableVersion___"] = value;
            }
        }


        #region MoreOptionsOnBroadcasting
        public 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

相关文章:

  • 2021-11-03
  • 2021-07-07
  • 2021-09-12
  • 2021-04-17
  • 2022-12-23
  • 2021-06-12
  • 2021-07-20
  • 2022-02-05
猜你喜欢
  • 2021-05-28
  • 2021-05-18
  • 2021-05-28
  • 2022-03-09
  • 2021-12-31
相关资源
相似解决方案