-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityProcessor.cs
More file actions
133 lines (124 loc) · 7.99 KB
/
EntityProcessor.cs
File metadata and controls
133 lines (124 loc) · 7.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using Rock.Data;
namespace EntityCoding
{
/// <summary>
/// Entity processors must inherit from this class to be able to provide
/// custom processing capabilities.
/// </summary>
/// <typeparam name="T">The IEntity class type that this processor is for.</typeparam>
public abstract class EntityProcessor<T> : IEntityProcessor where T : IEntity
{
/// <summary>
/// The unique identifier for this entity processor. This is used to identify the correct
/// processor to use when importing so we match the one used during export.
/// </summary>
abstract public Guid Identifier { get; }
/// <summary>
/// Evaluate the list of referenced entities. This is a list of key value pairs that identify
/// the property that the reference came from as well as the referenced entity itself. Implementations
/// of this method may add or remove from this list. For example, an AttributeValue has
/// the entity it is referencing in a EntityId column, but there is no general use information for
/// what kind of entity it is. The processor can provide that information.
/// </summary>
/// <param name="entity">The parent entity of the references.</param>
/// <param name="references">The referenced entities and what properties of the parent they came from.</param>
/// <param name="helper">The helper class for this export.</param>
public void EvaluateReferencedEntities( IEntity entity, List<KeyValuePair<string, IEntity>> references, EntityCoder helper )
{
EvaluateReferencedEntities( ( T ) entity, references, helper );
}
/// <summary>
/// Evaluate the list of referenced entities. This is a list of key value pairs that identify
/// the property that the reference came from as well as the referenced entity itself. Implementations
/// of this method may add or remove from this list. For example, an AttributeValue has
/// the entity it is referencing in a EntityId column, but there is no general use information for
/// what kind of entity it is. The processor can provide that information.
/// </summary>
/// <param name="entity">The parent entity of the references.</param>
/// <param name="references">The referenced entities and what properties of the parent they came from.</param>
/// <param name="helper">The helper class for this export.</param>
protected virtual void EvaluateReferencedEntities( T entity, List<KeyValuePair<string, IEntity>> references, EntityCoder helper )
{
}
/// <summary>
/// Evaluate the list of child entities. This is a list of key value pairs that identify
/// the property that the child came from as well as the child entity itself. Implementations
/// of this method may add or remove from this list. For example, a WorkflowActionForm has
/// it's actions encoded in a single string. This must processed to include any other
/// objects that should exist (such as a DefinedValue for the button type).
/// </summary>
/// <param name="entity">The parent entity of the children.</param>
/// <param name="children">The child entities and what properties of the parent they came from.</param>
/// <param name="helper">The helper class for this export.</param>
public void EvaluateChildEntities( IEntity entity, List<KeyValuePair<string, IEntity>> children, EntityCoder helper )
{
EvaluateChildEntities( ( T ) entity, children, helper );
}
/// <summary>
/// Evaluate the list of child entities. This is a list of key value pairs that identify
/// the property that the child came from as well as the child entity itself. Implementations
/// of this method may add or remove from this list. For example, a WorkflowActionForm has
/// it's actions encoded in a single string. This must processed to include any other
/// objects that should exist (such as a DefinedValue for the button type).
/// </summary>
/// <param name="entity">The parent entity of the children.</param>
/// <param name="children">The child entities and what properties of the parent they came from.</param>
/// <param name="helper">The helper class for this export.</param>
protected virtual void EvaluateChildEntities( T entity, List<KeyValuePair<string, IEntity>> children, EntityCoder helper )
{
}
/// <summary>
/// An entity has been exported and can now have any post-processing done to it
/// that is needed. For example a processor might remove some properties that shouldn't
/// actually have been exported.
/// </summary>
/// <param name="entity">The source entity that was exported.</param>
/// <param name="encodedEntity">The exported data from the entity.</param>
/// <param name="helper">The helper that is doing the exporting.</param>
/// <returns>An object that will be encoded with the entity and passed to the ProcessImportEntity method later, or null.</returns>
public object ProcessExportedEntity( IEntity entity, EncodedEntity encodedEntity, EntityCoder helper )
{
return ProcessExportedEntity( ( T ) entity, encodedEntity, helper );
}
/// <summary>
/// An entity has been exported and can now have any post-processing done to it
/// that is needed. For example a processor might remove some properties that shouldn't
/// actually have been exported.
/// </summary>
/// <param name="entity">The source entity that was exported.</param>
/// <param name="encodedEntity">The exported data from the entity.</param>
/// <param name="helper">The helper that is doing the exporting.</param>
/// <returns>An object that will be encoded with the entity and passed to the ProcessImportEntity method later, or null.</returns>
protected virtual object ProcessExportedEntity( T entity, EncodedEntity encodedEntity, EntityCoder helper )
{
return null;
}
/// <summary>
/// This method is called before the entity is saved and allows any final changes to the
/// entity before it is stored in the database. Any Guid references that are not standard
/// properties must also be updated, such as the Actions string of a WorkflowActionForm.
/// </summary>
/// <param name="entity">The in-memory entity that is about to be saved.</param>
/// <param name="encodedEntity">The encoded information that was used to reconstruct the entity.</param>
/// <param name="data">Custom data that was previously returned by ProcessExportedEntity.</param>
/// <param name="helper">The helper in charge of the import process.</param>
public void ProcessImportedEntity( IEntity entity, EncodedEntity encodedEntity, object data, EntityDecoder helper )
{
ProcessImportedEntity( ( T ) entity, encodedEntity, data, helper );
}
/// <summary>
/// This method is called before the entity is saved and allows any final changes to the
/// entity before it is stored in the database. Any Guid references that are not standard
/// properties must also be updated, such as the Actions string of a WorkflowActionForm.
/// </summary>
/// <param name="entity">The in-memory entity that is about to be saved.</param>
/// <param name="encodedEntity">The encoded information that was used to reconstruct the entity.</param>
/// <param name="data">Custom data that was previously returned by ProcessExportedEntity.</param>
/// <param name="helper">The helper in charge of the import process.</param>
protected virtual void ProcessImportedEntity( T entity, EncodedEntity encodedEntity, object data, EntityDecoder helper )
{
}
}
}