public async void LoadExamplesToStore() { var messages = new StringBuilder(); var notifier = new HubContextProgressNotifier(_hubContext, _logger); try { await notifier.SendProgressUpdate("Loading examples data...", 1); _resources = GetExampleData(); var resarray = _resources.ToArray(); _resourceCount = resarray.Count(); for (int x = 0; x <= _resourceCount - 1; x++) { var res = resarray[x]; // Sending message: var msg = Message("Importing " + res.ResourceType.ToString() + " " + res.Id + "...", x); await notifier.SendProgressUpdate(msg.Message, msg.Progress); try { Key key = res.ExtractKey(); if (res.Id != null && res.Id != "") { _fhirService.Put(key, res); } else { _fhirService.Create(key, res); } } catch (Exception e) { // Sending message: var msgError = Message("ERROR Importing " + res.ResourceType.ToString() + " " + res.Id + "... ", x); await Clients.All.SendAsync("Error", msg); messages.AppendLine(msgError.Message + ": " + e.Message); } } await notifier.SendProgressUpdate(messages.ToString(), 100); } catch (Exception e) { await notifier.Progress("Error: " + e.Message); } }
public async void ClearStore() { var notifier = new HubContextProgressNotifier(_hubContext, _logger); try { await notifier.SendProgressUpdate("Clearing the database...", 0); _fhirStoreAdministration.Clean(); _fhirIndex.Clean(); await notifier.SendProgressUpdate("Database cleared", 100); } catch (Exception e) { await notifier.SendProgressUpdate("ERROR CLEARING :( " + e.InnerException, 100); } }
public async void RebuildIndex() { var notifier = new HubContextProgressNotifier(_hubContext, _logger); try { await _indexRebuildService.RebuildIndexAsync(notifier) .ConfigureAwait(false); } catch (Exception e) { _logger.LogError(e, "Failed to rebuild index"); await notifier.SendProgressUpdate("ERROR REBUILDING INDEX :( " + e.InnerException, 100) .ConfigureAwait(false); } }