This project is read-only.

Example below shows how to make a custom persist layer for record of type Tick:

public class Tick
{
    public DateTime Timestamp { get; set; }
    public double Bid { get; set; }
    public double Ask { get; set; }
 
    public Tick()
    {
    }
}

To write a custom persist layer we have to make a serializable class that implements IBinaryPersist> interface:

[Serializable]
public class TickBinaryPersist : IBinaryPersist>
{
    #region IBinaryPersist> Members
 
    public void Store(BinaryWriter writer, IIndexer data)
    {
    }
 
    public void Load(BinaryReader reader, ref IIndexer data)
    {
    }
 
    #endregion
}

and then write a simple implementation:

[Serializable]
public class TickBinaryPersist : IBinaryPersist>
{
    #region IBinaryPersist> Members
 
    public void Store(BinaryWriter writer, IIndexer data)
    {
        for (int i = 0; i < data.Count; i++)
        {
            Tick record = data[i];
 
            writer.Write(record.Timestamp.Ticks);
            writer.Write(record.Bid);
            writer.Write(record.Ask);
        }
    }
 
    public void Load(BinaryReader reader, ref IIndexer data)
    {
        for (int i = 0; i < data.Count; i++)
        {
            Tick record = new Tick();
 
            record.Timestamp = new DateTime(reader.ReadInt64());
            record.Bid = reader.ReadDouble();
            record.Ask = reader.ReadDouble();
 
            data[i] = record;
        }
    }
 
    #endregion
}

 

That's it. The engine will do the rest of work. It groups the records by 1024 (XTable.BlockCapacity property) and passes them as IIndexer data parameter. All we have to do is to write the records to BinaryWriter.

The reading process is analogous.

After the writing of the implementation we must tell the relevant table to use the new persist by setting RecordPersis property:

using (StorageEngine stsdb = StorageEngine.FromFile("test.stsdb"))
{
    var table = stsdb.Scheme.CreateOrOpenXTable(new Locator("table"));
    table.RecordPersist = new TickBinaryPersist();
    stsdb.Scheme.Commit();
 
    ...
}

Last edited Aug 17, 2013 at 9:41 AM by SvetoslavMateev, version 1

Comments

No comments yet.