Hi all,
I have a quick question I am working on an automation script and have run into an issue. I have created a dialog button and I am trying to run a method when the butto is pressed. so far I have this:
public event EventHandler<EventArgs> Pressed;
public void Button_Pressed(object sender, EventArgs e)
{
controller.Engine.Log("Entering Event");
AddPort(sender, e, protocol.Protocol);
controller.Engine.ExitSuccess("0");
}
I have tried both of these but the method does not trigger when button is pressed
dialog.Button.Pressed += new EventHandler<EventArgs>(Button_Pressed);
dialog.Button.Pressed += (sender,e) => Pressed(sender,e);
I have a drop down list and everything works for the OnChange event but for the button I can't get it to work.
Thank you so much in advance.
Hi Thomas and Floris,
The example that you shared was pretty much what I had, thanks to your questions and help I have been able to finaly solve it.
the issue was after running the dialog again after making a few changes to the original dialog and running the second altered dialog it does not have the event registered so what I did was add the event again before the second controller.Run(dialog).
Thank you for the help
Hi Amer,
Together with Thomas, I made an IAS that handles a button press that we tested our local DMA. Maybe this can serve as an example?
IAS_Button_Pressed/DOJO_1.cs at RC · FlorisCO/IAS_Button_Pressed · GitHub
From the code you posted, it looks like you're registering the event outside of your Dialog class, which we also did in our example. Is it possible that you are adding the event after calling controller.Run(dialog)?
Also note that the ExitSuccess is throwing a ScriptAbortException, which should be caught in the Run function, or it will be rethrown as a fail.
The Engine.Log statement will be logged in SLAutomation.txt .
Hi Amer,
If the example fails on your system, can you let us know what DataMiner version you are using?
Could you also check what toolkit version you are using? The linked example should be using the latest stable version.
Hi Amer,
I assume the button is a property of your dialog class.
Check that the button property does not get overwritten after subscribing to the Pressed event.
In case you are running a very old version of the toolkit, make sure the WantsOnChange property of the button is set to True.
This is not needed on recent versions, and you might not be able to access the property, ignore this if that is the case.
The 2 examples you gave to subscribe seem to be valid.
But I would write it like this:
dialog.Button.Pressed += Button_Pressed;
If nothing worked, would it be possible to share more of the code in the dialog class?
Yes the button is a property of the dialog class and I am using the newest toolset so OnChange should be set to true when subscribed to the event as it is with the dropdown event.
Button = new Button(“Update Name”);
public Button Button { get; set; }
if any more info is needed to help with this let me know.
I wrote it as you have there and still the same the client waits for user input I press the button and nothing happens but in the logs it detects the button was pressed but does not trigger the method at all as I am logging when it enters the method
Would it be possible to share the code via github gist?
Hi Floris,
You are correct it is outside the dialog class and I am adding the event before the controller.Run(dialog) as that is the last thing that I do and yes I am aware of this and handleing the exceptions properly. I will look and try the sample that you have shared thank you so much