Json item versioning

Feb 2, 2011 at 2:33 PM
Edited Feb 2, 2011 at 9:14 PM

The release with the same title as this discussion topic (corresponding to Change Set 5296) supports item versioning in the Json serializer. 

You make a type versionable by adding a property of type CIP4ItemVersionsType with DontSerialize=true - for example

        [CIP4Property(DontSerialize = true)]        
public CIP4.Item.CIP4ItemVersionsType<PersonType> Versions { get; set; }

The type parameter must be the same as the enclosing type. The property must be get/set.

The StrongWrapperType supports a GetVersionsFunction that will return a SortedDictionary of item versions with a UTC DateTime expressed as Ticks as the dictionary key. You can do things like:

                foreach (KeyValuePair<long, PersonType> freds in wrapper.GetItemVersions(fred4))
                    Console.WriteLine(string.Format("Fred's name was {0} on {1}", freds.Value.Name, new DateTime(freds.Key)));

The Versions property on the item supports a SortedDictionary that represents the per-property changes for each version. You can do things like:

                foreach (KeyValuePair<long, CIP4ItemVersionType<PersonType>> version in fred4.Versions.Versions)
                    Console.WriteLine(String.Format("Version as of {0} has the following changes", new DateTime(version.Key)));
                    foreach (KeyValuePair<string, object> propertyValue in version.Value.Values)
                        Console.WriteLine(string.Format("{0}={1}", propertyValue.Key, propertyValue.Value));

This is only supported for json at the present time - I will do an Xml version (which, if anything should be easier) some time soon.

The versioning works for simple properties, compound properties and multi-valued properties.

It will not version reference properties, Stream properties or scalable properties.