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 events, threading or background workers.
Events .Net framework provides a number of events for controls, forms and such. Additionally, the ARC framework provides events for various activities. It is highly preferred to use Events rather than Timers. This includes servo movements, new camera frames, adding/removing controls to workspace, and more. It's good etiquette to unsubscribe from events when your plugin is being closed in the OnClosing() event. If you do not unsubscribe from events, the .Net framework will not know your plugin and respective controls have been disposed, and therefore it may still attempt to execute the method. Notice that an unsubscribe from event is a -= and a subscribe to event is +=
public MyPluginForm() {
// Subscribe to events to monitor control activity on the workspace
OnBehaviorControlAdded += FormMain_OnBehaviorControlAdded;
OnBehaviorControlRemoved += FormMain_OnBehaviorControlRemoved;
}
private void FormMain_OnBehaviorControlAdded(object newControl, int page) {
MessageBox(string.Format("{0} has been added to the workspace #{1}", newControl.Text, page));
}
private void FormMain_OnBehaviorControlRemoved(object removedControl) {
MessageBox(string.Format("{0} has been removed from the workspace", removedControl.Text);
}
private void MyPluginForm_FormClosing(object sender, FormClosingEventArgs e) {
// Unsubscribe from events that I subscribed to while my plugin is going away
OnBehaviorControlAdded -= FormMain_OnBehaviorControlAdded;
OnBehaviorControlRemoved -= FormMain_OnBehaviorControlRemoved;
}
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...
System.Timers.Timer _timer;
bool _isRunning = false; // variable to ensure timer runs once at a time
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) {
// Check if another copy of the time event is running, if so get out
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. ARC has a helper class to make life easy for you, which is EZ_Builder.Invokers. You will need to use Invokers when updating UI components from System.Timers.Timer or most events that aren't triggered by UI. The Invokers class will check if an invoke is required.
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 ARC 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 ARC 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 ARC master assembly. If your plugin throws an error that is not handled within an exception, the ARC instance may close.
try {
// do some work
} catch (Exception ex) {
EZ_Builder.EZBManager.Log("Error in control '{0}'. Message: {1}", this.Text, ex.Message);
}
When the popup says it doesn’t detect visual studio, you can still skip and continue. I wonder why it’s not detecting it? We had a hard time trying to find a proper way of detecting - even Microsoft’s suggestion didn’t actually work eye roll
ill look into it a bit further and see if we can find a better way of detecting
@DJ: It's easy to find the Visual Studio 2017 and up: Microsoft: https://github.com/Microsoft/vswhere/wiki/Find-MSBuild
Some quick c# code to use with .NET: https://github.com/ppedro74/Utils/blob/master/FindVisualStudio/Program.cs
We went this route and it didn’t work on my computer - because I had a preview of visual studio installed which isn’t in that directory path. Microsoft had numerous suggestions of detecting visual studio. The one which worked for our various installations was a registry check.
apparently with the above individual, the registry didn’t work either. I’ll have to combine a few methods.
everything looks simple from the outside - until you have a hundred thousand+ installations of your software. That’s when you run into things like this lol
@DJ: I agree sometimes the things go out of script easily.
I avoid going through the registry keys, unless is recommended by the vendor. A lot of people blame the changes (keys, entries are renamed etc), but, that is normal if I own my product is my business and is part of the software evolution. Some products you can break the support contract agreement if you query directly the database, or if you look elsewhere outside of the public API.
Is true story some years ago a "rogue" developer on my team released a Sharepoint integration using a mix of APIs and database queries, everything worked well with multiple clients, until one day the Microsoft Black suits visit one of the customers to follow up on an unrelated support ticket, and they basically used "unsupported" card and left the client hanging, and we had problems too, unfortunately the Rogue developer went to another galaxy ... and the team suffered the consequences.
That does not mean I'm not tempted to do it...
I used the vswhere before and I would say is almost 99% bulletproof, is used with Xamarin, NVIDIA, Intel setups. If you add vswhere.exe to your project (nuget package) you cover scenarios where the tool is not present or have been deleted (broken uninstalls).
The other fallback could be ask the user the visual studio version.
The other reason to avoid registry is due to Visual Studio uses a private exclusive registry keys to store more stuff: http://www.visualstudioextensibility.com/2017/07/15/about-the-new-privateregistry-bin-file-of-visual-studio-2017/
So the things are getting more complex.
The above post is only part of the "Full solution" for example I have one setup with visual studio 2017 c# installed and Visual studio 2019 with Python and C++, vswhere will return 2019 version, but my c# is done with VS2017.
If you are generating customized vs version project files, maybe a fallback (ask the VS version) will cover more bases.
Yes - Microsoft has a few pages on how to identify visual studio and we tried them all during testing - the one we went with was with registry. I'm going to combine the two as using only one method apparently doesn't work for all cases.