protected virtual IDisposable Present(Func<UIAlertController> alertControllerFactory) { UIAlertController alertController = null; InvokeOnMainThread(() => { alertController = alertControllerFactory(); var viewController = ViewControllerFactory(); if (viewController == null) { throw new InvalidOperationException("'ViewControllerFactory' must produce not null view controller"); } viewController.PresentViewController(alertController, true, null); }); return new DisposableAction(() => { try { InvokeOnMainThread(() => alertController.DismissViewController(true, null)); } catch (Exception exception) { Mvx.TaggedError(Tag, exception.ToString()); } }); }
protected async Task <MvxViewModelInstanceRequest> NavigationRouteRequest(string path, IMvxBundle presentationBundle = null) { KeyValuePair <Regex, Type> entry; if (!TryGetRoute(path, out entry)) { return(null); } var regex = entry.Key; var match = regex.Match(path); var paramDict = BuildParamDictionary(regex, match); var parameterValues = new MvxBundle(paramDict); var viewModelType = entry.Value; IMvxViewModel viewModel; if (viewModelType.GetInterfaces().Contains(typeof(IMvxNavigationFacade))) { var facade = (IMvxNavigationFacade)Mvx.IocConstruct(viewModelType); try { var facadeRequest = await facade.BuildViewModelRequest(path, paramDict); viewModel = (IMvxViewModel)Mvx.IocConstruct(facadeRequest.ViewModelType); if (facadeRequest == null) { Mvx.TaggedWarning("MvxNavigationService", "Facade did not return a valid MvxViewModelRequest."); return(null); } } catch (Exception ex) { Mvx.TaggedError("MvxNavigationService", "Exception thrown while processing URL: {0} with RoutingFacade: {1}, {2}", path, viewModelType, ex); return(null); } } else { try { viewModel = (IMvxViewModel)Mvx.IocConstruct(viewModelType); } catch (Exception exception) { throw exception.MvxWrap("Problem creating viewModel of type {0}", viewModelType.Name); } } return(new MvxViewModelInstanceRequest(viewModel) { ParameterValues = parameterValues.SafeGetData(), PresentationValues = presentationBundle?.SafeGetData() }); }
private async Task <IMvxViewModel> NavigateRoute(string path) { KeyValuePair <Regex, Type> entry; if (!TryGetRoute(path, out entry)) { return(null); } var regex = entry.Key; var match = regex.Match(path); var paramDict = BuildParamDictionary(regex, match); var viewModelType = entry.Value; MvxViewModelRequest request = null; IMvxViewModel viewModel; if (viewModelType.GetInterfaces().Contains(typeof(IMvxNavigationFacade))) { var facade = (IMvxNavigationFacade)Mvx.IocConstruct(viewModelType); try { var facadeRequest = await facade.BuildViewModelRequest(path, paramDict); viewModel = (IMvxViewModel)Mvx.IocConstruct(facadeRequest.ViewModelType); if (facadeRequest == null) { Mvx.TaggedWarning("MvxNavigationService", "Facade did not return a valid MvxViewModelRequest."); return(null); } } catch (Exception ex) { Mvx.TaggedError("MvxNavigationService", "Exception thrown while processing URL: {0} with RoutingFacade: {1}, {2}", path, viewModelType, ex); return(null); } } else { viewModel = (IMvxViewModel)Mvx.IocConstruct(viewModelType); } request = new MvxViewModelInstanceRequest(viewModel) { ParameterValues = new MvxBundle(paramDict).SafeGetData() }; _viewDispatcher.ShowViewModel(request); return(viewModel); }
private int GetSectionCount() { try { return(ItemsSource?.Count() ?? 0); } catch (Exception ex) { Mvx.TaggedError(LogTag, "Exception in {0} ({1})", nameof(GetSectionCount), ex); } return(0); }
private int GetSectionItemCount(int sectionIndex) { try { var sectionItems = ItemsSource?.ElementAt(sectionIndex) as IEnumerable; return(sectionItems?.Count() ?? 0); } catch (Exception ex) { Mvx.TaggedError(LogTag, "Exception in {0} ({1})", nameof(GetSectionItemCount), ex); } return(0); }
public async Task RouteAsync(string url, MvxRequestedBy requestedBy) { KeyValuePair <Regex, Type> entry; if (!TryGetRoute(url, out entry)) { return; } var regex = entry.Key; var match = regex.Match(url); var paramDict = BuildParamDictionary(regex, match); var viewModelType = entry.Value; MvxViewModelRequest request = null; if (viewModelType.GetInterfaces().Contains(typeof(IMvxRoutingFacade))) { var facade = (IMvxRoutingFacade)Mvx.IocConstruct(viewModelType); try { request = await facade.BuildViewModelRequest(url, paramDict, requestedBy); } catch (Exception ex) { Mvx.TaggedError("MvxRoutingService", "Exception thrown while processing URL: {0} with RoutingFacade: {1}, {2}", url, viewModelType, ex); } if (request == null) { Mvx.TaggedWarning("MvxRoutingService", "Facade did not return a valid MvxViewModelRequest."); return; } } else { request = new MvxViewModelRequest( viewModelType, new MvxBundle(paramDict), null, requestedBy); } _viewDispatcher.ShowViewModel(request); }
protected override async Task Load() { await base.Load(); try { await UpdateService.UpdateAsync(); } catch (Exception exception) { Mvx.TaggedError(Tag, exception.ToString()); await AlertService.ErrorAsync(exception.Message); } finally { await NavigationService.Navigate <CitiesViewModel>(); } }
private static bool TryGetRoute(string url, out KeyValuePair <Regex, Type> entry) { try { var matches = Routes.Where(t => t.Key.IsMatch(url)).ToList(); switch (matches.Count) { case 0: entry = default(KeyValuePair <Regex, Type>); Mvx.TaggedTrace("MvxNavigationService", "Unable to find routing for {0}", url); return(false); case 1: entry = matches[0]; return(true); } var directMatch = matches.Where(t => t.Key.Match(url).Groups.Count == 1).ToList(); if (directMatch.Count == 1) { entry = directMatch[0]; return(true); } Mvx.TaggedWarning("MvxNavigationService", "The following regular expressions match the provided url ({0}), each RegEx must be unique (otherwise try using IMvxRoutingFacade): {1}", matches.Count - 1, string.Join(", ", matches.Select(t => t.Key.ToString()))); // there is more than one match return(false); } catch (Exception ex) { Mvx.TaggedError("MvxNavigationService", "Unable to determine routability: {0}", ex); return(false); } }
private async Task DoGetAllWifiInfoCommand(CancellationToken token = default(CancellationToken)) { IsScanning = true; try { var allInfo = await _wifi.GetAllWifiInfoAsync(token).ConfigureAwait(false); _dispatcher.RequestMainThreadAction(() => { WifiInfo.Clear(); WifiInfo.AddRange(allInfo.Select(info => new WifiInfoViewModel(info))); }); } catch (Exception e) { Mvx.TaggedError("WifiViewModel", $"Failed getting All Wifi Info: {e}"); } finally { IsScanning = false; } }
public override void OnConnectionStateChange(BluetoothGatt gatt, GattStatus status, ProfileState newState) { base.OnConnectionStateChange(gatt, status, newState); IDevice device = null; if (status != GattStatus.Success) { Mvx.TaggedError("OnConnectionStateChange", "GattCallback error: {0}", status); device = new Device(gatt.Device, gatt, this, 0); DeviceConnectionError(this, new DeviceConnectionEventArgs() { Device = device }); // We don't return. Allowing to fall-through to the SWITCH, which will assume a disconnect, close GATT and clean up. // The above error event handles the case where the error happened during a Connect call, which will close out any waiting asyncs. } else { Mvx.Trace("GattCallback state: {0}", newState.ToString()); } switch (newState) { // disconnected case ProfileState.Disconnected: if (DeviceOperationRegistry.TryGetValue(gatt.Device.Address, out device)) { Mvx.Trace("Disconnected by user"); //Found so we can remove it DeviceOperationRegistry.Remove(gatt.Device.Address); ConnectedDeviceRegistry.Remove(gatt.Device.Address); gatt.Close(); DeviceDisconnected(this, new DeviceConnectionEventArgs { Device = device }); break; } //connection must have been lost, bacause our device was not found in the registry but was still connected if (ConnectedDeviceRegistry.TryGetValue(gatt.Device.Address, out device)) { Mvx.Trace("Disconnected by lost connection"); ConnectedDeviceRegistry.Remove(gatt.Device.Address); gatt.Close(); DeviceConnectionLost(this, new DeviceConnectionEventArgs() { Device = device }); break; } gatt.Close(); // Close GATT regardless, else we can accumulate zombie gatts. Mvx.Trace("Disconnect. Device not found in registry. Not raising disconnect/lost event."); break; // connecting case ProfileState.Connecting: Mvx.Trace("Connecting"); break; // connected case ProfileState.Connected: Mvx.Trace("Connected"); //Try to find the device in the registry so that the same instance is updated if (DeviceOperationRegistry.TryGetValue(gatt.Device.Address, out device)) { ((Device)device).Update(gatt.Device, gatt, this); //Found so we can remove it DeviceOperationRegistry.Remove(gatt.Device.Address); } else { //only for on auto-reconnect (device is not in operation registry) device = new Device(gatt.Device, gatt, this, 0); } ConnectedDeviceRegistry[gatt.Device.Address] = device; DeviceConnected(this, new DeviceConnectionEventArgs() { Device = device }); break; // disconnecting case ProfileState.Disconnecting: Mvx.Trace("Disconnecting"); break; } }
public void Error(string format, params object[] args) { Mvx.TaggedError(_tag, format, args); }
public static void NetError(string message, params object[] args) { Mvx.TaggedError("MyAppNet", message, args); }
public static void TaggedError(string tag, string message, params object[] args) { Mvx.TaggedError(tag, message, args); }
public void Error(string message, params object[] args) { Mvx.TaggedError(_tag, message, args); }