1,
Interface IOriginator <T>
Where T: IState
{
/// <Summary>
/// Save a memo
/// </Summary>
/// <Remarks>
/// Default method -- full memo of all current data
/// </Remarks>
Void SaveCheckPoint ();
/// <Summary>
/// Restore a memo
/// </Summary>
/// <Remarks>
/// Default method -- restore the last full memo
/// </Remarks>
Void Undo ();
/// <Summary>
/// Save a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
Void SaveCheckPoint (string name );
/// <Summary>
/// Restore a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
Void Undo (string name );
/// <Summary>
/// Save a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
Void SaveCheckPoint (string name, string version );
/// <Summary>
/// Restore a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
Void Undo (string name, string version );
/// <Summary>
/// Save a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
/// <Param name = "subjectName"> business topic name </param>
Void SaveCheckPoint (string name, string version, string subjectName );
/// <Summary>
/// Restore a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
/// <Param name = "subjectName"> business topic name </param>
Void Undo (string name, string version, string subjectName );
/// <Summary>
/// Save a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
/// <Param name = "subjectName"> business topic name </param>
/// <Param name = "start"> start of the time interval </param>
/// <Param name = "end"> end of the time interval </param>
Void SaveCheckPoint (string name, string version, string subjectName, DateTime start, DateTime end );
/// <Summary>
/// Restore a memo
/// </Summary>
/// <Param name = "name"> name of the memo </param>
/// <Param name = "version"> version </param>
/// <Param name = "subjectName"> business topic name </param>
/// <Param name = "start"> start of the time interval </param>
/// <Param name = "end"> end of the time interval </param>
Void Undo (string name, string version, string subjectName, DateTime start, DateTime end );
}
2. Integrate Memento and CoR
Example:
1) to simplify the example, replace the IState interface with string
2) CoR does not use the linked list method, but is implemented through the LINQ method.
3) each Handler in CoR is designed as an interface with closed operations (compression, signature, encryption, etc., and corresponding reverse processing is also required during recovery)
4) in the process of SaveCheckPoint () and Undo (), forward and reverse processes of CoR are called respectively.
Using System;
Using System. Collections. Generic;
Using System. Diagnostics;
Using System. Linq;
Using Microsoft. VisualStudio. TestTools. UnitTesting;
Namespace MarvellousWorks. PracticalPattern. Memento. Tests. Exercise
{
[TestClass]
Public class MementoCoRFixture
{
/// <Summary>
/// To simplify the definition of the primary interface, the type of the primary interface is directly defined.
/// </Summary>
Class Originator
{
Public string State {get; set ;}
Memento m;
Public HandlerCoRBuilder <string> HandlerCoRBuilder {get; set ;}
/// <Summary>
/// Define the memorandum as the internal type of the primary Device
/// </Summary>
/// <Typeparam name = "T"> </typeparam>
Class Memento
{
Public string State {get; set ;}
}
/// <Summary>
/// Save the status to the memo
/// </Summary>
Public virtual void SaveCheckpoint ()
{
Trace. WriteLine ("Originator. void SaveCheckpoint ()-----------------");
M = new Memento ()
{
State = ProcessState (HandlerCoRBuilder. BuildUpProcessCoR (), this. State)
};
}
/// <Summary>
/// Restore the previous status from the Memorandum
/// </Summary>