Book a Demo

Author Topic: Problem importing/exporting imagess  (Read 3634 times)

RhysH

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Problem importing/exporting imagess
« on: November 22, 2013, 02:04:03 pm »
Hi All,

We are trying to share a project between a few members of our team, and have run into a problem importing and exporting images. When we export the XSI, the ImageID is written to the file:

<UML:DiagramElement <snip> style="ImageID=1395115689; <snip> "/>

We then export the images through the "Project"/"Model Import/Export"/"Export reference data" menu, which builds an XML of our images. If you look in the file, it has the same ImageID:

<Column name="ImageID" value="1395115689"/>
<Column name="Name" value="Server"/>
<Column name="Image" xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64">AQAAAGwAAAAAAAAA

So you can see that the ImageIDs match, and on that machine we can see the image in the diagram.

However, when we import the reference data on a second machine, the ImageIDs do not seem to be preserved, as a) the images don't show up in the diagrams, and b) if you export the images as reference data, you end up with the same file with different IDs:

<Column name="ImageID" value="115534508"/>
<Column name="Name" value="Server"/>
<Column name="Image" xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64">AQAAAGwAAAAAAAAA

Is there some way to import the image reference data keeping the IDs intact? Are we doing something wrong in exporting images as reference data and then trying to import them again on a separate machine?

Thanks.


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Problem importing/exporting imagess
« Reply #1 on: November 22, 2013, 09:44:13 pm »
I had this issue some 2 years ago (pretty sure I reported that). As it looks it is still not fixed :-(
What I did was to write a script to replace the regular import with my own which does restore the image id.

q.

P.S. Please go ahead and report this as bug.
« Last Edit: November 22, 2013, 09:45:00 pm by qwerty »

RhysH

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Problem importing/exporting imagess
« Reply #2 on: November 25, 2013, 09:23:41 am »
Thanks for the reply, Q.

I have submitted this as a bug. I guess in the meantime we will write our own script too

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Problem importing/exporting imagess
« Reply #3 on: November 25, 2013, 07:12:10 pm »
Don't know if that helps, but here's my Perl script:
Code: [Select]
use strict;
no strict 'refs';
use Win32::OLE qw (in);
use XML::Simple;
use MIME::Base64 ();
use DBI;

my %tableData =
  ('t_image' => {PRIMARY => 'ImageID', COLUMNS => ['Type', 'Name', 'ImageID', 'Image']},
   't_propertytypes' => {PRIMARY => 'Property', COLUMNS => ['Property', 'Description', 'Notes']},
   't_statustypes' => {PRIMARY => 'Status', COLUMNS => ['Status', 'Description']});

my $rep = $ENV{'REP'};

my $dbName = $rep->ConnectionString;
my $dbi;
if ($dbName =~ /\.eap$/i) { $dbi = "dbi:ADO:Data Source=$dbName;Provider=Microsoft.Jet.OLEDB.4.0" }
elsif ($dbName =~ /Data Source=([^;]*)/) { $dbi = "dbi:ODBC:$1" }
else { die "can not figure out DB type from $dbName" }
my $dbh = DBI->connect($dbi, "") or die "Can't connect to $dbi";

my $fn = $rep->xmiPath($rep->GetTreeSelectedObject()) . 'RefData.xml';

my $xs = XML::Simple->new(); # convert the XML return string into a hash
my $ref = $xs->XMLin($fn);

for my $key (keys %{$ref->{'DataSet'}}) {
  import ($ref->{'DataSet'}->{$key});
}

return 1;

sub import {
  my $data = shift;
  my $table = $data->{'table'};
  my $primary = $tableData{$table}->{PRIMARY} or return;

  my %xref;
  my $columns = "`" . join ("`, `", @{$tableData{$table}->{COLUMNS}}) . "`";
  my $sth;
  $sth = $dbh->prepare("delete * from $table where 1");
  $sth->execute();

  if (ref ($data->{'DataRow'}) eq "HASH") {
    $data->{'DataRow'} = [$data->{'DataRow'}];
  }
  for (in @{$data->{'DataRow'}}) {
    my $row = $_->{ 'Column'};
    next if $#{$tableData{$table}->{COLUMNS}} < 0;
    my $sql;

    $sql = "INSERT INTO $table (";
    my $values = "";
    my $sep = "";
    for my $col (@{$tableData{$table}->{COLUMNS}}) {
      if ($row->{$col}->{'dt:dt'} eq "bin.base64") {
        $values .= $sep . '?';
      } else {
        next unless $row->{$col}->{'value'};
        $values .= $sep . quote ($row->{$col}->{'value'});
      }
      $sql .= "$sep`$col`";
      $sep = ", ";
    }
    $sql .= ") VALUES ($values)";
    $sth = $dbh->prepare($sql);
    my $param = 0;
    for my $col (@{$tableData{$table}->{COLUMNS}}) {
      if ($row->{$col}->{'dt:dt'} eq "bin.base64") {
        $param++;
        $sth->bind_param($param, MIME::Base64::decode($row->{$col}->{'content'}), DBI::SQL_BLOB);
      }
    }
    $sth->execute();
  }
}

sub quote {
  $_ = shift();
  s/'/''/gm;
  s/‰/&auml;/gm;
  s/ˆ/&ouml;/gm;
  s/¸/&uuml;/gm;
  s/ƒ/&Auml;/gm;
  s/÷/&Ouml;/gm;
  s/‹/&Uuml;/gm;
  s/[ch64258]/&szlig;/gm;
  return "'$_'";
}

q.

RhysH

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Problem importing/exporting imagess
« Reply #4 on: November 26, 2013, 10:08:59 am »
Thats quite a script! I am sure that will be useful to other people for other things too :)

I got in touch with Sparx about it, and they seemed to suggest that the correct way to share images was to use the "Export Alternate Images" functionality of the XSI export, and not to share the image reference data:

=========================
There is an option in the XMI specifications for this - I suggest you try
setting the following:

Main menu: Tools | Options |  XMI Specifications | Export Alternate Images
=========================

So in the end, it seems that this behaviour wont get fixed, but there is a work-around in the exporting of the images within the XSI.