We have element Parameters and Automation scripts that are used dynamically to create various DM items such as elements and services and as such they should not allow a user to use characters that DM does not allow for such items. What would be the best way to filter user text input in an automation script and for a parameter edit to not allow characters considered invalid by DM for such item names? Would using c# regex object with IsMatch() routine the best way or is there a better way. Can someone please provide an example.
Hi Jeff,
The DataMinerSystems Library is the best way to perform such actions in your DataMiner system. It is a public NuGet library and can be used for Protocols, Automation, or other C# apps. To do this from automation or Qactions (Protocols) there are dedicated libraries:
Some example code to create a view to get you started (you can return the message of the ArgumentException for detailed info to the user):
Here is an example of what I am doing for anyone that is interested. This is added to a script that prompts the user for various items that will eventually be used to update SNMP devices. Once the user tries move to the next step in the process the inputted string is validated and any characters that match the list in the Regex string are replaced with ‘?’ and an error message is presented to the user telling them that the string they inputted contains invalid characters.
Hope this helps someone else.
String NameFilterString = @”[^ -~]|[/\:;*?””\|!%]”;
Regex MyregEx = new Regex(NameFilterString);
if(MyregEx.IsMatch(user inputted string ))//jdd
{
user inputted string = MyregEx.Replace(data.CapacityGroup.Name,”?”);
errors[“name”]= “ERROR: Invalid Name”;
}
Thank you for the info Michiel, I will take a look at this. I was able to come up with a solution utilizing C#’s Regex capabilities. It is not the most elegant solution as It does not allow for validation logic to be applied at/during the character input level, but does allow for the final resulting string to get validated. It also requires that the validation logic/code get added to every script and protocol at every point where validation is required which can require a lot of changes throughout a system depending on how many parameters need to get validated and where the validation needs to take place.