public DaProperty[] ReadAvailableProperties(string itemId, bool updateCache)
{
string methodName = "IOPCItemProperties.QueryAvailableProperties";
// query for available properties.
int count = 0;
IntPtr pPropertyIds = IntPtr.Zero;
IntPtr pDescriptions = IntPtr.Zero;
IntPtr pDataTypes = IntPtr.Zero;
try
{
IOPCItemProperties server = BeginComCall<IOPCItemProperties>(methodName, true);
server.QueryAvailableProperties(
itemId,
out count,
out pPropertyIds,
out pDescriptions,
out pDataTypes);
}
catch (Exception e)
{
if (ComUtils.IsUnknownError(e, ResultIds.E_FAIL, ResultIds.E_INVALIDARG, ResultIds.E_UNKNOWNITEMID, ResultIds.E_INVALIDITEMID))
{
ComUtils.TraceComError(e, methodName);
}
return null;
}
finally
{
EndComCall(methodName);
}
// unmarshal results.
int[] propertyIds = ComUtils.GetInt32s(ref pPropertyIds, count, true);
string[] descriptions = ComUtils.GetUnicodeStrings(ref pDescriptions, count, true);
short[] datatype = ComUtils.GetInt16s(ref pDataTypes, count, true);
List<DaProperty> properties = new List<DaProperty>();
for (int ii = 0; ii < count; ii++)
{
// do not return any of the built in properties.
if (propertyIds[ii] <= PropertyIds.TimeZone)
{
continue;
}
DaProperty property = new DaProperty();
property.PropertyId = propertyIds[ii];
property.Name = descriptions[ii];
property.DataType = datatype[ii];
properties.Add(property);
}
// fetch the item ids.
if (properties.Count > 0)
{
DaProperty[] array = properties.ToArray();
GetPropertyItemIds(itemId, array);
// update the cache.
if (updateCache)
{
lock (m_cache)
{
DaElement element = null;
if (m_cache.TryGetValue(itemId, out element))
{
element.Properties = array;
}
}
}
return array;
}
return null;
}
#endregion