You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/DOM/Model/Document.cs

120 lines
3.6 KiB

6 years ago
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<Document>(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<AttachContent>();
6 years ago
Assotiations = new List<Assotiation>();
Categories = new List<Category>();
}
/// <summary>
/// ID
6 years ago
/// </summary>
public Guid Id;
/// <summary>
/// Short description
6 years ago
/// </summary>
public string Summary;
/// <summary>
/// Title
6 years ago
/// </summary>
public string Header;
/// <summary>
/// Identification block
6 years ago
/// </summary>
public Identifier Identifier;
/// <summary>
/// Content
6 years ago
/// </summary>
public FlowContent Content;
/// <summary>
/// Tags
6 years ago
/// </summary>
public TagMetadata TagMetadata;
/// <summary>
/// Metadata
6 years ago
/// </summary>
public DescriptiveMetadata DescriptiveMetadata;
/// <summary>
/// Attachments
6 years ago
/// </summary>
public List<AttachContent> Attachments;
6 years ago
/// <summary>
/// Binded documents
6 years ago
/// </summary>
public List<Assotiation> Assotiations;
/// <summary>
/// Categories
6 years ago
/// </summary>
public List<Category> 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<AttachContent>(this.Attachments);
6 years ago
writer.WriteCollection<Assotiation>(this.Assotiations);
writer.WriteCollection<Category>(this.Categories);
}
public void Deserialize(IBinaryReader reader)
{
this.Id = reader.ReadGuid();
this.Summary = reader.ReadString();
this.Header = reader.ReadString();
this.Identifier = reader.Read<Identifier>();
this.Content = reader.Read<FlowContent>();
this.TagMetadata = reader.Read<TagMetadata>();
this.DescriptiveMetadata = reader.Read<DescriptiveMetadata>();
this.Attachments = reader.ReadCollection<AttachContent>();
6 years ago
this.Assotiations = reader.ReadCollection<Assotiation>();
this.Categories = reader.ReadCollection<Category>();
}
#endregion
}
}

Powered by TurnKey Linux.