The plugin derived class


#1

Working in c#. I would like to check the user license from within the plugin derived class - if they don’t have a license I want to unload the plugin/prevent them from using the commands.

What’s the best way to do this? License check is fine - it’s the “preventing them from using the plugin” that I’m trying to work out the best solution for.


(Luis Fraguada) #2

You could load the plugin at startup, and override the OnLoad method. You can choose to return an error in that method if you do not want the plugin to load or return success if all goes to plan.


(Steve Baer) #3

You don’t even need to force loading at start up. The return code from OnLoad will be respected. If you return ErrorShowDialog or ErrorNoDialog, then your plug-in will not be executed.


(Dale Fugier) #4

To elaborate on what Luis and Steve mentioned, you can do something like this:

/// <summary>
/// Is called when the plug-in is being loaded.
/// </summary>
/// If a load error is returned and this string is set. This string is the 
/// error message that will be reported back to the user.
/// <returns>An appropriate load return code.</returns>
protected override LoadReturnCode OnLoad(ref string errorMessage)
{
  if (!HaveValidLicense())
  {
    errorMessage = string.Format("Unable to load {0} plug-in. No valid license found.", this.Name);
    return LoadReturnCode.ErrorShowDialog;
  }
  return LoadReturnCode.Success;
}

Or, you could popup your own UI, giving the customer directions on how to purchase a license, and just return LoadReturnCode.ErrorNoDialog.


#5

Thanks very much all 3 of you! Very useful - am putting it into practice right now.

Hannah


#6

In Rhino 5, we have the render plugin class:

public class Plugin : Rhino.PlugIns.RenderPlugIn,…

and when loading the plugin, if some predefined MDL folder does not exist, user can chose to avoid loading the plugin.
We then return ErrorShowDialog code:

protected override Rhino.PlugIns.LoadReturnCode OnLoad(ref string errorMessage)

Rhino.PlugIns.LoadReturnCode.ErrorShowDialog

Now, the plugin is not loaded but the Iray renderer is still listed in the list of viewport renderers.

When user chose Iray, the viewport freezes, when user chose wireframe, Rhino crashes.
Is there something to do in addition to returning ErrorShowDialog ?
To unregister the viewport renderer?
@andy?


(Nathan 'jesterKing' Letwory) #7

I’ll take a look at this.

https://mcneel.myjetbrains.com/youtrack/issue/RH-38119

/Nathan


(Nathan 'jesterKing' Letwory) #8

@nvp, I have created a pull request that should fix this problem. As part of the non-loading all custom render content and other extensions registered by the plug-in are also unloaded.

With the next WIP please test this and report whether it works or not. (It does in my own tests :wink: )

/Nathan


#9

Hi @nathanletwory, this is an issue we would like to address in Rhino 5. Would it be possible to port the fix?


(Nathan 'jesterKing' Letwory) #10

I’m not sure about that. I’ll have to ask @andy. I haven’t really ever touched the Rhino 5 code base.

/Nathan


(Nathan 'jesterKing' Letwory) #11

@nvp, for Rhino 5 there will be no more changes. Note that the realtime integration code does not work in v5.


#12

Is there nothing which can be done on our side then?


(Nathan 'jesterKing' Letwory) #13

As I understand it the plug-in developer should take care themselves to clean up in case of load failure. Maybe @stevebaer or @andy can tell more.


(Brian Gillespie) #15

RH-38119 is fixed in the latest WIP


(Nathan 'jesterKing' Letwory) #16

@nvp, could you confirm this works now as expected in Rhino WIP for your plug-in? Thanks.