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

142 lines
3.8 KiB

6 years ago
using System;
using System.Collections.Generic;
using ZeroLevel.Services.Serialization;
namespace ZeroLevel.DocumentObjectModel
{
public class Document
6 years ago
: IBinarySerializable
{
private static readonly Document _empty = new Document();
6 years ago
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);
}
6 years ago
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;
6 years ago
/// <summary>
/// Short description
6 years ago
/// </summary>
public string Summary;
6 years ago
/// <summary>
/// Title
6 years ago
/// </summary>
public string Header;
6 years ago
/// <summary>
/// Identification block
6 years ago
/// </summary>
public Identifier Identifier;
6 years ago
/// <summary>
/// Content
6 years ago
/// </summary>
public FlowContent Content;
6 years ago
/// <summary>
/// Tags
6 years ago
/// </summary>
public TagMetadata TagMetadata;
6 years ago
/// <summary>
/// Metadata
6 years ago
/// </summary>
public DescriptiveMetadata DescriptiveMetadata;
6 years ago
/// <summary>
/// Attachments
6 years ago
/// </summary>
public List<AttachContent> Attachments;
6 years ago
/// <summary>
/// Binded documents
6 years ago
/// </summary>
public List<Assotiation> Assotiations;
6 years ago
/// <summary>
/// Categories
6 years ago
/// </summary>
public List<Category> Categories;
#region IBinarySerializable
6 years ago
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 IBinarySerializable
6 years ago
}
}

Powered by TurnKey Linux.