Book a Demo

Author Topic: Importing Baseline in EA programatically  (Read 14936 times)

Arshad

  • EA User
  • **
  • Posts: 291
  • Karma: +21/-1
    • View Profile
Importing Baseline in EA programatically
« on: November 22, 2017, 05:16:21 pm »
For my requirement of comparing package with another model package , i need to import a baseline from one model to another model in EA.I know EA doesn't provide any direct API calls for importing baseline. Tried using *DoBaselineCompare*but it doesn't work .

So i exported baseline from one package using below code
Code: [Select]
Byte[] byteBLOBData = new Byte[0];
  byteBLOBData = Convert.FromBase64String(sValues);
  Stream data = new MemoryStream(byteBLOBData);
  Stream otherData = new MemoryStream();
  ZipArchive archive = new ZipArchive(data);
  foreach (ZipArchiveEntry entry in archive.Entries)
    if (entry.Name == "str.dat")
      otherData = entry.Open();
  MemoryStream ms = new MemoryStream();
  otherData.CopyTo(ms);
  byte[] bytesInStream = ms.ToArray(); // simpler way of converting to array
  XmlDocument doc = new XmlDocument();
  string sss = Encoding.Unicode.GetString(bytesInStream);
  doc.LoadXml(sss);
  doc.Save(@"C:\ExportedBaseline.xml");

And it get exported successfully in the given path. I just tried importing the baseline manually in a package to check whether it works , and its working perfectly . Now i need the same to do it programmatically .
  • How to create a blob data from that exported baseline file ?
  • If blob data is created i will just create a new value in t_document table and insert that blob content in BinContent property.
Can anyone suggest a way to import baseline into a package programmatically :( :o

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile

Arshad

  • EA User
  • **
  • Posts: 291
  • Karma: +21/-1
    • View Profile
Re: Importing Baseline in EA programatically
« Reply #2 on: November 22, 2017, 10:35:57 pm »
Hii Qwerty
I tried inserting an existing blob content into a new row and its getting inserted.
Even in the Baseline UI its getting displayed, but couldn't able to restore or import\export that baseline .

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Importing Baseline in EA programatically
« Reply #3 on: November 23, 2017, 12:47:21 am »
I'll have a look, but it might take a moment. How did you transfer the record?

q.

hugelsb

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
  • Modelling is the future!
    • View Profile
Re: Importing Baseline in EA programatically
« Reply #4 on: May 21, 2019, 01:24:50 am »
Does anyone have a solution for this?
I need a possibility to import baselines programmatically from an other project (database) in order to merge models finally.
Thanks to any hint.

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
Re: Importing Baseline in EA programatically
« Reply #5 on: May 22, 2019, 12:56:27 pm »
Does anyone have a solution for this?
I need a possibility to import baselines programmatically from an other project (database) in order to merge models finally.
Thanks to any hint.

Please don't create zombie threads.  If you have a question or an issue create your own thread with all of your context.

hugelsb

  • EA User
  • **
  • Posts: 20
  • Karma: +0/-0
  • Modelling is the future!
    • View Profile
Re: Importing Baseline in EA programatically
« Reply #6 on: September 04, 2019, 02:07:32 am »
I used the following code to import an XMI file as a Baseline. The used ZIP file is the result of the extracting the bin data of t_document.
But know I have the same behavior as Arshad posted.
Does someone managed to import XMI programmatically?

Code: [Select]
Sub createBaseline()
     Dim eaConn As New EAConnector

     Dim baselinePackGUID As String
     Dim docGUID As String
     Dim baselineVersion As String
     Dim baselineName As String
     Dim baselineNotes As String
     Dim baselineContent() As Byte

     Dim insertSql As String

     Dim strFilePath As String
     Dim objStream As New ADODB.Stream
     Const adTypeBinary = 1

     baselinePackGUID = "{CFABA5B2-D733-4b80-B761-EECDCA09BB45}"
     baselineVersion = "1.0.1"
     baselineName = "Merge Test"
     baselineNotes = "Notes of the Baseline"

     strFilePath = "C:\temp\zip\txt.zip" 'This is the path to the file on disk.

     'Set objStream = CreateObject("ADODB.Stream")
     objStream.Open
     objStream.Type = adTypeBinary
     objStream.LoadFromFile strFilePath
     baselineContent = objStream.Read

     docGUID = generateEA_GUID

     insertSql = "INSERT INTO t_document " & _
             "(DocID, DocName, ElementID, Version, Notes, BinContent, DocDate, ElementType, DocType,Style,isActive)" & _
             " VALUES ('" & docGUID & "','" & _
             baselineName & "','" & _
             baselinePackGUID & "','" & _
             baselineVersion & "','" & _
             baselineNotes & "','" & _
             EncodeBase64(baselineContent) & "'," & _
             "Now(),'" & _
            "Package','Baseline','Zip=1;',0)"
     Debug.Print (insertSql)
     Call eaConn.getRepository.Execute(insertSql)
     objStream.Close
End Sub 'createBaseline