本文整理汇总了C#中Measurement.SetTagName方法的典型用法代码示例。如果您正苦于以下问题:C# Measurement.SetTagName方法的具体用法?C# Measurement.SetTagName怎么用?C# Measurement.SetTagName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Measurement
的用法示例。
在下文中一共展示了Measurement.SetTagName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseOutputMeasurements
//.........这里部分代码省略.........
for (int i = 0; i < elem.Length; i++)
elem[i] = elem[i].Trim();
if (Guid.TryParse(elem[0], out id))
{
// The item was parsed as a signal ID so do a straight lookup
key = MeasurementKey.LookUpBySignalID(id);
if (key == MeasurementKey.Undefined && dataSourceAvailable && dataSource.Tables.Contains(measurementTable))
{
DataRow[] filteredRows = dataSource.Tables[measurementTable].Select($"SignalID = '{id}'");
if (filteredRows.Length > 0)
MeasurementKey.TryCreateOrUpdate(id, filteredRows[0]["ID"].ToString(), out key);
}
}
else if (!MeasurementKey.TryParse(elem[0], out key))
{
if (dataSourceAvailable && dataSource.Tables.Contains(measurementTable))
{
DataRow[] filteredRows;
// The item could not be parsed as a signal ID, but we do have a data source we can use to find the signal ID
filteredRows = dataSource.Tables[measurementTable].Select($"ID = '{elem[0]}'");
if (filteredRows.Length == 0)
{
// Point tags can have commas so we do not support specification of adders and multipliers in this case -
// therefore, we must do our lookup based on item (not elem) and clear elem if the lookup is successful
filteredRows = dataSource.Tables[measurementTable].Select($"PointTag = '{item.Trim()}'");
if (filteredRows.Length > 0)
elem = new string[0];
}
if (filteredRows.Length > 0)
key = MeasurementKey.LookUpOrCreate(filteredRows[0]["SignalID"].ToNonNullString(Guid.Empty.ToString()).ConvertToType<Guid>(), filteredRows[0]["ID"].ToString());
}
// If all else fails, attempt to parse the item as a measurement key
if (key == MeasurementKey.Undefined)
{
if (id == Guid.Empty)
throw new InvalidOperationException($"Could not parse output measurement definition \"{item}\" as a filter expression, measurement key, point tag or Guid");
throw new InvalidOperationException($"Measurement (targeted for output) with an ID of \"{item}\" is not defined or is not enabled");
}
}
if (key == MeasurementKey.Undefined)
continue;
// Adder and multiplier may be optionally specified
if (elem.Length < 2 || !double.TryParse(elem[1], out adder))
adder = 0.0D;
if (elem.Length < 3 || !double.TryParse(elem[2], out multipler))
multipler = 1.0D;
// Create a new measurement for the provided field level information
measurement = new Measurement
{
Metadata = key.Metadata.ChangeAdderMultiplier(adder, multipler),
};
// Attempt to lookup other associated measurement meta-data from default measurement table, if defined
try
{
if (dataSourceAvailable && dataSource.Tables.Contains(measurementTable))
{
DataRow[] filteredRows = dataSource.Tables[measurementTable].Select($"ID = '{key}'");
if (filteredRows.Length > 0)
{
DataRow row = filteredRows[0];
measurement.SetTagName(row["PointTag"].ToNonNullString());
// Manually specified adder and multiplier take precedence, but if none were specified,
// then those defined in the meta-data are used instead
if (elem.Length < 3)
measurement.SetMultiplier(double.Parse(row["Multiplier"].ToString()));
if (elem.Length < 2)
measurement.SetAdder(double.Parse(row["Adder"].ToString()));
}
}
}
catch
{
// Errors here are not catastrophic, this simply limits the available meta-data
measurement.SetTagName(string.Empty);
}
measurements.Add(measurement);
}
}
return measurements.ToArray();
}