This project is read-only.

Subscriptions

Subscription can be created on any object instance in the data model by invoking:
Subscription s = Workspace.CreateSubscription(instance, delegate)


Delegate is invoked when:
  • any property of given instance has changed
  • any property of any reachable child object has changed

Delegate is invoked immediately after the commit which alters the instance. Call is made from the thread performing the commit.

Overload can be used to define if changes from the same workspace shall be notified. When parameter is not defined default is false, which means only changes from other workspaces are notified.

Overload can be used to limit notifications to specific object property. In this case, property name is defined as additional argument.

Subscription is removed by invoking:
Workspace.RemoveSubscription(s)

Event arguments

ObjectChangedEventArgs is passed to delegate method when notification is made. It contains following arguments:
  • SnapshotId - defines snapshot ID where the change happened
  • OldRevisionId - defines old instance revision ID
  • NewRevisionId - defines new instance revision ID
  • Subscription - subscrition which triggered the notification
  • RenewSubscription - defines if subscription should be renewed after notification, default is true

With these parameters, changed data can be observed within the delegate method, like in following example:
EventHandler<Events.ObjectChangedEventArgs> del = new EventHandler<Events.ObjectChangedEventArgs>((sender, args) =>
            {
                using (var ws = ctx.OpenWorkspace<IDatabase>(args.SnapshotId, IsolationLevel.ReadOnly))
                {
                    var oldPerson = ws.Spawn<IPerson>(args.OldRevisionId);
                    var newPerson = ws.Spawn<IPerson>(args.NewRevisionId);

                    Assert.AreEqual("John Connor", oldPerson.Name);
                    Assert.AreEqual("Changed", newPerson.Name);
                }
            });


First, the workspace is opened to read from the newly created snapshot ID, passed by SnapshotId parameter in ObjectChangedEventArgs. Then, Spawn method is used to create instances of new and old object versions, from OldRevisionId and NewRevisionId parameters.

After that, object state may be inspected for differences, including traversal through child objects.

Last edited Mar 28, 2012 at 2:56 PM by nenadsabo, version 1

Comments

No comments yet.