forked from EVEIPH/EVE-IPH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCorporation.vb
176 lines (133 loc) · 5.29 KB
/
Corporation.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
164
165
166
167
168
169
170
171
172
173
174
175
176
Imports System.Data.SQLite
' Corporation class will handle all processing for corporation data.
Public Class Corporation
Private KeyID As Long
Private APIKey As String
Private Name As String
Private ID As Long ' Corp ID
Private CorpMemberID As Long ' The corp member id we are associating with this corp
Private KeyData As APIKeyData
Private Jobs As EVEIndustryJobs
' Private Facilities As CorporationFacilities ' Maybe use later
Private Assets As EVEAssets
Private Blueprints As EVEBlueprints
Private AccessMask As Long
Private AssetsAccess As Boolean
Private IndustryJobsAccess As Boolean
Public Sub New(Optional ByVal CorpID As Long = 0, Optional ByVal CorpName As String = "No Corp", Optional ByVal MemberID As Long = 0)
ID = CorpID
Name = CorpName
CorpMemberID = MemberID
KeyID = 0
APIKey = ""
AccessMask = 0
AssetsAccess = False
IndustryJobsAccess = False
KeyData = New APIKeyData
End Sub
' Load the API and key from the DB if a corp key exists.
Public Sub LoadCorpAPIData(RefreshAssets As Boolean, RefreshBlueprints As Boolean)
Dim rsAPI As SQLiteDataReader
Dim SQL As String
Dim RefreshDate As Date
Dim UpdatedNewData As Boolean
SQL = "SELECT KEY_ID, API_KEY, CACHED_UNTIL, API_TYPE FROM API WHERE API_TYPE = '" & CorporationAPITypeName & "' "
SQL = SQL & "AND CORPORATION_ID =" & ID & " AND CORPORATION_NAME ='" & FormatDBString(Name) & "'"
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
rsAPI = DBCommand.ExecuteReader
' If the key exists, then update it first
If rsAPI.Read Then
' RefreshDate is in UTC time
RefreshDate = CDate(rsAPI.GetString(2))
' See if we want to refresh the corp data
If RefreshDate < DateTime.UtcNow Then
UpdatedNewData = UpdateAccountAPIData(rsAPI.GetInt64(0), rsAPI.GetString(1), rsAPI.GetString(3))
Else
' Data wasn't updated, so don't run API updates on other API data either
UpdatedNewData = False
End If
End If
rsAPI.Close()
SQL = "SELECT KEY_ID, API_KEY, ACCESS_MASK "
SQL = SQL & "FROM API WHERE API_TYPE = '" & CorporationAPITypeName & "' "
SQL = SQL & "AND CORPORATION_ID =" & ID & " AND CORPORATION_NAME ='" & FormatDBString(Name) & "'"
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
rsAPI = DBCommand.ExecuteReader
If rsAPI.Read Then
KeyID = rsAPI.GetInt64(0)
APIKey = rsAPI.GetString(1)
AccessMask = rsAPI.GetInt64(2)
End If
' Now that we have the API, set the access variables
Call SetAPIAccess()
KeyData.ID = CorpMemberID
KeyData.KeyID = KeyID
KeyData.APIKey = APIKey
' Load industry jobs here
KeyData.Access = IndustryJobsAccess
Jobs = New EVEIndustryJobs(KeyData, ID)
Call Jobs.LoadIndustryJobs(ScanType.Corporation, UpdatedNewData)
'' Load corp facilities
'KeyData.Access = IndustryJobsAccess ' Temp
'Facilities = New CorporationFacilities(KeyData, ID)
'Call Facilities.LoadCorpFacilities(UpdatedNewData)
' Wait on loading assets until they look at them due to long refresh time
KeyData.Access = AssetsAccess
Assets = New EVEAssets(KeyData, ID)
Call Assets.LoadAssets(ScanType.Corporation, RefreshAssets)
' Load the Blueprints but don't update due to long api cache times
KeyData.Access = AssetsAccess
Blueprints = New EVEBlueprints(KeyData, ID)
Call Blueprints.LoadBlueprints(ScanType.Corporation, RefreshBlueprints)
rsAPI.Close()
End Sub
' Sets the Access variables for the corp key
Private Sub SetAPIAccess()
Dim BitString As String
Dim BitLen As Integer
' Access mask is a bitmask
BitString = GetBits(AccessMask)
BitLen = Len(BitString)
' Just do a bool cast on the bits for any API access stuff we want
If BitLen >= AccessMaskBitLocs.AssetList Then
AssetsAccess = CBool(BitString.Substring(BitLen - AccessMaskBitLocs.AssetList, 1))
Else
AssetsAccess = False
End If
If BitLen >= AccessMaskBitLocs.IndustryJobs Then
IndustryJobsAccess = CBool(BitString.Substring(BitLen - AccessMaskBitLocs.IndustryJobs, 1))
Else
IndustryJobsAccess = False
End If
End Sub
Public Function GetIndustryJobs() As EVEIndustryJobs
Return Jobs
End Function
Public Function GetAssets() As EVEAssets
Return Assets
End Function
Public Function GetBlueprints() As EVEBlueprints
Return Blueprints
End Function
ReadOnly Property JobsAccess() As Boolean
Get
Return IndustryJobsAccess
End Get
End Property
ReadOnly Property AssetAccess() As Boolean
Get
Return AssetsAccess
End Get
End Property
ReadOnly Property CorporationID() As Long
Get
Return ID
End Get
End Property
ReadOnly Property CorporationName() As String
Get
Return Name
End Get
End Property
End Class