1+ /*==============================================================================================================================
2+ | Author Ignia, LLC
3+ | Client Ignia, LLC
4+ | Project Topics Library
5+ \=============================================================================================================================*/
6+ using System ;
7+ using OnTopic . Internal . Diagnostics ;
8+ using OnTopic . Metadata ;
9+
10+ namespace OnTopic . Repositories {
11+
12+ /*============================================================================================================================
13+ | CLASS: TOPIC REPOSITORY DECORATOR
14+ \---------------------------------------------------------------------------------------------------------------------------*/
15+ /// <summary>
16+ /// Defines a base abstract class for establishing a decorator of an <see cref="ITopicRepository"/>.
17+ /// </summary>
18+ /// <remarks>
19+ /// Decorators allow implementors to operate off of an underlying version of an <see cref="ITopicRepository"/>, while
20+ /// intercepting calls in order to extend their functionality. They do this by establishing passthrough members to each of
21+ /// the underlying members. The <see cref="TopicRepositoryDecorator"/> offers a base class for implementing decorators by
22+ /// accepting a <see cref="ITopicRepository"/> via its constructor, and then wiring up each of the members as a passthrough.
23+ /// It also subscribes to the underlying <see cref="ITopicRepository"/>'s events so that they will correctly bubble up
24+ /// through the decorator. This way, derived decorators must only implement the specific methods they wish to override, and
25+ /// can leave everything else as is.
26+ /// </remarks>
27+ public abstract class TopicRepositoryDecorator : ObservableTopicRepository {
28+
29+ /*==========================================================================================================================
30+ | CONSTRUCTOR
31+ \-------------------------------------------------------------------------------------------------------------------------*/
32+ /// <summary>
33+ /// Instantiates a new instance of the <see cref="TopicRepositoryDecorator"/> with a dependency on an underlying <see cref
34+ /// ="ITopicRepository"/> in order to provide necessary data access.
35+ /// </summary>
36+ /// <param name="topicRepository">
37+ /// A concrete instance of an <see cref="ITopicRepository"/>, which will be used for data access.
38+ /// </param>
39+ /// <returns>A new instance of the <see cref="TopicRepositoryDecorator"/>.</returns>
40+ protected TopicRepositoryDecorator ( ITopicRepository topicRepository ) : base ( ) {
41+
42+ /*------------------------------------------------------------------------------------------------------------------------
43+ | Validate input
44+ \-----------------------------------------------------------------------------------------------------------------------*/
45+ Contract . Requires ( topicRepository , "A concrete implementation of an ITopicRepository is required." ) ;
46+
47+ /*------------------------------------------------------------------------------------------------------------------------
48+ | Set values locally
49+ \-----------------------------------------------------------------------------------------------------------------------*/
50+ TopicRepository = topicRepository ;
51+
52+ /*------------------------------------------------------------------------------------------------------------------------
53+ | Subscribe to underlying events
54+ \-----------------------------------------------------------------------------------------------------------------------*/
55+ TopicRepository . DeleteEvent += ( object sender , DeleteEventArgs args ) => OnTopicDeleted ( args ) ;
56+ TopicRepository . MoveEvent += ( object sender , MoveEventArgs args ) => OnTopicMoved ( args ) ;
57+ TopicRepository . RenameEvent += ( object sender , RenameEventArgs args ) => OnTopicRenamed ( args ) ;
58+
59+
60+ }
61+
62+ /*==========================================================================================================================
63+ | DATA PROVIDER
64+ \-------------------------------------------------------------------------------------------------------------------------*/
65+ /// <summary>
66+ /// Provides access to the underlying <see cref="ITopicRepository"/> that this decorates.
67+ /// </summary>
68+ protected ITopicRepository TopicRepository { get ; set ; }
69+
70+ /*==========================================================================================================================
71+ | GET CONTENT TYPE DESCRIPTORS
72+ \-------------------------------------------------------------------------------------------------------------------------*/
73+ /// <inheritdoc />
74+ public override ContentTypeDescriptorCollection GetContentTypeDescriptors ( ) => TopicRepository . GetContentTypeDescriptors ( ) ;
75+
76+ /*==========================================================================================================================
77+ | METHOD: LOAD
78+ \-------------------------------------------------------------------------------------------------------------------------*/
79+ /// <inheritdoc />
80+ public override Topic ? Load ( int topicId , Topic ? referenceTopic = null , bool isRecursive = true ) =>
81+ TopicRepository . Load ( topicId , referenceTopic , isRecursive ) ;
82+
83+ /// <inheritdoc />
84+ public override Topic ? Load ( string ? uniqueKey = null , Topic ? referenceTopic = null , bool isRecursive = true ) =>
85+ TopicRepository . Load ( uniqueKey , referenceTopic , isRecursive ) ;
86+
87+ /// <inheritdoc />
88+ public override Topic ? Load ( Topic topic , DateTime version )
89+ => TopicRepository . Load ( topic , version ) ;
90+
91+ /// <inheritdoc />
92+ public override Topic ? Load ( int topicId , DateTime version , Topic ? referenceTopic = null ) =>
93+ TopicRepository . Load ( topicId , version , referenceTopic ) ;
94+
95+ /*==========================================================================================================================
96+ | METHOD: REFRESH
97+ \-------------------------------------------------------------------------------------------------------------------------*/
98+ /// <inheritdoc />
99+ public override void Refresh ( Topic referenceTopic , DateTime since ) => TopicRepository . Refresh ( referenceTopic , since ) ;
100+
101+ /*==========================================================================================================================
102+ | METHOD: ROLLBACK
103+ \-------------------------------------------------------------------------------------------------------------------------*/
104+ /// <inheritdoc />
105+ public override void Rollback ( Topic topic , DateTime version ) => TopicRepository . Rollback ( topic , version ) ;
106+
107+ /*==========================================================================================================================
108+ | METHOD: SAVE
109+ \-------------------------------------------------------------------------------------------------------------------------*/
110+ /// <inheritdoc />
111+ public override void Save ( Topic topic , bool isRecursive = false ) => TopicRepository . Save ( topic , isRecursive ) ;
112+
113+ /*==========================================================================================================================
114+ | METHOD: MOVE
115+ \-------------------------------------------------------------------------------------------------------------------------*/
116+ /// <inheritdoc />
117+ public override void Move ( Topic topic , Topic target , Topic ? sibling = null ) => TopicRepository . Move ( topic , target , sibling ) ;
118+
119+ /*==========================================================================================================================
120+ | METHOD: DELETE
121+ \-------------------------------------------------------------------------------------------------------------------------*/
122+ /// <inheritdoc />
123+ public override void Delete ( Topic topic , bool isRecursive ) => TopicRepository . Delete ( topic , isRecursive ) ;
124+
125+ } //Class
126+ } //Namespace
0 commit comments