本文整理汇总了C#中IDbConnection.RetrieveData方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.RetrieveData方法的具体用法?C# IDbConnection.RetrieveData怎么用?C# IDbConnection.RetrieveData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbConnection
的用法示例。
在下文中一共展示了IDbConnection.RetrieveData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EstablishDefaultCache
/// <summary>
/// Establish default <see cref="MeasurementKey"/> cache.
/// </summary>
/// <param name="connection">The database connection.</param>
/// <param name="adapterType">The database adapter type.</param>
/// <param name="measurementTable">Measurement table name used to load measurement key cache.</param>
/// <remarks>
/// Source tables are expected to have at least the following fields:
/// <code>
/// ID NVARCHAR Measurement key formatted as: ArchiveSource:PointID
/// SignalID GUID Unique identification for measurement
/// </code>
/// </remarks>
public static void EstablishDefaultCache(IDbConnection connection, Type adapterType, string measurementTable = "ActiveMeasurement")
{
string source;
uint id;
// Establish default measurement key cache
foreach (DataRow measurement in connection.RetrieveData(adapterType, $"SELECT ID, SignalID FROM {measurementTable}").Rows)
{
if (TrySplit(measurement["ID"].ToString(), out source, out id))
CreateOrUpdate(measurement["SignalID"].ToNonNullString(Guid.Empty.ToString()).ConvertToType<Guid>(), source, id);
}
}
示例2: ValidateStatistics
//.........这里部分代码省略.........
}
// Ensure that subscriber statistics exist
if (publisherStatCount == 0)
{
for (int i = 0; i < PublisherStatNames.Length; i++)
{
signalIndex = i + 1;
statName = PublisherStatNames[i];
statDescription = PublisherStatDescriptions[i];
statMethodSuffix = PublisherStatMethodSuffix[i];
statType = PublisherStatTypes[i];
statFormat = PublisherStatFormats[i];
connection.ExecuteNonQuery(string.Format(PublisherStatInsertFormat, signalIndex, statName, statDescription, statMethodSuffix, statType, statFormat));
}
}
// Ensure that system statistic measurements exist
statHistorianID = Convert.ToInt32(connection.ExecuteScalar(string.Format(StatHistorianIDFormat, nodeIDQueryString)));
statSignalTypeID = Convert.ToInt32(connection.ExecuteScalar(StatSignalTypeIDFormat));
nodeName = GetNodeName(connection, nodeIDQueryString);
// Modify node name so that it can be applied in a measurement point tag
nodeName = nodeName.RemoveCharacters(c => !char.IsLetterOrDigit(c));
nodeName = nodeName.Replace(' ', '_').ToUpper();
for (int i = 0; i < SystemStatNames.Length; i++)
{
signalIndex = i + 1;
signalReference = string.Format("{0}!SYSTEM-ST{1}", nodeName, signalIndex);
statMeasurementCount = Convert.ToInt32(connection.ExecuteScalar(string.Format(StatMeasurementCountFormat, signalReference, statHistorianID)));
if (statMeasurementCount == 0)
{
pointTag = string.Format("{0}!SYSTEM:ST{1}", nodeName, signalIndex);
measurementDescription = string.Format("System Statistic for {0}", SystemStatDescriptions[i]);
connection.ExecuteNonQuery(statMeasurementInsertQuery, (object)statHistorianID, pointTag, statSignalTypeID, signalReference, measurementDescription);
}
}
// Ensure that subscriber statistic measurements exist
foreach (DataRow subscriber in connection.RetrieveData(s_adapterType, string.Format(SubscriberRowsFormat, nodeIDQueryString)).Rows)
{
adapterID = subscriber.ConvertField<int>("ID");
adapterSourceID = Convert.ToInt32(connection.ExecuteScalar(string.Format(RuntimeSourceIDFormat, adapterID)));
runtimeDeviceCount = Convert.ToInt32(connection.ExecuteScalar(string.Format(RuntimeDeviceCountFormat, adapterID)));
adapterName = subscriber.Field<string>("AdapterName");
if (!TryGetCompanyAcronymFromDevice(connection, adapterSourceID, out companyAcronym))
companyAcronym = GetCompanyAcronym(connection, nodeIDQueryString);
for (int i = 0; i < SubscriberStatNames.Length; i++)
{
signalIndex = i + 1;
signalReference = string.Format("{0}!SUB-ST{1}", adapterName, signalIndex);
statMeasurementCount = Convert.ToInt32(connection.ExecuteScalar(string.Format(StatMeasurementCountFormat, signalReference, statHistorianID)));
if (statMeasurementCount == 0)
{
pointTag = string.Format("{0}_{1}!SUB:ST{2}", companyAcronym, adapterName, signalIndex);
measurementDescription = string.Format("Subscriber Statistic for {0}", SubscriberStatDescriptions[i]);
if (runtimeDeviceCount > 0)
{
// Subscriber is defined in the Device table; include the device ID in the insert query
connection.ExecuteNonQuery(subscriberDeviceStatInsertQuery, (object)statHistorianID, adapterSourceID, pointTag, statSignalTypeID, signalReference, measurementDescription);
}
else
{
// Subscriber is not defined in the Device table; do not include a device ID
connection.ExecuteNonQuery(statMeasurementInsertQuery, (object)statHistorianID, pointTag, statSignalTypeID, signalReference, measurementDescription);
}
}
}
}
// Ensure that publisher statistic measurements exist
companyAcronym = GetCompanyAcronym(connection, nodeIDQueryString);
foreach (DataRow publisher in connection.RetrieveData(s_adapterType, string.Format(PublisherRowsFormat, nodeIDQueryString)).Rows)
{
adapterID = publisher.ConvertField<int>("ID");
adapterSourceID = Convert.ToInt32(connection.ExecuteScalar(string.Format(RuntimeSourceIDFormat, adapterID)));
adapterName = publisher.Field<string>("AdapterName");
for (int i = 0; i < PublisherStatNames.Length; i++)
{
signalIndex = i + 1;
signalReference = string.Format("{0}!PUB-ST{1}", adapterName, signalIndex);
statMeasurementCount = Convert.ToInt32(connection.ExecuteScalar(string.Format(StatMeasurementCountFormat, signalReference, statHistorianID)));
if (statMeasurementCount == 0)
{
pointTag = string.Format("{0}_{1}!PUB:ST{2}", companyAcronym, adapterName, signalIndex);
measurementDescription = string.Format("Publisher Statistic for {0}", PublisherStatDescriptions[i]);
connection.ExecuteNonQuery(statMeasurementInsertQuery, (object)statHistorianID, pointTag, statSignalTypeID, signalReference, measurementDescription);
}
}
}
}
示例3: ExecuteStartupDataOperations
// Execute any defined startup data operations
private void ExecuteStartupDataOperations(IDbConnection connection, Type adapterType)
{
try
{
string assemblyName = "", typeName = "", methodName = "", arguments;
Assembly assembly;
Type type;
MethodInfo method;
foreach (DataRow row in connection.RetrieveData(adapterType, string.Format("SELECT * FROM DataOperation WHERE (NodeID IS NULL OR NodeID={0}) AND Enabled <> 0 ORDER BY LoadOrder", m_nodeIDQueryString)).Rows)
{
try
{
DisplayStatusMessage("Executing startup data operation \"{0}\".", UpdateType.Information, row["Description"].ToNonNullString("Unlabled"));
// Load data operation parameters
assemblyName = row["AssemblyName"].ToNonNullString();
typeName = row["TypeName"].ToNonNullString();
methodName = row["MethodName"].ToNonNullString();
arguments = row["Arguments"].ToNonNullString();
if (string.IsNullOrWhiteSpace(assemblyName))
throw new InvalidOperationException("Data operation assembly name was not defined.");
if (string.IsNullOrWhiteSpace(typeName))
throw new InvalidOperationException("Data operation type name was not defined.");
if (string.IsNullOrWhiteSpace(methodName))
throw new InvalidOperationException("Data operation method name was not defined.");
// Load data operation from containing assembly and type
assembly = Assembly.LoadFrom(FilePath.GetAbsolutePath(assemblyName));
type = assembly.GetType(typeName);
method = type.GetMethod(methodName, BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod);
// Execute data operation via loaded assembly method
((DataOperationFunction)Delegate.CreateDelegate(typeof(DataOperationFunction), method))(connection, adapterType, m_nodeIDQueryString, arguments, m_iaonSession.StatusMessageHandler, m_iaonSession.ProcessExceptionHandler);
}
catch (Exception ex)
{
DisplayStatusMessage("Failed to execute startup data operation \"{0} [{1}::{2}()]\" due to exception: {3}", UpdateType.Warning, assemblyName, typeName, methodName, ex.Message);
m_serviceHelper.ErrorLogger.Log(ex);
}
}
}
catch (Exception ex)
{
DisplayStatusMessage("Failed to execute startup data operations due to exception: {0}", UpdateType.Warning, ex.Message);
m_serviceHelper.ErrorLogger.Log(ex);
}
}