本文整理匯總了C#中Service.List.Sum方法的典型用法代碼示例。如果您正苦於以下問題:C# List.Sum方法的具體用法?C# List.Sum怎麽用?C# List.Sum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Service.List
的用法示例。
在下文中一共展示了List.Sum方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetTime
/// <summary>
/// Gets the total time spended on TS3 for specified client.
/// </summary>
/// <param name="clientDatabaseId">The client database id.</param>
/// <param name="fromTime">From time.</param>
/// <param name="toTime">To time.</param>
/// <returns></returns>
public double GetTime(uint clientDatabaseId, DateTime? fromTime, DateTime? toTime)
{
lock (Container.lockTimeClientList)
{
lock (Repository.Container.lockDatabase)
{
var times = new List<TimeClientEntity>();
using (var command = new SQLiteCommand(this.Container.DatabaseConnection))
{
command.CommandText = string.Format("SELECT ClientDatabaseId, Joined, Disconnected, TotalMinutes FROM Time WHERE ClientDatabaseId = {0}", clientDatabaseId);
if (fromTime.HasValue) command.CommandText += string.Format(" AND Disconnected > {0}", fromTime.Value.ToTimeStamp());
if (toTime.HasValue) command.CommandText += string.Format(" AND Joined < {0}", toTime.Value.ToTimeStamp());
using (var reader = command.ExecuteReader())
{
while (reader.HasRows && reader.Read())
{
times.Add(new TimeClientEntity
{
User = (uint)reader.GetInt32(0),
Joined = reader.GetInt32(1).ToDateTime(),
Disconnected = reader.GetInt32(2).ToDateTime(),
TotalMinutes = reader.GetInt32(3)
});
}
}
}
return times.Sum(m => m.GetTime(fromTime, toTime));
}
}
}