BlueCollar.SQLiteRepository.GetHistoryList C# (CSharp) Метод

GetHistoryList() публичный Метод

Gets a list of history records.
public GetHistoryList ( string applicationName, string search, int limit, int offset, IDbTransaction transaction ) : RecordList
applicationName string The name of the application to get the history list for.
search string The search query to filter the collection with.
limit int The paging limit to use.
offset int The paging offset to use.
transaction IDbTransaction The transaction to use, if applicable.
Результат RecordList
        public RecordList<HistoryListRecord> GetHistoryList(string applicationName, string search, int limit, int offset, IDbTransaction transaction)
        {
            StringBuilder cb = new StringBuilder(
            @"SELECT CAST(COUNT(h.[Id]) AS bigint)
            FROM [BlueCollarHistory] h
            LEFT OUTER JOIN [BlueCollarSchedule] s ON h.[ScheduleId] = s.[Id]
            WHERE
            h.[ApplicationName] = @ApplicationName");

            StringBuilder sb = new StringBuilder(
            @"SELECT
            h.[Id],
            h.[QueueName],
            h.[JobName],
            h.[JobType],
            h.[QueuedOn],
            h.[TryNumber],
            h.[StartedOn],
            h.[Status],
            h.[FinishedOn],
            s.[Name] AS [ScheduleName]
            FROM [BlueCollarHistory] h
            LEFT OUTER JOIN [BlueCollarSchedule] s ON h.[ScheduleId] = s.[Id]
            WHERE
            h.[ApplicationName] = @ApplicationName");

            if (!string.IsNullOrEmpty(search))
            {
                const string Search = @"
            AND
            (
            h.[QueueName] LIKE @Search
            OR h.[JobName] LIKE @Search
            OR h.[JobType] LIKE @Search
            OR h.[Status] LIKE @Search
            OR s.[Name] LIKE @Search
            )";

                cb.Append(Search);
                sb.Append(Search);
            }

            cb.Append(";\n\n");

            sb.Append("\n");
            sb.Append(
            @"ORDER BY h.[QueuedOn] DESC, h.[JobName] ASC, h.[TryNumber] DESC
            LIMIT @Limit OFFSET @Offset;");

            sb.Append("\n");
            sb.Append(CountsSql);

            var p = new
            {
                ApplicationName = applicationName,
                Search = !string.IsNullOrEmpty(search) ? string.Concat("%", search, "%") : null,
                Limit = limit,
                Offset = offset
            };

            var list = new RecordList<HistoryListRecord>();

            using (var multi = this.connection.QueryMultiple(cb.ToString() + sb.ToString(), p, transaction, null, null))
            {
                list.SetPaging(multi.Read<long>().First(), limit, offset);

                foreach (var record in multi.Read<HistoryListRecord>())
                {
                    list.Records.Add(record);
                }

                list.Counts = CreateCounts(multi);
            }

            return list;
        }