/
AuxiliaryObjects.vb
163 lines (155 loc) · 5.06 KB
/
AuxiliaryObjects.vb
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports DevExpress.Data.Filtering
Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.DC
Imports DevExpress.Persistent.Base
Imports DevExpress.Persistent.Validation
Namespace NonPersistentObjectsDemo.Module.BusinessObjects
<DefaultClassOptions>
<DefaultListViewOptions(True, NewItemRowPosition.Top)>
<DefaultProperty("Subject")>
<DevExpress.ExpressApp.DC.DomainComponent>
Public Class Message
Inherits NonPersistentObjectBase
'INSTANT VB NOTE: The field id was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private id_Conflict As Integer
<Browsable(False)>
<DevExpress.ExpressApp.Data.Key>
Public ReadOnly Property ID() As Integer
Get
Return id_Conflict
End Get
End Property
Public Sub SetKey(ByVal id As Integer)
Me.id_Conflict = id
End Sub
Private _Sender As Account
Public Property Sender() As Account
Get
Return _Sender
End Get
Set(ByVal value As Account)
SetPropertyValue(NameOf(Sender), _Sender, value)
End Set
End Property
Private _Recepient As Account
Public Property Recepient() As Account
Get
Return _Recepient
End Get
Set(ByVal value As Account)
SetPropertyValue(NameOf(Recepient), _Recepient, value)
End Set
End Property
Private _Subject As String
Public Property Subject() As String
Get
Return _Subject
End Get
Set(ByVal value As String)
SetPropertyValue(Of String)(NameOf(Subject), _Subject, value)
End Set
End Property
Private _Body As String
<FieldSize(-1)>
Public Property Body() As String
Get
Return _Body
End Get
Set(ByVal value As String)
SetPropertyValue(Of String)(NameOf(Body), _Body, value)
End Set
End Property
End Class
<DefaultClassOptions>
<DefaultListViewOptions(True, NewItemRowPosition.Top)>
<DefaultProperty("PublicName")>
<DevExpress.ExpressApp.DC.DomainComponent>
Public Class Account
Inherits NonPersistentObjectBase
'INSTANT VB NOTE: The field userName was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private userName_Conflict As String
'[Browsable(false)]
<DevExpress.ExpressApp.ConditionalAppearance.Appearance("", Enabled := False, Criteria := "Not IsNewObject(This)")>
<RuleRequiredField>
<DevExpress.ExpressApp.Data.Key>
Public Property UserName() As String
Get
Return userName_Conflict
End Get
Set(ByVal value As String)
userName_Conflict = value
End Set
End Property
Public Sub SetKey(ByVal userName As String)
Me.userName_Conflict = userName
End Sub
'INSTANT VB NOTE: The field publicName was renamed since Visual Basic does not allow fields to have the same name as other class members:
Private publicName_Conflict As String
Public Property PublicName() As String
Get
Return publicName_Conflict
End Get
Set(ByVal value As String)
SetPropertyValue(NameOf(PublicName), publicName_Conflict, value)
End Set
End Property
End Class
Public Class PostOfficeFactory
Inherits NonPersistentObjectFactoryBase
Private ReadOnly Property Storage() As PostOfficeClient
Get
Return GlobalServiceProvider(Of PostOfficeClient).GetService()
End Get
End Property
Private isLoading As Boolean = False
Private objectMap As ObjectMap
Public Sub New(ByVal objectMap As ObjectMap)
Me.objectMap = objectMap
End Sub
Public Overrides Function GetObjectByKey(ByVal objectType As Type, ByVal key As Object) As Object
If key Is Nothing Then
Throw New ArgumentNullException(NameOf(key))
End If
Dim mapping As DataStoreMapping
If Storage.Mappings.TryGetValue(objectType, mapping) Then
Return WrapLoading(Function()
Dim loader = New DataStoreObjectLoader(Storage.Mappings, Storage.DataStore, objectMap)
Return loader.LoadObjectByKey(objectType, key)
End Function)
End If
Throw New NotImplementedException()
End Function
Public Overrides Function GetObjects(ByVal objectType As Type, ByVal criteria As CriteriaOperator, ByVal sorting As IList(Of DevExpress.Xpo.SortProperty)) As IEnumerable
Dim mapping As DataStoreMapping
If Storage.Mappings.TryGetValue(objectType, mapping) Then
Return WrapLoading(Function()
Dim loader = New DataStoreObjectLoader(Storage.Mappings, Storage.DataStore, objectMap)
Return loader.LoadObjects(objectType, criteria)
End Function)
End If
Throw New NotImplementedException()
End Function
Private Function WrapLoading(Of T)(ByVal doer As Func(Of T)) As T
If isLoading Then
Throw New InvalidOperationException()
End If
isLoading = True
Try
Return doer.Invoke()
Finally
isLoading = False
End Try
End Function
Public Overrides Sub SaveObjects(ByVal toInsert As ICollection, ByVal toUpdate As ICollection, ByVal toDelete As ICollection)
Dim saver = New DataStoreObjectSaver(Storage.Mappings, Storage.DataStore)
saver.SaveObjects(toInsert, toUpdate, toDelete)
End Sub
End Class
End Namespace