public void GeneratingStringForDebugging() { var sql = new SqlObjectDefault(@"select * from users where name = @Name and age > @Age", new System.Collections.Generic.Dictionary <string, object> { { "@Name", "John" }, { "@Age", "15" } }); Assert.Equal("select * from users where name = John and age > 15", sql.ToString()); }
/// <summary> /// Execute job /// </summary> public async Task Execute(IJobExecutionContext context) { JobDataMap dataMap = context.JobDetail.JobDataMap; var logger = (ILogger <MainJob>)dataMap["Logger"]; var repository = (IRepository)dataMap["Repository"]; var sender = (ISenderEntity)dataMap["Sender"]; var config = (JobTriggerInfo)dataMap["Config"]; logger.LogInformation($"Start job for {config.ContextType}"); try { IEnumerable <StoryRunnerMessageWork> sendItems = Enumerable.Empty <StoryRunnerMessageWork>(); // Context value objects if (config.ContextValue != null) { sendItems = await CreateSendObjects(config.ContextValue, config.ContextType); } // SQL if (!string.IsNullOrEmpty(config.SqlString)) { var sqlObject = new SqlObjectDefault( config.SqlString, new { DateChangeFrom = config.DateChangeOffsetFrom.HasValue ? DateTime.Now.AddHours(config.DateChangeOffsetFrom.Value) : new DateTime(1900, 01, 01), DateChangeTo = config.DateChangeOffsetTo.HasValue ? DateTime.Now.AddHours(config.DateChangeOffsetTo.Value) : new DateTime(1900, 01, 01), }); sendItems = await CreateSendObjectsSQL(repository, sqlObject, config.ContextType); } logger.LogInformation($"Find send Items - {sendItems.Count()}"); Parallel.ForEach(sendItems, new ParallelOptions() { MaxDegreeOfParallelism = 50 }, item => { sender.Send <QueueMessageRabbitMQ>(item, config.ContextType, config.NameQueue); }); } catch (Exception exp) { logger.LogCritical(exp, exp.Message); } logger.LogInformation($"End job for {config.ContextType}"); }