This repository has been archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Updater.vb
66 lines (63 loc) · 2.86 KB
/
Updater.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
Imports Microsoft.VisualBasic
Imports System
Imports DevExpress.ExpressApp.Updating
Imports DevExpress.Xpo
Imports DevExpress.Data.Filtering
Imports DevExpress.Persistent.BaseImpl
Imports DevExpress.ExpressApp
Namespace WinSample.Module
Public Class Updater
Inherits ModuleUpdater
Public Sub New(ByVal objectSpace As IObjectSpace, ByVal currentDBVersion As Version)
MyBase.New(objectSpace, currentDBVersion)
End Sub
Public Overrides Sub UpdateDatabaseAfterUpdateSchema()
MyBase.UpdateDatabaseAfterUpdateSchema()
Dim john As Person = CreateObject(Of Person)(New String() { "FirstName" }, New Object() { "John" })
Dim sam As Person = CreateObject(Of Person)(New String() { "FirstName" }, New Object() { "Sam" })
Dim analysedObject As AnalysedObject = CreateObject(Of AnalysedObject)(New String() { "Employee", "Year" }, New Object() { john, 2009 })
If ObjectSpace.IsNewObject(analysedObject) Then
analysedObject.BooleanProperty1 = True
End If
analysedObject = CreateObject(Of AnalysedObject)(New String() { "Employee", "Year" }, New Object() { john, 2010 })
If ObjectSpace.IsNewObject(analysedObject) Then
analysedObject.BooleanProperty2 = True
End If
analysedObject = CreateObject(Of AnalysedObject)(New String() { "Employee", "Year" }, New Object() { john, 2011 })
If ObjectSpace.IsNewObject(analysedObject) Then
analysedObject.BooleanProperty2 = True
analysedObject.BooleanProperty3 = True
End If
analysedObject = CreateObject(Of AnalysedObject)(New String() { "Employee", "Year" }, New Object() { sam, 2009 })
If ObjectSpace.IsNewObject(analysedObject) Then
analysedObject.BooleanProperty3 = True
End If
analysedObject = CreateObject(Of AnalysedObject)(New String() { "Employee", "Year" }, New Object() { sam, 2010 })
If ObjectSpace.IsNewObject(analysedObject) Then
analysedObject.BooleanProperty1 = True
analysedObject.BooleanProperty2 = True
End If
analysedObject = CreateObject(Of AnalysedObject)(New String() { "Employee", "Year" }, New Object() { sam, 2011 })
If ObjectSpace.IsNewObject(analysedObject) Then
analysedObject.BooleanProperty1 = True
End If
End Sub
Private Function CreateObject(Of T As XPBaseObject)(ByVal propertyNames() As String, ByVal propertyValues() As Object) As T
If propertyValues.Length <> propertyNames.Length Then
Throw New ArgumentException()
End If
Dim criteria As New GroupOperator()
For i As Integer = 0 To propertyNames.Length - 1
criteria.Operands.Add(New BinaryOperator(propertyNames(i), propertyValues(i)))
Next i
Dim obj As T = ObjectSpace.FindObject(Of T)(criteria)
If obj Is Nothing Then
obj = ObjectSpace.CreateObject(Of T)()
For i As Integer = 0 To propertyNames.Length - 1
obj.ClassInfo.FindMember(propertyNames(i)).SetValue(obj, propertyValues(i))
Next i
End If
Return obj
End Function
End Class
End Namespace