# Historical data support

One of the distinguishing features of the format is the support of historical data is the chronology of changes in public properties of a custom class — a business object. This allows you to get the value of a property at a specific point in time.

In order for a business object class to support working with historical data, it must implement the XyloCode.BusinessData.IBusinessObject interface:

public interface IBusinessObject
{
    IDictionary<string, byte[]> BusinessObjectData { get; set; }
}

For example:

[BusinessObjectId(3)]
public class Person : IBusinessObject
{
    IDictionary<string, byte[]> IBusinessObject.BusinessObjectData { get; set; }

    [TagId(1)]
    public int Id { get; set; }

    [TagId(2)]
    public string Surname { get; set; }
 
    [TagId(3)]
    public string Name { get; set; }
}

# Auto-commit changes

For the mode "serialization – deserialization – editing – serialization", automatic capture of changes when working with a business object is possible, it is activated by the HistoricalCapture property of the binary serializer:

var serializer = new XyloCode.BusinessData.Serializer();
serializer.HistoricalCapture = true;

# Working with historical objects

Historical object (class XyloCode.BusinessData.HistoricalObject) is a special tool for working with the historical data of a business object, it allows you to set, edit and get property values at a certain point in time.

var serializer = new XyloCode.BusinessData.Serializer();

var person = new Person {
    Id = 1,
    Surname = "Ciccone",
    Name = "Madonna"
};

var histObj = new XyloCode.BusinessData.HistoricalObject<Person>(serializer, person);
histObj.SetAfter<string>("Surname", new DateTime(1985, 8, 16), "Penn");
histObj.SetAfter<string>("Surname", new DateTime(2000, 12, 22), "Ritchie");
histObj.Save();

var now = histObj.Get<string>("Surname");
Console.WriteLine(now);
> Ritchie

The main methods used when working with historical objects:

  • Load() — loading the BusinessObjectData dictionary and storages of historical values;
  • Refresh() — actualization of the BusinessObjectData dictionary in accordance with the data of the storages of historical values;
  • Update() — updating the BusinessObjectData dictionary with the current values of the properties of an instance of the business object class;
  • Get() — getting the value of a property of a business object for a specific date and time;
  • Set() — setting the current value of the property of the business object;
  • SetAfter() — setting the historical value of the property of the business object, which should take effect from the specified date;
  • SetBefore() — setting the historical value of the property of the business object, which must be valid until the specified date;
  • RemoveOnDate() — removal of the historical value of the property of the business object, which is valid on the specified date;
  • RemoveFromPastBefore() — remove all historical values of the business object property that were in effect before the specified date and whose validity period has passed;
  • RemoveFromPastAfter() — remove all historical values of the business object property that have been in effect since the specified date and whose validity period has passed;
  • RemoveFromFutureBefore() — remove all historical values of the business object property that must be valid before the specified date and whose validity time has not yet arrived;
  • RemoveFromFutureAfter() — remove all historical values of the property of the business object, which should be valid from the specified date and whose validity time has not yet arrived;
  • Save() — saving changes to the storage of historical values.