Radical Documentation
View on GitHub
Primary version
Primary version
  • Home
  • Presentation
    • AbstractViewModel
    • Conventions
      • Bootstrap Conventions
      • Runtime Conventions
      • Conventions override
    • Commands and DelegateCommand
    • IViewResolver
      • Default view behaviors
      • view life cycle events
        • Callback expectations
        • notify messages
    • Message broker MVVM built-in messages
    • Application boot process
      • Application configuration
      • Application shutdown
      • Singleton applications
    • AbstractMementoViewModel
      • Simple ViewModel graphs
      • Collections and complex ViewModel graphs
    • Validation and Validation Services
    • Resources
      • Services as resources
      • ViewModels as resources
  • UI Composition
    • UI Composition
      • Region content lifecycle
      • TabControl region
      • Create a custom region
  • Concepts
    • Inversion of Control
      • Third party DI containers
    • Entities
      • Property System
    • Messaging and Message Broker
      • POCO messages
      • Standalone message handlers
    • Observers
      • PropertyObserver
      • MementoObserver
      • BrokerObserver
  • Memento
    • Change Tracking Service
      • MementoEntity and MementoEntityCollection
      • Handling change tracking:
        • Simple model
        • Collections
        • Complex objects graph
      • Atomic operations
      • Change Tracking Service API
      • Property Metadata for the ChangeTrackingService
      • Handling collection sync
      • Property State
  • Behaviors
    • DataGrid Behaviors
    • Password
    • Generic routed event handler to command behavior
    • Overlay adorner
      • Busy status manager
    • TextBox behaviors:
      • Command
      • Auto select
      • DisableUndoManager (.Net 3.5 only)
  • Markup Extensions
    • Editor binding
    • Auto Command binding
  • How to
    • Get the view of a given view model
    • Bi-directional communication between different windows/views
    • Handle the busy status during async/long running operations
    • Implement a customer improvement program
    • Manage focus
    • Create a splash screen
    • Access view model after view is closed
    • Intercept ViewModels before they are used
  • Upgrade guides
    • Radical Presentation 1.x to Radical 2.x for .NET Core
    • Radical 2.0.0 to Radical 2.1.0
Powered by GitBook
On this page
  1. Memento
  2. Change Tracking Service

MementoEntity and MementoEntityCollection

PreviousChange Tracking ServiceNextHandling change tracking:

Last updated 3 years ago

In we introduced a code snippet as the following:

var person = new Person();
person.FirstName = "first name value";
person.LastName = "last name value";

To start using memento services we can extend the above snippet as follows:

var memento = new ChangeTrackingService();

var person = new Person();
memento.Attach(person);

person.FirstName = "first name";
person.LastName = "last name";

var isChanged = memento.IsChanged; //true
var canUndo = memento.CanUndo; //true

Calling memento.Undo() will trigger the undo of the last operation, we can call Undo until CanUndo is true rolling back changes change by change. In the above sample calling Undo will revert back the LastName property value to its default value.

The requirement to achieve the above is that the Person class is a Radical memento entity:

class Person : MementoEntity
{   
    public String FirstName
    {
        get { return this.GetPropertyValue(() => this.FirstName); }
        set { this.SetPropertyValue(() => this.FirstName, value); }
    }

    public String LastName
    {
        get { return this.GetPropertyValue(() => this.LastName); }
        set { this.SetPropertyValue(() => this.LastName, value); }
    }
}

A similar approach can be used to keep track of items in a collection:

var memento = new ChangeTrackingService();

var list = new MementoEntityCollection<String>();
memento.Attach(list);

list.Add("a value");
list.Add("another value");

var isChanged = memento.IsChanged; //true
var canUndo = memento.CanUndo; //true

Calling memento.Undo() will trigger the undo of the last operation that in the above sample will revert the collection status removing the last added value.

We can do more:

As we can see from the above snippet all we need to do is to create a class the inherits from the MementoEntity base class and declare all the properties we want to track as .

;

;

;

Change Tracking Service
Radical properties
Handling change tracking in a simple model
Handling change tracking in collections
Handling change tracking in complex objects graph