private async Task ProcessPostImportAsync() { int updates; DictPostImport(); using (BankingDbContext db = new BankingDbContext(Options.DbConnection)) { foreach (var item in PostImport) { try { updates = await db.Database.ExecuteSqlCommandAsync(item.Value); Log(item.Key, updates); } catch (Exception ex) { Log($"Error in SQL '{item.Key}' with [{ex}]"); } } } PostImport.Clear(); }
public IList <PostImport> GetPostImport() { IList <PostImport> objList = new List <PostImport>(); Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "USP_POST_IMPORT_G"; DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { PostImport obj = CreateModelObject(dataReader); objList.Add(obj); } } return(objList); }
public async Task <IEnumerable <ILive <TModel> > > Import(ProgressNotification notification, params ImportTask[] tasks) { if (tasks.Length == 0) { notification.CompletionText = $"No {HumanisedModelName}s were found to import!"; notification.State = ProgressNotificationState.Completed; return(Enumerable.Empty <ILive <TModel> >()); } notification.Progress = 0; notification.Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import is initialising..."; int current = 0; var imported = new List <ILive <TModel> >(); bool isLowPriorityImport = tasks.Length > low_priority_import_batch_size; try { await Task.WhenAll(tasks.Select(async task => { notification.CancellationToken.ThrowIfCancellationRequested(); try { var model = await Import(task, isLowPriorityImport, notification.CancellationToken).ConfigureAwait(false); lock (imported) { if (model != null) { imported.Add(model); } current++; notification.Text = $"Imported {current} of {tasks.Length} {HumanisedModelName}s"; notification.Progress = (float)current / tasks.Length; } } catch (TaskCanceledException) { throw; } catch (Exception e) { Logger.Error(e, $@"Could not import ({task})", LoggingTarget.Database); } })).ConfigureAwait(false); } catch (OperationCanceledException) { if (imported.Count == 0) { notification.State = ProgressNotificationState.Cancelled; return(imported); } } if (imported.Count == 0) { notification.Text = $"{HumanisedModelName.Humanize(LetterCasing.Title)} import failed!"; notification.State = ProgressNotificationState.Cancelled; } else { notification.CompletionText = imported.Count == 1 ? $"Imported {imported.First().Value.GetDisplayString()}!" : $"Imported {imported.Count} {HumanisedModelName}s!"; if (imported.Count > 0 && PostImport != null) { notification.CompletionText += " Click to view."; notification.CompletionClickAction = () => { PostImport?.Invoke(imported); return(true); }; } notification.State = ProgressNotificationState.Completed; } return(imported); }