public void Load() { Mvx.RegisterType <IMvxReachability, MvxReachability>(); Mvx.RegisterType <IMvxRestClient, MvxJsonRestClient>(); Mvx.RegisterType <IMvxJsonRestClient, MvxJsonRestClient>(); }
public void Load() { Mvx.RegisterSingleton <IDeviceInfo>(new WindowsCommonDeviceInfo()); Mvx.RegisterSingleton <IDisplay>(new WindowsCommonDisplay()); }
public void Load() { Mvx.RegisterType <IMvxShareTask, MvxShareTask>(); }
private void RegisterIocServices() { Mvx.LazyConstructAndRegisterSingleton <IStockService, StockService>(); }
public void EnsureLoaded() { var manager = Mvx.Resolve <IMvxPluginManager>(); manager.EnsurePlatformAdaptionLoaded <PluginLoader>(); }
/// <summary> /// Reports the success. /// </summary> /// <param name="message">The message.</param> public static void ReportSuccess(string message) { Mvx.Resolve <IErrorReporter>().ReportSuccess(message); }
protected override void InitializeIoC() { base.InitializeIoC(); Mvx.RegisterSingleton <IDialogService>(() => new DialogService()); }
protected MvxTableViewSource(IntPtr handle) : base(handle) { Mvx.Warning("TableViewSource IntPtr constructor used - we expect this only to be called during memory leak debugging - see https://github.com/MvvmCross/MvvmCross/pull/467"); }
public App() { Mvx.RegisterType <ICalculation, Calculation>(); Mvx.RegisterSingleton <IMvxAppStart>(new MvxAppStart <TipCalcViewModel>()); }
/// <summary> /// Show Fragment with a specific tag at a specific placeholder /// </summary> /// <param name="tag">The tag for the fragment to lookup</param> /// <param name="contentId">Where you want to show the Fragment</param> /// <param name="bundle">Bundle which usually contains a Serialized MvxViewModelRequest</param> /// <param name="forceAddToBackStack">If you want to force add the fragment to the backstack so on backbutton it will go back to it. Note: This will override IMvxCachedFragmentInfo.AddToBackStack configuration.</param> /// <param name="forceReplaceFragment">If you want the fragment to be re-created</param> protected virtual void ShowFragment(string tag, int contentId, Bundle bundle, bool forceAddToBackStack = false, bool forceReplaceFragment = false) { IMvxCachedFragmentInfo fragInfo; FragmentCacheConfiguration.TryGetValue(tag, out fragInfo); IMvxCachedFragmentInfo currentFragInfo = null; var currentFragment = FragmentManager.FindFragmentById(contentId); if (currentFragment != null) { FragmentCacheConfiguration.TryGetValue(currentFragment.Tag, out currentFragInfo); } if (fragInfo == null) { throw new MvxException("Could not find tag: {0} in cache, you need to register it first.", tag); } // We shouldn't replace the current fragment unless we really need to. FragmentReplaceMode fragmentReplaceMode = FragmentReplaceMode.ReplaceFragmentAndViewModel; if (!forceReplaceFragment) { fragmentReplaceMode = ShouldReplaceCurrentFragment(fragInfo, currentFragInfo, bundle); } if (fragmentReplaceMode == FragmentReplaceMode.NoReplace) { return; } var ft = FragmentManager.BeginTransaction(); OnBeforeFragmentChanging(fragInfo, ft); fragInfo.ContentId = contentId; //If we already have a previously created fragment, we only need to send the new parameters if (fragInfo.CachedFragment != null && fragmentReplaceMode == FragmentReplaceMode.ReplaceFragment) { (fragInfo.CachedFragment as Fragment).Arguments.Clear(); (fragInfo.CachedFragment as Fragment).Arguments.PutAll(bundle); var childViewModelCache = Mvx.GetSingleton <IMvxChildViewModelCache>(); var viewModelType = fragInfo.CachedFragment.ViewModel.GetType(); if (childViewModelCache.Exists(viewModelType)) { fragInfo.CachedFragment.ViewModel = childViewModelCache.Get(viewModelType); childViewModelCache.Remove(viewModelType); } } else { //Otherwise, create one and cache it fragInfo.CachedFragment = Fragment.Instantiate(this, FragmentJavaName(fragInfo.FragmentType), bundle) as IMvxFragmentView; OnFragmentCreated(fragInfo, ft); } currentFragment = fragInfo.CachedFragment as Fragment; ft.Replace(fragInfo.ContentId, fragInfo.CachedFragment as Fragment, fragInfo.Tag); //if replacing ViewModel then clear the cache after the fragment //has been added to the transaction so that the Tag property is not null //and the UniqueImmutableCacheTag property (if not overridden) has the correct value if (fragmentReplaceMode == FragmentReplaceMode.ReplaceFragmentAndViewModel) { var cache = Mvx.GetSingleton <IMvxMultipleViewModelCache>(); cache.GetAndClear(fragInfo.ViewModelType, GetTagFromFragment(fragInfo.CachedFragment as Fragment)); } if (currentFragment != null && fragInfo.AddToBackStack || forceAddToBackStack) { ft.AddToBackStack(fragInfo.Tag); } OnFragmentChanging(fragInfo, ft); ft.Commit(); FragmentManager.ExecutePendingTransactions(); OnFragmentChanged(fragInfo); }
public void Load() { Mvx.RegisterType <IMvxResourceLoader, MvxStoreResourceLoader>(); }
public MainView() { InitializeComponent(); DataContext = Mvx.Resolve <MainViewModel>(); }
public async Task TellApiAboutUnRegistrationAsync() { Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, "ApiService", "Telling Api Server to remove all registrations"); await Task.Delay(3000); }
// You would probably actually talk with an actual API somewhere in here public async Task TellApiAboutRegistrationAsync(string registrationId) { Mvx.TaggedTrace(MvxTraceLevel.Diagnostic, "ApiService", "Telling Api Server about {0}", registrationId); await Task.Delay(3000); }
/// <summary> /// Reports the error. /// </summary> /// <param name="error">The error.</param> /// <param name="buttonText">The button text.</param> /// <param name="action">The action.</param> /// <param name="length">The length.</param> public static void ReportError(string error, string buttonText, Action <View> action, ErrorLength length = ErrorLength.Finite) { Mvx.Resolve <IErrorReporter>().ReportError(error, buttonText, action, length); }
public static void Mn(string message = "", [CallerMemberName] string callerName = "") { Mvx.Trace(string.Format("[{0}] - {1}", callerName, message)); }
/// <summary> /// Reports the error. /// </summary> /// <param name="error">The error.</param> /// <param name="length">The length.</param> public static void ReportError(string error, ErrorLength length = ErrorLength.Finite) { Mvx.Resolve <IErrorReporter>().ReportError(error, length); }
public StoredSettingsService() { _storedSettingsBase = Mvx.Resolve <IStoredSettingsBase>(); }
protected override void InitializeLastChance() { Mvx.RegisterSingleton <IAsyncStorageService>(new AsyncStorageTouchService()); base.InitializeLastChance(); }
private async Task RequestImageAsync(string imageSource) { FireImageChanged(null); if (string.IsNullOrEmpty(imageSource)) { await ShowDefaultImage().ConfigureAwait(false); return; } if (imageSource.ToUpper().StartsWith("HTTP")) { await NewHttpImageRequestedAsync().ConfigureAwait(false); var error = false; try { var cache = Mvx.Resolve <IMvxImageCache <T> >(); var image = await cache.RequestImage(imageSource).ConfigureAwait(false); if (image == null) { await ShowErrorImage().ConfigureAwait(false); } else { NewImageAvailable(image); } } catch (Exception ex) { Mvx.Trace("failed to download image {0} : {1}", imageSource, ex.ToLongString()); error = true; } if (error) { await HttpImageErrorSeenAsync().ConfigureAwait(false); } } else { try { var image = await ImageFromLocalFileAsync(imageSource).ConfigureAwait(false); if (image == null) { await ShowErrorImage().ConfigureAwait(false); } else { NewImageAvailable(image); } } catch (Exception ex) { Mvx.Error(ex.Message); } } }
public void Load() { Mvx.RegisterSingleton <IMvxLocationWatcher>(() => new MvxIosLocationWatcher()); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif Window.Current.CoreWindow.VisibilityChanged += (sender, args) => { try { if (args.Visible) { _isActive = true; _cancellationToken?.Cancel(); } else { _isActive = false; _cancellationToken = new CancellationTokenSource(); Task.Run(async() => { NotificationService.Run(ServiceBus.SettingsService.GetSettings()); while (true) { if (_cancellationToken != null && _cancellationToken.IsCancellationRequested) { break; } await Task.Delay(TimeSpan.FromSeconds(NotificationService.CheckIntervalSec)); if (!_isActive) { NotificationService.CheckServerState(); } } }, _cancellationToken.Token); } } catch (Exception ex) { //TODO: log } }; Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter //rootFrame.Navigate(typeof(MainPage), e.Arguments); var setup = new Setup(rootFrame); setup.Initialize(); var start = Mvx.Resolve <IMvxAppStart>(); start.Start(); } // Set min window size ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(580, 480)); // Ensure the current window is active Window.Current.Activate(); } if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView")) { var titleBar = ApplicationView.GetForCurrentView().TitleBar; if (titleBar != null) { var lightGrayColor = Color.FromArgb(255, 249, 249, 249); titleBar.ButtonBackgroundColor = Colors.White; titleBar.ButtonForegroundColor = Colors.Black; titleBar.BackgroundColor = Colors.White; titleBar.ForegroundColor = Colors.Black; } } }
/// <summary> /// Gets the service. /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <returns>An instance of the service.</returns> protected TService GetService <TService>() where TService : class { return(Mvx.Resolve <TService>()); }
public void Load() { Mvx.RegisterType <IMvxSqliteConnectionFactory, TouchSqliteConnectionFactory>(); }
public UserTableDatabaseAzure() { azureDatabase = Mvx.Resolve <IAzureDatabase>().GetMobileServiceClient("UserTable"); azureSyncTable = azureDatabase.GetSyncTable <UserTable>(); }
private async Task ExecuteConcurrentAsync(object parameter, bool hideCanceledException) { bool started = false; try { lock (_syncRoot) { if (_concurrentExecutions == 0) { InitCancellationTokenSource(); } else if (!_allowConcurrentExecutions) { Mvx.Trace(MvxTraceLevel.Diagnostic, "MvxAsyncCommand : execute ignored, already running."); return; } _concurrentExecutions++; started = true; } if (!_allowConcurrentExecutions) { RaiseCanExecuteChanged(); } if (!CancelToken.IsCancellationRequested) { try { // With configure await false, the CanExecuteChanged raised in finally clause might run in another thread. // This should not be an issue as long as ShouldAlwaysRaiseCECOnUserInterfaceThread is true. await ExecuteAsyncImpl(parameter).ConfigureAwait(false); } catch (OperationCanceledException e) { Mvx.Trace(MvxTraceLevel.Diagnostic, "MvxAsyncCommand : OperationCanceledException"); //Rethrow if the exception does not comes from the current cancellation token if (!hideCanceledException || e.CancellationToken != CancelToken) { throw; } } } } finally { if (started) { lock (_syncRoot) { _concurrentExecutions--; if (_concurrentExecutions == 0) { ClearCancellationTokenSource(); } } if (!_allowConcurrentExecutions) { RaiseCanExecuteChanged(); } } } }
protected override void InitializePlatformServices() { base.InitializePlatformServices(); Mvx.RegisterType <ITimer, Timer>(); }
private void InitializeCommon() { ContentType = MvxContentType.Json; JsonConverterProvider = () => Mvx.Resolve <IMvxJsonConverter>(); }
public InstituteNameConverter() { this._textProvider = (IMvxTextProvider)Mvx.get_IoCProvider().Resolve <IMvxTextProvider>(); }
protected override void InitializeFirstChance() { base.InitializeFirstChance(); // instantiate and register helper Mvx.RegisterSingleton <ILocalizationHelper>(new LocalizationHelper(_applicationContext)); }