I have several user defined APIs set up that need to interact with elements across the system. When one of the agent is stopping (e.g. initiating an upgrade) another agent can still be processing the API > running the automation script > trying to do a set on an element on the agent that is stopping.
In those cases I encounter an exception on the param set even when the logic will first:
- verify the element exists via engine.FindElement
- verify the element is active via element.IsActive
most likely this is because at that point in time, the agent was busy stopping.
Is there a way to know that this has been initiated? This would allow the API to return the proper response and not crash.
Though that particular use case has never been verified and tested. You could try to use the following method Method IsStartupComplete | DataMiner Docs, part of the Skyline.DataMiner.Core.DataMinerSystem namespace (available through a NuGet package).
It's a bit more clever in its checking, in that it handles if data is fully loaded or not.
The IDms classes will also do more validation on sets, making sure the element exists before most calls.
If you want to check the state of an agent specifically:
You can ask the the agent state: Verify if agent is running
IDms dms = engine.GetDms();
IDma agent = dms.GetAgent(346);
AgentState state = agent.State;