4403 lines
167 KiB
Plaintext
4403 lines
167 KiB
Plaintext
' DxDesigner 7.9.5 native part replacement bridge. ASCII-only source.
|
|
|
|
Class DxBridgeJsonArray
|
|
Private Values
|
|
Private ValueCount
|
|
|
|
Private Sub Class_Initialize()
|
|
ReDim Values(0)
|
|
ValueCount = 0
|
|
End Sub
|
|
|
|
Public Sub Add(ByRef Value)
|
|
If ValueCount > 0 Then ReDim Preserve Values(ValueCount)
|
|
If IsObject(Value) Then
|
|
Set Values(ValueCount) = Value
|
|
Else
|
|
Values(ValueCount) = Value
|
|
End If
|
|
ValueCount = ValueCount + 1
|
|
End Sub
|
|
|
|
Public Property Get Count
|
|
Count = ValueCount
|
|
End Property
|
|
|
|
Public Default Property Get Item(ByVal Index)
|
|
If Index < 0 Or Index >= ValueCount Then
|
|
Err.Raise vbObjectError + 829, "DxBridgeJsonArray", _
|
|
"JSON array index is out of range"
|
|
End If
|
|
If IsObject(Values(Index)) Then
|
|
Set Item = Values(Index)
|
|
Else
|
|
Item = Values(Index)
|
|
End If
|
|
End Property
|
|
End Class
|
|
|
|
Sub DxRunPartReplaceBridge(ByVal RequestedAction, ByVal ProfileRelativePath, _
|
|
ByVal CommandRelativePath, ByVal StatusRelativePath, _
|
|
ByVal SnapshotRelativePath, ByVal ProjectPathArgument)
|
|
Dim RootPath
|
|
Dim StatusPath
|
|
Dim ProfilePath
|
|
Dim CommandPath
|
|
Dim SnapshotPath
|
|
Dim ProfileText
|
|
Dim CommandText
|
|
Dim Profile
|
|
Dim Command
|
|
Dim StatusCommand
|
|
Dim PriorStatus
|
|
Dim Failure
|
|
Dim LiveMap
|
|
Dim SnapshotText
|
|
Dim Fingerprint
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim ModifiedValue
|
|
Dim TargetProjectPath
|
|
Dim ActualProjectPath
|
|
Dim LiveAccepted
|
|
Dim ManualContinuation
|
|
Dim FileSystem
|
|
|
|
Set Failure = DxBridgeNewFailure()
|
|
RootPath = CStr(Scripting.GetEnvVariable("DXTOOLS_HOME"))
|
|
If Len(RootPath) = 0 Then
|
|
Err.Raise vbObjectError + 795, "DxRunPartReplaceBridge", _
|
|
"DXTOOLS_HOME is not set in the injected scripting host"
|
|
End If
|
|
|
|
On Error Resume Next
|
|
StatusPath = DxResolveRunPath(RootPath, StatusRelativePath)
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
Err.Raise ErrorNumber, ErrorSource, ErrorDescription
|
|
End If
|
|
|
|
On Error Resume Next
|
|
ProfilePath = DxResolveRunPath(RootPath, ProfileRelativePath)
|
|
CommandPath = DxResolveRunPath(RootPath, CommandRelativePath)
|
|
SnapshotPath = DxResolveRunPath(RootPath, SnapshotRelativePath)
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgePublishBareStatus StatusPath, RequestedAction, _
|
|
"invalid_run_path", ErrorDescription
|
|
Exit Sub
|
|
End If
|
|
|
|
If Not DxBridgeLoadJsonObject(ProfilePath, "compatibility profile", _
|
|
Profile, Failure) Then
|
|
DxBridgePublishBareFailure StatusPath, RequestedAction, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeLoadJsonObject(CommandPath, "bridge command", _
|
|
Command, Failure) Then
|
|
DxBridgePublishBareFailure StatusPath, RequestedAction, Failure
|
|
Exit Sub
|
|
End If
|
|
Set StatusCommand = DxBridgeSanitizeCommandForFailure(Command, _
|
|
RequestedAction)
|
|
If Not DxBridgeValidateCommand(Command, RequestedAction, Failure) Then
|
|
DxBridgePublishFailure StatusPath, StatusCommand, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeValidateProfile(Profile, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
LiveAccepted = DxBridgeProfileLiveAccepted(Profile)
|
|
|
|
If Not LiveAccepted Then
|
|
If RequestedAction = "replace_part" Then
|
|
DxBridgePublishManual StatusPath, Command, _
|
|
"manual_exact_selection", _
|
|
"Select exactly the expected full-project logical group"
|
|
Exit Sub
|
|
End If
|
|
End If
|
|
|
|
If Not DxBridgeVerifyProfileIdentity(Profile, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
|
|
Select Case CStr(RequestedAction)
|
|
Case "inventory"
|
|
If Not DxBridgeReadScalar(Application, "Modified", _
|
|
"Application.Modified", ModifiedValue, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If VarType(ModifiedValue) <> vbBoolean Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Application.Modified is not a Boolean", _
|
|
"Application.Modified", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If CBool(ModifiedValue) Then
|
|
DxBridgeSetFailure Failure, "dirty_project", _
|
|
"Inventory requires a saved, non-dirty active project", _
|
|
"Application.Modified", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeWriteDocument(SnapshotPath, SnapshotText, _
|
|
"snapshot publication", Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
DxBridgePublishStatus StatusPath, Command, "inventory_exported", _
|
|
SnapshotPath, Null, Null, Empty
|
|
Case "replace_part"
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If StrComp(Fingerprint, _
|
|
CStr(Command("expected_fingerprint")), _
|
|
vbBinaryCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, "stale_snapshot", _
|
|
"Complete current snapshot does not match the command", _
|
|
"snapshot.fingerprint", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeVerifyExpectedLiveState(Command, LiveMap, _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeRouteVerified(Profile, "exact_set_selection", _
|
|
"ActiveView.SelectExactSet") Then
|
|
DxBridgePublishManual StatusPath, Command, _
|
|
"manual_exact_selection", _
|
|
"Select exactly the expected full-project logical group"
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeSelectLogicalKeys(Command, LiveMap, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If CStr(Profile("production_replace_route")) <> _
|
|
"native_replace_part" Or _
|
|
Not DxBridgeRouteVerified(Profile, _
|
|
"native_replace_part", _
|
|
"Application.OpenReplacePartDialog") Or _
|
|
Not DxBridgeRouteVerified(Profile, _
|
|
"completion_observation", _
|
|
"Application.ReplacePartCompleted") Then
|
|
DxBridgePublishManual StatusPath, Command, _
|
|
"manual_native_dialog", _
|
|
"Open native Replace Part, choose the displayed target, " & _
|
|
"and use Library Wins"
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeRunNativeDialog(StatusPath, SnapshotPath, _
|
|
Command, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
Case "continue_after_manual_selection"
|
|
If Not DxBridgeLoadJsonObject(StatusPath, _
|
|
"prior bridge status", PriorStatus, Failure) Then
|
|
DxBridgeSetFailure Failure, _
|
|
"manual_continuation_mismatch", _
|
|
"Prior manual-selection status is missing or invalid", _
|
|
"status.manual_continuation", Failure("number"), _
|
|
Failure("source"), Failure("description")
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeValidateManualContinuation(Command, _
|
|
PriorStatus, "manual_exact_selection", Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Fingerprint <> Command("expected_fingerprint") Then
|
|
DxBridgeSetFailure Failure, "stale_snapshot", _
|
|
"Complete current snapshot does not match the command", _
|
|
"snapshot.fingerprint", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeVerifyExpectedLiveState(Command, LiveMap, _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeVerifySelectedLogicalKeys(Command, LiveMap, _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Profile("production_replace_route") <> _
|
|
"native_replace_part" Or _
|
|
Not DxBridgeRouteVerified(Profile, _
|
|
"native_replace_part", _
|
|
"Application.OpenReplacePartDialog") Or _
|
|
Not DxBridgeRouteVerified(Profile, _
|
|
"completion_observation", _
|
|
"Application.ReplacePartCompleted") Then
|
|
DxBridgePublishManual StatusPath, Command, _
|
|
"manual_native_dialog", _
|
|
"Open native Replace Part, choose the displayed target, " & _
|
|
"and use Library Wins"
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeRunNativeDialog(StatusPath, SnapshotPath, _
|
|
Command, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
Case "continue_after_manual_dialog"
|
|
If Not DxBridgeLoadJsonObject(StatusPath, _
|
|
"prior bridge status", PriorStatus, Failure) Then
|
|
DxBridgeSetFailure Failure, _
|
|
"manual_continuation_mismatch", _
|
|
"Prior manual-dialog status is missing or invalid", _
|
|
"status.manual_continuation", Failure("number"), _
|
|
Failure("source"), Failure("description")
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeValidateManualContinuation(Command, _
|
|
PriorStatus, "manual_native_dialog", Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeWriteDocument(SnapshotPath, SnapshotText, _
|
|
"manual post-operation snapshot publication", _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
DxBridgePublishStatus StatusPath, Command, "applied", _
|
|
SnapshotPath, Null, Null, Empty
|
|
Case "undo", "save"
|
|
If Not DxBridgeLoadJsonObject(StatusPath, _
|
|
"prior bridge status", PriorStatus, Failure) Then
|
|
DxBridgeSetFailure Failure, "control_status_mismatch", _
|
|
"Prior applied status is missing or invalid", _
|
|
"status.control", Failure("number"), _
|
|
Failure("source"), Failure("description")
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
ManualContinuation = False
|
|
If PriorStatus.Exists("state") Then
|
|
If VarType(PriorStatus("state")) = vbString Then
|
|
ManualContinuation = _
|
|
CStr(PriorStatus("state")) = _
|
|
"manual_action_required"
|
|
End If
|
|
End If
|
|
If ManualContinuation Then
|
|
If Not DxBridgeValidateManualContinuation(Command, _
|
|
PriorStatus, _
|
|
"manual_native_" & RequestedAction, _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
Else
|
|
If Not DxBridgeValidateControlStatus(Command, PriorStatus, _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
End If
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If (Not ManualContinuation Or _
|
|
RequestedAction = "save") And _
|
|
StrComp(Fingerprint, _
|
|
CStr(Command("expected_fingerprint")), _
|
|
vbBinaryCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, "stale_snapshot", _
|
|
"Complete current snapshot does not match the control command", _
|
|
"snapshot.fingerprint", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not ManualContinuation Then
|
|
If Not DxBridgeRouteVerified(Profile, RequestedAction, _
|
|
"Application." & _
|
|
UCase(Left(RequestedAction, 1)) & _
|
|
Mid(RequestedAction, 2)) Then
|
|
DxBridgePublishManual StatusPath, Command, _
|
|
"manual_native_" & RequestedAction, _
|
|
"Use native " & RequestedAction & _
|
|
" manually; completion is not automatically verified"
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeInvokeNoArgumentRoute(RequestedAction, _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
End If
|
|
If RequestedAction = "save" Then
|
|
If Not DxBridgeReadScalar(Application, "Modified", _
|
|
"Application.Modified.after_save", ModifiedValue, _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If VarType(ModifiedValue) <> vbBoolean Then
|
|
DxBridgeSetFailure Failure, "save_not_persisted", _
|
|
"Native Save returned an invalid dirty-state value", _
|
|
"Application.Modified.after_save", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If CBool(ModifiedValue) Then
|
|
DxBridgeSetFailure Failure, "save_not_persisted", _
|
|
"Native Save returned but the active project remains dirty", _
|
|
"Application.Modified.after_save", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
End If
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeWriteDocument(SnapshotPath, SnapshotText, _
|
|
RequestedAction & " snapshot publication", _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If RequestedAction = "undo" Then
|
|
DxBridgePublishControlStatus StatusPath, Command, _
|
|
"undo_verified", SnapshotPath
|
|
Else
|
|
DxBridgePublishControlStatus StatusPath, Command, _
|
|
"saved", SnapshotPath
|
|
End If
|
|
Case "close_project", "close_without_save"
|
|
If Not DxBridgeReadScalar(Application, "ProjectPath", _
|
|
"Application.ProjectPath.before_close", _
|
|
ActualProjectPath, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If VarType(ActualProjectPath) <> vbString Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Application.ProjectPath is not a string", _
|
|
"Application.ProjectPath.before_close", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Len(CStr(ActualProjectPath)) = 0 Then
|
|
If Not DxBridgeLoadJsonObject(StatusPath, _
|
|
"prior bridge status", PriorStatus, Failure) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeValidateManualContinuation(Command, _
|
|
PriorStatus, "manual_" & RequestedAction, _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
Set FileSystem = _
|
|
CreateObject("Scripting.FileSystemObject")
|
|
If Not FileSystem.FileExists(SnapshotPath) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
DxBridgePublishStatus StatusPath, Command, _
|
|
"project_closed", SnapshotPath, Null, Null, Empty
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeReadScalar(Application, "Modified", _
|
|
"Application.Modified.before_close", ModifiedValue, _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If VarType(ModifiedValue) <> vbBoolean Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Application.Modified is not a Boolean", _
|
|
"Application.Modified.before_close", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If RequestedAction = "close_project" And _
|
|
CBool(ModifiedValue) Then
|
|
DxBridgeSetFailure Failure, "dirty_project", _
|
|
"Backup close requires a saved, non-dirty active project", _
|
|
"Application.Modified.before_close", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If RequestedAction = "close_project" And _
|
|
StrComp(Fingerprint, _
|
|
CStr(Command("expected_fingerprint")), _
|
|
vbBinaryCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, "stale_snapshot", _
|
|
"Complete current snapshot does not match the close command", _
|
|
"snapshot.fingerprint", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeWriteDocument(SnapshotPath, SnapshotText, _
|
|
"pre-close snapshot publication", Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeRouteVerified(Profile, "close_project", _
|
|
"Application.CloseProject") Then
|
|
DxBridgePublishManual StatusPath, Command, _
|
|
"manual_" & RequestedAction, _
|
|
"Close the active project manually without saving"
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeInvokeNoArgumentRoute("close_project", _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeReadScalar(Application, "ProjectPath", _
|
|
"Application.ProjectPath.after_close", _
|
|
ActualProjectPath, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If VarType(ActualProjectPath) <> vbString Or _
|
|
Len(CStr(ActualProjectPath)) <> 0 Then
|
|
DxBridgeSetFailure Failure, "project_close_incomplete", _
|
|
"Native Close returned but a project remains active", _
|
|
"Application.ProjectPath.after_close", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
DxBridgePublishStatus StatusPath, Command, "project_closed", _
|
|
SnapshotPath, Null, Null, Empty
|
|
Case "open_project"
|
|
If Not DxBridgeCanonicalProjectPath(ProjectPathArgument, _
|
|
TargetProjectPath, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeVerifyPathProjectId(TargetProjectPath, _
|
|
CStr(Command("project_id")), Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeReadScalar(Application, "ProjectPath", _
|
|
"Application.ProjectPath.before_open", _
|
|
ActualProjectPath, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If VarType(ActualProjectPath) <> vbString Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Application.ProjectPath is not a string", _
|
|
"Application.ProjectPath.before_open", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
ManualContinuation = False
|
|
If Len(CStr(ActualProjectPath)) <> 0 Then
|
|
Set FileSystem = _
|
|
CreateObject("Scripting.FileSystemObject")
|
|
If Not FileSystem.FileExists(StatusPath) Then
|
|
DxBridgeSetFailure Failure, "project_already_open", _
|
|
"Project open requires the current project to be closed", _
|
|
"Application.ProjectPath.before_open", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeLoadJsonObject(StatusPath, _
|
|
"prior bridge status", PriorStatus, Failure) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeValidateManualContinuation(Command, _
|
|
PriorStatus, "manual_project_open", Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
ManualContinuation = True
|
|
Else
|
|
If Not DxBridgeRouteVerified(Profile, "open_project", _
|
|
"Application.OpenProject") Then
|
|
DxBridgePublishProjectOpenManual StatusPath, Command, _
|
|
TargetProjectPath
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeInvokeOpenProject(TargetProjectPath, _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeReadScalar(Application, "ProjectPath", _
|
|
"Application.ProjectPath.after_open", _
|
|
ActualProjectPath, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
End If
|
|
If VarType(ActualProjectPath) <> vbString Or _
|
|
Not DxBridgePathsEqual(ActualProjectPath, _
|
|
TargetProjectPath) Then
|
|
DxBridgeSetFailure Failure, "project_identity_mismatch", _
|
|
"Opened project does not match the requested canonical path", _
|
|
"Application.ProjectPath.after_open", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If StrComp(Fingerprint, _
|
|
CStr(Command("expected_fingerprint")), _
|
|
vbBinaryCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, "stale_snapshot", _
|
|
"Opened project snapshot does not match the command", _
|
|
"snapshot.fingerprint", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeWriteDocument(SnapshotPath, SnapshotText, _
|
|
"opened-project snapshot publication", Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
DxBridgePublishStatus StatusPath, Command, "project_opened", _
|
|
SnapshotPath, Null, Null, Empty
|
|
Case "packager", "erc", "netlist"
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If StrComp(Fingerprint, _
|
|
CStr(Command("expected_fingerprint")), _
|
|
vbBinaryCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, "stale_snapshot", _
|
|
"Complete current snapshot does not match the check command", _
|
|
"snapshot.fingerprint.before_check", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeRouteVerified(Profile, RequestedAction, _
|
|
DxBridgeExpectedProfileRoute(RequestedAction)) Then
|
|
DxBridgeSetFailure Failure, "external_check_unverified", _
|
|
"External check lacks a live-accepted automatic route", _
|
|
"profile.routes." & RequestedAction, 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeInvokeBooleanRoute(RequestedAction, _
|
|
ModifiedValue, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If VarType(ModifiedValue) <> vbBoolean Or _
|
|
Not CBool(ModifiedValue) Then
|
|
DxBridgeSetFailure Failure, "external_check_failed", _
|
|
"External check did not return explicit success", _
|
|
"route." & RequestedAction, 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If StrComp(Fingerprint, _
|
|
CStr(Command("expected_fingerprint")), _
|
|
vbBinaryCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, _
|
|
"external_check_modified_design", _
|
|
"External check changed the complete design snapshot", _
|
|
"snapshot.fingerprint.after_check", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
If Not DxBridgeWriteDocument(SnapshotPath, SnapshotText, _
|
|
RequestedAction & " snapshot publication", _
|
|
Failure) Then
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
Exit Sub
|
|
End If
|
|
DxBridgePublishStatus StatusPath, Command, _
|
|
"external_check_passed", SnapshotPath, Null, Null, Empty
|
|
Case Else
|
|
DxBridgeSetFailure Failure, "unsupported_action", _
|
|
"The requested bridge action is not implemented", _
|
|
"bridge.action", 0, "", ""
|
|
DxBridgePublishFailure StatusPath, Command, Failure
|
|
End Select
|
|
End Sub
|
|
|
|
Function DxBridgeNewFailure()
|
|
Dim Result
|
|
Set Result = CreateObject("Scripting.Dictionary")
|
|
Result.Add "code", "bridge_error"
|
|
Result.Add "message", "Bridge operation failed"
|
|
Result.Add "operation", "bridge"
|
|
Result.Add "number", 0
|
|
Result.Add "source", ""
|
|
Result.Add "description", ""
|
|
Set DxBridgeNewFailure = Result
|
|
End Function
|
|
|
|
Sub DxBridgeSetFailure(ByRef Failure, ByVal Code, ByVal Message, _
|
|
ByVal Operation, ByVal ErrorNumber, ByVal ErrorSource, _
|
|
ByVal ErrorDescription)
|
|
Failure("code") = CStr(Code)
|
|
Failure("message") = CStr(Message)
|
|
Failure("operation") = CStr(Operation)
|
|
Failure("number") = CLng(ErrorNumber)
|
|
Failure("source") = CStr(ErrorSource)
|
|
Failure("description") = CStr(ErrorDescription)
|
|
End Sub
|
|
|
|
Sub DxBridgeSetApiFailure(ByRef Failure, ByVal Operation, _
|
|
ByVal ErrorNumber, ByVal ErrorSource, ByVal ErrorDescription)
|
|
DxBridgeSetFailure Failure, "api_error", _
|
|
"DxDesigner API operation failed", Operation, ErrorNumber, _
|
|
ErrorSource, ErrorDescription
|
|
End Sub
|
|
|
|
Function DxBridgeLoadJsonObject(ByVal FilePath, ByVal DocumentName, _
|
|
ByRef Result, ByRef Failure)
|
|
Dim Text
|
|
Dim Parsed
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
|
|
On Error Resume Next
|
|
Text = DxReadUtf8(FilePath)
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetFailure Failure, "protocol_file", _
|
|
"Cannot read " & CStr(DocumentName), "read." & _
|
|
CStr(DocumentName), ErrorNumber, ErrorSource, ErrorDescription
|
|
DxBridgeLoadJsonObject = False
|
|
Exit Function
|
|
End If
|
|
|
|
On Error Resume Next
|
|
Set Parsed = DxBridgeParseJson(Text)
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetFailure Failure, "invalid_json", _
|
|
"Invalid " & CStr(DocumentName), "parse." & CStr(DocumentName), _
|
|
ErrorNumber, ErrorSource, ErrorDescription
|
|
DxBridgeLoadJsonObject = False
|
|
Exit Function
|
|
End If
|
|
Set Result = Parsed
|
|
DxBridgeLoadJsonObject = True
|
|
End Function
|
|
|
|
Function DxBridgeParseJson(ByVal JsonText)
|
|
Dim Position
|
|
Dim Value
|
|
Position = 1
|
|
DxBridgeJsonSkipSpace JsonText, Position
|
|
DxBridgeJsonParseValue JsonText, Position, Value
|
|
DxBridgeJsonSkipSpace JsonText, Position
|
|
If Position <= Len(JsonText) Then
|
|
Err.Raise vbObjectError + 830, "DxBridgeParseJson", _
|
|
"Trailing data after JSON document"
|
|
End If
|
|
If Not IsObject(Value) Then
|
|
Err.Raise vbObjectError + 831, "DxBridgeParseJson", _
|
|
"JSON root must be an object"
|
|
End If
|
|
If TypeName(Value) <> "Dictionary" Then
|
|
Err.Raise vbObjectError + 832, "DxBridgeParseJson", _
|
|
"JSON root must be an object"
|
|
End If
|
|
Set DxBridgeParseJson = Value
|
|
End Function
|
|
|
|
Sub DxBridgeJsonSkipSpace(ByVal Text, ByRef Position)
|
|
Dim Character
|
|
Do While Position <= Len(Text)
|
|
Character = Mid(Text, Position, 1)
|
|
If Character = " " Or Character = vbTab Or _
|
|
Character = vbCr Or Character = vbLf Then
|
|
Position = Position + 1
|
|
Else
|
|
Exit Do
|
|
End If
|
|
Loop
|
|
End Sub
|
|
|
|
Sub DxBridgeJsonParseValue(ByVal Text, ByRef Position, ByRef Value)
|
|
Dim Character
|
|
Dim Token
|
|
DxBridgeJsonSkipSpace Text, Position
|
|
If Position > Len(Text) Then
|
|
Err.Raise vbObjectError + 833, "DxBridgeParseJson", _
|
|
"Unexpected end of JSON"
|
|
End If
|
|
Character = Mid(Text, Position, 1)
|
|
Select Case Character
|
|
Case "{"
|
|
Set Value = DxBridgeJsonParseObject(Text, Position)
|
|
Case "["
|
|
Set Value = DxBridgeJsonParseArray(Text, Position)
|
|
Case Chr(34)
|
|
Value = DxBridgeJsonParseString(Text, Position)
|
|
Case "t"
|
|
Token = Mid(Text, Position, 4)
|
|
If Token <> "true" Then DxBridgeJsonSyntaxError
|
|
Value = True
|
|
Position = Position + 4
|
|
Case "f"
|
|
Token = Mid(Text, Position, 5)
|
|
If Token <> "false" Then DxBridgeJsonSyntaxError
|
|
Value = False
|
|
Position = Position + 5
|
|
Case "n"
|
|
Token = Mid(Text, Position, 4)
|
|
If Token <> "null" Then DxBridgeJsonSyntaxError
|
|
Value = Null
|
|
Position = Position + 4
|
|
Case Else
|
|
Value = DxBridgeJsonParseNumber(Text, Position)
|
|
End Select
|
|
End Sub
|
|
|
|
Function DxBridgeJsonParseObject(ByVal Text, ByRef Position)
|
|
Dim Result
|
|
Dim Name
|
|
Dim Item
|
|
Set Result = CreateObject("Scripting.Dictionary")
|
|
Position = Position + 1
|
|
DxBridgeJsonSkipSpace Text, Position
|
|
If Mid(Text, Position, 1) = "}" Then
|
|
Position = Position + 1
|
|
Set DxBridgeJsonParseObject = Result
|
|
Exit Function
|
|
End If
|
|
Do
|
|
If Mid(Text, Position, 1) <> Chr(34) Then DxBridgeJsonSyntaxError
|
|
Name = DxBridgeJsonParseString(Text, Position)
|
|
If Result.Exists(Name) Then
|
|
Err.Raise vbObjectError + 834, "DxBridgeParseJson", _
|
|
"Duplicate JSON object field"
|
|
End If
|
|
DxBridgeJsonSkipSpace Text, Position
|
|
If Mid(Text, Position, 1) <> ":" Then DxBridgeJsonSyntaxError
|
|
Position = Position + 1
|
|
DxBridgeJsonParseValue Text, Position, Item
|
|
Result.Add Name, Empty
|
|
If IsObject(Item) Then
|
|
Set Result(Name) = Item
|
|
Else
|
|
Result(Name) = Item
|
|
End If
|
|
DxBridgeJsonSkipSpace Text, Position
|
|
Select Case Mid(Text, Position, 1)
|
|
Case "}"
|
|
Position = Position + 1
|
|
Exit Do
|
|
Case ","
|
|
Position = Position + 1
|
|
DxBridgeJsonSkipSpace Text, Position
|
|
Case Else
|
|
DxBridgeJsonSyntaxError
|
|
End Select
|
|
Loop
|
|
Set DxBridgeJsonParseObject = Result
|
|
End Function
|
|
|
|
Function DxBridgeJsonParseArray(ByVal Text, ByRef Position)
|
|
Dim Result
|
|
Dim Item
|
|
Set Result = New DxBridgeJsonArray
|
|
Position = Position + 1
|
|
DxBridgeJsonSkipSpace Text, Position
|
|
If Mid(Text, Position, 1) = "]" Then
|
|
Position = Position + 1
|
|
Set DxBridgeJsonParseArray = Result
|
|
Exit Function
|
|
End If
|
|
Do
|
|
DxBridgeJsonParseValue Text, Position, Item
|
|
Result.Add Item
|
|
DxBridgeJsonSkipSpace Text, Position
|
|
Select Case Mid(Text, Position, 1)
|
|
Case "]"
|
|
Position = Position + 1
|
|
Exit Do
|
|
Case ","
|
|
Position = Position + 1
|
|
Case Else
|
|
DxBridgeJsonSyntaxError
|
|
End Select
|
|
Loop
|
|
Set DxBridgeJsonParseArray = Result
|
|
End Function
|
|
|
|
Function DxBridgeJsonParseString(ByVal Text, ByRef Position)
|
|
Dim Result
|
|
Dim Character
|
|
Dim Escape
|
|
Dim HexText
|
|
Dim CodePoint
|
|
Result = ""
|
|
Position = Position + 1
|
|
Do While Position <= Len(Text)
|
|
Character = Mid(Text, Position, 1)
|
|
Position = Position + 1
|
|
If Character = Chr(34) Then
|
|
DxBridgeJsonParseString = Result
|
|
Exit Function
|
|
End If
|
|
If AscW(Character) >= 0 And AscW(Character) < 32 Then
|
|
DxBridgeJsonSyntaxError
|
|
End If
|
|
If Character <> Chr(92) Then
|
|
Result = Result & Character
|
|
Else
|
|
If Position > Len(Text) Then DxBridgeJsonSyntaxError
|
|
Escape = Mid(Text, Position, 1)
|
|
Position = Position + 1
|
|
Select Case Escape
|
|
Case Chr(34), Chr(92), "/"
|
|
Result = Result & Escape
|
|
Case "b"
|
|
Result = Result & Chr(8)
|
|
Case "f"
|
|
Result = Result & Chr(12)
|
|
Case "n"
|
|
Result = Result & vbLf
|
|
Case "r"
|
|
Result = Result & vbCr
|
|
Case "t"
|
|
Result = Result & vbTab
|
|
Case "u"
|
|
HexText = Mid(Text, Position, 4)
|
|
If Len(HexText) <> 4 Or Not DxBridgeIsHex(HexText) Then
|
|
DxBridgeJsonSyntaxError
|
|
End If
|
|
CodePoint = CLng("&H" & HexText)
|
|
If CodePoint > 32767 Then CodePoint = CodePoint - 65536
|
|
Result = Result & ChrW(CodePoint)
|
|
Position = Position + 4
|
|
Case Else
|
|
DxBridgeJsonSyntaxError
|
|
End Select
|
|
End If
|
|
Loop
|
|
DxBridgeJsonSyntaxError
|
|
End Function
|
|
|
|
Function DxBridgeJsonParseNumber(ByVal Text, ByRef Position)
|
|
Dim StartPosition
|
|
Dim Character
|
|
Dim NumberText
|
|
Dim HasFractionOrExponent
|
|
StartPosition = Position
|
|
HasFractionOrExponent = False
|
|
|
|
If Mid(Text, Position, 1) = "-" Then
|
|
Position = Position + 1
|
|
End If
|
|
If Position > Len(Text) Then DxBridgeJsonSyntaxError
|
|
|
|
Character = Mid(Text, Position, 1)
|
|
If Character = "0" Then
|
|
Position = Position + 1
|
|
If Position <= Len(Text) And _
|
|
DxBridgeJsonIsDigit(Mid(Text, Position, 1)) Then
|
|
DxBridgeJsonSyntaxError
|
|
End If
|
|
ElseIf InStr(1, "123456789", Character, vbBinaryCompare) > 0 Then
|
|
Position = Position + 1
|
|
Do While Position <= Len(Text)
|
|
Character = Mid(Text, Position, 1)
|
|
If Not DxBridgeJsonIsDigit(Character) Then Exit Do
|
|
Position = Position + 1
|
|
Loop
|
|
Else
|
|
DxBridgeJsonSyntaxError
|
|
End If
|
|
|
|
If Mid(Text, Position, 1) = "." Then
|
|
HasFractionOrExponent = True
|
|
Position = Position + 1
|
|
If Position > Len(Text) Or _
|
|
Not DxBridgeJsonIsDigit(Mid(Text, Position, 1)) Then
|
|
DxBridgeJsonSyntaxError
|
|
End If
|
|
Do While Position <= Len(Text)
|
|
Character = Mid(Text, Position, 1)
|
|
If Not DxBridgeJsonIsDigit(Character) Then Exit Do
|
|
Position = Position + 1
|
|
Loop
|
|
End If
|
|
|
|
Character = LCase(Mid(Text, Position, 1))
|
|
If Character = "e" Then
|
|
HasFractionOrExponent = True
|
|
Position = Position + 1
|
|
Character = Mid(Text, Position, 1)
|
|
If Character = "+" Or Character = "-" Then
|
|
Position = Position + 1
|
|
End If
|
|
If Position > Len(Text) Or _
|
|
Not DxBridgeJsonIsDigit(Mid(Text, Position, 1)) Then
|
|
DxBridgeJsonSyntaxError
|
|
End If
|
|
Do While Position <= Len(Text)
|
|
Character = Mid(Text, Position, 1)
|
|
If Not DxBridgeJsonIsDigit(Character) Then Exit Do
|
|
Position = Position + 1
|
|
Loop
|
|
End If
|
|
|
|
NumberText = Mid(Text, StartPosition, Position - StartPosition)
|
|
If HasFractionOrExponent Then
|
|
DxBridgeJsonParseNumber = DxBridgeJsonInvariantDouble(NumberText)
|
|
Else
|
|
DxBridgeJsonParseNumber = DxBridgeJsonInt32(NumberText)
|
|
End If
|
|
End Function
|
|
|
|
Function DxBridgeJsonInt32(ByVal NumberText)
|
|
Dim Negative
|
|
Dim Index
|
|
Dim Digit
|
|
Dim Value
|
|
Negative = (Left(NumberText, 1) = "-")
|
|
If Negative Then
|
|
Index = 2
|
|
Else
|
|
Index = 1
|
|
End If
|
|
Value = 0.0
|
|
For Index = Index To Len(NumberText)
|
|
Digit = Asc(Mid(NumberText, Index, 1)) - Asc("0")
|
|
Value = Value * 10.0 + Digit
|
|
If Value > 2147483648.0 Then DxBridgeJsonSyntaxError
|
|
Next
|
|
If Negative Then
|
|
Value = -Value
|
|
ElseIf Value > 2147483647.0 Then
|
|
DxBridgeJsonSyntaxError
|
|
End If
|
|
DxBridgeJsonInt32 = CLng(Value)
|
|
End Function
|
|
|
|
Function DxBridgeJsonInvariantDouble(ByVal NumberText)
|
|
Dim Negative
|
|
Dim MantissaStart
|
|
Dim ExponentPosition
|
|
Dim MantissaEnd
|
|
Dim DecimalPosition
|
|
Dim FractionDigits
|
|
Dim ExponentNegative
|
|
Dim ExponentValue
|
|
Dim ExponentDominatesMantissa
|
|
Dim Index
|
|
Dim Character
|
|
Dim Digit
|
|
Dim SignificantStarted
|
|
Dim SignificantDigits
|
|
Dim ComparisonDigits
|
|
Dim RetainedDigits
|
|
Dim OmittedDigits
|
|
Dim Value
|
|
Dim Scale
|
|
Dim AdjustedExponent
|
|
|
|
Negative = (Left(NumberText, 1) = "-")
|
|
If Negative Then
|
|
MantissaStart = 2
|
|
Else
|
|
MantissaStart = 1
|
|
End If
|
|
ExponentPosition = InStr(1, NumberText, "e", vbTextCompare)
|
|
If ExponentPosition = 0 Then
|
|
MantissaEnd = Len(NumberText)
|
|
Else
|
|
MantissaEnd = ExponentPosition - 1
|
|
End If
|
|
DecimalPosition = InStr(1, Left(NumberText, MantissaEnd), ".", _
|
|
vbBinaryCompare)
|
|
If DecimalPosition = 0 Then
|
|
FractionDigits = 0
|
|
Else
|
|
FractionDigits = MantissaEnd - DecimalPosition
|
|
End If
|
|
|
|
ExponentValue = 0.0
|
|
ExponentDominatesMantissa = False
|
|
If ExponentPosition > 0 Then
|
|
Index = ExponentPosition + 1
|
|
Character = Mid(NumberText, Index, 1)
|
|
ExponentNegative = (Character = "-")
|
|
If Character = "+" Or Character = "-" Then Index = Index + 1
|
|
Do While Index < Len(NumberText) And _
|
|
Mid(NumberText, Index, 1) = "0"
|
|
Index = Index + 1
|
|
Loop
|
|
' Eleven exponent digits dominate every possible VBScript string length.
|
|
If Len(NumberText) - Index + 1 > 10 Then
|
|
ExponentDominatesMantissa = True
|
|
Else
|
|
Do While Index <= Len(NumberText)
|
|
Digit = Asc(Mid(NumberText, Index, 1)) - Asc("0")
|
|
ExponentValue = ExponentValue * 10 + Digit
|
|
Index = Index + 1
|
|
Loop
|
|
If ExponentNegative Then ExponentValue = -ExponentValue
|
|
End If
|
|
End If
|
|
|
|
Value = 0.0
|
|
SignificantStarted = False
|
|
SignificantDigits = 0
|
|
ComparisonDigits = ""
|
|
RetainedDigits = 0
|
|
OmittedDigits = 0
|
|
For Index = MantissaStart To MantissaEnd
|
|
Character = Mid(NumberText, Index, 1)
|
|
If Character <> "." Then
|
|
Digit = Asc(Character) - Asc("0")
|
|
If SignificantStarted Or Digit <> 0 Then
|
|
SignificantStarted = True
|
|
SignificantDigits = SignificantDigits + 1
|
|
If SignificantDigits <= 309 Then _
|
|
ComparisonDigits = ComparisonDigits & Character
|
|
If RetainedDigits < 16 Then
|
|
Value = Value * 10.0 + Digit
|
|
RetainedDigits = RetainedDigits + 1
|
|
Else
|
|
OmittedDigits = OmittedDigits + 1
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
If Not SignificantStarted Then
|
|
DxBridgeJsonInvariantDouble = 0.0
|
|
Exit Function
|
|
End If
|
|
If ExponentDominatesMantissa Then
|
|
If Not ExponentNegative Then DxBridgeJsonSyntaxError
|
|
Value = 0.0
|
|
If Negative Then Value = -Value
|
|
DxBridgeJsonInvariantDouble = Value
|
|
Exit Function
|
|
End If
|
|
|
|
AdjustedExponent = ExponentValue - FractionDigits + _
|
|
SignificantDigits - 1
|
|
If AdjustedExponent > 308 Then DxBridgeJsonSyntaxError
|
|
If AdjustedExponent = 308 Then
|
|
If DxBridgeJsonAtOrAboveDoubleOverflow(ComparisonDigits) Then _
|
|
DxBridgeJsonSyntaxError
|
|
End If
|
|
|
|
Scale = ExponentValue - FractionDigits + OmittedDigits
|
|
If Scale > 308 Then DxBridgeJsonSyntaxError
|
|
If Scale < -400 Then
|
|
Value = 0.0
|
|
Else
|
|
Do While Scale > 0
|
|
Value = Value * 10.0
|
|
Scale = Scale - 1
|
|
Loop
|
|
Do While Scale < 0
|
|
Value = Value / 10.0
|
|
Scale = Scale + 1
|
|
Loop
|
|
End If
|
|
If Negative Then Value = -Value
|
|
DxBridgeJsonInvariantDouble = Value
|
|
End Function
|
|
|
|
Function DxBridgeJsonAtOrAboveDoubleOverflow(ByVal SignificantDigits)
|
|
Dim OverflowBoundary
|
|
Dim Index
|
|
Dim InputDigit
|
|
Dim BoundaryDigit
|
|
' Exact binary64 overflow midpoint: 2^1024 - 2^970.
|
|
OverflowBoundary = _
|
|
"179769313486231580793728971405303415079934132710037826936173" & _
|
|
"778980444968292764750946649017977587207096330286416692887910" & _
|
|
"946555547851940402630657488671505820681908902000708383676273" & _
|
|
"854845817711531764475730270069855571366959622842914819860834" & _
|
|
"936475292719074168444365510704342711559699508093042880177904" & _
|
|
"174497792"
|
|
For Index = 1 To Len(OverflowBoundary)
|
|
If Index <= Len(SignificantDigits) Then
|
|
InputDigit = Asc(Mid(SignificantDigits, Index, 1)) - Asc("0")
|
|
Else
|
|
InputDigit = 0
|
|
End If
|
|
BoundaryDigit = Asc(Mid(OverflowBoundary, Index, 1)) - Asc("0")
|
|
If InputDigit < BoundaryDigit Then
|
|
DxBridgeJsonAtOrAboveDoubleOverflow = False
|
|
Exit Function
|
|
End If
|
|
If InputDigit > BoundaryDigit Then
|
|
DxBridgeJsonAtOrAboveDoubleOverflow = True
|
|
Exit Function
|
|
End If
|
|
Next
|
|
DxBridgeJsonAtOrAboveDoubleOverflow = True
|
|
End Function
|
|
|
|
Function DxBridgeJsonIsDigit(ByVal Character)
|
|
DxBridgeJsonIsDigit = Len(Character) = 1 And _
|
|
InStr(1, "0123456789", Character, vbBinaryCompare) > 0
|
|
End Function
|
|
|
|
Sub DxBridgeJsonSyntaxError()
|
|
Err.Raise vbObjectError + 835, "DxBridgeParseJson", "Invalid JSON syntax"
|
|
End Sub
|
|
|
|
Function DxBridgeIsHex(ByVal Text)
|
|
Dim Index
|
|
Dim Character
|
|
DxBridgeIsHex = False
|
|
For Index = 1 To Len(Text)
|
|
Character = LCase(Mid(Text, Index, 1))
|
|
If InStr("0123456789abcdef", Character) = 0 Then Exit Function
|
|
Next
|
|
DxBridgeIsHex = Len(Text) > 0
|
|
End Function
|
|
|
|
Function DxBridgeSanitizeCommandForFailure(ByRef Command, _
|
|
ByVal RequestedAction)
|
|
Dim Result
|
|
Dim Name
|
|
Set Result = CreateObject("Scripting.Dictionary")
|
|
Result.Add "action", ""
|
|
Result.Add "command_id", ""
|
|
Result.Add "expected_count", 0
|
|
Result.Add "job_id", ""
|
|
Result.Add "project_id", ""
|
|
If VarType(RequestedAction) = vbString Then
|
|
Result("action") = RequestedAction
|
|
End If
|
|
If Command.Exists("action") Then
|
|
If VarType(Command("action")) = vbString Then
|
|
Result("action") = Command("action")
|
|
End If
|
|
End If
|
|
For Each Name In Array("command_id", "job_id", "project_id")
|
|
If Command.Exists(CStr(Name)) Then
|
|
If VarType(Command(CStr(Name))) = vbString Then
|
|
Result(CStr(Name)) = Command(CStr(Name))
|
|
End If
|
|
End If
|
|
Next
|
|
If Command.Exists("expected_count") Then
|
|
If DxBridgeIsProtocolInteger(Command("expected_count")) Then
|
|
Result("expected_count") = Command("expected_count")
|
|
End If
|
|
End If
|
|
Set DxBridgeSanitizeCommandForFailure = Result
|
|
End Function
|
|
|
|
Function DxBridgeValidateCommand(ByRef Command, ByVal RequestedAction, _
|
|
ByRef Failure)
|
|
Dim Required
|
|
Dim Name
|
|
Dim ExpectedKeys
|
|
Dim Item
|
|
Dim ItemIndex
|
|
Dim Seen
|
|
Dim AllowedAction
|
|
Required = Array("action", "command_id", "expected_count", _
|
|
"expected_fingerprint", "expected_logical_keys", "format_version", _
|
|
"job_id", "new_part_number", "old_part_number", "project_id", "scope")
|
|
If Command.Count <> 11 Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Bridge command fields do not match format version 1", _
|
|
"command.schema", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
For Each Name In Required
|
|
If Not Command.Exists(CStr(Name)) Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Bridge command is missing a required field", _
|
|
"command.schema", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
Next
|
|
If VarType(Command("format_version")) <> vbInteger And _
|
|
VarType(Command("format_version")) <> vbLong Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Command format_version must be integer 1", _
|
|
"command.format_version", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
If CLng(Command("format_version")) <> 1 Then
|
|
DxBridgeSetFailure Failure, "unsupported_format_version", _
|
|
"Unsupported command format version", _
|
|
"command.format_version", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
For Each Name In Array("action", "command_id", _
|
|
"expected_fingerprint", "job_id", "new_part_number", _
|
|
"old_part_number", "project_id", "scope")
|
|
If VarType(Command(CStr(Name))) <> vbString Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Bridge command string field has the wrong type", _
|
|
"command." & CStr(Name), 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
Next
|
|
If Len(Command("command_id")) = 0 Or Len(Command("job_id")) = 0 Or _
|
|
Len(Command("project_id")) = 0 Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Command identity fields must be non-empty", _
|
|
"command.identity", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
If Command("scope") <> "full_project" Then
|
|
DxBridgeSetFailure Failure, "invalid_scope", _
|
|
"Live bridge commands require full_project scope", _
|
|
"command.scope", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
If VarType(Command("expected_count")) <> vbInteger And _
|
|
VarType(Command("expected_count")) <> vbLong Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"expected_count must be an integer", _
|
|
"command.expected_count", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
If Not IsObject(Command("expected_logical_keys")) Or _
|
|
TypeName(Command("expected_logical_keys")) <> _
|
|
"DxBridgeJsonArray" Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"expected_logical_keys must be an array", _
|
|
"command.expected_logical_keys", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
Set ExpectedKeys = Command("expected_logical_keys")
|
|
Set Seen = CreateObject("Scripting.Dictionary")
|
|
For ItemIndex = 0 To ExpectedKeys.Count - 1
|
|
If IsObject(ExpectedKeys(ItemIndex)) Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Expected logical keys must be non-empty and unique strings", _
|
|
"command.expected_logical_keys", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
Item = ExpectedKeys(ItemIndex)
|
|
If VarType(Item) <> vbString Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Expected logical keys must be non-empty and unique strings", _
|
|
"command.expected_logical_keys", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
If Len(Item) = 0 Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Expected logical keys must be non-empty and unique strings", _
|
|
"command.expected_logical_keys", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
If Seen.Exists(Item) Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Expected logical keys must be non-empty and unique strings", _
|
|
"command.expected_logical_keys", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
Seen.Add Item, True
|
|
Next
|
|
If CLng(Command("expected_count")) <> ExpectedKeys.Count Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"expected_count does not match expected_logical_keys", _
|
|
"command.expected_count", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
|
|
AllowedAction = CStr(RequestedAction)
|
|
If AllowedAction = "continue_after_manual_selection" Or _
|
|
AllowedAction = "continue_after_manual_dialog" Then
|
|
AllowedAction = "replace_part"
|
|
End If
|
|
If CStr(Command("action")) <> AllowedAction Then
|
|
DxBridgeSetFailure Failure, "command_action_mismatch", _
|
|
"Requested action does not match the bridge command", _
|
|
"command.action", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
If RequestedAction = "inventory" Then
|
|
If ExpectedKeys.Count <> 0 Or Command("expected_fingerprint") <> "" Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Inventory command must not contain Apply expectations", _
|
|
"command.inventory", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
ElseIf RequestedAction = "replace_part" Or _
|
|
RequestedAction = "continue_after_manual_selection" Or _
|
|
RequestedAction = "continue_after_manual_dialog" Then
|
|
If ExpectedKeys.Count = 0 Or _
|
|
Len(Trim(CStr(Command("old_part_number")))) = 0 Or _
|
|
Len(Trim(CStr(Command("new_part_number")))) = 0 Or _
|
|
Len(CStr(Command("expected_fingerprint"))) <> 64 Or _
|
|
Not DxBridgeIsHex(CStr(Command("expected_fingerprint"))) Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Replace command expectations are incomplete", _
|
|
"command.replace_part", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
ElseIf RequestedAction = "undo" Or RequestedAction = "save" Then
|
|
If Len(CStr(Command("expected_fingerprint"))) <> 64 Or _
|
|
Not DxBridgeIsHex(CStr(Command("expected_fingerprint"))) Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Control command requires a complete expected fingerprint", _
|
|
"command.expected_fingerprint", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
ElseIf RequestedAction = "close_project" Or _
|
|
RequestedAction = "close_without_save" Then
|
|
If ExpectedKeys.Count <> 0 Or _
|
|
CLng(Command("expected_count")) <> 0 Or _
|
|
Len(Trim(CStr(Command("old_part_number")))) <> 0 Or _
|
|
Len(Trim(CStr(Command("new_part_number")))) <> 0 Or _
|
|
Len(CStr(Command("expected_fingerprint"))) <> 64 Or _
|
|
Not DxBridgeIsHex(CStr(Command("expected_fingerprint"))) Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Project-close command expectations are invalid", _
|
|
"command.close_project", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
ElseIf RequestedAction = "open_project" Then
|
|
If ExpectedKeys.Count <> 0 Or _
|
|
CLng(Command("expected_count")) <> 0 Or _
|
|
Len(Trim(CStr(Command("old_part_number")))) <> 0 Or _
|
|
Len(Trim(CStr(Command("new_part_number")))) <> 0 Or _
|
|
Len(CStr(Command("expected_fingerprint"))) <> 64 Or _
|
|
Not DxBridgeIsHex(CStr(Command("expected_fingerprint"))) Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"Project-open command expectations are invalid", _
|
|
"command.open_project", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
ElseIf RequestedAction = "packager" Or _
|
|
RequestedAction = "erc" Or _
|
|
RequestedAction = "netlist" Then
|
|
If ExpectedKeys.Count <> 0 Or _
|
|
CLng(Command("expected_count")) <> 0 Or _
|
|
Len(Trim(CStr(Command("old_part_number")))) <> 0 Or _
|
|
Len(Trim(CStr(Command("new_part_number")))) <> 0 Or _
|
|
Len(CStr(Command("expected_fingerprint"))) <> 64 Or _
|
|
Not DxBridgeIsHex(CStr(Command("expected_fingerprint"))) Then
|
|
DxBridgeSetFailure Failure, "invalid_command", _
|
|
"External-check command expectations are invalid", _
|
|
"command.external_check", 0, "", ""
|
|
DxBridgeValidateCommand = False
|
|
Exit Function
|
|
End If
|
|
End If
|
|
DxBridgeValidateCommand = True
|
|
End Function
|
|
|
|
Function DxBridgeValidateManualContinuation(ByRef Command, _
|
|
ByRef PriorStatus, ByVal ExpectedManualRoute, ByRef Failure)
|
|
Dim Required
|
|
Dim Name
|
|
Dim DetailsArray
|
|
Dim Entry
|
|
Dim Details
|
|
Dim Index
|
|
Dim ExpectedState
|
|
DxBridgeValidateManualContinuation = False
|
|
Required = Array("command_id", "details", "error_code", _
|
|
"error_message", "format_version", "project_id", _
|
|
"snapshot_path", "state")
|
|
If PriorStatus.Count <> 8 Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
For Each Name In Required
|
|
If Not PriorStatus.Exists(CStr(Name)) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
Next
|
|
If Not DxBridgeIsProtocolInteger(PriorStatus("format_version")) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
If CLng(PriorStatus("format_version")) <> 1 Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
If VarType(PriorStatus("command_id")) <> vbString Or _
|
|
VarType(PriorStatus("project_id")) <> vbString Or _
|
|
VarType(PriorStatus("state")) <> vbString Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
ExpectedState = "manual_action_required"
|
|
If CStr(ExpectedManualRoute) = "manual_project_open" Then
|
|
ExpectedState = "manual_project_open_required"
|
|
End If
|
|
If StrComp(CStr(PriorStatus("command_id")), _
|
|
CStr(Command("command_id")), vbBinaryCompare) <> 0 Or _
|
|
StrComp(CStr(PriorStatus("project_id")), _
|
|
CStr(Command("project_id")), vbBinaryCompare) <> 0 Or _
|
|
CStr(PriorStatus("state")) <> ExpectedState Or _
|
|
Not IsNull(PriorStatus("error_code")) Or _
|
|
Not IsNull(PriorStatus("error_message")) Or _
|
|
Not IsNull(PriorStatus("snapshot_path")) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
If Not IsObject(PriorStatus("details")) Or _
|
|
TypeName(PriorStatus("details")) <> _
|
|
"DxBridgeJsonArray" Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
Set DetailsArray = PriorStatus("details")
|
|
Set Details = CreateObject("Scripting.Dictionary")
|
|
For Index = 0 To DetailsArray.Count - 1
|
|
If Not IsObject(DetailsArray(Index)) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
Set Entry = DetailsArray(Index)
|
|
If TypeName(Entry) <> "DxBridgeJsonArray" Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
If Entry.Count <> 2 Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
If VarType(Entry(0)) <> vbString Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
If VarType(Entry(1)) <> vbString Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
If Details.Exists(CStr(Entry(0))) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
Details.Add CStr(Entry(0)), CStr(Entry(1))
|
|
Next
|
|
For Each Name In Array("action", "expected_count", "job_id", _
|
|
"manual_route")
|
|
If Not Details.Exists(CStr(Name)) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
Next
|
|
If CStr(Details("action")) <> CStr(Command("action")) Or _
|
|
CStr(Details("expected_count")) <> _
|
|
DxInvariantNumber(Command("expected_count")) Or _
|
|
CStr(Details("job_id")) <> CStr(Command("job_id")) Or _
|
|
CStr(Details("manual_route")) <> CStr(ExpectedManualRoute) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
If CStr(Command("action")) = "replace_part" Then
|
|
If Not Details.Exists("new_part_number") Or _
|
|
Not Details.Exists("old_part_number") Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
If CStr(Details("new_part_number")) <> _
|
|
CStr(Command("new_part_number")) Or _
|
|
CStr(Details("old_part_number")) <> _
|
|
CStr(Command("old_part_number")) Then
|
|
DxBridgeSetManualContinuationFailure Failure
|
|
Exit Function
|
|
End If
|
|
End If
|
|
DxBridgeValidateManualContinuation = True
|
|
End Function
|
|
|
|
Sub DxBridgeSetManualContinuationFailure(ByRef Failure)
|
|
DxBridgeSetFailure Failure, "manual_continuation_mismatch", _
|
|
"Manual continuation does not match the prior bridge status", _
|
|
"status.manual_continuation", 0, "", ""
|
|
End Sub
|
|
|
|
Function DxBridgeValidateControlStatus(ByRef Command, ByRef PriorStatus, _
|
|
ByRef Failure)
|
|
Dim Required
|
|
Dim Name
|
|
Dim DetailsArray
|
|
Dim Entry
|
|
Dim Details
|
|
Dim Index
|
|
DxBridgeValidateControlStatus = False
|
|
Required = Array("command_id", "details", "error_code", _
|
|
"error_message", "format_version", "project_id", _
|
|
"snapshot_path", "state")
|
|
If PriorStatus.Count <> 8 Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
For Each Name In Required
|
|
If Not PriorStatus.Exists(CStr(Name)) Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
Next
|
|
If Not DxBridgeIsProtocolInteger(PriorStatus("format_version")) Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
If CLng(PriorStatus("format_version")) <> 1 Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
If VarType(PriorStatus("command_id")) <> vbString Or _
|
|
VarType(PriorStatus("project_id")) <> vbString Or _
|
|
VarType(PriorStatus("state")) <> vbString Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
If VarType(PriorStatus("snapshot_path")) <> vbString Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
If Len(PriorStatus("snapshot_path")) = 0 Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
If CStr(PriorStatus("command_id")) <> CStr(Command("command_id")) Or _
|
|
CStr(PriorStatus("project_id")) <> _
|
|
CStr(Command("project_id")) Or _
|
|
CStr(PriorStatus("state")) <> "applied" Or _
|
|
Not IsNull(PriorStatus("error_code")) Or _
|
|
Not IsNull(PriorStatus("error_message")) Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
If Not IsObject(PriorStatus("details")) Or _
|
|
TypeName(PriorStatus("details")) <> _
|
|
"DxBridgeJsonArray" Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
Set DetailsArray = PriorStatus("details")
|
|
Set Details = CreateObject("Scripting.Dictionary")
|
|
For Index = 0 To DetailsArray.Count - 1
|
|
If Not IsObject(DetailsArray(Index)) Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
Set Entry = DetailsArray(Index)
|
|
If TypeName(Entry) <> "DxBridgeJsonArray" Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
If Entry.Count <> 2 Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
If VarType(Entry(0)) <> vbString Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
If VarType(Entry(1)) <> vbString Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
If Details.Exists(Entry(0)) Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
Details.Add Entry(0), Entry(1)
|
|
Next
|
|
For Each Name In Array("action", "expected_count", "job_id")
|
|
If Not Details.Exists(CStr(Name)) Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
Next
|
|
If CStr(Details("action")) <> "replace_part" Or _
|
|
CStr(Details("expected_count")) <> _
|
|
DxInvariantNumber(Command("expected_count")) Or _
|
|
CStr(Details("job_id")) <> CStr(Command("job_id")) Then
|
|
DxBridgeSetControlStatusFailure Failure
|
|
Exit Function
|
|
End If
|
|
DxBridgeValidateControlStatus = True
|
|
End Function
|
|
|
|
Sub DxBridgeSetControlStatusFailure(ByRef Failure)
|
|
DxBridgeSetFailure Failure, "control_status_mismatch", _
|
|
"Control command does not match the prior applied bridge status", _
|
|
"status.control", 0, "", ""
|
|
End Sub
|
|
|
|
Function DxBridgeCanonicalProjectPath(ByVal Value, ByRef Result, _
|
|
ByRef Failure)
|
|
Dim Fso
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Set Fso = CreateObject("Scripting.FileSystemObject")
|
|
If Len(Trim(CStr(Value))) = 0 Then
|
|
DxBridgeSetFailure Failure, "invalid_project_path", _
|
|
"Next project path is empty", "project.open_path", _
|
|
0, "", ""
|
|
DxBridgeCanonicalProjectPath = False
|
|
Exit Function
|
|
End If
|
|
On Error Resume Next
|
|
Result = Fso.GetAbsolutePathName(CStr(Value))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetFailure Failure, "invalid_project_path", _
|
|
"Cannot canonicalize next project path", "project.open_path", _
|
|
ErrorNumber, ErrorSource, ErrorDescription
|
|
DxBridgeCanonicalProjectPath = False
|
|
Exit Function
|
|
End If
|
|
If Not Fso.FileExists(Result) Then
|
|
DxBridgeSetFailure Failure, "invalid_project_path", _
|
|
"Next project path does not exist", "project.open_path", _
|
|
0, "", ""
|
|
DxBridgeCanonicalProjectPath = False
|
|
Exit Function
|
|
End If
|
|
DxBridgeCanonicalProjectPath = True
|
|
End Function
|
|
|
|
Function DxBridgeVerifyPathProjectId(ByVal ProjectPath, _
|
|
ByVal ExpectedProjectId, ByRef Failure)
|
|
Dim ActualProjectId
|
|
If Not DxBridgeProjectId(ProjectPath, ActualProjectId, Failure) Then
|
|
DxBridgeVerifyPathProjectId = False
|
|
Exit Function
|
|
End If
|
|
If StrComp(ActualProjectId, CStr(ExpectedProjectId), _
|
|
vbBinaryCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, "project_identity_mismatch", _
|
|
"Canonical project path does not match the command project ID", _
|
|
"project.open_path", 0, "", ""
|
|
DxBridgeVerifyPathProjectId = False
|
|
Else
|
|
DxBridgeVerifyPathProjectId = True
|
|
End If
|
|
End Function
|
|
|
|
Function DxBridgePathsEqual(ByVal LeftPath, ByVal RightPath)
|
|
Dim Fso
|
|
Set Fso = CreateObject("Scripting.FileSystemObject")
|
|
DxBridgePathsEqual = StrComp( _
|
|
Fso.GetAbsolutePathName(CStr(LeftPath)), _
|
|
Fso.GetAbsolutePathName(CStr(RightPath)), vbTextCompare) = 0
|
|
End Function
|
|
|
|
Function DxBridgeRouteVerified(ByRef Profile, ByVal Name, ByVal ExactRoute)
|
|
Dim Routes
|
|
Dim Record
|
|
Dim Attempts
|
|
Dim Attempt
|
|
DxBridgeRouteVerified = False
|
|
If Not DxBridgeProfileLiveAccepted(Profile) Then Exit Function
|
|
If Not DxBridgeIsDictionary(Profile("routes")) Then Exit Function
|
|
Set Routes = Profile("routes")
|
|
If Not Routes.Exists(CStr(Name)) Then Exit Function
|
|
If Not DxBridgeIsDictionary(Routes(CStr(Name))) Then Exit Function
|
|
Set Record = Routes(CStr(Name))
|
|
If Not Record.Exists("attempted") Or _
|
|
Not Record.Exists("available") Or _
|
|
Not Record.Exists("route") Or _
|
|
Not Record.Exists("attempts") Then Exit Function
|
|
If VarType(Record("attempted")) <> vbBoolean Or _
|
|
VarType(Record("available")) <> vbBoolean Then Exit Function
|
|
If Not CBool(Record("attempted")) Or _
|
|
Not CBool(Record("available")) Then Exit Function
|
|
If VarType(Record("route")) <> vbString Then Exit Function
|
|
If StrComp(CStr(Record("route")), CStr(ExactRoute), _
|
|
vbBinaryCompare) <> 0 Then Exit Function
|
|
If Not IsObject(Record("attempts")) Or _
|
|
TypeName(Record("attempts")) <> "DxBridgeJsonArray" Then _
|
|
Exit Function
|
|
Set Attempts = Record("attempts")
|
|
If Attempts.Count <> 1 Then Exit Function
|
|
If Not DxBridgeIsDictionary(Attempts(0)) Then Exit Function
|
|
Set Attempt = Attempts(0)
|
|
If Not Attempt.Exists("attempted") Or _
|
|
Not Attempt.Exists("available") Or _
|
|
Not Attempt.Exists("route") Or _
|
|
Not Attempt.Exists("error") Then Exit Function
|
|
If VarType(Attempt("attempted")) <> vbBoolean Or _
|
|
VarType(Attempt("available")) <> vbBoolean Then Exit Function
|
|
If Not CBool(Attempt("attempted")) Or _
|
|
Not CBool(Attempt("available")) Then Exit Function
|
|
If VarType(Attempt("route")) <> vbString Then Exit Function
|
|
If StrComp(CStr(Attempt("route")), CStr(ExactRoute), _
|
|
vbBinaryCompare) <> 0 Then Exit Function
|
|
If Not IsNull(Attempt("error")) Then Exit Function
|
|
DxBridgeRouteVerified = True
|
|
End Function
|
|
|
|
Function DxBridgeVerifyExpectedLiveState(ByRef Command, ByRef LiveMap, _
|
|
ByRef Failure)
|
|
Dim ExpectedKeys
|
|
Dim ExpectedSet
|
|
Dim ItemIndex
|
|
Dim LogicalKey
|
|
Dim Key
|
|
Dim Objects
|
|
Dim ObjectIndex
|
|
Dim ObjectItem
|
|
Dim RefDes
|
|
Dim UnitId
|
|
Dim PartNumber
|
|
Dim MatchCount
|
|
Set ExpectedKeys = Command("expected_logical_keys")
|
|
Set ExpectedSet = CreateObject("Scripting.Dictionary")
|
|
For ItemIndex = 0 To ExpectedKeys.Count - 1
|
|
LogicalKey = CStr(ExpectedKeys(ItemIndex))
|
|
ExpectedSet.Add LogicalKey, True
|
|
If Not LiveMap.Exists(LogicalKey) Then
|
|
DxBridgeSetFailure Failure, "expected_logical_key_missing", _
|
|
"Expected logical component is absent from the live project", _
|
|
"selection.logical_key", 0, "", ""
|
|
DxBridgeVerifyExpectedLiveState = False
|
|
Exit Function
|
|
End If
|
|
Set Objects = LiveMap(LogicalKey)
|
|
RefDes = ""
|
|
For ObjectIndex = 0 To Objects.Count - 1
|
|
Set ObjectItem = Objects(ObjectIndex)
|
|
If Not DxBridgeRereadObject(ObjectItem, LogicalKey, _
|
|
CStr(Command("old_part_number")), RefDes, UnitId, _
|
|
Failure) Then
|
|
DxBridgeVerifyExpectedLiveState = False
|
|
Exit Function
|
|
End If
|
|
Next
|
|
Next
|
|
|
|
MatchCount = 0
|
|
For Each Key In LiveMap.Keys
|
|
Set Objects = LiveMap(CStr(Key))
|
|
Set ObjectItem = Objects(0)
|
|
If Not DxBridgeReadRequiredString(ObjectItem, "PartNumber", _
|
|
"component.PartNumber.reread", PartNumber, Failure) Then
|
|
DxBridgeVerifyExpectedLiveState = False
|
|
Exit Function
|
|
End If
|
|
If StrComp(Trim(PartNumber), _
|
|
Trim(CStr(Command("old_part_number"))), _
|
|
vbTextCompare) = 0 Then
|
|
MatchCount = MatchCount + 1
|
|
If Not ExpectedSet.Exists(CStr(Key)) Then
|
|
DxBridgeSetFailure Failure, "unexpected_eligible_component", _
|
|
"Full-project command omits a matching logical component", _
|
|
"selection.full_project", 0, "", ""
|
|
DxBridgeVerifyExpectedLiveState = False
|
|
Exit Function
|
|
End If
|
|
End If
|
|
Next
|
|
If MatchCount <> CLng(Command("expected_count")) Then
|
|
DxBridgeSetFailure Failure, "expected_count_mismatch", _
|
|
"Live matching logical-component count does not match the command", _
|
|
"selection.expected_count", 0, "", ""
|
|
DxBridgeVerifyExpectedLiveState = False
|
|
Exit Function
|
|
End If
|
|
DxBridgeVerifyExpectedLiveState = True
|
|
End Function
|
|
|
|
Function DxBridgeRereadObject(ByRef ObjectItem, ByVal ExpectedKey, _
|
|
ByVal ExpectedPartNumber, ByRef ExpectedRefDes, ByRef UnitId, _
|
|
ByRef Failure)
|
|
Dim LogicalKey
|
|
Dim PartNumber
|
|
Dim RefDes
|
|
Dim Hierarchy
|
|
Dim UnitCountValue
|
|
Dim SymbolName
|
|
Dim OriginX
|
|
Dim OriginY
|
|
Dim PositionX
|
|
Dim PositionY
|
|
Dim Rotation
|
|
Dim Mirrored
|
|
Dim AttributesJson
|
|
Dim UnitJson
|
|
If Not DxBridgeReadRequiredString(ObjectItem, "LogicalIdentity", _
|
|
"component.LogicalIdentity.reread", LogicalKey, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If StrComp(LogicalKey, CStr(ExpectedKey), vbBinaryCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, "logical_identity_changed", _
|
|
"Live object logical identity changed before selection", _
|
|
"component.LogicalIdentity.reread", 0, "", ""
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredString(ObjectItem, "PartNumber", _
|
|
"component.PartNumber.reread", PartNumber, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If StrComp(Trim(PartNumber), Trim(CStr(ExpectedPartNumber)), _
|
|
vbTextCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, "source_part_number_mismatch", _
|
|
"Expected live object no longer has the source Part Number", _
|
|
"component.PartNumber.reread", 0, "", ""
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredString(ObjectItem, "RefDes", _
|
|
"component.RefDes.reread", RefDes, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Len(ExpectedRefDes) = 0 Then
|
|
ExpectedRefDes = RefDes
|
|
ElseIf StrComp(ExpectedRefDes, RefDes, vbBinaryCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, "ambiguous_logical_identity", _
|
|
"Units sharing a logical key disagree on RefDes", _
|
|
"component.RefDes.reread", 0, "", ""
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredString(ObjectItem, "Hierarchy", _
|
|
"component.Hierarchy.reread", Hierarchy, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadScalar(ObjectItem, "Units", _
|
|
"component.Units.reread", UnitCountValue, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsProtocolInteger(UnitCountValue) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Component unit count is invalid on reread", _
|
|
"component.Units.reread", 0, "", ""
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If CLng(UnitCountValue) < 1 Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Component unit count is invalid on reread", _
|
|
"component.Units.reread", 0, "", ""
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredString(ObjectItem, "SymbolName", _
|
|
"component.SymbolName.reread", SymbolName, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredNumber(ObjectItem, "OriginX", _
|
|
"component.OriginX.reread", OriginX, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredNumber(ObjectItem, "OriginY", _
|
|
"component.OriginY.reread", OriginY, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredNumber(ObjectItem, "X", _
|
|
"component.X.reread", PositionX, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredNumber(ObjectItem, "Y", _
|
|
"component.Y.reread", PositionY, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadScalar(ObjectItem, "Rotation", _
|
|
"component.Rotation.reread", Rotation, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsProtocolInteger(Rotation) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Component rotation is invalid on reread", _
|
|
"component.Rotation.reread", 0, "", ""
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadScalar(ObjectItem, "Mirrored", _
|
|
"component.Mirrored.reread", Mirrored, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If VarType(Mirrored) <> vbBoolean Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Component mirror state is invalid on reread", _
|
|
"component.Mirrored.reread", 0, "", ""
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeSerializeAttributes(ObjectItem, AttributesJson, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeUnitIdentity(ObjectItem, UnitId, Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeSerializeUnit(ObjectItem, UnitId, Hierarchy, SymbolName, _
|
|
OriginX, OriginY, PositionX, PositionY, Rotation, Mirrored, UnitJson, _
|
|
Failure) Then
|
|
DxBridgeRereadObject = False
|
|
Exit Function
|
|
End If
|
|
DxBridgeRereadObject = True
|
|
End Function
|
|
|
|
Function DxBridgeSelectLogicalKeys(ByRef Command, ByRef LiveMap, _
|
|
ByRef Failure)
|
|
Dim ExpectedKeys
|
|
Dim ExpectedTokens
|
|
Dim SeenTokens
|
|
Dim LogicalKey
|
|
Dim Objects
|
|
Dim ObjectItem
|
|
Dim TotalObjects
|
|
Dim SelectionObjects
|
|
Dim SelectionIndex
|
|
Dim KeyIndex
|
|
Dim ObjectIndex
|
|
Dim RefDes
|
|
Dim UnitId
|
|
Dim Token
|
|
Dim Ignored
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim SelectedItems
|
|
Dim SelectedCount
|
|
Set ExpectedKeys = Command("expected_logical_keys")
|
|
Set ExpectedTokens = CreateObject("Scripting.Dictionary")
|
|
TotalObjects = 0
|
|
For KeyIndex = 0 To ExpectedKeys.Count - 1
|
|
LogicalKey = CStr(ExpectedKeys(KeyIndex))
|
|
Set Objects = LiveMap(LogicalKey)
|
|
TotalObjects = TotalObjects + Objects.Count
|
|
Next
|
|
ReDim SelectionObjects(TotalObjects - 1)
|
|
SelectionIndex = 0
|
|
For KeyIndex = 0 To ExpectedKeys.Count - 1
|
|
LogicalKey = CStr(ExpectedKeys(KeyIndex))
|
|
Set Objects = LiveMap(LogicalKey)
|
|
RefDes = ""
|
|
For ObjectIndex = 0 To Objects.Count - 1
|
|
Set ObjectItem = Objects(ObjectIndex)
|
|
If Not DxBridgeRereadObject(ObjectItem, LogicalKey, _
|
|
CStr(Command("old_part_number")), RefDes, UnitId, _
|
|
Failure) Then
|
|
DxBridgeSelectLogicalKeys = False
|
|
Exit Function
|
|
End If
|
|
Token = LogicalKey & Chr(31) & UnitId
|
|
If ExpectedTokens.Exists(Token) Then
|
|
DxBridgeSetFailure Failure, "duplicate_unit_identity", _
|
|
"Selection contains duplicate logical-unit identity", _
|
|
"selection.expected", 0, "", ""
|
|
DxBridgeSelectLogicalKeys = False
|
|
Exit Function
|
|
End If
|
|
ExpectedTokens.Add Token, True
|
|
Set SelectionObjects(SelectionIndex) = ObjectItem
|
|
SelectionIndex = SelectionIndex + 1
|
|
Next
|
|
Next
|
|
On Error Resume Next
|
|
Ignored = ActiveView.SelectExactSet(SelectionObjects)
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetApiFailure Failure, "ActiveView.SelectExactSet", _
|
|
ErrorNumber, ErrorSource, ErrorDescription
|
|
DxBridgeSelectLogicalKeys = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadCollection(ActiveView, "SelectedObjects", _
|
|
"ActiveView.SelectedObjects", SelectedItems, SelectedCount, _
|
|
Failure) Then
|
|
DxBridgeSelectLogicalKeys = False
|
|
Exit Function
|
|
End If
|
|
If SelectedCount <> TotalObjects Then
|
|
DxBridgeSetFailure Failure, "selection_mismatch", _
|
|
"Exact selection route returned an unexpected object count", _
|
|
"ActiveView.SelectedObjects", 0, "", ""
|
|
DxBridgeSelectLogicalKeys = False
|
|
Exit Function
|
|
End If
|
|
Set SeenTokens = CreateObject("Scripting.Dictionary")
|
|
For SelectionIndex = 0 To SelectedCount - 1
|
|
If Not IsObject(SelectedItems(SelectionIndex)) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Selected-object collection contains a non-object value", _
|
|
"ActiveView.SelectedObjects", 0, "", ""
|
|
DxBridgeSelectLogicalKeys = False
|
|
Exit Function
|
|
End If
|
|
Set ObjectItem = SelectedItems(SelectionIndex)
|
|
If Not DxBridgeReadRequiredString(ObjectItem, "LogicalIdentity", _
|
|
"selected.LogicalIdentity", LogicalKey, Failure) Then
|
|
DxBridgeSelectLogicalKeys = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeUnitIdentity(ObjectItem, UnitId, Failure) Then
|
|
DxBridgeSelectLogicalKeys = False
|
|
Exit Function
|
|
End If
|
|
Token = LogicalKey & Chr(31) & UnitId
|
|
If Not ExpectedTokens.Exists(Token) Or SeenTokens.Exists(Token) Then
|
|
DxBridgeSetFailure Failure, "selection_mismatch", _
|
|
"Exact selection route returned an extra or duplicate object", _
|
|
"ActiveView.SelectedObjects", 0, "", ""
|
|
DxBridgeSelectLogicalKeys = False
|
|
Exit Function
|
|
End If
|
|
SeenTokens.Add Token, True
|
|
Next
|
|
DxBridgeSelectLogicalKeys = True
|
|
End Function
|
|
|
|
Function DxBridgeVerifySelectedLogicalKeys(ByRef Command, ByRef LiveMap, _
|
|
ByRef Failure)
|
|
Dim ExpectedKeys
|
|
Dim ExpectedTokens
|
|
Dim SeenTokens
|
|
Dim SelectedRefDes
|
|
Dim Objects
|
|
Dim ObjectItem
|
|
Dim SelectedItems
|
|
Dim SelectedCount
|
|
Dim KeyIndex
|
|
Dim ObjectIndex
|
|
Dim LogicalKey
|
|
Dim UnitId
|
|
Dim RefDes
|
|
Dim Token
|
|
Dim TotalObjects
|
|
DxBridgeVerifySelectedLogicalKeys = False
|
|
Set ExpectedKeys = Command("expected_logical_keys")
|
|
Set ExpectedTokens = CreateObject("Scripting.Dictionary")
|
|
TotalObjects = 0
|
|
For KeyIndex = 0 To ExpectedKeys.Count - 1
|
|
LogicalKey = CStr(ExpectedKeys(KeyIndex))
|
|
Set Objects = LiveMap(LogicalKey)
|
|
For ObjectIndex = 0 To Objects.Count - 1
|
|
If Not IsObject(Objects(ObjectIndex)) Then
|
|
DxBridgeSetFailure Failure, "selection_mismatch", _
|
|
"Expected live selection object is invalid", _
|
|
"selection.expected", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
Set ObjectItem = Objects(ObjectIndex)
|
|
If Not DxBridgeUnitIdentity(ObjectItem, UnitId, Failure) Then _
|
|
Exit Function
|
|
Token = LogicalKey & Chr(31) & UnitId
|
|
If ExpectedTokens.Exists(Token) Then
|
|
DxBridgeSetFailure Failure, "duplicate_unit_identity", _
|
|
"Expected selection contains duplicate unit identity", _
|
|
"selection.expected", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
ExpectedTokens.Add Token, True
|
|
TotalObjects = TotalObjects + 1
|
|
Next
|
|
Next
|
|
|
|
If Not DxBridgeReadCollection(ActiveView, "SelectedObjects", _
|
|
"ActiveView.SelectedObjects", SelectedItems, SelectedCount, _
|
|
Failure) Then Exit Function
|
|
If SelectedCount <> TotalObjects Then
|
|
DxBridgeSetFailure Failure, "selection_mismatch", _
|
|
"Manual selection has an unexpected object count", _
|
|
"ActiveView.SelectedObjects", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
Set SeenTokens = CreateObject("Scripting.Dictionary")
|
|
Set SelectedRefDes = CreateObject("Scripting.Dictionary")
|
|
For ObjectIndex = 0 To SelectedCount - 1
|
|
If Not IsObject(SelectedItems(ObjectIndex)) Then
|
|
DxBridgeSetFailure Failure, "selection_mismatch", _
|
|
"Manual selection contains a non-object value", _
|
|
"ActiveView.SelectedObjects", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
Set ObjectItem = SelectedItems(ObjectIndex)
|
|
If Not DxBridgeReadRequiredString(ObjectItem, "LogicalIdentity", _
|
|
"selected.LogicalIdentity", LogicalKey, Failure) Then _
|
|
Exit Function
|
|
If Not LiveMap.Exists(LogicalKey) Then
|
|
DxBridgeSetFailure Failure, "selection_mismatch", _
|
|
"Manual selection contains an unrelated logical component", _
|
|
"ActiveView.SelectedObjects", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
RefDes = ""
|
|
If SelectedRefDes.Exists(LogicalKey) Then _
|
|
RefDes = SelectedRefDes(LogicalKey)
|
|
If Not DxBridgeRereadObject(ObjectItem, LogicalKey, _
|
|
Command("old_part_number"), RefDes, UnitId, Failure) Then _
|
|
Exit Function
|
|
SelectedRefDes(LogicalKey) = RefDes
|
|
Token = LogicalKey & Chr(31) & UnitId
|
|
If Not ExpectedTokens.Exists(Token) Then
|
|
DxBridgeSetFailure Failure, "selection_mismatch", _
|
|
"Manual selection contains an unexpected unit", _
|
|
"ActiveView.SelectedObjects", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
If SeenTokens.Exists(Token) Then
|
|
DxBridgeSetFailure Failure, "selection_mismatch", _
|
|
"Manual selection contains a duplicate unit", _
|
|
"ActiveView.SelectedObjects", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
SeenTokens.Add Token, True
|
|
Next
|
|
DxBridgeVerifySelectedLogicalKeys = True
|
|
End Function
|
|
|
|
Function DxBridgeInvokeNoArgumentRoute(ByVal Name, ByRef Failure)
|
|
Dim Ignored
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
On Error Resume Next
|
|
Select Case CStr(Name)
|
|
Case "native_replace_part"
|
|
Ignored = Application.OpenReplacePartDialog
|
|
Case "undo"
|
|
Ignored = Application.Undo
|
|
Case "save"
|
|
Ignored = Application.Save
|
|
Case "close_project"
|
|
Ignored = Application.CloseProject
|
|
Case Else
|
|
Err.Raise vbObjectError + 838, _
|
|
"DxBridgeInvokeNoArgumentRoute", "Unknown route"
|
|
End Select
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetApiFailure Failure, _
|
|
"route." & CStr(Name), ErrorNumber, ErrorSource, ErrorDescription
|
|
DxBridgeInvokeNoArgumentRoute = False
|
|
Else
|
|
DxBridgeInvokeNoArgumentRoute = True
|
|
End If
|
|
End Function
|
|
|
|
Function DxBridgeInvokeOpenProject(ByVal ProjectPath, ByRef Failure)
|
|
Dim Ignored
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
On Error Resume Next
|
|
Ignored = Application.OpenProject(CStr(ProjectPath))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetApiFailure Failure, "route.open_project", _
|
|
ErrorNumber, ErrorSource, ErrorDescription
|
|
DxBridgeInvokeOpenProject = False
|
|
Else
|
|
DxBridgeInvokeOpenProject = True
|
|
End If
|
|
End Function
|
|
|
|
Function DxBridgeInvokeBooleanRoute(ByVal Name, ByRef RouteResult, _
|
|
ByRef Failure)
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
DxBridgeInvokeBooleanRoute = False
|
|
On Error Resume Next
|
|
Select Case CStr(Name)
|
|
Case "packager"
|
|
RouteResult = Application.RunPackager
|
|
Case "erc"
|
|
RouteResult = Application.RunERC
|
|
Case "netlist"
|
|
RouteResult = Application.RunNetlist
|
|
Case Else
|
|
Err.Raise vbObjectError + 839, _
|
|
"DxBridgeInvokeBooleanRoute", "Unknown Boolean route"
|
|
End Select
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetApiFailure Failure, "route." & CStr(Name), _
|
|
ErrorNumber, ErrorSource, ErrorDescription
|
|
Exit Function
|
|
End If
|
|
DxBridgeInvokeBooleanRoute = True
|
|
End Function
|
|
|
|
Function DxBridgeRunNativeDialog(ByVal StatusPath, ByVal SnapshotPath, _
|
|
ByRef Command, ByRef Failure)
|
|
Dim LiveMap
|
|
Dim SnapshotText
|
|
Dim Fingerprint
|
|
DxBridgeRunNativeDialog = False
|
|
DxBridgePublishNativeDialogOpening StatusPath, Command
|
|
If Not DxBridgeInvokeNoArgumentRoute("native_replace_part", _
|
|
Failure) Then Exit Function
|
|
If Not DxBridgeObserveReplacePartCompletion(Failure) Then Exit Function
|
|
If Not DxBridgeBuildSnapshot(Command, LiveMap, SnapshotText, _
|
|
Fingerprint, Failure) Then Exit Function
|
|
If Not DxBridgeWriteDocument(SnapshotPath, SnapshotText, _
|
|
"post-operation snapshot publication", Failure) Then _
|
|
Exit Function
|
|
DxBridgePublishStatus StatusPath, Command, "applied", _
|
|
SnapshotPath, Null, Null, Empty
|
|
DxBridgeRunNativeDialog = True
|
|
End Function
|
|
|
|
Function DxBridgeObserveReplacePartCompletion(ByRef Failure)
|
|
Dim CompletedValue
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
DxBridgeObserveReplacePartCompletion = False
|
|
On Error Resume Next
|
|
CompletedValue = Application.ReplacePartCompleted
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetApiFailure Failure, _
|
|
"Application.ReplacePartCompleted", ErrorNumber, _
|
|
ErrorSource, ErrorDescription
|
|
Exit Function
|
|
End If
|
|
If VarType(CompletedValue) <> vbBoolean Or _
|
|
Not CBool(CompletedValue) Then
|
|
DxBridgeSetFailure Failure, "replace_part_incomplete", _
|
|
"Native Replace Part completion was not positively observed", _
|
|
"Application.ReplacePartCompleted", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
DxBridgeObserveReplacePartCompletion = True
|
|
End Function
|
|
|
|
Sub DxBridgePublishNativeDialogOpening(ByVal StatusPath, ByRef Command)
|
|
Dim Details
|
|
Set Details = CreateObject("Scripting.Dictionary")
|
|
Details.Add "instruction", _
|
|
"Confirm the displayed target and choose Library Wins"
|
|
Details.Add "library_choice", "Library Wins"
|
|
Details.Add "new_part_number", Command("new_part_number")
|
|
Details.Add "old_part_number", Command("old_part_number")
|
|
DxBridgePublishStatus StatusPath, Command, "native_dialog_opening", _
|
|
Null, Null, Null, Details
|
|
End Sub
|
|
|
|
Sub DxBridgePublishManual(ByVal StatusPath, ByRef Command, _
|
|
ByVal ManualRoute, ByVal Instruction)
|
|
Dim Details
|
|
Set Details = CreateObject("Scripting.Dictionary")
|
|
Details.Add "instruction", CStr(Instruction)
|
|
Details.Add "manual_route", CStr(ManualRoute)
|
|
Details.Add "new_part_number", CStr(Command("new_part_number"))
|
|
Details.Add "old_part_number", CStr(Command("old_part_number"))
|
|
DxBridgePublishStatus StatusPath, Command, "manual_action_required", _
|
|
Null, Null, Null, Details
|
|
End Sub
|
|
|
|
Sub DxBridgePublishProjectOpenManual(ByVal StatusPath, ByRef Command, _
|
|
ByVal TargetProjectPath)
|
|
Dim Details
|
|
Set Details = CreateObject("Scripting.Dictionary")
|
|
Details.Add "canonical_next_path", CStr(TargetProjectPath)
|
|
Details.Add "instruction", "Open the canonical project path manually"
|
|
Details.Add "manual_route", "manual_project_open"
|
|
DxBridgePublishStatus StatusPath, Command, _
|
|
"manual_project_open_required", Null, Null, Null, Details
|
|
End Sub
|
|
|
|
Sub DxBridgePublishControlStatus(ByVal StatusPath, ByRef Command, _
|
|
ByVal State, ByVal SnapshotPath)
|
|
Dim ControlAction
|
|
ControlAction = CStr(Command("action"))
|
|
Command("action") = "replace_part"
|
|
DxBridgePublishStatus StatusPath, Command, State, SnapshotPath, _
|
|
Null, Null, Empty
|
|
Command("action") = ControlAction
|
|
End Sub
|
|
|
|
Function DxBridgeIsDictionary(ByVal Value)
|
|
DxBridgeIsDictionary = False
|
|
If Not IsObject(Value) Then Exit Function
|
|
DxBridgeIsDictionary = TypeName(Value) = "Dictionary"
|
|
End Function
|
|
|
|
Function DxBridgeIsJsonArray(ByVal Value)
|
|
DxBridgeIsJsonArray = False
|
|
If Not IsObject(Value) Then Exit Function
|
|
DxBridgeIsJsonArray = TypeName(Value) = "DxBridgeJsonArray"
|
|
End Function
|
|
|
|
Function DxBridgeIsProtocolInteger(ByVal Value)
|
|
DxBridgeIsProtocolInteger = _
|
|
VarType(Value) = vbInteger Or VarType(Value) = vbLong
|
|
End Function
|
|
|
|
Function DxBridgeIsJsonNumber(ByVal Value)
|
|
Select Case VarType(Value)
|
|
Case vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbDecimal
|
|
DxBridgeIsJsonNumber = True
|
|
Case Else
|
|
DxBridgeIsJsonNumber = False
|
|
End Select
|
|
End Function
|
|
|
|
Sub DxBridgeSetProfileInvalid(ByRef Failure, ByVal Operation)
|
|
DxBridgeSetFailure Failure, "compatibility_profile_invalid", _
|
|
"Compatibility profile schema is invalid", Operation, 0, "", ""
|
|
End Sub
|
|
|
|
Function DxBridgeRequireProfileFields(ByRef Record, ByVal FieldNames, _
|
|
ByVal ExpectedCount, ByVal Operation, ByRef Failure)
|
|
Dim Name
|
|
DxBridgeRequireProfileFields = False
|
|
If Record.Count <> ExpectedCount Then
|
|
DxBridgeSetProfileInvalid Failure, Operation
|
|
Exit Function
|
|
End If
|
|
For Each Name In Split(CStr(FieldNames), ",")
|
|
If Not Record.Exists(CStr(Name)) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation
|
|
Exit Function
|
|
End If
|
|
Next
|
|
DxBridgeRequireProfileFields = True
|
|
End Function
|
|
|
|
Function DxBridgeValidateProfileErrorRecord(ByRef Record, ByVal Operation, _
|
|
ByRef Failure)
|
|
DxBridgeValidateProfileErrorRecord = False
|
|
If Not DxBridgeRequireProfileFields(Record, _
|
|
"description,number,operation,source", 4, Operation, Failure) Then
|
|
Exit Function
|
|
End If
|
|
If VarType(Record("description")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, Operation & ".description"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsProtocolInteger(Record("number")) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation & ".number"
|
|
Exit Function
|
|
End If
|
|
If VarType(Record("operation")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, Operation & ".operation"
|
|
Exit Function
|
|
End If
|
|
If VarType(Record("source")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, Operation & ".source"
|
|
Exit Function
|
|
End If
|
|
DxBridgeValidateProfileErrorRecord = True
|
|
End Function
|
|
|
|
Function DxBridgeValidateProfileErrors(ByVal Value, ByVal Operation, _
|
|
ByRef Failure)
|
|
Dim Errors
|
|
Dim Index
|
|
Dim Record
|
|
DxBridgeValidateProfileErrors = False
|
|
If Not DxBridgeIsJsonArray(Value) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation
|
|
Exit Function
|
|
End If
|
|
Set Errors = Value
|
|
For Index = 0 To Errors.Count - 1
|
|
If Not IsObject(Errors(Index)) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
Set Record = Errors(Index)
|
|
If Not DxBridgeIsDictionary(Record) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeValidateProfileErrorRecord(Record, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]", _
|
|
Failure) Then Exit Function
|
|
Next
|
|
DxBridgeValidateProfileErrors = True
|
|
End Function
|
|
|
|
Function DxBridgeValidateProfilePoint(ByRef Component, ByVal FieldName, _
|
|
ByVal Operation, ByRef Failure)
|
|
Dim Point
|
|
DxBridgeValidateProfilePoint = False
|
|
If Not IsObject(Component(CStr(FieldName))) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation
|
|
Exit Function
|
|
End If
|
|
Set Point = Component(CStr(FieldName))
|
|
If Not DxBridgeIsDictionary(Point) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeRequireProfileFields(Point, "x,y", 2, Operation, _
|
|
Failure) Then Exit Function
|
|
If Not DxBridgeIsJsonNumber(Point("x")) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation & ".x"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsJsonNumber(Point("y")) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation & ".y"
|
|
Exit Function
|
|
End If
|
|
DxBridgeValidateProfilePoint = True
|
|
End Function
|
|
|
|
Function DxBridgeValidateProfileGates(ByVal Value, ByVal Operation, _
|
|
ByRef Failure)
|
|
Dim Values
|
|
Dim Index
|
|
Dim Record
|
|
DxBridgeValidateProfileGates = False
|
|
If Not DxBridgeIsJsonArray(Value) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation
|
|
Exit Function
|
|
End If
|
|
Set Values = Value
|
|
For Index = 0 To Values.Count - 1
|
|
If Not IsObject(Values(Index)) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
Set Record = Values(Index)
|
|
If Not DxBridgeIsDictionary(Record) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeRequireProfileFields(Record, "name,unit_number", 2, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]", _
|
|
Failure) Then Exit Function
|
|
If VarType(Record("name")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "].name"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsJsonNumber(Record("unit_number")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "].unit_number"
|
|
Exit Function
|
|
End If
|
|
Next
|
|
DxBridgeValidateProfileGates = True
|
|
End Function
|
|
|
|
Function DxBridgeValidateProfileAttributes(ByVal Value, ByVal Operation, _
|
|
ByRef Failure)
|
|
Dim Values
|
|
Dim Index
|
|
Dim Record
|
|
DxBridgeValidateProfileAttributes = False
|
|
If Not DxBridgeIsJsonArray(Value) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation
|
|
Exit Function
|
|
End If
|
|
Set Values = Value
|
|
For Index = 0 To Values.Count - 1
|
|
If Not IsObject(Values(Index)) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
Set Record = Values(Index)
|
|
If Not DxBridgeIsDictionary(Record) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeRequireProfileFields(Record, "name,value", 2, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]", _
|
|
Failure) Then Exit Function
|
|
If VarType(Record("name")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "].name"
|
|
Exit Function
|
|
End If
|
|
If VarType(Record("value")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "].value"
|
|
Exit Function
|
|
End If
|
|
Next
|
|
DxBridgeValidateProfileAttributes = True
|
|
End Function
|
|
|
|
Function DxBridgeValidateProfilePins(ByVal Value, ByVal Operation, _
|
|
ByRef Failure)
|
|
Dim Values
|
|
Dim Index
|
|
Dim Record
|
|
Dim NetValue
|
|
DxBridgeValidateProfilePins = False
|
|
If Not DxBridgeIsJsonArray(Value) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation
|
|
Exit Function
|
|
End If
|
|
Set Values = Value
|
|
For Index = 0 To Values.Count - 1
|
|
If Not IsObject(Values(Index)) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
Set Record = Values(Index)
|
|
If Not DxBridgeIsDictionary(Record) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeRequireProfileFields(Record, _
|
|
"name,net_identity,number,x,y", 5, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]", _
|
|
Failure) Then Exit Function
|
|
If VarType(Record("name")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "].name"
|
|
Exit Function
|
|
End If
|
|
If VarType(Record("number")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "].number"
|
|
Exit Function
|
|
End If
|
|
If IsObject(Record("net_identity")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & _
|
|
"].net_identity"
|
|
Exit Function
|
|
End If
|
|
NetValue = Record("net_identity")
|
|
If Not IsNull(NetValue) Then
|
|
If VarType(NetValue) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & _
|
|
"].net_identity"
|
|
Exit Function
|
|
End If
|
|
End If
|
|
If Not DxBridgeIsJsonNumber(Record("x")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "].x"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsJsonNumber(Record("y")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "].y"
|
|
Exit Function
|
|
End If
|
|
Next
|
|
DxBridgeValidateProfilePins = True
|
|
End Function
|
|
|
|
Function DxBridgeValidateProfileNets(ByVal Value, ByVal Operation, _
|
|
ByRef Failure)
|
|
Dim Values
|
|
Dim Index
|
|
DxBridgeValidateProfileNets = False
|
|
If Not DxBridgeIsJsonArray(Value) Then
|
|
DxBridgeSetProfileInvalid Failure, Operation
|
|
Exit Function
|
|
End If
|
|
Set Values = Value
|
|
For Index = 0 To Values.Count - 1
|
|
If VarType(Values(Index)) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Operation & "[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
Next
|
|
DxBridgeValidateProfileNets = True
|
|
End Function
|
|
|
|
Function DxBridgeValidateProfileComponents(ByVal Value, ByRef Failure)
|
|
Dim Components
|
|
Dim Index
|
|
Dim Component
|
|
Dim Name
|
|
Dim Prefix
|
|
DxBridgeValidateProfileComponents = False
|
|
If Not DxBridgeIsJsonArray(Value) Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.components"
|
|
Exit Function
|
|
End If
|
|
Set Components = Value
|
|
For Index = 0 To Components.Count - 1
|
|
Prefix = "profile.components[" & DxInvariantNumber(Index) & "]"
|
|
If Not IsObject(Components(Index)) Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix
|
|
Exit Function
|
|
End If
|
|
Set Component = Components(Index)
|
|
If Not DxBridgeIsDictionary(Component) Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeRequireProfileFields(Component, _
|
|
"api_errors,attributes,gates,hierarchy,logical_identity," & _
|
|
"mirror,nets,origin,part_number,pins,position,refdes," & _
|
|
"rotation,symbol_identity,units", 15, Prefix, _
|
|
Failure) Then Exit Function
|
|
For Each Name In Array("hierarchy", "logical_identity", _
|
|
"part_number", "refdes", "symbol_identity")
|
|
If VarType(Component(CStr(Name))) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & "." & CStr(Name)
|
|
Exit Function
|
|
End If
|
|
Next
|
|
If Not DxBridgeIsProtocolInteger(Component("units")) Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".units"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsJsonNumber(Component("rotation")) Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".rotation"
|
|
Exit Function
|
|
End If
|
|
If VarType(Component("mirror")) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".mirror"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeValidateProfilePoint(Component, "origin", _
|
|
Prefix & ".origin", Failure) Then Exit Function
|
|
If Not DxBridgeValidateProfilePoint(Component, "position", _
|
|
Prefix & ".position", Failure) Then Exit Function
|
|
If Not DxBridgeValidateProfileGates(Component("gates"), _
|
|
Prefix & ".gates", Failure) Then Exit Function
|
|
If Not DxBridgeValidateProfileAttributes(Component("attributes"), _
|
|
Prefix & ".attributes", Failure) Then Exit Function
|
|
If Not DxBridgeValidateProfilePins(Component("pins"), _
|
|
Prefix & ".pins", Failure) Then Exit Function
|
|
If Not DxBridgeValidateProfileNets(Component("nets"), _
|
|
Prefix & ".nets", Failure) Then Exit Function
|
|
If Not DxBridgeValidateProfileErrors(Component("api_errors"), _
|
|
Prefix & ".api_errors", Failure) Then Exit Function
|
|
Next
|
|
DxBridgeValidateProfileComponents = True
|
|
End Function
|
|
|
|
Function DxBridgeExpectedProfileRoute(ByVal Name)
|
|
Select Case CStr(Name)
|
|
Case "exact_set_selection"
|
|
DxBridgeExpectedProfileRoute = "ActiveView.SelectExactSet"
|
|
Case "native_replace_part"
|
|
DxBridgeExpectedProfileRoute = _
|
|
"Application.OpenReplacePartDialog"
|
|
Case "completion_observation"
|
|
DxBridgeExpectedProfileRoute = _
|
|
"Application.ReplacePartCompleted"
|
|
Case "undo"
|
|
DxBridgeExpectedProfileRoute = "Application.Undo"
|
|
Case "save"
|
|
DxBridgeExpectedProfileRoute = "Application.Save"
|
|
Case "open_project"
|
|
DxBridgeExpectedProfileRoute = "Application.OpenProject"
|
|
Case "close_project"
|
|
DxBridgeExpectedProfileRoute = "Application.CloseProject"
|
|
Case "packager"
|
|
DxBridgeExpectedProfileRoute = "Application.RunPackager"
|
|
Case "erc"
|
|
DxBridgeExpectedProfileRoute = "Application.RunERC"
|
|
Case "netlist"
|
|
DxBridgeExpectedProfileRoute = "Application.RunNetlist"
|
|
Case "ccomp_research"
|
|
DxBridgeExpectedProfileRoute = "Application.CComp"
|
|
Case Else
|
|
DxBridgeExpectedProfileRoute = ""
|
|
End Select
|
|
End Function
|
|
|
|
Function DxBridgeValidateProfileRoutes(ByRef Routes, ByRef Failure)
|
|
Dim Name
|
|
Dim Record
|
|
Dim Attempts
|
|
Dim Attempt
|
|
Dim Index
|
|
Dim Prefix
|
|
Dim ErrorRecord
|
|
Dim ExpectedRoute
|
|
DxBridgeValidateProfileRoutes = False
|
|
If Not DxBridgeRequireProfileFields(Routes, _
|
|
"exact_set_selection,native_replace_part," & _
|
|
"completion_observation,undo,save,open_project," & _
|
|
"close_project,packager,erc,netlist,ccomp_research", _
|
|
11, "profile.routes", Failure) Then Exit Function
|
|
For Each Name In Routes.Keys
|
|
Prefix = "profile.routes." & CStr(Name)
|
|
ExpectedRoute = DxBridgeExpectedProfileRoute(CStr(Name))
|
|
If Len(ExpectedRoute) = 0 Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix
|
|
Exit Function
|
|
End If
|
|
If Not IsObject(Routes(CStr(Name))) Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix
|
|
Exit Function
|
|
End If
|
|
Set Record = Routes(CStr(Name))
|
|
If Not DxBridgeIsDictionary(Record) Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix
|
|
Exit Function
|
|
End If
|
|
If CStr(Name) = "ccomp_research" Then
|
|
If Record.Count <> 6 Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix
|
|
Exit Function
|
|
End If
|
|
Else
|
|
If Record.Count <> 5 Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix
|
|
Exit Function
|
|
End If
|
|
End If
|
|
For Each Index In Array("attempted", "available", _
|
|
"manual_fallback", "route", "attempts")
|
|
If Not Record.Exists(CStr(Index)) Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix
|
|
Exit Function
|
|
End If
|
|
Next
|
|
If VarType(Record("attempted")) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".attempted"
|
|
Exit Function
|
|
End If
|
|
If VarType(Record("available")) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".available"
|
|
Exit Function
|
|
End If
|
|
If VarType(Record("manual_fallback")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".manual_fallback"
|
|
Exit Function
|
|
End If
|
|
If VarType(Record("route")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".route"
|
|
Exit Function
|
|
End If
|
|
If CStr(Record("route")) <> ExpectedRoute Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".route"
|
|
Exit Function
|
|
End If
|
|
If CStr(Name) = "ccomp_research" Then
|
|
If Not Record.Exists("production_enabled") Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix
|
|
Exit Function
|
|
End If
|
|
If VarType(Record("production_enabled")) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".production_enabled"
|
|
Exit Function
|
|
End If
|
|
If CBool(Record("production_enabled")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".production_enabled"
|
|
Exit Function
|
|
End If
|
|
End If
|
|
If Not DxBridgeIsJsonArray(Record("attempts")) Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".attempts"
|
|
Exit Function
|
|
End If
|
|
Set Attempts = Record("attempts")
|
|
If Attempts.Count <> 1 Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".attempts"
|
|
Exit Function
|
|
End If
|
|
For Index = 0 To Attempts.Count - 1
|
|
If Not IsObject(Attempts(Index)) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
Set Attempt = Attempts(Index)
|
|
If Not DxBridgeIsDictionary(Attempt) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & "]"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeRequireProfileFields(Attempt, _
|
|
"attempted,available,error,route", 4, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & "]", _
|
|
Failure) Then Exit Function
|
|
If VarType(Attempt("attempted")) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & _
|
|
"].attempted"
|
|
Exit Function
|
|
End If
|
|
If VarType(Attempt("available")) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & _
|
|
"].available"
|
|
Exit Function
|
|
End If
|
|
If VarType(Attempt("route")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & _
|
|
"].route"
|
|
Exit Function
|
|
End If
|
|
If CStr(Attempt("route")) <> ExpectedRoute Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & _
|
|
"].route"
|
|
Exit Function
|
|
End If
|
|
If Not IsNull(Attempt("error")) Then
|
|
If Not IsObject(Attempt("error")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & _
|
|
"].error"
|
|
Exit Function
|
|
End If
|
|
Set ErrorRecord = Attempt("error")
|
|
If Not DxBridgeIsDictionary(ErrorRecord) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & _
|
|
"].error"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeValidateProfileErrorRecord(ErrorRecord, _
|
|
Prefix & ".attempts[" & _
|
|
DxInvariantNumber(Index) & "].error", _
|
|
Failure) Then Exit Function
|
|
End If
|
|
If CBool(Record("attempted")) <> _
|
|
CBool(Attempt("attempted")) Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".attempted"
|
|
Exit Function
|
|
End If
|
|
If CBool(Record("available")) <> _
|
|
CBool(Attempt("available")) Then
|
|
DxBridgeSetProfileInvalid Failure, Prefix & ".available"
|
|
Exit Function
|
|
End If
|
|
If CBool(Attempt("available")) And _
|
|
Not CBool(Attempt("attempted")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & _
|
|
"].available"
|
|
Exit Function
|
|
End If
|
|
If CBool(Attempt("attempted")) And _
|
|
Not CBool(Attempt("available")) Then
|
|
If IsNull(Attempt("error")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & _
|
|
"].error"
|
|
Exit Function
|
|
End If
|
|
ElseIf Not IsNull(Attempt("error")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
Prefix & ".attempts[" & DxInvariantNumber(Index) & _
|
|
"].error"
|
|
Exit Function
|
|
End If
|
|
Next
|
|
Next
|
|
DxBridgeValidateProfileRoutes = True
|
|
End Function
|
|
|
|
Function DxBridgeIsLowerSha256(ByVal Value)
|
|
Dim Index
|
|
Dim Character
|
|
DxBridgeIsLowerSha256 = False
|
|
If VarType(Value) <> vbString Then Exit Function
|
|
If Len(CStr(Value)) <> 64 Then Exit Function
|
|
For Index = 1 To 64
|
|
Character = Mid(CStr(Value), Index, 1)
|
|
If Not ((Character >= "0" And Character <= "9") Or _
|
|
(Character >= "a" And Character <= "f")) Then Exit Function
|
|
Next
|
|
DxBridgeIsLowerSha256 = True
|
|
End Function
|
|
|
|
Function DxBridgeValidateProfile(ByRef Profile, ByRef Failure)
|
|
Dim LiveAcceptance
|
|
Dim DxDesigner
|
|
Dim Project
|
|
Dim Enumeration
|
|
Dim Interfaces
|
|
Dim InterfaceName
|
|
Dim Record
|
|
Dim Routes
|
|
Dim Safety
|
|
Dim Name
|
|
Dim InterfacesComplete
|
|
Dim ExpectedAuthorized
|
|
Dim MutatingAttempted
|
|
DxBridgeValidateProfile = False
|
|
If Not DxBridgeRequireProfileFields(Profile, _
|
|
"api_errors,components,dxdesigner,enumeration,format_version," & _
|
|
"interfaces,live_acceptance,production_replace_route,project," & _
|
|
"routes,safety", 11, "profile.schema", Failure) Then
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsProtocolInteger(Profile("format_version")) Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.format_version"
|
|
Exit Function
|
|
End If
|
|
If CLng(Profile("format_version")) <> 1 Then
|
|
DxBridgeSetFailure Failure, "unsupported_format_version", _
|
|
"Unsupported compatibility profile format version", _
|
|
"profile.format_version", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsDictionary(Profile("live_acceptance")) Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.live_acceptance"
|
|
Exit Function
|
|
End If
|
|
Set LiveAcceptance = Profile("live_acceptance")
|
|
If Not LiveAcceptance.Exists("checked") Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.live_acceptance.checked"
|
|
Exit Function
|
|
End If
|
|
If VarType(LiveAcceptance("checked")) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.live_acceptance.checked"
|
|
Exit Function
|
|
End If
|
|
If CBool(LiveAcceptance("checked")) Then
|
|
If Not DxBridgeRequireProfileFields(LiveAcceptance, _
|
|
"checked,evidence_sha256,reason", 3, _
|
|
"profile.live_acceptance", Failure) Then Exit Function
|
|
Else
|
|
If Not DxBridgeRequireProfileFields(LiveAcceptance, _
|
|
"checked,reason", 2, "profile.live_acceptance", _
|
|
Failure) Then Exit Function
|
|
End If
|
|
If VarType(LiveAcceptance("reason")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.live_acceptance.reason"
|
|
Exit Function
|
|
End If
|
|
If CBool(LiveAcceptance("checked")) Then
|
|
If CStr(LiveAcceptance("reason")) <> _
|
|
"live_795_acceptance_completed" Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.live_acceptance.reason"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsLowerSha256( _
|
|
LiveAcceptance("evidence_sha256")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.live_acceptance.evidence_sha256"
|
|
Exit Function
|
|
End If
|
|
ElseIf CStr(LiveAcceptance("reason")) <> _
|
|
"live_795_host_not_exercised" Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.live_acceptance.reason"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsDictionary(Profile("dxdesigner")) Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.dxdesigner"
|
|
Exit Function
|
|
End If
|
|
Set DxDesigner = Profile("dxdesigner")
|
|
If Not DxBridgeRequireProfileFields(DxDesigner, "build,version", 2, _
|
|
"profile.dxdesigner", Failure) Then Exit Function
|
|
If VarType(DxDesigner("version")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.dxdesigner.version"
|
|
Exit Function
|
|
End If
|
|
If VarType(DxDesigner("build")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.dxdesigner.build"
|
|
Exit Function
|
|
End If
|
|
If CStr(DxDesigner("version")) <> "7.9.5" Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.dxdesigner.version"
|
|
Exit Function
|
|
End If
|
|
If CStr(DxDesigner("build")) <> "7.9.5" And _
|
|
Left(CStr(DxDesigner("build")), 6) <> "7.9.5." Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.dxdesigner.build"
|
|
Exit Function
|
|
End If
|
|
|
|
If Not DxBridgeIsDictionary(Profile("project")) Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.project"
|
|
Exit Function
|
|
End If
|
|
Set Project = Profile("project")
|
|
If Not DxBridgeRequireProfileFields(Project, _
|
|
"active_view,dirty,identity", 3, "profile.project", _
|
|
Failure) Then Exit Function
|
|
If VarType(Project("active_view")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.project.active_view"
|
|
Exit Function
|
|
End If
|
|
If VarType(Project("dirty")) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.project.dirty"
|
|
Exit Function
|
|
End If
|
|
If VarType(Project("identity")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.project.identity"
|
|
Exit Function
|
|
End If
|
|
|
|
If Not DxBridgeIsDictionary(Profile("enumeration")) Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.enumeration"
|
|
Exit Function
|
|
End If
|
|
Set Enumeration = Profile("enumeration")
|
|
If Not DxBridgeRequireProfileFields(Enumeration, _
|
|
"available,component_count,route", 3, "profile.enumeration", _
|
|
Failure) Then Exit Function
|
|
If VarType(Enumeration("available")) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.enumeration.available"
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsProtocolInteger(Enumeration("component_count")) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.enumeration.component_count"
|
|
Exit Function
|
|
End If
|
|
If CLng(Enumeration("component_count")) < 0 Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.enumeration.component_count"
|
|
Exit Function
|
|
End If
|
|
If VarType(Enumeration("route")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.enumeration.route"
|
|
Exit Function
|
|
End If
|
|
|
|
If Not DxBridgeValidateProfileComponents(Profile("components"), _
|
|
Failure) Then
|
|
Exit Function
|
|
End If
|
|
|
|
If Not DxBridgeIsDictionary(Profile("interfaces")) Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.interfaces"
|
|
Exit Function
|
|
End If
|
|
Set Interfaces = Profile("interfaces")
|
|
If Interfaces.Count <> 16 Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.interfaces"
|
|
Exit Function
|
|
End If
|
|
InterfacesComplete = True
|
|
For Each InterfaceName In Array("attributes", "gates", "hierarchy", _
|
|
"logical_identity", "mirror", "nets", "origin_x", "origin_y", _
|
|
"part_number", "pins", "position_x", "position_y", "refdes", _
|
|
"rotation", "symbol_identity", "units")
|
|
If Not Interfaces.Exists(CStr(InterfaceName)) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.interfaces." & CStr(InterfaceName)
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsDictionary( _
|
|
Interfaces(CStr(InterfaceName))) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.interfaces." & CStr(InterfaceName)
|
|
Exit Function
|
|
End If
|
|
Set Record = Interfaces(CStr(InterfaceName))
|
|
If Not DxBridgeRequireProfileFields(Record, "available", 1, _
|
|
"profile.interfaces." & CStr(InterfaceName), _
|
|
Failure) Then Exit Function
|
|
If VarType(Record("available")) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.interfaces." & CStr(InterfaceName) & ".available"
|
|
Exit Function
|
|
End If
|
|
If Not CBool(Record("available")) Then InterfacesComplete = False
|
|
Next
|
|
|
|
If Not DxBridgeIsDictionary(Profile("routes")) Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.routes"
|
|
Exit Function
|
|
End If
|
|
Set Routes = Profile("routes")
|
|
If Not DxBridgeValidateProfileRoutes(Routes, Failure) Then Exit Function
|
|
|
|
If VarType(Profile("production_replace_route")) <> vbString Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.production_replace_route"
|
|
Exit Function
|
|
End If
|
|
If CStr(Profile("production_replace_route")) <> _
|
|
"native_replace_part" Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.production_replace_route"
|
|
Exit Function
|
|
End If
|
|
|
|
If Not DxBridgeIsDictionary(Profile("safety")) Then
|
|
DxBridgeSetProfileInvalid Failure, "profile.safety"
|
|
Exit Function
|
|
End If
|
|
Set Safety = Profile("safety")
|
|
If Not DxBridgeRequireProfileFields(Safety, _
|
|
"disposable_project_marker,mutating_probe_attempted," & _
|
|
"mutating_probe_authorized,operator_confirmation,request_valid", _
|
|
5, "profile.safety", Failure) Then Exit Function
|
|
For Each Name In Array("disposable_project_marker", _
|
|
"mutating_probe_attempted", "mutating_probe_authorized", _
|
|
"operator_confirmation", "request_valid")
|
|
If VarType(Safety(CStr(Name))) <> vbBoolean Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.safety." & CStr(Name)
|
|
Exit Function
|
|
End If
|
|
Next
|
|
ExpectedAuthorized = CBool(Safety("request_valid")) And _
|
|
CBool(Safety("disposable_project_marker")) And _
|
|
CBool(Safety("operator_confirmation"))
|
|
If CBool(Safety("mutating_probe_authorized")) <> _
|
|
CBool(ExpectedAuthorized) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.safety.mutating_probe_authorized"
|
|
Exit Function
|
|
End If
|
|
MutatingAttempted = False
|
|
For Each Name In Array("exact_set_selection", "native_replace_part", _
|
|
"undo", "save", "open_project", "close_project", _
|
|
"packager", "erc", "netlist", "ccomp_research")
|
|
Set Record = Routes(CStr(Name))
|
|
If CBool(Record("attempted")) Then MutatingAttempted = True
|
|
Next
|
|
If CBool(Safety("mutating_probe_attempted")) <> _
|
|
CBool(MutatingAttempted) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.safety.mutating_probe_attempted"
|
|
Exit Function
|
|
End If
|
|
If CBool(MutatingAttempted) And Not CBool(ExpectedAuthorized) Then
|
|
DxBridgeSetProfileInvalid Failure, _
|
|
"profile.safety.mutating_probe_attempted"
|
|
Exit Function
|
|
End If
|
|
|
|
If Not DxBridgeValidateProfileErrors(Profile("api_errors"), _
|
|
"profile.api_errors", Failure) Then Exit Function
|
|
|
|
If Len(DxDesigner("version")) = 0 Or Len(DxDesigner("build")) = 0 Or _
|
|
Not CBool(Enumeration("available")) Or _
|
|
Enumeration("route") <> "Application.DesignComponents" Or _
|
|
Not InterfacesComplete Then
|
|
DxBridgeSetFailure Failure, "compatibility_profile_incomplete", _
|
|
"Compatibility profile lacks required read-only evidence", _
|
|
"profile.evidence", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
DxBridgeValidateProfile = True
|
|
End Function
|
|
|
|
Function DxBridgeProfileLiveAccepted(ByRef Profile)
|
|
Dim LiveAcceptance
|
|
DxBridgeProfileLiveAccepted = False
|
|
If Not Profile.Exists("live_acceptance") Then Exit Function
|
|
If Not DxBridgeIsDictionary(Profile("live_acceptance")) Then Exit Function
|
|
Set LiveAcceptance = Profile("live_acceptance")
|
|
If Not LiveAcceptance.Exists("checked") Then Exit Function
|
|
If VarType(LiveAcceptance("checked")) <> vbBoolean Then Exit Function
|
|
DxBridgeProfileLiveAccepted = CBool(LiveAcceptance("checked"))
|
|
End Function
|
|
|
|
Function DxBridgeVerifyProfileIdentity(ByRef Profile, ByRef Failure)
|
|
Dim DxDesigner
|
|
Dim VersionValue
|
|
Dim BuildValue
|
|
DxBridgeVerifyProfileIdentity = False
|
|
Set DxDesigner = Profile("dxdesigner")
|
|
If Not DxBridgeReadScalar(Application, "Version", _
|
|
"Application.Version", VersionValue, Failure) Then Exit Function
|
|
If Not DxBridgeReadScalar(Application, "Build", _
|
|
"Application.Build", BuildValue, Failure) Then Exit Function
|
|
If VarType(VersionValue) <> vbString Then
|
|
DxBridgeSetFailure Failure, "compatibility_profile_mismatch", _
|
|
"Active DxDesigner version has an unexpected type", _
|
|
"Application.Version", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
If VarType(BuildValue) <> vbString Then
|
|
DxBridgeSetFailure Failure, "compatibility_profile_mismatch", _
|
|
"Active DxDesigner build has an unexpected type", _
|
|
"Application.Build", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
If VersionValue <> DxDesigner("version") Or _
|
|
BuildValue <> DxDesigner("build") Then
|
|
DxBridgeSetFailure Failure, "compatibility_profile_mismatch", _
|
|
"Active DxDesigner version/build does not match the profile", _
|
|
"profile.dxdesigner", 0, "", ""
|
|
Exit Function
|
|
End If
|
|
DxBridgeVerifyProfileIdentity = True
|
|
End Function
|
|
|
|
Function DxBridgeReadScalar(ByRef Target, ByVal FieldName, _
|
|
ByVal Operation, ByRef Value, ByRef Failure)
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim RetryNumber
|
|
Dim RetryDescription
|
|
Dim RetrySource
|
|
DxBridgeReadScalar = False
|
|
On Error Resume Next
|
|
Set Value = Eval("Target." & CStr(FieldName))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber = 0 Then
|
|
DxBridgeReadScalar = True
|
|
Exit Function
|
|
End If
|
|
If ErrorNumber <> 424 Then
|
|
DxBridgeSetApiFailure Failure, Operation, ErrorNumber, ErrorSource, _
|
|
ErrorDescription
|
|
Exit Function
|
|
End If
|
|
Set Value = Nothing
|
|
On Error Resume Next
|
|
Value = Eval("Target." & CStr(FieldName))
|
|
RetryNumber = Err.Number
|
|
RetryDescription = Err.Description
|
|
RetrySource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If RetryNumber <> 0 Then
|
|
DxBridgeSetApiFailure Failure, Operation, RetryNumber, RetrySource, _
|
|
RetryDescription
|
|
Exit Function
|
|
End If
|
|
DxBridgeReadScalar = True
|
|
End Function
|
|
|
|
Function DxBridgeReadCollection(ByRef Target, ByVal FieldName, _
|
|
ByVal Operation, ByRef Items, ByRef ItemCount, ByRef Failure)
|
|
Dim Values
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim RetryNumber
|
|
Dim RetryDescription
|
|
Dim RetrySource
|
|
DxBridgeReadCollection = False
|
|
On Error Resume Next
|
|
Set Values = Eval("Target." & CStr(FieldName))
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber = 0 Then
|
|
DxBridgeReadCollection = DxBridgeCollectItems(Values, Operation, _
|
|
Items, ItemCount, Failure)
|
|
Exit Function
|
|
End If
|
|
If ErrorNumber <> 424 Then
|
|
DxBridgeSetApiFailure Failure, Operation, ErrorNumber, ErrorSource, _
|
|
ErrorDescription
|
|
Exit Function
|
|
End If
|
|
Set Values = Nothing
|
|
On Error Resume Next
|
|
Values = Eval("Target." & CStr(FieldName))
|
|
RetryNumber = Err.Number
|
|
RetryDescription = Err.Description
|
|
RetrySource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If RetryNumber <> 0 Then
|
|
DxBridgeSetApiFailure Failure, Operation, RetryNumber, RetrySource, _
|
|
RetryDescription
|
|
Exit Function
|
|
End If
|
|
DxBridgeReadCollection = DxBridgeCollectItems(Values, Operation, Items, _
|
|
ItemCount, Failure)
|
|
End Function
|
|
|
|
Function DxBridgeCollectItems(ByRef Values, ByVal Operation, ByRef Items, _
|
|
ByRef ItemCount, ByRef Failure)
|
|
Dim Item
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Dim LowerBound
|
|
Dim UpperBound
|
|
Dim Index
|
|
ItemCount = 0
|
|
ReDim Items(0)
|
|
DxBridgeCollectItems = False
|
|
If IsArray(Values) Then
|
|
On Error Resume Next
|
|
LowerBound = LBound(Values)
|
|
UpperBound = UBound(Values)
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetApiFailure Failure, Operation, ErrorNumber, _
|
|
ErrorSource, ErrorDescription
|
|
Exit Function
|
|
End If
|
|
For Index = LowerBound To UpperBound
|
|
If ItemCount > 0 Then ReDim Preserve Items(ItemCount)
|
|
If IsObject(Values(Index)) Then
|
|
Set Items(ItemCount) = Values(Index)
|
|
Else
|
|
Items(ItemCount) = Values(Index)
|
|
End If
|
|
ItemCount = ItemCount + 1
|
|
Next
|
|
DxBridgeCollectItems = True
|
|
Exit Function
|
|
End If
|
|
|
|
ErrorNumber = 0
|
|
ErrorDescription = ""
|
|
ErrorSource = ""
|
|
On Error Resume Next
|
|
For Each Item In Values
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
ItemCount = 0
|
|
DxBridgeSetApiFailure Failure, Operation, ErrorNumber, _
|
|
ErrorSource, ErrorDescription
|
|
Exit Function
|
|
End If
|
|
If ItemCount > 0 Then ReDim Preserve Items(ItemCount)
|
|
If IsObject(Item) Then
|
|
Set Items(ItemCount) = Item
|
|
Else
|
|
Items(ItemCount) = Item
|
|
End If
|
|
ItemCount = ItemCount + 1
|
|
On Error Resume Next
|
|
Next
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
ItemCount = 0
|
|
DxBridgeSetApiFailure Failure, Operation, ErrorNumber, ErrorSource, _
|
|
ErrorDescription
|
|
Else
|
|
DxBridgeCollectItems = True
|
|
End If
|
|
End Function
|
|
|
|
Function DxBridgeBuildSnapshot(ByRef Command, ByRef LiveMap, _
|
|
ByRef SnapshotText, ByRef Fingerprint, ByRef Failure)
|
|
Dim ProjectPath
|
|
Dim ActualProjectId
|
|
Dim ComponentItems
|
|
Dim ComponentCount
|
|
Dim Index
|
|
Dim Component
|
|
Dim Groups
|
|
Dim LogicalKey
|
|
Dim PartNumber
|
|
Dim RefDes
|
|
Dim Hierarchy
|
|
Dim UnitCountValue
|
|
Dim SymbolName
|
|
Dim OriginX
|
|
Dim OriginY
|
|
Dim PositionX
|
|
Dim PositionY
|
|
Dim Rotation
|
|
Dim Mirrored
|
|
Dim AttributesJson
|
|
Dim UnitId
|
|
Dim UnitJson
|
|
Dim Group
|
|
Dim Objects
|
|
Dim Units
|
|
Dim ComponentsJson
|
|
Dim SemanticJson
|
|
Dim GroupKeys
|
|
Dim KeyIndex
|
|
|
|
Set LiveMap = CreateObject("Scripting.Dictionary")
|
|
If Not DxBridgeReadScalar(Application, "ProjectPath", _
|
|
"Application.ProjectPath", ProjectPath, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If VarType(ProjectPath) <> vbString Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Active project identity is not a string", _
|
|
"Application.ProjectPath", 0, "", ""
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Len(Trim(ProjectPath)) = 0 Then
|
|
DxBridgeSetFailure Failure, "project_identity_missing", _
|
|
"Active project identity is empty", "Application.ProjectPath", _
|
|
0, "", ""
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeProjectId(CStr(ProjectPath), ActualProjectId, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If StrComp(ActualProjectId, CStr(Command("project_id")), _
|
|
vbBinaryCompare) <> 0 Then
|
|
DxBridgeSetFailure Failure, "project_identity_mismatch", _
|
|
"Active project does not match the bridge command", _
|
|
"project.identity", 0, "", ""
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadCollection(Application, "DesignComponents", _
|
|
"Application.DesignComponents", ComponentItems, ComponentCount, _
|
|
Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
Set Groups = CreateObject("Scripting.Dictionary")
|
|
For Index = 0 To ComponentCount - 1
|
|
If Not IsObject(ComponentItems(Index)) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Component collection contains a non-object value", _
|
|
"Application.DesignComponents", 0, "", ""
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
Set Component = ComponentItems(Index)
|
|
If Not DxBridgeReadRequiredString(Component, "LogicalIdentity", _
|
|
"component.LogicalIdentity", LogicalKey, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredString(Component, "PartNumber", _
|
|
"component.PartNumber", PartNumber, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredString(Component, "RefDes", _
|
|
"component.RefDes", RefDes, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredString(Component, "Hierarchy", _
|
|
"component.Hierarchy", Hierarchy, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadScalar(Component, "Units", "component.Units", _
|
|
UnitCountValue, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsProtocolInteger(UnitCountValue) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Component unit count is invalid", "component.Units", _
|
|
0, "", ""
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If CLng(UnitCountValue) < 1 Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Component unit count is invalid", "component.Units", _
|
|
0, "", ""
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredString(Component, "SymbolName", _
|
|
"component.SymbolName", SymbolName, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredNumber(Component, "OriginX", _
|
|
"component.OriginX", OriginX, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredNumber(Component, "OriginY", _
|
|
"component.OriginY", OriginY, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredNumber(Component, "X", _
|
|
"component.X", PositionX, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredNumber(Component, "Y", _
|
|
"component.Y", PositionY, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadScalar(Component, "Rotation", _
|
|
"component.Rotation", Rotation, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeIsProtocolInteger(Rotation) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Component rotation is not an integer", _
|
|
"component.Rotation", 0, "", ""
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadScalar(Component, "Mirrored", _
|
|
"component.Mirrored", Mirrored, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If VarType(Mirrored) <> vbBoolean Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Component mirror state is not a Boolean", _
|
|
"component.Mirrored", 0, "", ""
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeSerializeAttributes(Component, AttributesJson, _
|
|
Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeUnitIdentity(Component, UnitId, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeSerializeUnit(Component, UnitId, Hierarchy, SymbolName, _
|
|
OriginX, OriginY, PositionX, PositionY, Rotation, Mirrored, _
|
|
UnitJson, _
|
|
Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
|
|
If Not Groups.Exists(LogicalKey) Then
|
|
Set Group = CreateObject("Scripting.Dictionary")
|
|
Group.Add "part_number", PartNumber
|
|
Group.Add "refdes", RefDes
|
|
Group.Add "attributes", AttributesJson
|
|
Set Objects = New DxBridgeJsonArray
|
|
Group.Add "objects", Objects
|
|
Set Units = CreateObject("Scripting.Dictionary")
|
|
Group.Add "units", Units
|
|
Groups.Add LogicalKey, Group
|
|
LiveMap.Add LogicalKey, Objects
|
|
Else
|
|
Set Group = Groups(LogicalKey)
|
|
If CStr(Group("part_number")) <> PartNumber Or _
|
|
CStr(Group("refdes")) <> RefDes Or _
|
|
CStr(Group("attributes")) <> AttributesJson Then
|
|
DxBridgeSetFailure Failure, "ambiguous_logical_identity", _
|
|
"Objects sharing a logical key disagree on identity fields", _
|
|
"component.logical_key", 0, "", ""
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
Set Objects = Group("objects")
|
|
Set Units = Group("units")
|
|
End If
|
|
If Units.Exists(UnitId) Then
|
|
DxBridgeSetFailure Failure, "duplicate_unit_identity", _
|
|
"Logical component has a duplicate unit identity", _
|
|
"component.unit_id", 0, "", ""
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
Units.Add UnitId, UnitJson
|
|
Objects.Add Component
|
|
Next
|
|
|
|
ComponentsJson = "["
|
|
GroupKeys = DxBridgeSortedKeys(Groups)
|
|
For KeyIndex = 0 To Groups.Count - 1
|
|
LogicalKey = CStr(GroupKeys(KeyIndex))
|
|
Set Group = Groups(LogicalKey)
|
|
Set Units = Group("units")
|
|
If KeyIndex > 0 Then ComponentsJson = ComponentsJson & ","
|
|
ComponentsJson = ComponentsJson & "{""attributes"":" & _
|
|
CStr(Group("attributes")) & ",""logical_key"":" & _
|
|
DxBridgeJsonString(LogicalKey) & ",""part_number"":" & _
|
|
DxBridgeJsonString(Group("part_number")) & ",""refdes"":" & _
|
|
DxBridgeJsonString(Group("refdes")) & ",""units"":" & _
|
|
DxBridgeJsonDictionaryValues(Units) & "}"
|
|
Next
|
|
ComponentsJson = ComponentsJson & "]"
|
|
SemanticJson = "{""components"":" & ComponentsJson & _
|
|
",""format_version"":2,""project_id"":" & _
|
|
DxBridgeJsonString(Command("project_id")) & _
|
|
",""project_path"":" & DxBridgeJsonString(ProjectPath) & "}"
|
|
If Not DxBridgeSha256(SemanticJson, Fingerprint, Failure) Then
|
|
DxBridgeBuildSnapshot = False
|
|
Exit Function
|
|
End If
|
|
SnapshotText = "{""components"":" & ComponentsJson & _
|
|
",""fingerprint"":" & DxBridgeJsonString(Fingerprint) & _
|
|
",""format_version"":2,""project_id"":" & _
|
|
DxBridgeJsonString(Command("project_id")) & _
|
|
",""project_path"":" & DxBridgeJsonString(ProjectPath) & "}" & vbLf
|
|
DxBridgeBuildSnapshot = True
|
|
End Function
|
|
|
|
Function DxBridgeReadRequiredString(ByRef Target, ByVal FieldName, _
|
|
ByVal Operation, ByRef Value, ByRef Failure)
|
|
If Not DxBridgeReadScalar(Target, FieldName, Operation, Value, Failure) Then
|
|
DxBridgeReadRequiredString = False
|
|
Exit Function
|
|
End If
|
|
If VarType(Value) <> vbString Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Required component identity field is not a string", Operation, _
|
|
0, "", ""
|
|
DxBridgeReadRequiredString = False
|
|
Exit Function
|
|
End If
|
|
If Len(Trim(Value)) = 0 Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Required component identity field is empty", Operation, _
|
|
0, "", ""
|
|
DxBridgeReadRequiredString = False
|
|
Exit Function
|
|
End If
|
|
Value = CStr(Value)
|
|
DxBridgeReadRequiredString = True
|
|
End Function
|
|
|
|
Function DxBridgeReadRequiredNumber(ByRef Target, ByVal FieldName, _
|
|
ByVal Operation, ByRef Value, ByRef Failure)
|
|
If Not DxBridgeReadScalar(Target, FieldName, Operation, Value, Failure) Then
|
|
DxBridgeReadRequiredNumber = False
|
|
Exit Function
|
|
End If
|
|
If IsObject(Value) Or IsNull(Value) Or IsEmpty(Value) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Required coordinate is not numeric", Operation, 0, "", ""
|
|
DxBridgeReadRequiredNumber = False
|
|
Exit Function
|
|
End If
|
|
If Not IsNumeric(Value) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Required coordinate is not numeric", Operation, 0, "", ""
|
|
DxBridgeReadRequiredNumber = False
|
|
Exit Function
|
|
End If
|
|
DxBridgeReadRequiredNumber = True
|
|
End Function
|
|
|
|
Function DxBridgeSerializeAttributes(ByRef Component, ByRef Result, _
|
|
ByRef Failure)
|
|
Dim Items
|
|
Dim Count
|
|
Dim Index
|
|
Dim Attribute
|
|
Dim Name
|
|
Dim Value
|
|
Dim Records
|
|
If Not DxBridgeReadCollection(Component, "Attributes", _
|
|
"component.Attributes", Items, Count, Failure) Then
|
|
DxBridgeSerializeAttributes = False
|
|
Exit Function
|
|
End If
|
|
Set Records = CreateObject("Scripting.Dictionary")
|
|
For Index = 0 To Count - 1
|
|
If Not IsObject(Items(Index)) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Attribute collection contains a non-object value", _
|
|
"component.Attributes", 0, "", ""
|
|
DxBridgeSerializeAttributes = False
|
|
Exit Function
|
|
End If
|
|
Set Attribute = Items(Index)
|
|
If Not DxBridgeReadRequiredString(Attribute, "Name", _
|
|
"component.Attributes.Name", Name, Failure) Then
|
|
DxBridgeSerializeAttributes = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadScalar(Attribute, "Value", _
|
|
"component.Attributes.Value", Value, Failure) Then
|
|
DxBridgeSerializeAttributes = False
|
|
Exit Function
|
|
End If
|
|
If IsNull(Value) Or IsEmpty(Value) Then Value = ""
|
|
If IsObject(Value) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Attribute value is not scalar", _
|
|
"component.Attributes.Value", 0, "", ""
|
|
DxBridgeSerializeAttributes = False
|
|
Exit Function
|
|
End If
|
|
If Records.Exists(Name) Then
|
|
DxBridgeSetFailure Failure, "duplicate_attribute_name", _
|
|
"Component has a duplicate attribute name", _
|
|
"component.Attributes.Name", 0, "", ""
|
|
DxBridgeSerializeAttributes = False
|
|
Exit Function
|
|
End If
|
|
Records.Add Name, "{""name"":" & DxBridgeJsonString(Name) & _
|
|
",""value"":" & DxBridgeJsonString(CStr(Value)) & "}"
|
|
Next
|
|
Result = DxBridgeJsonDictionaryValues(Records)
|
|
DxBridgeSerializeAttributes = True
|
|
End Function
|
|
|
|
Function DxBridgeUnitIdentity(ByRef Component, ByRef UnitId, ByRef Failure)
|
|
Dim Gates
|
|
Dim Count
|
|
Dim Gate
|
|
Dim Name
|
|
Dim Number
|
|
If Not DxBridgeReadCollection(Component, "Gates", "component.Gates", _
|
|
Gates, Count, Failure) Then
|
|
DxBridgeUnitIdentity = False
|
|
Exit Function
|
|
End If
|
|
If Count <> 1 Then
|
|
DxBridgeSetFailure Failure, "ambiguous_unit_identity", _
|
|
"Each placed object must expose exactly one gate identity", _
|
|
"component.Gates", 0, "", ""
|
|
DxBridgeUnitIdentity = False
|
|
Exit Function
|
|
End If
|
|
If Not IsObject(Gates(0)) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Gate collection contains a non-object value", _
|
|
"component.Gates", 0, "", ""
|
|
DxBridgeUnitIdentity = False
|
|
Exit Function
|
|
End If
|
|
Set Gate = Gates(0)
|
|
If Not DxBridgeReadScalar(Gate, "Name", "component.Gates.Name", _
|
|
Name, Failure) Then
|
|
DxBridgeUnitIdentity = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadScalar(Gate, "UnitNumber", _
|
|
"component.Gates.UnitNumber", Number, Failure) Then
|
|
DxBridgeUnitIdentity = False
|
|
Exit Function
|
|
End If
|
|
If IsObject(Name) Or IsNull(Name) Or IsEmpty(Name) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Gate name has an invalid type", "component.Gates.Name", _
|
|
0, "", ""
|
|
DxBridgeUnitIdentity = False
|
|
Exit Function
|
|
End If
|
|
If VarType(Name) <> vbString Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Gate name has an invalid type", "component.Gates.Name", _
|
|
0, "", ""
|
|
DxBridgeUnitIdentity = False
|
|
Exit Function
|
|
End If
|
|
If Len(Trim(Name)) > 0 Then
|
|
UnitId = Name
|
|
ElseIf DxBridgeIsProtocolInteger(Number) Then
|
|
UnitId = DxInvariantNumber(Number)
|
|
Else
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Gate identity is empty", "component.Gates", 0, "", ""
|
|
DxBridgeUnitIdentity = False
|
|
Exit Function
|
|
End If
|
|
DxBridgeUnitIdentity = True
|
|
End Function
|
|
|
|
Function DxBridgeSerializeUnit(ByRef Component, ByVal UnitId, _
|
|
ByVal Hierarchy, ByVal SymbolName, ByVal OriginX, ByVal OriginY, _
|
|
ByVal PositionX, ByVal PositionY, ByVal Rotation, ByVal Mirrored, _
|
|
ByRef Result, ByRef Failure)
|
|
Dim PinsJson
|
|
If Not DxBridgeSerializePins(Component, PinsJson, Failure) Then
|
|
DxBridgeSerializeUnit = False
|
|
Exit Function
|
|
End If
|
|
Result = "{""mirrored"":" & DxBridgeBoolean(Mirrored) & _
|
|
",""origin_x"":" & _
|
|
DxBridgeJsonString(DxInvariantNumber(OriginX)) & _
|
|
",""origin_y"":" & _
|
|
DxBridgeJsonString(DxInvariantNumber(OriginY)) & _
|
|
",""pins"":" & PinsJson & ",""rotation"":" & _
|
|
DxInvariantNumber(CLng(Rotation)) & ",""sheet"":" & _
|
|
DxBridgeJsonString(Hierarchy) & ",""symbol"":" & _
|
|
DxBridgeJsonString(SymbolName) & ",""unit_id"":" & _
|
|
DxBridgeJsonString(UnitId) & ",""x"":" & _
|
|
DxBridgeJsonString(DxInvariantNumber(PositionX)) & ",""y"":" & _
|
|
DxBridgeJsonString(DxInvariantNumber(PositionY)) & "}"
|
|
DxBridgeSerializeUnit = True
|
|
End Function
|
|
|
|
Function DxBridgeSerializePins(ByRef Component, ByRef Result, ByRef Failure)
|
|
Dim PinItems
|
|
Dim PinCount
|
|
Dim NetItems
|
|
Dim NetCount
|
|
Dim Nets
|
|
Dim Index
|
|
Dim Pin
|
|
Dim Number
|
|
Dim Name
|
|
Dim X
|
|
Dim Y
|
|
Dim NetIdentity
|
|
Dim NetJson
|
|
Dim Records
|
|
If Not DxBridgeReadCollection(Component, "Nets", "component.Nets", _
|
|
NetItems, NetCount, Failure) Then
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
Set Nets = CreateObject("Scripting.Dictionary")
|
|
For Index = 0 To NetCount - 1
|
|
If IsObject(NetItems(Index)) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Net collection contains a non-string value", _
|
|
"component.Nets", 0, "", ""
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
If VarType(NetItems(Index)) <> vbString Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Net collection contains a non-string value", _
|
|
"component.Nets", 0, "", ""
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
Nets(NetItems(Index)) = True
|
|
Next
|
|
If Not DxBridgeReadCollection(Component, "Pins", "component.Pins", _
|
|
PinItems, PinCount, Failure) Then
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
If PinCount = 0 Then
|
|
DxBridgeSetFailure Failure, "missing_pin_data", _
|
|
"Placed unit exposes no pin evidence", "component.Pins", _
|
|
0, "", ""
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
Set Records = CreateObject("Scripting.Dictionary")
|
|
For Index = 0 To PinCount - 1
|
|
If Not IsObject(PinItems(Index)) Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Pin collection contains a non-object value", _
|
|
"component.Pins", 0, "", ""
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
Set Pin = PinItems(Index)
|
|
If Not DxBridgeReadRequiredString(Pin, "Number", _
|
|
"component.Pins.Number", Number, Failure) Then
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredString(Pin, "Name", _
|
|
"component.Pins.Name", Name, Failure) Then
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredNumber(Pin, "X", _
|
|
"component.Pins.X", X, Failure) Then
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadRequiredNumber(Pin, "Y", _
|
|
"component.Pins.Y", Y, Failure) Then
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
If Not DxBridgeReadScalar(Pin, "NetIdentity", _
|
|
"component.Pins.NetIdentity", NetIdentity, Failure) Then
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
If Records.Exists(Number) Then
|
|
DxBridgeSetFailure Failure, "duplicate_pin_number", _
|
|
"Placed unit has a duplicate pin number", _
|
|
"component.Pins.Number", 0, "", ""
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
If IsNull(NetIdentity) Then
|
|
NetJson = "null"
|
|
ElseIf IsEmpty(NetIdentity) Then
|
|
NetJson = "null"
|
|
Else
|
|
If VarType(NetIdentity) <> vbString Then
|
|
DxBridgeSetFailure Failure, "missing_protected_field", _
|
|
"Pin net identity is not a string or null", _
|
|
"component.Pins.NetIdentity", 0, "", ""
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
End If
|
|
If Len(NetIdentity) = 0 Then
|
|
NetJson = "null"
|
|
ElseIf Not Nets.Exists(NetIdentity) Then
|
|
DxBridgeSetFailure Failure, "missing_net_data", _
|
|
"Pin net identity is absent from component net evidence", _
|
|
"component.Pins.NetIdentity", 0, "", ""
|
|
DxBridgeSerializePins = False
|
|
Exit Function
|
|
Else
|
|
NetJson = DxBridgeJsonString(NetIdentity)
|
|
End If
|
|
End If
|
|
Records.Add Number, "{""name"":" & DxBridgeJsonString(Name) & _
|
|
",""net"":" & NetJson & ",""number"":" & _
|
|
DxBridgeJsonString(Number) & ",""x"":" & _
|
|
DxBridgeJsonString(DxInvariantNumber(X)) & ",""y"":" & _
|
|
DxBridgeJsonString(DxInvariantNumber(Y)) & "}"
|
|
Next
|
|
Result = DxBridgeJsonDictionaryValues(Records)
|
|
DxBridgeSerializePins = True
|
|
End Function
|
|
|
|
Function DxBridgeSortedKeys(ByRef Dictionary)
|
|
Dim Keys
|
|
Dim LeftIndex
|
|
Dim RightIndex
|
|
Dim Temporary
|
|
Keys = Dictionary.Keys
|
|
For LeftIndex = 0 To Dictionary.Count - 2
|
|
For RightIndex = LeftIndex + 1 To Dictionary.Count - 1
|
|
If StrComp(CStr(Keys(LeftIndex)), CStr(Keys(RightIndex)), _
|
|
vbBinaryCompare) > 0 Then
|
|
Temporary = Keys(LeftIndex)
|
|
Keys(LeftIndex) = Keys(RightIndex)
|
|
Keys(RightIndex) = Temporary
|
|
End If
|
|
Next
|
|
Next
|
|
DxBridgeSortedKeys = Keys
|
|
End Function
|
|
|
|
Function DxBridgeJsonDictionaryValues(ByRef Dictionary)
|
|
Dim Keys
|
|
Dim Index
|
|
Dim Result
|
|
Result = "["
|
|
Keys = DxBridgeSortedKeys(Dictionary)
|
|
For Index = 0 To Dictionary.Count - 1
|
|
If Index > 0 Then Result = Result & ","
|
|
Result = Result & CStr(Dictionary(CStr(Keys(Index))))
|
|
Next
|
|
DxBridgeJsonDictionaryValues = Result & "]"
|
|
End Function
|
|
|
|
Function DxBridgeProjectId(ByVal ProjectPath, ByRef ProjectId, ByRef Failure)
|
|
Dim Fso
|
|
Dim Identity
|
|
Dim HashValue
|
|
Set Fso = CreateObject("Scripting.FileSystemObject")
|
|
Identity = LCase(Replace(Fso.GetAbsolutePathName(CStr(ProjectPath)), _
|
|
"/", "\"))
|
|
If Not DxBridgeSha256(Identity, HashValue, Failure) Then
|
|
DxBridgeProjectId = False
|
|
Exit Function
|
|
End If
|
|
ProjectId = Left(HashValue, 16)
|
|
DxBridgeProjectId = True
|
|
End Function
|
|
|
|
Function DxBridgeSha256(ByVal Text, ByRef HashValue, ByRef Failure)
|
|
Dim Fso
|
|
Dim Shell
|
|
Dim TemporaryFolder
|
|
Dim ParentPath
|
|
Dim InputPath
|
|
Dim OutputPath
|
|
Dim CommandLine
|
|
Dim ExitCode
|
|
Dim Reader
|
|
Dim OutputText
|
|
Dim Lines
|
|
Dim Line
|
|
Dim Candidate
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Set Fso = CreateObject("Scripting.FileSystemObject")
|
|
Set TemporaryFolder = Fso.GetSpecialFolder(2)
|
|
ParentPath = TemporaryFolder.Path
|
|
InputPath = Fso.BuildPath(ParentPath, Fso.GetTempName)
|
|
OutputPath = Fso.BuildPath(ParentPath, Fso.GetTempName)
|
|
On Error Resume Next
|
|
DxBridgeWriteUtf8Atomic InputPath, Text
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetFailure Failure, "hash_error", _
|
|
"Cannot stage canonical fingerprint input", _
|
|
"hash.stage", ErrorNumber, ErrorSource, ErrorDescription
|
|
DxBridgeSha256 = False
|
|
Exit Function
|
|
End If
|
|
Set Shell = CreateObject("WScript.Shell")
|
|
CommandLine = DxCommandQuote(Shell.ExpandEnvironmentStrings( _
|
|
"%SystemRoot%\System32\certutil.exe")) & " -hashfile " & _
|
|
DxCommandQuote(InputPath) & " SHA256 > " & _
|
|
DxCommandQuote(OutputPath) & " 2>&1"
|
|
On Error Resume Next
|
|
ExitCode = Shell.Run(Shell.ExpandEnvironmentStrings("%ComSpec%") & _
|
|
" /d /s /c " & Chr(34) & CommandLine & Chr(34), 0, True)
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Or ExitCode <> 0 Then
|
|
DxBridgeSetFailure Failure, "hash_error", _
|
|
"SHA-256 utility failed", "hash.certutil", ErrorNumber, _
|
|
ErrorSource, ErrorDescription
|
|
DxBridgeDeleteFile InputPath
|
|
DxBridgeDeleteFile OutputPath
|
|
DxBridgeSha256 = False
|
|
Exit Function
|
|
End If
|
|
On Error Resume Next
|
|
Set Reader = Fso.OpenTextFile(OutputPath, 1, False, 0)
|
|
OutputText = Reader.ReadAll
|
|
Reader.Close
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetFailure Failure, "hash_error", _
|
|
"Cannot read SHA-256 utility output", "hash.output", _
|
|
ErrorNumber, ErrorSource, ErrorDescription
|
|
DxBridgeDeleteFile InputPath
|
|
DxBridgeDeleteFile OutputPath
|
|
DxBridgeSha256 = False
|
|
Exit Function
|
|
End If
|
|
HashValue = ""
|
|
Lines = Split(Replace(OutputText, vbCr, ""), vbLf)
|
|
For Each Line In Lines
|
|
Candidate = LCase(Replace(Replace(Trim(CStr(Line)), " ", ""), _
|
|
vbTab, ""))
|
|
If Len(Candidate) = 64 And DxBridgeIsHex(Candidate) Then
|
|
HashValue = Candidate
|
|
Exit For
|
|
End If
|
|
Next
|
|
DxBridgeDeleteFile InputPath
|
|
DxBridgeDeleteFile OutputPath
|
|
If Len(HashValue) <> 64 Then
|
|
DxBridgeSetFailure Failure, "hash_error", _
|
|
"SHA-256 utility did not return a hash", "hash.output", _
|
|
0, "", ""
|
|
DxBridgeSha256 = False
|
|
Else
|
|
DxBridgeSha256 = True
|
|
End If
|
|
End Function
|
|
|
|
Sub DxBridgeDeleteFile(ByVal FilePath)
|
|
Dim Fso
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Set Fso = CreateObject("Scripting.FileSystemObject")
|
|
On Error Resume Next
|
|
If Fso.FileExists(FilePath) Then Fso.DeleteFile FilePath, True
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
Err.Raise ErrorNumber, ErrorSource, ErrorDescription
|
|
End If
|
|
End Sub
|
|
|
|
Sub DxBridgeWriteUtf8Atomic(ByVal FilePath, ByVal Text)
|
|
Dim Fso
|
|
Dim TextStream
|
|
Dim BinaryStream
|
|
Dim Shell
|
|
Dim ParentPath
|
|
Dim TemporaryPath
|
|
Dim CommandLine
|
|
Dim ExitCode
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
Set Fso = CreateObject("Scripting.FileSystemObject")
|
|
ParentPath = Fso.GetParentFolderName(Fso.GetAbsolutePathName(CStr(FilePath)))
|
|
If Not Fso.FolderExists(ParentPath) Then
|
|
Err.Raise vbObjectError + 836, "DxBridgeWriteUtf8Atomic", _
|
|
"Destination directory does not exist"
|
|
End If
|
|
TemporaryPath = Fso.BuildPath(ParentPath, Fso.GetTempName)
|
|
Set TextStream = CreateObject("ADODB.Stream")
|
|
TextStream.Type = 2
|
|
TextStream.Charset = "utf-8"
|
|
TextStream.Open
|
|
TextStream.WriteText CStr(Text)
|
|
TextStream.Position = 0
|
|
TextStream.Type = 1
|
|
TextStream.Position = 3
|
|
Set BinaryStream = CreateObject("ADODB.Stream")
|
|
BinaryStream.Type = 1
|
|
BinaryStream.Open
|
|
TextStream.CopyTo BinaryStream
|
|
On Error Resume Next
|
|
BinaryStream.SaveToFile TemporaryPath, 2
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
BinaryStream.Close
|
|
TextStream.Close
|
|
If ErrorNumber <> 0 Then
|
|
Err.Raise ErrorNumber, ErrorSource, ErrorDescription
|
|
End If
|
|
Set Shell = CreateObject("WScript.Shell")
|
|
CommandLine = DxCommandQuote(Shell.ExpandEnvironmentStrings("%ComSpec%")) & _
|
|
" /d /s /c " & Chr(34) & "move /y " & _
|
|
DxCommandQuote(TemporaryPath) & " " & _
|
|
DxCommandQuote(Fso.GetAbsolutePathName(CStr(FilePath))) & _
|
|
" >nul" & Chr(34)
|
|
On Error Resume Next
|
|
ExitCode = Shell.Run(CommandLine, 0, True)
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Or ExitCode <> 0 Then
|
|
DxBridgeDeleteFile TemporaryPath
|
|
If ErrorNumber <> 0 Then
|
|
Err.Raise ErrorNumber, ErrorSource, ErrorDescription
|
|
Else
|
|
Err.Raise vbObjectError + 837, "DxBridgeWriteUtf8Atomic", _
|
|
"Cannot atomically replace destination file"
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Function DxBridgeWriteDocument(ByVal FilePath, ByVal Text, _
|
|
ByVal Operation, ByRef Failure)
|
|
Dim ErrorNumber
|
|
Dim ErrorDescription
|
|
Dim ErrorSource
|
|
On Error Resume Next
|
|
DxBridgeWriteUtf8Atomic FilePath, Text
|
|
ErrorNumber = Err.Number
|
|
ErrorDescription = Err.Description
|
|
ErrorSource = Err.Source
|
|
Err.Clear
|
|
On Error GoTo 0
|
|
If ErrorNumber <> 0 Then
|
|
DxBridgeSetFailure Failure, "protocol_file", _
|
|
"Cannot publish bridge document", Operation, ErrorNumber, _
|
|
ErrorSource, ErrorDescription
|
|
DxBridgeWriteDocument = False
|
|
Else
|
|
DxBridgeWriteDocument = True
|
|
End If
|
|
End Function
|
|
|
|
Function DxBridgeJsonString(ByVal Value)
|
|
DxBridgeJsonString = Chr(34) & DxJsonEscape(CStr(Value)) & Chr(34)
|
|
End Function
|
|
|
|
Function DxBridgeBoolean(ByVal Value)
|
|
If CBool(Value) Then
|
|
DxBridgeBoolean = "true"
|
|
Else
|
|
DxBridgeBoolean = "false"
|
|
End If
|
|
End Function
|
|
|
|
Sub DxBridgePublishFailure(ByVal StatusPath, ByRef Command, ByRef Failure)
|
|
Dim Details
|
|
Set Details = CreateObject("Scripting.Dictionary")
|
|
Details.Add "error_description", CStr(Failure("description"))
|
|
Details.Add "error_number", DxInvariantNumber(Failure("number"))
|
|
Details.Add "error_source", CStr(Failure("source"))
|
|
Details.Add "operation", CStr(Failure("operation"))
|
|
DxBridgePublishStatus StatusPath, Command, "blocked", Null, _
|
|
CStr(Failure("code")), CStr(Failure("message")), Details
|
|
End Sub
|
|
|
|
Sub DxBridgePublishBareFailure(ByVal StatusPath, ByVal RequestedAction, _
|
|
ByRef Failure)
|
|
DxBridgePublishBareStatus StatusPath, RequestedAction, _
|
|
CStr(Failure("code")), CStr(Failure("message")) & ": " & _
|
|
CStr(Failure("description"))
|
|
End Sub
|
|
|
|
Sub DxBridgePublishBareStatus(ByVal StatusPath, ByVal RequestedAction, _
|
|
ByVal ErrorCode, ByVal ErrorMessage)
|
|
Dim Text
|
|
Text = "{""command_id"":"""",""details"":[[""action""," & _
|
|
DxBridgeJsonString(RequestedAction) & "],[""expected_count"",""0""]," & _
|
|
"[""job_id"",""""]],""error_code"":" & _
|
|
DxBridgeJsonString(ErrorCode) & ",""error_message"":" & _
|
|
DxBridgeJsonString(ErrorMessage) & ",""format_version"":1," & _
|
|
"""project_id"":"""",""snapshot_path"":null," & _
|
|
"""state"":""blocked""}" & vbLf
|
|
DxBridgeWriteUtf8Atomic StatusPath, Text
|
|
End Sub
|
|
|
|
Sub DxBridgePublishStatus(ByVal StatusPath, ByRef Command, ByVal State, _
|
|
ByVal SnapshotPath, ByVal ErrorCode, ByVal ErrorMessage, _
|
|
ByVal ExtraDetails)
|
|
Dim Details
|
|
Dim Keys
|
|
Dim Index
|
|
Dim Text
|
|
Details = "[[""action""," & DxBridgeJsonString(Command("action")) & _
|
|
"],[""expected_count""," & _
|
|
DxBridgeJsonString(DxInvariantNumber(Command("expected_count"))) & _
|
|
"],[""job_id""," & DxBridgeJsonString(Command("job_id")) & "]"
|
|
If IsObject(ExtraDetails) Then
|
|
Keys = DxBridgeSortedKeys(ExtraDetails)
|
|
For Index = 0 To ExtraDetails.Count - 1
|
|
Details = Details & ",[" & _
|
|
DxBridgeJsonString(CStr(Keys(Index))) & "," & _
|
|
DxBridgeJsonString(CStr(ExtraDetails(CStr(Keys(Index))))) & "]"
|
|
Next
|
|
End If
|
|
Details = Details & "]"
|
|
Text = "{""command_id"":" & DxBridgeJsonString(Command("command_id")) & _
|
|
",""details"":" & Details & ",""error_code"":" & _
|
|
DxBridgeNullableString(ErrorCode) & ",""error_message"":" & _
|
|
DxBridgeNullableString(ErrorMessage) & ",""format_version"":1," & _
|
|
"""project_id"":" & DxBridgeJsonString(Command("project_id")) & _
|
|
",""snapshot_path"":" & DxBridgeNullableString(SnapshotPath) & _
|
|
",""state"":" & DxBridgeJsonString(State) & "}" & vbLf
|
|
DxBridgeWriteUtf8Atomic StatusPath, Text
|
|
End Sub
|
|
|
|
Function DxBridgeNullableString(ByVal Value)
|
|
If IsNull(Value) Or IsEmpty(Value) Then
|
|
DxBridgeNullableString = "null"
|
|
Else
|
|
DxBridgeNullableString = DxBridgeJsonString(CStr(Value))
|
|
End If
|
|
End Function
|