protected async override void OnAppearing() { // invoked just before the screen appears to the user. base.OnAppearing(); Domain.Models.ResponseModels.RegisterDeviceModel registrationInfo = await ViewModel.GetDeviceStatusAsync(); // TODO: move Status to enum as in specification if (registrationInfo.Status == "0") { Domain.Models.ResponseModels.RegisterDeviceModel regMod = await ViewModel.RegisterDeviceAsync(); // TODO: add if DEBUG before going to prod if (regMod.Success) { var answer = await DisplayAlert("Device Registration", "This device has not been approved to run the EFR " + "app. Would you like to submit an approval request so this device can be approved to run the EFR app?", "Yes", "No"); // Request hasn't been sent nor processed -- debug will approve if (answer) { // TODO: Remove automatic approval of device. await ViewModel.ChangeDeviceStatusAsync(); await DisplayAlert("Device Registration", "An approval request for this device to be used with the EFR " + "app has been sent. The approval process can take a few business days. Please check back tomorrow.", "OK"); } else { } } } // Registration request received, but not processed yet. else if (registrationInfo.Status == "1") { await DisplayAlert("Device Registration", "An approval request for this device to be used with the EFR app has " + "been sent, but the approval has yet to be granted. The approval process can take a few business days. Please " + "check back tomorrow.", "OK"); } // Success - Device has been approved and can run this application else if (registrationInfo.Status == "2") { //TODO: Settings needs to be moved out of Services. Settings.SetAuthorizationToken(registrationInfo.AuthToken); } // Device not allowed to run this application else if (registrationInfo.Status == "3") { await DisplayAlert("Device Registration", "This mobile application is not allowed to run on this device. Please " + "contact support if you need help. The app will now close.", "OK"); } // Request was declined else if (registrationInfo.Status == "4") { await DisplayAlert("Device Registration", "The request to register this device was declined by a system admin and " + "blocked from connecting to Passport. The app will now close.", "OK"); } }
/// <summary>Gets the device status indicating if the device can be used with the system asynchronous.</summary> public async Task <Domain.Models.ResponseModels.RegisterDeviceModel> GetDeviceStatusAsync() { Acs.Domain.Models.RequestModels.RegisterDeviceModel deviceInfo = GetDeviceDetails(); Domain.Models.ResponseModels.RegisterDeviceModel sd = await _authService.GetDeviceStatusAsync(deviceInfo); Settings.SetAuthorizationToken(sd.AuthToken); return(sd); }
/// <summary>Registers the device asynchronously.</summary> /// <returns>A Task<Domain.Models.ResponseModels.RegisterDeviceModel>.</returns> public async Task <Domain.Models.ResponseModels.RegisterDeviceModel> RegisterDeviceAsync() { Acs.Domain.Models.RequestModels.RegisterDeviceModel deviceInfo = GetDeviceDetails(); // Register device and set AuthToken Domain.Models.ResponseModels.RegisterDeviceModel registerModel = await _authService.RegisterDeviceAsync(deviceInfo); Settings.SetAuthorizationToken(registerModel.AuthToken); return(registerModel); }
/// <summary> /// Allows a user to request a physical device be registered for use with the eForm platform. A device must be /// approved before it will be allowed to access the syste. /// </summary> /// <param name="registerModel">A set of information that uniquely identifies the device.</param> /// <returns></returns> public async Task <Domain.Models.ResponseModels.RegisterDeviceModel> RegisterDeviceAsync( Domain.Models.RequestModels.RegisterDeviceModel registerModel) { if (null == registerModel) { throw new ArgumentException($"Argument can neither be null nor empty.", nameof(registerModel)); } var apiSegment = "/device"; // Use the base url and append the api's segment for this method. string requestUrl = new StringBuilder(50) .Append(UrlBuildFactory.GetDefaultBaseUrl()) .Append(apiSegment).ToString(); Domain.Models.ResponseModels.RegisterDeviceModel result = null; try { //var client = new HttpClient(); using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(requestUrl); var data = JsonConvert.SerializeObject(registerModel); var content = new StringContent(data, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(requestUrl, content); result = JsonConvert.DeserializeObject <Domain.Models.ResponseModels.RegisterDeviceModel>( response.Content.ReadAsStringAsync().Result); } } catch (Exception e) { var inMsg = (null == e.InnerException) ? String.Empty : $"Inner Excp: {e.InnerException.Message}"; var msg = ($"Exception in RegistrerDeviceService: {e.Message}{Environment.NewLine}{inMsg}"); Debug.WriteLine(msg); } return(result); }
/// <summary>Checks for the status of a particular device.</summary> /// <param name="deviceInfo">A <see cref="Domain.Models.ResponseModels.RegisterDeviceModel"/> type providing necessary /// on which to verify the device.</param> /// <returns><see cref="Domain.Models.ResponseModels.RegisterDeviceModel"/> containing the current <c>Status</c> /// of the device.</returns> public async Task <Domain.Models.ResponseModels.RegisterDeviceModel> GetDeviceStatusAsync( Domain.Models.RequestModels.RegisterDeviceModel deviceInfo) { if (null == deviceInfo || String.IsNullOrWhiteSpace(deviceInfo.SerialNumber)) { throw new ArgumentException($"Argument can neither be null nor empty.", nameof(deviceInfo)); } var apiSegment = "/device/"; // Use the base url and append the api's segment for this method. string requestUrl = new StringBuilder(50).Append(UrlBuildFactory.GetDefaultBaseUrl()).Append(apiSegment) .Append(deviceInfo.SerialNumber).ToString(); // https://passport-lab.accessefm.com/api/v2/mobile/device/R38J60D3CDN Domain.Models.ResponseModels.RegisterDeviceModel result = null; try { // Ensure the HttpClient is being disposed. using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(requestUrl); // Calling the API. var response = await client.GetAsync(requestUrl); var placesJson = response.Content.ReadAsStringAsync().Result; result = JsonConvert.DeserializeObject <Domain.Models.ResponseModels.RegisterDeviceModel>(placesJson); } } catch (Exception ex) { Debug.WriteLine($"EXCEPTION: {ex.Message}"); } return(result); }