using System; using System.Collections.Generic; using ZeroLevel.Services.Serialization; namespace ZeroLevel.DocumentObjectModel { public class Document : IBinarySerializable { private static readonly Document _empty = new Document(); public static Document Empty { get { var data = MessageSerializer.Serialize(_empty); return MessageSerializer.Deserialize(data); } } public Document() { Id = Guid.NewGuid(); Initialize(); } public Document(Guid id) { Id = id; Initialize(); } public Document(IBinaryReader reader) { Deserialize(reader); } public Document(Document other) { var data = MessageSerializer.Serialize(other); using (var reader = new MemoryStreamReader(data)) { Deserialize(reader); } } private void Initialize() { Identifier = new Identifier(); Content = new FlowContent(); TagMetadata = new TagMetadata(); DescriptiveMetadata = new DescriptiveMetadata(); Aside = new List(); Assotiations = new List(); Categories = new List(); } /// /// Идентификатор документа /// public Guid Id; /// /// Краткое описание, лид /// public string Summary; /// /// Заголовок /// public string Header; /// /// Дополнительные идентификаторы /// public Identifier Identifier; /// /// Содержимое документа /// public FlowContent Content; /// /// Теги /// public TagMetadata TagMetadata; /// /// Метаданные документа /// public DescriptiveMetadata DescriptiveMetadata; /// /// Вложенные документы /// public List Aside; /// /// Связанные документы /// public List Assotiations; /// /// Категории /// public List Categories; #region IBinarySerializable public void Serialize(IBinaryWriter writer) { writer.WriteGuid(this.Id); writer.WriteString(this.Summary); writer.WriteString(this.Header); writer.Write(this.Identifier); writer.Write(this.Content); writer.Write(this.TagMetadata); writer.Write(this.DescriptiveMetadata); writer.WriteCollection(this.Aside); writer.WriteCollection(this.Assotiations); writer.WriteCollection(this.Categories); } public void Deserialize(IBinaryReader reader) { this.Id = reader.ReadGuid(); this.Summary = reader.ReadString(); this.Header = reader.ReadString(); this.Identifier = reader.Read(); this.Content = reader.Read(); this.TagMetadata = reader.Read(); this.DescriptiveMetadata = reader.Read(); this.Aside = reader.ReadCollection(); this.Assotiations = reader.ReadCollection(); this.Categories = reader.ReadCollection(); } #endregion } }