Files
imsInterface/interface/asm/dotnet/MesTools/ImsApi/ImsApiResultEvaluator.cs
2025-06-06 09:15:13 +02:00

101 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
namespace MesTools.ImsApi
{
public class ImsApiResultEvaluator
{
public StringBuilder evaluate(Object result, List<string> orderedOutArgs, Dictionary<String, String[]> resultValueMap, Dictionary<String, String[]> uploadValues)
{
// check preconditions
StringBuilder stb = new StringBuilder();
if (result == null)
{
stb.Append("(null");
return stb;
}
// print type info
ObjectEvaluator oe = new ObjectEvaluator();
stb.Append('(').Append(result).Append(")\n");
// handle all out params...
if (orderedOutArgs != null && orderedOutArgs.Count > 0)
{
// evaluate return values (key-value arrays...)
foreach (string fieldName in orderedOutArgs)
{
// find the stationResultUploadKeys for out stationResultValues
string[] values = resultValueMap[fieldName];
Debug.WriteLine(fieldName);
string[] keys = null;
// key-information available for this parameter?
string baseName = fieldName;
if (fieldName.EndsWith("Values") && uploadValues != null)
{
if (uploadValues.ContainsKey(fieldName))
{
keys = uploadValues[fieldName];
}
else
{
// replace "Values" by "Upload"
baseName = fieldName.Substring(0, fieldName.Length - 6) + "Upload";
if (uploadValues.ContainsKey(baseName))
{
keys = uploadValues[baseName];
}
}
if (keys != null)
{
Object v = new String[] { };
try
{
v = values;
}
catch (Exception)
{
// explicitly no error handling
}
// print formatted imsapi-key-Value
ImsApiTools.printKeyValues(stb, baseName, keys, (String[])v);
stb.Append('\n');
}
continue;
}
// print ordinary values
/* try
{
Object v = field.GetValue(result);
StringBuilder pstb = new StringBuilder();
oe.evaluateObject(field.Name, v, pstb);
stb.Append(pstb.ToString()).Append('\n');
}
catch (Exception)
{
// explicitly no error handling
}*/
}
}
foreach (FieldInfo field in result.GetType().GetFields())
{
}
return stb;
}
}
}