3

In addin for Sparx EA I use this code to get pictures and assign to entity. Then I use images from entities, to, as example, save at some folders or insert in word report etc (from this answer)

/// <summary>
/// Access to diagram image without using clipboard
/// </summary>
/// <param name="projectInterface">Ea Sparx interface</param>
/// <param name="eaDiagramGuid">Guid of the diagramm</param>
/// <returns></returns>
public static Image GetDiagramImage(this Project projectInterface, Guid eaDiagramGuid, ApplicationLogger _logger)
{
    Image diagramImage;
    try
    {
        var diagramByGuid = projectInterface.GUIDtoXML(eaDiagramGuid.ToString("B"));
        string tempFilename = string.Format("{0}{1}{2}", Path.GetTempPath(), Guid.NewGuid().ToString(), ".png");
        bool imageToFileSuccess = projectInterface.PutDiagramImageToFile(diagramByGuid, tempFilename, FileExtensionByName);

        if (imageToFileSuccess)
        {
            using (var imageStream = new MemoryStream(File.ReadAllBytes(tempFilename)))
            {
                diagramImage = Image.FromStream(imageStream);
            }


            File.Delete(tempFilename);
        }
        else
        {

            throw new Exception(string.Format("Image to file exprot fail {0}", projectInterface.GetLastError()));
        }
    }
    catch (Exception e)
    {
        throw;
    }
    return diagramImage;
}

The problem is - it works if project I work with saved as .eap file.

If it's .feap file, which, as I believe means that it works with Firebird database (instead of Access), all saved/exproted to report images are blank, like this down below

enter image description here

Why does it happens and is there workaround?

UPD

It works if I use projectInterface.PutDiagramImageOnClipboard instead but I don't wont to use clipboard at all

UPD 2

After some experiments today at the morning (at my timezone, gmt+3, it's still morning) I found out that the problem was with GUIDs register!

After I decided to apply .toUpper() here

var diagramByGuid = projectInterface.GUIDtoXML(eaDiagramGuid.ToString("B").ToUpper());

it started work fine!

enter image description here

Strange thing thou that if project is *.EAP type everything works even when guid is not in upper register!

UPD3

Well, unfortunately, I was wrong. Some pictures are still blank. But somehow that changes got impact on diagrams, I keep testing this stuff.

And some of the pictures are appeared twice or in wrong place. But it's kinda interesting (if I could say so) behaviour.

UPD 4

I was wrong in my UPD2 part! GUID can contain down register symbols as well as upper ones. So, first I removed that part. What I done next - I started to pass GUID directly from diagram, so signature changed like that

public static Image GetDiagramImage(this Project projectInterface, string eaDiagramGuid, ApplicationLogger _logger)

and eaDiagramGuid should be passed right from EA.Diagram object.

When we parse it as Guid by Guid.Parse(eaDiagramGuid) it convert everything in lowercase like here

enter image description here

so, thats why I got the problem.

But for some reason it was not appeared in *.EAP type of projects!

Also it strange that register matters in that case, really. Seems like GUID in common and GUID in sparx ea are different things!

Community
  • 1
  • 1
DanilGholtsman
  • 2,354
  • 4
  • 38
  • 69

1 Answers1

1

Okay, as I founded out here, the thing is, in case of *.FEAP all items GUIDs are surprisingly case sensetive.

So, my mistake was to store item GUID as Guid type - when we use Guid.Parse(myGuidString) function and then we converting it back to string - all symbols are appers to be in lowercase.

Also, I got my answer from support (they were surprisingly fast, I really like that)

Hello Danil,

Running over the Stack Overflow - it sounds like it's effectively answered. The core point is that the Feap files are case sensitive. To be technical, the collation used for our Firebird databases is case sensitive.

So, in the Automation script you do need to adhere to the case.

So, I just change things to work directly with GUID string from project item like

Image diagramImage = _eaProjectInterface.GetDiagramImage(diagram.DiagramGUID, _logger);

and function now look like this

    public static Image GetDiagramImage(this Project projectInterface, string eaDiagramGuid, ApplicationLogger _logger)
    {
        Image diagramImage;

        try
        {
            var diagramByGuid = projectInterface.GUIDtoXML(eaDiagramGuid);
            string tempFilename = string.Format("{0}{1}{2}", Path.GetTempPath(), Guid.NewGuid().ToString(), ".png");
            bool imageToFileSuccess = projectInterface.PutDiagramImageToFile(diagramByGuid, tempFilename, FileExtensionByName);

            if (imageToFileSuccess)
            {
                using (var imageStream = new MemoryStream(File.ReadAllBytes(tempFilename)))
                {
                    diagramImage = Image.FromStream(imageStream);
                }

                File.Delete(tempFilename);
            }
            else
            {
                throw new Exception(string.Format("Image to file exprot fail {0}", projectInterface.GetLastError()));
            }
        }
        catch (Exception e)
        {
            throw;
        }

        return diagramImage;
    }

So, this means that Sparx EA *.FEAP project GUIDs are NOT really GUIDs but just string-keys (as I assume).

Be careful when your work with them :-)

DanilGholtsman
  • 2,354
  • 4
  • 38
  • 69
  • 1
    I think Sparx should declare columns containing guids either with a case insensitive collation, or - better - to use `CHAR(16) CHARACTER SET OCTETS` and convert between bytes and human readable guids with [`CHAR_TO_UUID`](https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-functions-scalarfuncs.html#fblangref25-functions-scalarfuncs-char_to_uuid) and [`UUID_TO_CHAR`](https://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25-functions-scalarfuncs.html#fblangref25-functions-scalarfuncs-uuid_to_char) – Mark Rotteveel Mar 16 '17 at 15:50