This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
/
XpoHelper.vb
60 lines (52 loc) · 1.91 KB
/
XpoHelper.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
Imports Microsoft.VisualBasic
Imports System
Imports DevExpress.Xpo
Imports System.Reflection
Imports DevExpress.Xpo.DB
Imports System.Configuration
Imports DevExpress.Xpo.Metadata
Public NotInheritable Class XpoHelper
Private Const ConnectionStringName As String = "CarsXtraSchedulingXPOConnectionString"
Private Sub New()
End Sub
Shared Sub New()
UpdateDatabase()
End Sub
Public Shared Function GetNewSession() As Session
Return New Session(DataLayer)
End Function
Public Shared Function GetNewUnitOfWork() As UnitOfWork
Return New UnitOfWork(DataLayer)
End Function
Private ReadOnly Shared lockObject As Object = New Object()
'INSTANT VB TODO TASK: There is no VB.NET equivalent to 'volatile':
'ORIGINAL LINE: static volatile IDataLayer fDataLayer;
Private Shared fDataLayer As IDataLayer
Private Shared ReadOnly Property DataLayer() As IDataLayer
Get
If fDataLayer Is Nothing Then
SyncLock lockObject
If fDataLayer Is Nothing Then
fDataLayer = GetDataLayer()
End If
End SyncLock
End If
Return fDataLayer
End Get
End Property
Private Shared Function GetDataLayer() As IDataLayer
XpoDefault.Session = Nothing
Dim dict As XPDictionary = New ReflectionDictionary()
dict.GetDataStoreSchema(System.Reflection.Assembly.GetExecutingAssembly())
Return New ThreadSafeDataLayer(dict, XpoDefault.GetConnectionProvider(ConfigurationManager.ConnectionStrings(ConnectionStringName).ConnectionString, AutoCreateOption.None))
End Function
Private Shared Sub UpdateDatabase()
Using dal As IDataLayer = XpoDefault.GetDataLayer(ConfigurationManager.ConnectionStrings(ConnectionStringName).ConnectionString, AutoCreateOption.DatabaseAndSchema)
Using session As New Session(dal)
Dim asm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
session.UpdateSchema(asm)
session.CreateObjectTypeRecords(asm)
End Using
End Using
End Sub
End Class