public async Task <SupportQueryResult> QuerySupport(ReportQuery query) { var files = (await QueryEvacuationFiles(readCtx, query)).Concat(await QueryTasks(readCtx, query)); var results = (await ParallelLoadSupportsAsync(readCtx, files)).Select(e => mapper.Map <Support>(e)).ToArray(); return(new SupportQueryResult { Items = results }); }
public async Task <SupportQueryResult> QuerySupport(ReportQuery query) { var ct = new CancellationTokenSource().Token; var files = (await QueryEvacuationFiles(readCtx, query, ct)).Concat(await QueryTasks(readCtx, query, ct)); var results = await ParallelLoadSupportsAsync(readCtx, files, ct); return(new SupportQueryResult { Items = mapper.Map <IEnumerable <Support> >(results) }); }
public async Task <SupportQueryResult> QuerySupport(ReportQuery query) { var readCtx = essContext.Clone(); readCtx.MergeOption = MergeOption.NoTracking; var files = (await QueryEvacuationFiles(readCtx, query)).Concat(await QueryTasks(readCtx, query)); var results = (await ParallelLoadSupportsAsync(essContext, files)).Select(e => mapper.Map <Support>(e)).ToArray(); return(new SupportQueryResult { Items = results }); }
private static async Task <IEnumerable <era_evacuationfile> > QueryTasks(EssContext ctx, ReportQuery query, CancellationToken ct) { var shouldQueryTasks = string.IsNullOrEmpty(query.FileId) && string.IsNullOrEmpty(query.EvacuatedFrom) && (!string.IsNullOrEmpty(query.TaskNumber) || !string.IsNullOrEmpty(query.EvacuatedTo)); if (!shouldQueryTasks) { return(Array.Empty <era_evacuationfile>()); } var taskQuery = ctx.era_tasks.AsQueryable(); if (!string.IsNullOrEmpty(query.TaskNumber)) { taskQuery = taskQuery.Where(f => f.era_name == query.TaskNumber); } if (!string.IsNullOrEmpty(query.EvacuatedTo)) { taskQuery = taskQuery.Where(f => f._era_jurisdictionid_value == Guid.Parse(query.EvacuatedTo)); } var tasks = (await((DataServiceQuery <era_task>)taskQuery).GetAllPagesAsync(ct)).ToArray(); tasks.AsParallel().ForAll(t => ctx.AttachTo(nameof(EssContext.era_tasks), t)); await Parallel.ForEachAsync(tasks, ct, async (t, ct) => await ctx.LoadPropertyAsync(t, nameof(era_task.era_era_task_era_evacuationfileId), ct)); tasks.AsParallel().ForAll(t => { foreach (var file in t.era_era_task_era_evacuationfileId) { file.era_TaskId = t; } }); return(tasks.SelectMany(t => t.era_era_task_era_evacuationfileId)); }
private static async Task <IEnumerable <era_evacuationfile> > QueryEvacuationFiles(EssContext ctx, ReportQuery query, CancellationToken ct) { bool getAllFiles = string.IsNullOrEmpty(query.FileId) && string.IsNullOrEmpty(query.TaskNumber) && string.IsNullOrEmpty(query.EvacuatedFrom) && string.IsNullOrEmpty(query.EvacuatedTo); var shouldQueryFiles = !string.IsNullOrEmpty(query.FileId) || !string.IsNullOrEmpty(query.EvacuatedFrom) || getAllFiles; if (!shouldQueryFiles) { return(Array.Empty <era_evacuationfile>()); } var filesQuery = ctx.era_evacuationfiles.Expand(f => f.era_TaskId).AsQueryable(); if (!string.IsNullOrEmpty(query.FileId)) { filesQuery = filesQuery.Where(f => f.era_name == query.FileId || f.era_paperbasedessfile == query.FileId); } if (!string.IsNullOrEmpty(query.EvacuatedFrom)) { filesQuery = filesQuery.Where(f => f._era_evacuatedfromid_value == Guid.Parse(query.EvacuatedFrom)); } var files = (await((DataServiceQuery <era_evacuationfile>)filesQuery).GetAllPagesAsync(ct)).ToArray(); if (!string.IsNullOrEmpty(query.TaskNumber)) { files = files.Where(f => f.era_TaskId != null && f.era_TaskId.era_name.Equals(query.TaskNumber, StringComparison.OrdinalIgnoreCase)).ToArray(); } if (!string.IsNullOrEmpty(query.EvacuatedTo)) { files = files.Where(f => f.era_TaskId != null && f.era_TaskId._era_jurisdictionid_value == Guid.Parse(query.EvacuatedTo)).ToArray(); } return(files); }
private static async Task <IEnumerable <era_evacuationfile> > QueryEvacuationFiles(EssContext ctx, ReportQuery query) { bool getAllFiles = string.IsNullOrEmpty(query.FileId) && string.IsNullOrEmpty(query.TaskNumber) && string.IsNullOrEmpty(query.EvacuatedFrom) && string.IsNullOrEmpty(query.EvacuatedTo); var shouldQueryFiles = !string.IsNullOrEmpty(query.FileId) || !string.IsNullOrEmpty(query.EvacuatedFrom) || getAllFiles; if (!shouldQueryFiles) { return(Array.Empty <era_evacuationfile>()); } var filesQuery = ctx.era_evacuationfiles.Expand(f => f.era_TaskId).Where(f => f.statecode == (int)EntityState.Active); if (!string.IsNullOrEmpty(query.FileId)) { filesQuery = filesQuery.Where(f => f.era_name == query.FileId); } if (!string.IsNullOrEmpty(query.EvacuatedFrom)) { filesQuery = filesQuery.Where(f => f._era_evacuatedfromid_value == Guid.Parse(query.EvacuatedFrom)); } var files = (await((DataServiceQuery <era_evacuationfile>)filesQuery).GetAllPagesAsync()).ToArray(); if (!string.IsNullOrEmpty(query.TaskNumber)) { files = files.Where(f => f.era_TaskId.era_name == query.TaskNumber).ToArray(); } if (!string.IsNullOrEmpty(query.EvacuatedTo)) { files = files.Where(f => f.era_TaskId._era_jurisdictionid_value == Guid.Parse(query.EvacuatedTo)).ToArray(); } return(files); }
private static async Task <IEnumerable <era_evacuationfile> > QueryTasks(EssContext ctx, ReportQuery query) { var shouldQueryTasks = string.IsNullOrEmpty(query.FileId) && string.IsNullOrEmpty(query.EvacuatedFrom) && (!string.IsNullOrEmpty(query.TaskNumber) || !string.IsNullOrEmpty(query.EvacuatedTo)); if (!shouldQueryTasks) { return(Array.Empty <era_evacuationfile>()); } var taskQuery = ctx.era_tasks .Where(n => n.statecode == (int)EntityState.Active); if (!string.IsNullOrEmpty(query.TaskNumber)) { taskQuery = taskQuery.Where(f => f.era_name == query.TaskNumber); } if (!string.IsNullOrEmpty(query.EvacuatedTo)) { taskQuery = taskQuery.Where(f => f._era_jurisdictionid_value == Guid.Parse(query.EvacuatedTo)); } var tasks = (await((DataServiceQuery <era_task>)taskQuery).GetAllPagesAsync()).ToArray(); var files = new List <era_evacuationfile>(); foreach (var task in tasks) { ctx.AttachTo(nameof(EssContext.era_tasks), task); var currentFiles = ctx.LoadProperty(task, nameof(era_task.era_era_task_era_evacuationfileId)); foreach (var file in currentFiles) { files.Add((era_evacuationfile)file); } } return(files); }