public async Task <bool> CheckConnection() { try { var response = await _activationService.AttempCheckVersion(Address); if (string.IsNullOrWhiteSpace(response)) { _dialogService.Alert($"you are using an old version of LiveHAPI"); IsBusy = false; CurrentStatus = $"send failed! updated LiveHAPI "; return(false); } int.TryParse(response, out var version); if (version != _hapiVersion) { _dialogService.Alert($"you are using an old version of LiveHAPI"); IsBusy = false; CurrentStatus = $"send failed! update LiveHAPI to v{_hapiVersion}"; return(false); } var pracs = _practiceSetupService.GetAll(); var presponse = await _activationService.AttemptEnrollPractice(Address, pracs); } catch (Exception e) { _dialogService.Alert($"connection Error {e.Message}"); IsBusy = false; return(false); } return(true); }
private async void PushData() { IsBusy = true; CurrentStatus = $"connecting..."; var practice = await _activationService.GetLocal(Address); if (null != practice) { bool completed = true; try { var response = await _activationService.AttempCheckVersion(Address); if (string.IsNullOrWhiteSpace(response)) { _dialogService.Alert($"you are using an old version of LiveHAPI"); IsBusy = false; CurrentStatus = $"send failed! updated LiveHAPI "; return; } int.TryParse(response, out var version); if (version != _hapiVersion) { _dialogService.Alert($"you are using an old version of LiveHAPI"); IsBusy = false; CurrentStatus = $"send failed! update LiveHAPI to v{_hapiVersion}"; return; } var pracs = _practiceSetupService.GetAll(); await _activationService.AttemptEnrollPractice(Address, pracs); } catch (Exception e) { _dialogService.Alert($"connetion Error {e.Message}"); IsBusy = false; return; } var ids = _clientReaderService.LoadClientIds(); var count = ids.Count; int n = 0; var clientIdsDelete = new List <ClientToDeleteDTO>(); var encountersDelete = new List <EnconterToDeleteDTO>(); var practicses = _practiceSetupService.GetAll(); foreach (var id in ids) { var clientToDeleteDto = new ClientToDeleteDTO(); n++; var client = _clientReaderService.LoadClient(id); if (null != client) { var clientInfo = new SyncClientDTO(client); clientInfo.PracticeCode = GetCode(clientInfo.PracticeId, practicses); CurrentStatus = showPerc("Clients", n, count); var status = await _clientSyncService.AttempSendClients(Address, clientInfo); if (status) { clientToDeleteDto = new ClientToDeleteDTO(client.Id, client.PersonId); } else { completed = false; } } if (!clientToDeleteDto.NotSent) { var encounters = _clientReaderService.LoadEncounters(id); if (null != encounters && encounters.Count > 0) { var syncEncounters = SyncClientEncounterDTO.Create(encounters, client); var status = await _clientSyncService.AttempSendClientEncounters(Address, syncEncounters); if (status) { foreach (var encounter in encounters) { clientToDeleteDto.AddEnounter(new EnconterToDeleteDTO(encounter.Id, encounter.EncounterType)); } } else { completed = false; } } var shrs = _clientReaderService.LoadPSmartStores(id); if (null != shrs && shrs.Count > 0) { await _clientSyncService.SendClientShrs(Address, shrs); } clientIdsDelete.Add(clientToDeleteDto); foreach (var toDeleteDto in clientIdsDelete) { //TODO: ALLOW DELETE [] if (deleteOnPush) { _clientReaderService.Purge(toDeleteDto); } } } } // send CurrentStatus = $"done! sent {clientIdsDelete.Count} of {count} "; if (completed) { _dialogService.ShowToast("completed successfully"); } else { CurrentStatus = $"{CurrentStatus} with some Errors, Please check server logs"; _dialogService.Alert("send completed with errors"); } } else { IsBusy = false; CurrentStatus = $"connection failed !!"; _dialogService.Alert("Could not connect to server"); } IsBusy = false; }