Book a Demo

Author Topic: How to use shared keys in add-in?  (Read 5617 times)

Slávek Rydval

  • EA User
  • **
  • Posts: 40
  • Karma: +2/-0
    • View Profile
    • homepage
How to use shared keys in add-in?
« on: February 22, 2018, 12:19:20 am »
I developed an add-in that uses EA licence abilities. Private keys work properly but shared have problems: I am always getting this error messages when trying to add a key via Add Registration Key in EA: The last key of this type has just been taken by someone else. That means (besides other) that EA_AddinLicenseValidate is not called.


https://www.dropbox.com/s/bru9tczuvn2xz0b/Key1.png?dl=0


https://www.dropbox.com/s/ikagz7gwbr9yupa/Key2.png?dl=0

When I check the licence in Sparx Systems Key Store, licence is not taken (assigned) to anyone so from user perspective is free.


https://www.dropbox.com/s/q66owf0ddxha1bq/Key3.png?dl=0

Where should I look for a solution?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to use shared keys in add-in?
« Reply #1 on: February 22, 2018, 12:26:48 am »
I once got it working for EA-Matic (which is now free).

This is the code I had back then:

Code: [Select]
/// <summary>
/// When a user directly enters a license key that doesn't match a Sparx Systems key into the License Management dialog EA_AddInLicenseValidate is broadcast to all Enterprise Architect Add-Ins,
/// providing them with a chance to use the Add-In key to determine the level of functionality to provide.
/// When a key is retrieved from the Sparx Systems Keystore only the target Add-In will be called with the key.
/// For the Add-In to validate itself against this key, the Add-In's EA_AddinLicenseValidate handler should return true to confirm that the license has been validated.
/// As the EA_AddinLicenseValidate event is broadcast to all Add-Ins, one license can validate many Add-Ins.
/// If an Add-In elects to handle a license key by returning true to EA_AddinLicenseValidate, it is called upon to provide a description of the license key through the
/// EA_AddinLicenseGetDescription event.
/// If more than one Add-In elects to handle a license key, the first Add-In that returns true to EA_AddinLicenseValidate is queried for the license key description.
/// </summary>
        /// <param name="Repository">An EA.Repository object representing the currently open Enterprise Architect model.
        /// Poll its members to retrieve model data and user interface status information.</param>
/// <param name="AddinKey">The Add-in license key that has been entered in the License Management dialog.</param>
/// <returns>For the Add-in to validate against this key it should return true to indicate that the key is valid and has been handled.</returns>
public override bool EA_AddInLicenseValidate(EA.Repository Repository, string AddinKey)
{
License eaLicense = new License(AddinKey, publicKey);
if (eaLicense.isValid)
{
//the license is valid so replace the evaluation license with this one
this.license = eaLicense;
}
//debug
EAAddinFramework.Utilities.Logger.log("license.Isvalid = "+eaLicense.isValid.ToString()+" for license key: " + AddinKey);
return license.isValid;
}

/// <summary>
/// Before the Enterprise Architect License Management dialog is displayed, EA_AddInLicenseGetDescription is sent once for each Add-In key to the first Add-In that elected to handle that key.
/// The value returned by EA_AddinLicenseGetDescription is used as the key's plain text description.
/// </summary>
        /// <param name="Repository">An EA.Repository object representing the currently open Enterprise Architect model.
        /// Poll its members to retrieve model data and user interface status information.</param>
/// <param name="AddinKey">The Add-In license key that Enterprise Architect requires a description for.</param>
/// <returns>A String containing a plain text description of the provided AddinKey.</returns>
public override string EA_AddinLicenseGetDescription(EA.Repository Repository, string AddinKey)
{
string licensedescription = string.Empty;
License license = new License(AddinKey, publicKey);
if (license.isValid)
{
licensedescription = "License for EA-Matic issued to " + license.client;
}
return licensedescription;
}
  /// <summary>
/// As an add-in writer you can distribute keys to your add-in via the Enterprise Architect Keystore providing your
/// keys are generated using a prefix that allows Enterprise Architect to identify the add-in to which they belong.
/// EA_GetSharedAddinName is called by Enterprise Architect to determine what prefix an add-in is using.
/// If a matching key is found in the keystore the License Management dialog will display the name returned
/// by EA_AddinLicenseGetDescription to your users.
/// Finally, when the user selects a key, that key will be passed to your add-in to validate
/// by calling EA_AddinLicenseValidate.
/// </summary>
        /// <param name="Repository">An EA.Repository object representing the currently open Enterprise Architect model.
        /// Poll its members to retrieve model data and user interface status information.</param>
/// <returns>A String containing a product name code for the provided Add-In. This will be shown in plain text at the start of any keys added to the keystore. We recommend contacting Sparx Systems directly with proposed values to ensure you don't clash with any other add-ins.
/// eg. The following keys would all be interpreted as belonging to an add-in returning "MYADDIN" from this function:
/// · MYADDIN-Test
/// · MYADDIN-{7AC4D426-9083-4fa2-93B7-25E2B7FB8DC5}
/// · MYADDIN-7AC4D426-9083-4fa2-93B7
/// · MYADDIN-25E2B7FB8DC5
/// · MYADDIN-2hDfHKA5jf0GAjn92UvqAnxwC13dxQGJtH7zLHJ9Ym8=</returns>
public override string EA_GetSharedAddinName(EA.Repository Repository)
{
return "EAMatic";
}

Geert
« Last Edit: February 22, 2018, 12:31:04 am by Geert Bellekens »

Slávek Rydval

  • EA User
  • **
  • Posts: 40
  • Karma: +2/-0
    • View Profile
    • homepage
Re: How to use shared keys in add-in?
« Reply #2 on: February 22, 2018, 01:12:04 am »
I have practically the same code, here isn't the problem.

On startup the operations are called in this order:
  • EA_GetSharedAddinName (I return a string)
  • EA_AddinLicenseGetDescription (another string for cosmetic purposes)
  • [EA_AddinLicenseValidate (checking the licence validity, not called because the shared licence is not entered)]
  • EA_OnInitializeTechnologies (here I check whether licence exists or it is a trial)

Code: [Select]
private const string AddinName = "CaprCheekyEAJira";

public string EA_GetSharedAddinName(EA.Repository Repository)
     => AddinName;

public string EA_AddinLicenseGetDescription(EA.Repository Repository, string AddinKey)
    => AddinName == AddinKey ? "Cheeky EA Connector for Jira": null;

public bool EA_AddinLicenseValidate(EA.Repository Repository, string AddinKey)
{
    try
    {
        mainViewModel.Licence = new LicenceViewModel (new LicenceModelService().Read(AddinKey.Substring (1, AddinKey.Length-2)), new DialogService());
        return true;
    }
    catch
    {
        return false;
    }
}


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to use shared keys in add-in?
« Reply #3 on: February 22, 2018, 01:23:54 am »
Did you prefix your license keys with your shared addin name?
Otherwise EA will not know who these licenses belong to, and it will not call your add-in to validate the license.

Geert

Slávek Rydval

  • EA User
  • **
  • Posts: 40
  • Karma: +2/-0
    • View Profile
    • homepage
Re: How to use shared keys in add-in?
« Reply #4 on: February 22, 2018, 01:31:20 am »
Yes, there is a prefix. I wouldn't be able to insert a licence into Key Store without the prefix.

Slávek Rydval

  • EA User
  • **
  • Posts: 40
  • Karma: +2/-0
    • View Profile
    • homepage
Re: How to use shared keys in add-in?
« Reply #5 on: February 22, 2018, 01:52:41 am »
Next point.

The problem is in case there is File Based Keystore.

When I use Keystore Server (ssks://...), it works fine.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to use shared keys in add-in?
« Reply #6 on: February 22, 2018, 01:59:20 am »
Next point.

The problem is in case there is File Based Keystore.

When I use Keystore Server (ssks://...), it works fine.

Ah, that explains a lot. I've never tried it with a file based keystore.

Geert