Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Ian Mitchell on May 30, 2019, 10:11:27 pm
-
Does anyone have a code fragment - ideally in VB, but C# is fine - to take a string and make it into the base64 encoded, zipped thing which EA expects (in all kinds of places).
By trial & error I figured out how to decode it (see below) without using an intermediate file, using the iconic.zip function, but now I want to put stuff back into EA, and going backwards is always harder...
'Specialist function, where we know the content is some XML...
'To return the raw string, just miss-off the last line where xElement is created
Friend Function getXMLFromEABase64(s As String) As XElement
'initial content is a long gobbledegook string
Dim content As String = ""
'comments here are assumptions, based on what I see
Dim d1() As Byte = System.Convert.FromBase64String(s)
'd1 is now an array of bytes.
'make the byte array into a memoryStream.
'Doing this to avoid creating a file anywhere - do all in memory
Using ms As New System.IO.MemoryStream(d1)
'make the memory stream into a zip
Using zip As ZipFile = ZipFile.Read(ms)
Dim e As ZipEntry
For Each e In zip
'no idea what this is doing...
Dim ms2 As New MemoryStream
e.Extract(ms2)
content = System.Text.Encoding.ASCII.GetChars(ms2.GetBuffer)
'not sure why this is needed, but without it, it doesn't work....
content = content.Replace(Chr(0), "")
Return XElement.Parse(content)
Exit Function
Next
End Using
End Using
Return Nothing
End Function
-
Hi Ian,
I take it you weren't able to resolve this?
Does anybody have any other scripting solutions such as for VBScript or Javascript?
TIA,
Paolo
-
Look at the example scripts for one that uses an MSXML activex object. That should have the functions that you need.
-
Look at the example scripts for one that uses an MSXML ActiveX object. That should have the functions that you need.
Hi Eve,
Is there any way to search the scripts? I tried a few scripts at random, with no luck then gave up. Can anyone point me at the script(s) Eve refers to?
Paolo
-
There's not one that actually uses MSXML to write the binary data, but Local Scripts.VBScript - Model Search (Operations) Example uses MSXML.
Here's somewhere that includes both a VBScript implementation and an MSXML implementation.
https://stackoverflow.com/questions/496751/base64-encode-string-in-vbscript (https://stackoverflow.com/questions/496751/base64-encode-string-in-vbscript)
-
To search script
- Open a script
- select a word
- right click
- select the option "search in scripts"
There's probably another way to get there, but this is the easiest and most used.
A quick google got me this: https://stackoverflow.com/questions/496751/base64-encode-string-in-vbscript (https://stackoverflow.com/questions/496751/base64-encode-string-in-vbscript) which looks exactly what Eve was hinting at.
Geert
-
To search script
- Open a script
- select a word
- right-click
- select the option "search in scripts"
There's probably another way to get there, but this is the easiest and most used.
A quick google got me this: https://stackoverflow.com/questions/496751/base64-encode-string-in-vbscript (https://stackoverflow.com/questions/496751/base64-encode-string-in-vbscript) which looks exactly what Eve was hinting at.
Geert
A quick Google by me DIDN'T find that! (which is why I asked) I even tried within Stack Overflow and it didn't come up either! (Aren't moderated searches wonderful?)
Anyway, thanks to both you and Eve.
Paolo
BTW: I DO know how to search within scripts. ;) I was asking across scripts ("Find in Files")
-
It was the first result for: base64 msxml
Of course if you were searching for vbscript base64 it probably wouldn't have been.
-
BTW: I DO know how to search within scripts. ;) I was asking across scripts ("Find in Files")
"Search in Scripts" searches across scripts doesn't it?
Geert
PS. I had the weirdest bug in that function for a couple of days. When I used this, it searched for another word then the one I selected. Presumably a search term I had used in the past. Today it seems to be behaving again.
-
PS. I had the weirdest bug in that function for a couple of days. When I used this, it searched for another word then the one I selected. Presumably a search term I had used in the past. Today it seems to be behaving again.
Yeah, I've had that. It's weird.
/Uffe