Complex plugins usually require configuration settings like the URL of a Rest API that is being used, email address for sending notifications, etc. It could be anything. Hard coding those values is always an option but definitely not the optimal one. Yes, you can also introduce a *dll.config file where plugin settings are stored but, then again, someone should modify that file manually. A better approach would be if we can somehow define our plugin settings inside our Logi application and that is what this article is all about.
There are primarily two ways of conveniently passing information down to a plugin - using the child Plugin Parameters element or using the application settings. We are going to look into the latter approach.
Defining Plugin Settings In The AppThe first step is to define the settings of our plugin inside our app. Open your Logi Info app and navigate to _Settings. Make sure that there is a Constants element - this is where the plugin settings will be defined. Once Constants is selected, add a parameter called MyPluginSettingsDataString with value equal to "Test String 01". MyPluginSettingsDataString is a setting that will be used by our plugin.
Retrieving Plugin Settings
The only task left to do now is to enable our plugin to read the settings that we have defined. We are going to use a very simple DataLayer plugin which generates sample data. Some of the data is based on the setting that we have defined in our app. Let's take a look at the plugin itself.
Very straightforward. The most important line is the first one where the plugin setting are initialized. Since we want to keep everything nice and tidy I've extracted the code that reads the settings in a separate class. Here it is.
This is where the actual job of retrieving the settings is done. rdServerObjects is the gateway to our app - it gives access to the current report definition, the current web request, current session and much more. More importantly, it exposes the "_Settings" node of our app which is represented by a property called SettingsDefinition. Standard XML methods are used to get a reference to Constants. Each parameter that we have defined in our app is available as an attribute of Constants. PluginSetting reads all settings and assigns them to properties for easy access. The settings can now be consumed by the plugin.
The sample plugin reads the MyPluginSettingsDataString setting and uses its value to generate data that is then displayed in a DataTable. Here is the result:
We have looked at a technique that can help you maintain and configure plugins developed for Logi Info apps. The same technique can be applied to plugins of any size and complexity.
The source code of the app and the plugin can be download from here.
As always, let me know that you think in the comment section below.