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(); Attachments = new List(); Assotiations = new List(); Categories = new List(); } /// /// ID /// public Guid Id; /// /// Short description /// public string Summary; /// /// Title /// public string Header; /// /// Identification block /// public Identifier Identifier; /// /// Content /// public FlowContent Content; /// /// Tags /// public TagMetadata TagMetadata; /// /// Metadata /// public DescriptiveMetadata DescriptiveMetadata; /// /// Attachments /// public List Attachments; /// /// Binded documents /// public List Assotiations; /// /// Categories /// 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.Attachments); 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.Attachments = reader.ReadCollection(); this.Assotiations = reader.ReadCollection(); this.Categories = reader.ReadCollection(); } #endregion } }