public int CreateQueuedAndHistoryForSchedule(long scheduleId, DateTime scheduleDate, IEnumerable<QueueRecord> queued, IEnumerable<HistoryRecord> history, IDbTransaction transaction)
{
int created = 0;
bool commitRollback = false;
if (transaction == null)
{
commitRollback = true;
transaction = this.BeginTransaction();
}
try
{
const string InsertQueuedSql =
@"INSERT INTO [BlueCollarQueue]([ApplicationName],[ScheduleId],[QueueName],[JobName],[JobType],[Data],[QueuedOn],[TryNumber])
VALUES(@ApplicationName,@ScheduleId,@QueueName,@JobName,@JobType,@Data,@QueuedOn,@TryNumber);";
const string InsertHistorySql =
@"INSERT INTO [BlueCollarHistory]([ApplicationName],[WorkerId],[ScheduleId],[QueueName],[JobName],[JobType],[Data],[QueuedOn],[TryNumber],[StartedOn],[Status],[Exception],[FinishedOn])
VALUES (@ApplicationName,@WorkerId,@ScheduleId,@QueueName,@JobName,@JobType,@Data,@QueuedOn,@TryNumber,@StartedOn,@StatusString,@Exception,@FinishedOn);";
if (queued != null && queued.Count() > 0)
{
created += this.connection.Execute(InsertQueuedSql, queued, transaction, null, null);
}
if (history != null && history.Count() > 0)
{
created += this.connection.Execute(InsertHistorySql, history, transaction, null, null);
}
if (commitRollback)
{
transaction.Commit();
}
}
catch
{
if (commitRollback)
{
transaction.Rollback();
}
throw;
}
finally
{
if (commitRollback)
{
transaction.Dispose();
}
}
return created;
}