All Tutorials / DJ Sures / How To Make An EZ-Builder Plugin

How To Make An EZ-Builder Plugin

Plugin Compliance

Overview
EZ-Robot is committed to offer users a secure and dependable robot development environment. Due to the high expectation of efficient, dependable and secure from users, there are a few dependencies and restrictions which we enforce in your plugins during review.


Avoid Length GUI Thread Processing
It is very convenient to throw a bunch of code into an event raised by a GUI widget, such as a button or checkbox. When code is executed in an event raised by the user interface, it runs in the thread of that object. This means lengthy code will delay/pause the user interface experience until the code has completed and processing is returned to the GUI thread. This behavior must be reduced at all cost by using threading or background workers.


Timers
One of the most common timers that is used from convenience is System.Windows.Forms.Timer, which is heavily frowned upon and will always have your plugin revoked from public access. An alternative and accepted timer for your background worker is System.Timers.Timer.

The difference between these two timers is trivial programatically, but vast in their operational behavior. The System.Windows.Forms.Timer will raise the elapsed event in the user interface thread, while the System.Timers.Timer will raise the event in a background thread.

As a new programmer, you may be familiar with the behavior of System.Windows.Forms.Timer not raising the elapsed event until the previous event has completed. With System.Timers.Timer, if your last elapsed event has not completed, a new one will still be raised. Avoid using a Lock() statement for this behavior, and instead use a boolean variable shown in this example...

Code:


System.Timers.Timer _timer;
bool _isRunning = false;

public FormMaster() {

InitializeComponent();

_timer = new System.Timers.Timer();
_timer.Elapsed += _timer_Elapsed;
_timer.Interval = 100;
_timer.Start();
}

void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {

if (_isRunning)
return;

_isRunning = true;

try {

// Do some work
} catch (Exception ex) {

// Uh oh!
} finally {

_isRunning = false;
}
}




Cross-Thread Invoking
While new programmers may feel comfort placing code in events owned by GUI widgets in the user interface thread, there is a different experience when working in a background thread. A background thread will not be able to modify parameters of a GUI object that exists on a different thread. This is called a Cross-Threading Exception. EZ-Builder has a helper class to make life easy for you, which is EZ_Builder.Invokers.

Code:


void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {

if (_isRunning)
return;

_isRunning = true;

try {

EZ_Builder.Invokers.SetText(textbox1, "Here is a number: {0}", 5);

EZ_Builder.Invokers.SetChecked(checkbox1, false);

EZ_Builder.Invokers.SetBackColor(button1, System.Drawing.Color.Red);
} catch (Exception ex) {

// Uh oh!
} finally {

_isRunning = false;
}
}




User Configuration Settings
Never under any circumstances save user configuration settings in a separate project file. Always save user configuration settings in the EZ-Builder Project File using the tutorial step for Saving/Loading Configuration. plugins that save configuration data locally to the drive will be revoked from public status. This is to ensure a seamless user experience within the EZ-Builder environment. If you have questions about saving custom user data, please inquire on the community forum for assistance.


Exception Handling
Always wrap code in Try {} Catch {} to avoid unhandled exceptions, which will exit EZ-Builder. Your plugin will execute under the EZ-Builder master assembly. If your plugin throws an error that is not handled within an exception, the EZ-Builder instance may close.

Code:


try {

// do some work

} catch (Exception ex) {

EZ_Builder.EZBManager.Log("Error in control '{0}'. Message: {1}", this.Text, ex.Message);
}