GeertBellekens / Enterprise-Architect-Add-in-Framework

Framework for add-ins on Sparx Systems Enterprise Architect
http://geertbellekens.github.com/Enterprise-Architect-Add-in-Framework/
BSD 2-Clause "Simplified" License
70 stars 42 forks source link

Automatically replacing Session.Output with Repository.WriteOutput breaks existing scripts #16

Open MichPaule opened 7 months ago

MichPaule commented 7 months ago

Found in EA-Matic from EAToolPack V3.5.6.0 Introduced by merge: #15

For example: Call Session.Output(text) will be converted to Call Repository.WriteOutput "Script", text, 0 which raises the error: Error: Error in loading code for script 'test': Expected end of statement ERROR : Expected end of statement | Line of error: 0 | Code error: Call Repository.WriteOutput "Script", text, 0

The RegEx itself is unspecific as it also matches here:

Option Explicit
'EA-Matic
Dim test : test = "Call Session.Output test"

results in: Error: Error in loading code for script 'Profile Helpers.Test': Expected end of statement ERROR : Expected end of statement | Line of error: 7 | Code error: Dim test : test = "Call Repository.WriteOutput "Script", test", 0

Furthermore there exist environments where the Session object is available and furthermore shall be used to output text. Please remove the automatic replacement as there are better solutions available.

GeertBellekens commented 7 months ago

@MichPaule I can't see a scenario where using Session.Output in an EA-matic script would not lead to an error. We insert the Repository object into the context of the script controller, but not the session object. Can you explain in which circumstances the session object is available. I understand that there are edge cases that are not handled correctly, but I don't see an alternative for replacing Session.Output

MichPaule commented 7 months ago

@GeertBellekens For example you could create a script containing an implementation of Session class and then !INC into your script. A basic implementation might look like:

Class ISession
    Private m_SessionName
    Private m_UserName
    Private m_Version
    Private m_OutputCreated

    Public Default Function Constructor()
        m_SessionName = "Script"
        m_UserName = CreateObject("WScript.Network").UserName
        m_Version = "1.0"
        m_OutputCreated = FALSE
        Set Constructor = Me
    End Function

    Public Property Get UserName()
        UserName = m_UserName
    End Property

    Public Property Get Version()
        Version = m_Version
    End Property

    Public Sub Output(text)
        If (m_OutputCreated = FALSE) Then
            Call Repository.CreateOutputTab(m_SessionName)
            m_OutputCreated = TRUE
        End If
        Call Repository.EnsureOutputVisible(m_SessionName)
        Call Repository.WriteOutput(m_SessionName, text, 0)
    End Sub

    Public Function Input(prmpt)
        Input = InputBox(prmpt)
    End Function

    Public Function Prompt(prmpt, prmptType)
        Dim buttons
        Select Case prmptType
        Case 1  ' promptOK
            buttons = 0 ' vbOKOnly
        Case 2  ' promptYESNO
            buttons = 4 ' vbYesNo
        Case 3  ' promptYESNOCANCEL
            buttons = 3 ' vbYesNoCancel
        Case 4  ' promptOKCANCEL
            buttons = 1 ' vbOKCancel
        Case Else
            buttons = 0 ' vbOKOnly
        End Select
        Select Case MsgBox(prmpt, buttons, m_SessionName)
        Case 1  ' vbOK
            Prompt = 1  ' resultOK
        Case 2  ' vbCancel
            Prompt = 2  ' resultCancel
        Case 6  ' vbYes
            Prompt = 3  ' resultYes
        Case 7  ' vbNo
            Prompt = 4  ' resultNo
        Case Else
            Prompt = 1  ' resultOK
        End Select
    End Function
End Class

Dim Session : Set Session = (New ISession)()
MichPaule commented 7 months ago

In our environment we even redirect the Session.Output to a file depending on the use case.