333 lines
13 KiB
Plaintext
333 lines
13 KiB
Plaintext
' DxDesigner 7.9.5 part replacement menu runtime. ASCII-only source.
|
|
|
|
Sub DxMenuRequireFields(ByRef Record, ByVal FieldNames, _
|
|
ByVal ExpectedCount, ByVal Context)
|
|
Dim Name
|
|
If Not DxBridgeIsDictionary(Record) Then
|
|
Err.Raise vbObjectError + 795, "DxMenuRequireFields", _
|
|
Context & " must be an object"
|
|
End If
|
|
If Record.Count <> ExpectedCount Then
|
|
Err.Raise vbObjectError + 795, "DxMenuRequireFields", _
|
|
Context & " fields are invalid"
|
|
End If
|
|
For Each Name In Split(CStr(FieldNames), ",")
|
|
If Not Record.Exists(CStr(Name)) Then
|
|
Err.Raise vbObjectError + 795, "DxMenuRequireFields", _
|
|
Context & " is missing " & CStr(Name)
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
Sub DxMenuRequireString(ByRef Record, ByVal Name, ByVal Context)
|
|
If VarType(Record(CStr(Name))) <> vbString Then
|
|
Err.Raise vbObjectError + 795, "DxMenuRequireString", _
|
|
Context & "." & CStr(Name) & " must be a string"
|
|
End If
|
|
If Len(CStr(Record(CStr(Name)))) = 0 Then
|
|
Err.Raise vbObjectError + 795, "DxMenuRequireString", _
|
|
Context & "." & CStr(Name) & " must not be empty"
|
|
End If
|
|
End Sub
|
|
|
|
Function DxMenuCanonicalProjectPath(ByRef Fso, ByVal Value)
|
|
DxMenuCanonicalProjectPath = LCase(Replace( _
|
|
Fso.GetAbsolutePathName(CStr(Value)), "/", "\"))
|
|
End Function
|
|
|
|
Sub DxMenuValidateManifestRecord(ByRef Record, ByVal Home)
|
|
Dim Name
|
|
DxMenuRequireFields Record, _
|
|
"command,profile,project_id,project_path,snapshot,status", 6, _
|
|
"runtime manifest project"
|
|
For Each Name In Array("command", "profile", "project_id", _
|
|
"project_path", "snapshot", "status")
|
|
DxMenuRequireString Record, CStr(Name), "runtime manifest project"
|
|
Next
|
|
If StrComp(CStr(Record("profile")), _
|
|
"runs/compatibility-profile.json", vbBinaryCompare) <> 0 Then
|
|
Err.Raise vbObjectError + 795, "DxMenuValidateManifestRecord", _
|
|
"runtime manifest profile is not the deployed profile"
|
|
End If
|
|
For Each Name In Array("profile", "command", "status", "snapshot")
|
|
Call DxResolveRunPath(Home, CStr(Record(CStr(Name))))
|
|
Next
|
|
End Sub
|
|
|
|
Function DxMenuReadManifest(ByVal Home)
|
|
Dim ManifestPath
|
|
Dim Manifest
|
|
ManifestPath = DxResolveRunPath(Home, _
|
|
"runs/current-part-replacement.json")
|
|
Set Manifest = DxBridgeParseJson(DxReadUtf8(ManifestPath))
|
|
DxMenuRequireFields Manifest, _
|
|
"complete,current_action,current_command_id,current_project_id," & _
|
|
"format_version,projects", 6, _
|
|
"runtime manifest"
|
|
If VarType(Manifest("complete")) <> vbBoolean Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadManifest", _
|
|
"runtime manifest complete must be Boolean"
|
|
End If
|
|
If Not DxBridgeIsProtocolInteger(Manifest("format_version")) Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadManifest", _
|
|
"runtime manifest format_version must be integer 2"
|
|
End If
|
|
If CLng(Manifest("format_version")) <> 2 Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadManifest", _
|
|
"runtime manifest format_version must be 2"
|
|
End If
|
|
If Not DxBridgeIsJsonArray(Manifest("projects")) Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadManifest", _
|
|
"runtime manifest projects must be an array"
|
|
End If
|
|
If CBool(Manifest("complete")) Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadManifest", _
|
|
"part replacement job is complete"
|
|
End If
|
|
DxMenuRequireString Manifest, "current_action", "runtime manifest"
|
|
DxMenuRequireString Manifest, "current_command_id", "runtime manifest"
|
|
DxMenuRequireString Manifest, "current_project_id", "runtime manifest"
|
|
If Not DxMenuIsBaseAction(CStr(Manifest("current_action"))) Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadManifest", _
|
|
"runtime manifest current_action is invalid"
|
|
End If
|
|
Set DxMenuReadManifest = Manifest
|
|
End Function
|
|
|
|
Function DxMenuReadManifestRecord(ByRef Manifest, ByVal Home)
|
|
Dim Entries
|
|
Dim Record
|
|
Dim MatchRecord
|
|
Dim Index
|
|
Dim Matches
|
|
Set Entries = Manifest("projects")
|
|
Matches = 0
|
|
For Index = 0 To Entries.Count - 1
|
|
If Not IsObject(Entries.Item(Index)) Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadManifestRecord", _
|
|
"runtime manifest project must be an object"
|
|
End If
|
|
Set Record = Entries.Item(Index)
|
|
DxMenuValidateManifestRecord Record, Home
|
|
If StrComp(CStr(Record("project_id")), _
|
|
CStr(Manifest("current_project_id")), _
|
|
vbBinaryCompare) = 0 Then
|
|
Matches = Matches + 1
|
|
Set MatchRecord = Record
|
|
End If
|
|
Next
|
|
If Matches <> 1 Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadManifestRecord", _
|
|
"current project has zero or multiple runtime manifest matches"
|
|
End If
|
|
Set DxMenuReadManifestRecord = MatchRecord
|
|
End Function
|
|
|
|
Function DxMenuIsBaseAction(ByVal ActionName)
|
|
Select Case CStr(ActionName)
|
|
Case "inventory", "close_project", "close_without_save", _
|
|
"open_project", "replace_part", "undo", "save", _
|
|
"packager", "erc", "netlist"
|
|
DxMenuIsBaseAction = True
|
|
Case Else
|
|
DxMenuIsBaseAction = False
|
|
End Select
|
|
End Function
|
|
|
|
Function DxMenuReadBoundCommand(ByVal Home, ByRef Manifest, ByRef Record)
|
|
Dim Command
|
|
Dim Failure
|
|
Set Command = DxBridgeParseJson(DxReadUtf8( _
|
|
DxResolveRunPath(Home, CStr(Record("command")))))
|
|
If Not DxBridgeIsDictionary(Command) Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadBoundCommand", _
|
|
"current bridge command must be an object"
|
|
End If
|
|
Set Failure = DxBridgeNewFailure()
|
|
If Not DxBridgeValidateCommand(Command, _
|
|
CStr(Manifest("current_action")), Failure) Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadBoundCommand", _
|
|
"current bridge command is missing or stale"
|
|
End If
|
|
If StrComp(CStr(Command("command_id")), _
|
|
CStr(Manifest("current_command_id")), _
|
|
vbBinaryCompare) <> 0 Or _
|
|
StrComp(CStr(Command("project_id")), _
|
|
CStr(Manifest("current_project_id")), _
|
|
vbBinaryCompare) <> 0 Or _
|
|
StrComp(CStr(Command("project_id")), _
|
|
CStr(Record("project_id")), _
|
|
vbBinaryCompare) <> 0 Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadBoundCommand", _
|
|
"runtime manifest and command bindings do not match"
|
|
End If
|
|
Set DxMenuReadBoundCommand = Command
|
|
End Function
|
|
|
|
Function DxMenuReadStatus(ByVal Home, ByRef Record)
|
|
Dim Status
|
|
Set Status = DxBridgeParseJson(DxReadUtf8( _
|
|
DxResolveRunPath(Home, CStr(Record("status")))))
|
|
If Not DxBridgeIsDictionary(Status) Then
|
|
Err.Raise vbObjectError + 795, "DxMenuReadStatus", _
|
|
"bridge status must be an object"
|
|
End If
|
|
Set DxMenuReadStatus = Status
|
|
End Function
|
|
|
|
Function DxMenuDispatchAction(ByVal Home, ByRef Record, _
|
|
ByRef Command, ByVal BaseAction, ByRef ManualRoute)
|
|
Dim Fso
|
|
Dim StatusPath
|
|
Dim Status
|
|
Dim Failure
|
|
Set Fso = CreateObject("Scripting.FileSystemObject")
|
|
StatusPath = DxResolveRunPath(Home, CStr(Record("status")))
|
|
ManualRoute = ""
|
|
If Not Fso.FileExists(StatusPath) Then
|
|
DxMenuDispatchAction = CStr(BaseAction)
|
|
Exit Function
|
|
End If
|
|
|
|
If BaseAction <> "replace_part" And _
|
|
BaseAction <> "undo" And BaseAction <> "save" And _
|
|
BaseAction <> "open_project" And _
|
|
BaseAction <> "close_project" And _
|
|
BaseAction <> "close_without_save" Then
|
|
DxMenuDispatchAction = CStr(BaseAction)
|
|
Exit Function
|
|
End If
|
|
|
|
Set Status = DxMenuReadStatus(Home, Record)
|
|
If BaseAction = "replace_part" Then
|
|
Set Failure = DxBridgeNewFailure()
|
|
If DxBridgeValidateManualContinuation(Command, Status, _
|
|
"manual_exact_selection", Failure) Then
|
|
ManualRoute = "manual_exact_selection"
|
|
DxMenuDispatchAction = "continue_after_manual_selection"
|
|
Exit Function
|
|
End If
|
|
Set Failure = DxBridgeNewFailure()
|
|
If DxBridgeValidateManualContinuation(Command, Status, _
|
|
"manual_native_dialog", Failure) Then
|
|
ManualRoute = "manual_native_dialog"
|
|
DxMenuDispatchAction = "continue_after_manual_dialog"
|
|
Exit Function
|
|
End If
|
|
Err.Raise vbObjectError + 795, "DxMenuDispatchAction", _
|
|
"bridge status does not permit replacement continuation"
|
|
End If
|
|
|
|
Select Case CStr(BaseAction)
|
|
Case "undo"
|
|
ManualRoute = "manual_native_undo"
|
|
Case "save"
|
|
ManualRoute = "manual_native_save"
|
|
Case "open_project"
|
|
ManualRoute = "manual_project_open"
|
|
Case "close_project"
|
|
ManualRoute = "manual_close_project"
|
|
Case "close_without_save"
|
|
ManualRoute = "manual_close_without_save"
|
|
End Select
|
|
Set Failure = DxBridgeNewFailure()
|
|
If DxBridgeValidateManualContinuation(Command, Status, _
|
|
ManualRoute, Failure) Then
|
|
DxMenuDispatchAction = CStr(BaseAction)
|
|
Exit Function
|
|
End If
|
|
|
|
If BaseAction = "undo" Or BaseAction = "save" Then
|
|
Set Failure = DxBridgeNewFailure()
|
|
If DxBridgeValidateControlStatus(Command, Status, Failure) Then
|
|
ManualRoute = ""
|
|
DxMenuDispatchAction = CStr(BaseAction)
|
|
Exit Function
|
|
End If
|
|
End If
|
|
Err.Raise vbObjectError + 795, "DxMenuDispatchAction", _
|
|
"bridge status does not permit control continuation"
|
|
End Function
|
|
|
|
Sub DxMenuRequireProjectContext(ByRef Record, ByVal BaseAction, _
|
|
ByVal ManualRoute)
|
|
Dim Fso
|
|
Dim ActiveValue
|
|
Dim ActivePath
|
|
Dim RecordPath
|
|
Set Fso = CreateObject("Scripting.FileSystemObject")
|
|
ActiveValue = Application.ProjectPath
|
|
If VarType(ActiveValue) <> vbString Then
|
|
Err.Raise vbObjectError + 795, "DxMenuRequireProjectContext", _
|
|
"active project path must be a string"
|
|
End If
|
|
If Len(CStr(ActiveValue)) = 0 Then
|
|
If BaseAction = "open_project" And Len(CStr(ManualRoute)) = 0 Then
|
|
Exit Sub
|
|
End If
|
|
If (BaseAction = "close_project" Or _
|
|
BaseAction = "close_without_save") And _
|
|
Len(CStr(ManualRoute)) > 0 Then
|
|
Exit Sub
|
|
End If
|
|
Err.Raise vbObjectError + 795, "DxMenuRequireProjectContext", _
|
|
"there is no active project for the current command"
|
|
End If
|
|
|
|
ActivePath = DxMenuCanonicalProjectPath(Fso, ActiveValue)
|
|
RecordPath = DxMenuCanonicalProjectPath(Fso, Record("project_path"))
|
|
If StrComp(ActivePath, RecordPath, vbTextCompare) <> 0 Then
|
|
Err.Raise vbObjectError + 795, "DxMenuRequireProjectContext", _
|
|
"active project does not match the current command"
|
|
End If
|
|
If BaseAction = "open_project" And _
|
|
CStr(ManualRoute) <> "manual_project_open" Then
|
|
Err.Raise vbObjectError + 795, "DxMenuRequireProjectContext", _
|
|
"project open requires a closed project or manual continuation"
|
|
End If
|
|
If (BaseAction = "close_project" Or _
|
|
BaseAction = "close_without_save") And _
|
|
Len(CStr(ManualRoute)) > 0 Then
|
|
Err.Raise vbObjectError + 795, "DxMenuRequireProjectContext", _
|
|
"manual project close has not completed"
|
|
End If
|
|
End Sub
|
|
|
|
Sub DxPartReplaceMenuDispatch(ByVal MenuAction)
|
|
Dim Home
|
|
Dim Manifest
|
|
Dim Record
|
|
Dim Command
|
|
Dim BaseAction
|
|
Dim DispatchAction
|
|
Dim ManualRoute
|
|
Dim ProfilePath
|
|
Dim CommandPath
|
|
Dim StatusPath
|
|
Dim SnapshotPath
|
|
Home = DxMenuHome()
|
|
Set Manifest = DxMenuReadManifest(Home)
|
|
BaseAction = CStr(Manifest("current_action"))
|
|
If CStr(MenuAction) = "inventory" And _
|
|
BaseAction <> "inventory" Then
|
|
Err.Raise vbObjectError + 795, "DxMenuBridge", _
|
|
"inventory menu action is not the current command"
|
|
End If
|
|
Set Record = DxMenuReadManifestRecord(Manifest, Home)
|
|
Set Command = DxMenuReadBoundCommand(Home, Manifest, Record)
|
|
DispatchAction = DxMenuDispatchAction(Home, Record, Command, _
|
|
BaseAction, ManualRoute)
|
|
DxMenuRequireProjectContext Record, BaseAction, ManualRoute
|
|
ProfilePath = CStr(Record("profile"))
|
|
CommandPath = CStr(Record("command"))
|
|
StatusPath = CStr(Record("status"))
|
|
SnapshotPath = CStr(Record("snapshot"))
|
|
If BaseAction = "open_project" Then
|
|
DxRunPartReplaceBridge DispatchAction, ProfilePath, CommandPath, _
|
|
StatusPath, SnapshotPath, CStr(Record("project_path"))
|
|
Else
|
|
DxRunPartReplaceBridge DispatchAction, ProfilePath, CommandPath, _
|
|
StatusPath, SnapshotPath, ""
|
|
End If
|
|
End Sub
|