Hi,
I want to retrieve the protocol related information and the table ids and names/description linked with the protocol in my automation script wherein I don't know the Ids and Description
for example:
Scenario:
I get protocol name from the selected device via parameter and then from there I want to get names and table ids as shown above related so that I can show it later in my application it will be helpful.
So from my Low code App as in above pic, once I click on that small gear I have protocol name, so from there I want to get all table ids and protocol related information as shown on top in my automation script in c#. There is no Dummy req. as I will get protocol info from clicking that row in table.
Showing list of resource types description and also for further functionality will be having table ids as well in order to get the further information for resources via GetTableDisplayKeys for the element selected. So, currently these are hardcoded but want them get the information automatically from Protocol.
Hello Apurva
With the following call, you can get a full definition of the protocol. This allows you to collect all table information.
var protocolInfo = engine.GetProtocolInfo(protocolName)Method not available.var protocolInfo = engine.GetUserConnection().GetProtocol(protocolName)
You can find the table parameters by looking for the correct parameter under the following property by either the table ID...
var tableParamInfoById = protocolInfo.Parameters.FirstOrDefault(param => param.ID == requestedTableId)
...or the name of the table
var tableParamInfoByDescription = protocolInfo.Parameters.FirstOrDefault(param => param.Description == requestedTableName)
Once you have the correct table parameter you can get all related column with
var columnParameters = tableParamInfo.TableColumnDefinitions;
This will allow you to find the parameter ID of each column, which you can then use again to find each param under protocolInfo.Parameters, in case you need additional info for that parameter, such as the description.
NOTE: Retrieving the protocol information is a big request on the system, so it is not advised to repeatedly do this. In case the automation script you mentioned will be executed very frequently, I would advise to implement additional caching to save previous results, instead of requesting it each time, otherwise performance issues might occur.
Caching can be done by using a static class, using a lock to avoid issues.
internal static class ProtocolInfoCache
{
private static readonly IDictionary<string, GetProtocolInfoResponseMessage> Cache = new ConcurrentDictionary<string, GetProtocolInfoResponseMessage>();
private static readonly object CacheLock = new object();
public static GetProtocolInfoResponseMessage GetCacheProtocol(IEngine engine, string name, string version)
{
lock (CacheLock)
{
string cacheKey = GetCacheKey(name, version);
if (Cache.ContainsKey(cacheKey))
{
return Cache[cacheKey];
}
return GetProtocolInfoFromDataMiner(engine, name, version);
}
}
private static string GetCacheKey(string name, string version)
{
return String.Join(".", name, version);
}
private static GetProtocolInfoResponseMessage GetProtocolInfoFromDataMiner(IEngine engine, string name, string version)
{
GetProtocolInfoResponseMessage response = engine.GetUserConnection().GetProtocol(name, version);
Cache.Add(new KeyValuePair<string, GetProtocolInfoResponseMessage>(GetCacheKey(name, version), response));
return response;
}
}
Apologies for the confusion. The GetProtocolInfo method is not available indeed. You can get a protocol via engine.GetUserConnection().GetProtocol(protocolName). But I believe the way you did it should lead you to the same result.
As for the caching. I added an example class to the answer.
Hi Apurva,
If you are intending to retrieve data from a table in a specific element, you could consider using the following methods, Method GetTableKeyMappings | DataMiner Docs together with Method GetTablePrimaryKeys | DataMiner Docs, to do so. Otherwise, if you are working with automation script dummies, you could also take a look at Class ScriptDummy | DataMiner Docs. I hope this is helpful.
Best Regards,
Joshua
I have updated the question, it is more clear now, wherein from the Protocol name I receive I want to get all related resource types such as S2X Input Ports, Demodulator etc, with table Ids in my automation script to get hat dropdown values filled.
Thanks Robin for the answer,
but I cannot see engine.GetProtocolInfo(“”) method, i there any other Nuget package which I need to install.
Apart from this from the device can I get like this:
var ele = engine.FindElement(“OST-X20-DM-001”);
var val = ele.Protocol.AllParameters.Where(x=>x.ArrayType);
Hope this won’t be heavy call.
And yes, for caching is there any link related to that?