Skip to content

Commit 4255938

Browse files
authored
3 control git repostitory directly from add in (#4)
* GitHub tree API for import * GitHubTreeview ready
1 parent 2475a63 commit 4255938

14 files changed

+950
-10
lines changed

access-add-in/ACLibImportWizard.accda

136 KB
Binary file not shown.

source/ACLibFileManager.cls

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Attribute VB_Description = "Import/Export der Access-Objekte in/aus lokaler Code
3030
'---------------------------------------------------------------------------------------
3131
'<codelib>
3232
' <file>%AppFolder%/source/ACLibFileManager.cls</file>
33-
' <description>Kuemmert sich um den Import und Export der Codemodule aus dem und in das Repository</description>
33+
' <description>Import/export of Access objects to/from local code library</description>
3434
' <license>_codelib/license.bas</license>
3535
' <use>base/ApplicationHandler.cls</use>
3636
' <use>file/modFiles.bas</use>
@@ -117,6 +117,7 @@ Private m_ExportAllToApplicationSourceFolder As Boolean
117117

118118
' Events
119119
Public Event PropertyMissingLocalRepositoryRootDirectory(ByRef NewValue As String)
120+
Public Event MissingLocalRepositoryFile(ByVal ACLibPath As String, ByVal FullFilePath As String)
120121
Public Event ImportRepositoryFile(ByVal ObjectName As String, ByVal RepositoryFile As String, _
121122
ByVal ElementType As CodeLibElementType, ByRef Dependency As Variant, _
122123
ByRef ImportFile As Object, ByRef Cancel As Integer)
@@ -323,6 +324,8 @@ Public Sub ImportRepositoryFile(ByVal RepositoryPath As String, _
323324

324325
PathString = GetRepositoryFullPath(RepositoryPath)
325326

327+
328+
326329
Dim TempFile As Object
327330
Set TempFile = fso.GetFile(PathString)
328331
AddMissingFile TempFile, ImportMode
@@ -638,6 +641,7 @@ End Property
638641
Public Function GetRepositoryFullPath(ByVal ReleativPath As String) As String
639642

640643
Dim RepPath As String
644+
Dim FullPath As String
641645

642646
ReleativPath = Replace(ReleativPath, "/", "\")
643647

@@ -671,8 +675,14 @@ Public Function GetRepositoryFullPath(ByVal ReleativPath As String) As String
671675
Do While Left$(ReleativPath, 1) = "\"
672676
ReleativPath = Mid$(ReleativPath, 2)
673677
Loop
678+
679+
FullPath = RepPath & ReleativPath
680+
681+
If Len(VBA.Dir(FullPath)) = 0 Then
682+
RaiseEvent MissingLocalRepositoryFile(ReleativPath, FullPath)
683+
End If
674684

675-
GetRepositoryFullPath = RepPath & ReleativPath
685+
GetRepositoryFullPath = FullPath
676686

677687
End Function
678688

@@ -1248,7 +1258,6 @@ Public Function GetCodeLibInfoFromFilePath(ByVal FilePath As String, Optional By
12481258
GetCodeLibInfoFromFilePath = cli
12491259
End Function
12501260

1251-
12521261
Private Sub GetCodeLibInfoFromFile(ByRef CodeLibInf As CodeLibInfo, ByVal InputFile As Object, _
12531262
Optional ByVal FindDependency As Boolean = True, _
12541263
Optional ByVal FindTests As Boolean = True)
@@ -1258,8 +1267,10 @@ Private Sub GetCodeLibInfoFromFile(ByRef CodeLibInf As CodeLibInfo, ByVal InputF
12581267
Dim TempString As String
12591268
Dim i As Long
12601269
Dim FileNumber As Long
1270+
Dim StringCutPos As Long
12611271

12621272
FileNumber = FreeFile
1273+
12631274
Open InputFile.Path For Binary Access Read As FileNumber
12641275
CheckString = String$(LOF(FileNumber), 0)
12651276
Get FileNumber, , CheckString
@@ -1269,7 +1280,12 @@ Private Sub GetCodeLibInfoFromFile(ByRef CodeLibInf As CodeLibInfo, ByVal InputF
12691280
CodeLibInf.Name = FindSubString(CheckString, SEARCHSTRING_ATTRIBUTNAME_BEGIN, SEARCHSTRING_ATTRIBUTNAME_END, Pos)
12701281

12711282
If Len(CodeLibInf.Name) = 0 Then ' from filenames
1272-
CodeLibInf.Name = Left$(InputFile.Name, InStrRev(InputFile.Name, ".") - 1)
1283+
StringCutPos = InStrRev(InputFile.Name, ".")
1284+
If StringCutPos > 1 Then
1285+
CodeLibInf.Name = Left$(InputFile.Name, InStrRev(InputFile.Name, ".") - 1)
1286+
Else
1287+
CodeLibInf.Name = InputFile.Name
1288+
End If
12731289
End If
12741290

12751291
'Determine type

source/ACLibImportWizardForm.frm

25.5 KB
Binary file not shown.

source/ACLibRepositoryTreeForm.frm

108 KB
Binary file not shown.

source/GitHubTreeJsonConverter.cls

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
VERSION 1.0 CLASS
2+
BEGIN
3+
MultiUse = -1 'True
4+
END
5+
Attribute VB_Name = "GitHubTreeJsonConverter"
6+
Attribute VB_GlobalNameSpace = False
7+
Attribute VB_Creatable = False
8+
Attribute VB_PredeclaredId = False
9+
Attribute VB_Exposed = False
10+
Option Compare Database
11+
Option Explicit
12+
13+
Const SubPropIndentLen As Long = 2
14+
15+
Public Function Json2TreeNode(ByVal JsonString As String) As JsonProperties
16+
17+
JsonString = OptimizeJsonString(JsonString)
18+
19+
If Left(JsonString, 1) <> "{" Then
20+
Err.Raise vbObjectError, "JsonConverter.Parse", "Missing JSON structure"
21+
End If
22+
23+
If Right(JsonString, 1) <> "}" Then
24+
Err.Raise vbObjectError, "JsonConverter.Parse", "Missing JSON structure"
25+
End If
26+
27+
Set Json2TreeNode = ParseProperties(JsonString)
28+
29+
End Function
30+
31+
'#############################################
32+
' Parse JSON
33+
34+
Private Function OptimizeJsonString(ByVal JsonString As String) As String
35+
36+
JsonString = Replace(JsonString, vbNewLine, vbNullString)
37+
JsonString = Replace(JsonString, vbTab, vbNullString)
38+
JsonString = Replace(JsonString, vbCr, vbNullString)
39+
JsonString = Replace(JsonString, vbLf, vbNullString)
40+
41+
JsonString = Trim(JsonString)
42+
43+
OptimizeJsonString = JsonString
44+
45+
End Function
46+
47+
Private Function ParseProperties(ByVal JsonString As String) As JsonProperties
48+
49+
Dim Props As JsonProperties
50+
Set Props = New JsonProperties
51+
52+
Dim PropStringArray() As String
53+
Dim i As Long
54+
Dim PropString As String
55+
56+
JsonString = Trim(JsonString)
57+
If Left(JsonString, 1) = "{" And Right(JsonString, 1) = "}" Then ' if
58+
JsonString = Mid(JsonString, 2, Len(JsonString) - 2)
59+
Else
60+
Err.Raise vbObjectError, "JsonConverter.ParseProperties", "Missing JSON structure"
61+
End If
62+
63+
64+
PropStringArray = Split(SetSplitMarker(JsonString), ",|")
65+
66+
For i = LBound(PropStringArray) To UBound(PropStringArray)
67+
PropString = Trim(PropStringArray(i))
68+
If Len(PropString) > 0 Then
69+
Props.Append ConvertString2Property(PropString)
70+
End If
71+
Next
72+
73+
Set ParseProperties = Props
74+
75+
End Function
76+
77+
Private Function ConvertString2Property(ByVal JsonString As String) As JsonProperty
78+
' "Name" : "abc" => Value
79+
' "Name" : 123 => Value
80+
' "Name" : { ... => Properties
81+
82+
Dim Prop As JsonProperty
83+
84+
Dim PropName As String
85+
Dim PropValueString As Variant
86+
87+
Dim CutPos As Long
88+
89+
Set Prop = New JsonProperty
90+
91+
CutPos = InStr(1, JsonString, ":")
92+
93+
PropName = Trim(Left(JsonString, CutPos - 1))
94+
If Left(PropName, 1) = """" And Right(PropName, 1) = """" Then
95+
PropName = Mid(PropName, 2, Len(PropName) - 2)
96+
End If
97+
Prop.Name = PropName
98+
99+
PropValueString = Trim(Mid(JsonString, CutPos + 1))
100+
101+
If Left(PropValueString, 1) = "{" Then ' new properties
102+
Set Prop.Properties = ParseProperties(PropValueString)
103+
ElseIf Left(PropValueString, 1) = "[" Then ' new properties
104+
Set Prop.ObjectValue = ConvertString2JsonItem(PropValueString)
105+
Else
106+
Prop.Value = ConvertString2JsonItem(PropValueString)
107+
End If
108+
109+
Set ConvertString2Property = Prop
110+
111+
End Function
112+
113+
Private Function ConvertString2JsonItem(ByVal PropValueString As String) As Variant
114+
115+
If Left(PropValueString, 1) = "{" Then ' new properties
116+
Set ConvertString2JsonItem = ParseProperties(PropValueString)
117+
ElseIf Left(PropValueString, 1) = "[" Then ' new nodes
118+
Set ConvertString2JsonItem = ParseJsonArray(PropValueString)
119+
ElseIf PropValueString = "null" Then
120+
ConvertString2JsonItem = Null
121+
ElseIf PropValueString = "true" Then
122+
ConvertString2JsonItem = True
123+
ElseIf PropValueString = "false" Then
124+
ConvertString2JsonItem = False
125+
ElseIf Left(PropValueString, 1) = """" Then 'string
126+
ConvertString2JsonItem = Mid(PropValueString, 2, Len(PropValueString) - 2)
127+
Else ' Variant
128+
ConvertString2JsonItem = CVar(PropValueString)
129+
End If
130+
131+
End Function
132+
133+
Private Function ParseJsonArray(ByVal JsonString As String) As Collection
134+
135+
Dim Items As Collection
136+
Dim PropStringArray() As String
137+
Dim i As Long
138+
Dim Props As Variant
139+
140+
If Left(JsonString, 1) = "[" And Right(JsonString, 1) = "]" Then
141+
JsonString = Trim(Mid(JsonString, 2, Len(JsonString) - 2))
142+
End If
143+
144+
PropStringArray = Split(SetSplitMarker(JsonString), ",|")
145+
146+
Set Items = New Collection
147+
For i = LBound(PropStringArray) To UBound(PropStringArray)
148+
Items.Add ConvertString2JsonItem(Trim(PropStringArray(i)))
149+
Next
150+
151+
Set ParseJsonArray = Items
152+
153+
End Function
154+
155+
Private Function ParseValueFromString(ByVal JsonString As String) As Variant
156+
157+
JsonString = Trim(JsonString)
158+
159+
If JsonString = "null" Then
160+
ParseValueFromString = Null
161+
ElseIf JsonString = "true" Then
162+
ParseValueFromString = True
163+
ElseIf JsonString = "false" Then
164+
ParseValueFromString = False
165+
ElseIf Left(JsonString, 1) = """" And Right(JsonString, 1) = """" Then 'string
166+
ParseValueFromString = Mid(JsonString, 2, Len(JsonString) - 2)
167+
Else
168+
ParseValueFromString = Val(JsonString)
169+
End If
170+
171+
End Function
172+
173+
Private Function SetSplitMarker(ByVal JsonString As String) As String
174+
175+
Dim Pos As Long
176+
Dim LeftPart As String
177+
Dim CheckString As String
178+
179+
JsonString = Replace(JsonString, ",", ", ") ' place to insert marker
180+
181+
Pos = InStr(1, JsonString, ",")
182+
183+
Do While Pos > 0
184+
CheckString = Left(JsonString, Pos - 1)
185+
If Not PosIsInSubObject(CheckString) Then
186+
If Not PosIsInArray(CheckString) Then
187+
Mid(JsonString, Pos + 1, 1) = "|"
188+
End If
189+
End If
190+
Pos = InStr(Pos + 1, JsonString, ",")
191+
Loop
192+
193+
SetSplitMarker = Replace(JsonString, ", ", ",")
194+
195+
End Function
196+
197+
Private Function PosIsInSubObject(ByVal StringToCheck As String) As Boolean
198+
199+
PosIsInSubObject = PosIsInOpenStruct(StringToCheck, "{", "}")
200+
201+
End Function
202+
203+
Private Function PosIsInArray(ByVal StringToCheck As String) As Boolean
204+
205+
PosIsInArray = PosIsInOpenStruct(StringToCheck, "[", "]")
206+
207+
End Function
208+
209+
Private Function PosIsInOpenStruct(ByVal StringToCheck As String, ByVal OpeningChar As String, ByVal ClosingChar As String) As Boolean
210+
211+
Dim CntOpeningBrackets As Long
212+
Dim CntClosingBrackets As Long
213+
214+
CntOpeningBrackets = Len(StringToCheck) - Len(Replace(StringToCheck, OpeningChar, vbNullString))
215+
CntClosingBrackets = Len(StringToCheck) - Len(Replace(StringToCheck, ClosingChar, vbNullString))
216+
217+
If CntOpeningBrackets > CntClosingBrackets Then
218+
PosIsInOpenStruct = True
219+
Else
220+
PosIsInOpenStruct = False
221+
End If
222+
223+
End Function

0 commit comments

Comments
 (0)