private async void FacadeNavigatingCancelEventHandler(object sender, NavigatingCancelEventArgs e) { DebugWrite(); object parameter = null; try { parameter = SerializationService.Deserialize(e.Parameter?.ToString()); } catch (Exception ex) { throw new Exception("Your parameter must be serializable. If it isn't, then use SessionState.", ex); } var deferral = new DeferralManager(); var args = new NavigatingEventArgs(deferral, e, Content as Page, e.SourcePageType, parameter, e.Parameter); if (NavigationModeHint != NavigationMode.New) { args.NavigationMode = NavigationModeHint; } NavigationModeHint = NavigationMode.New; _navigatingEventHandlers.ForEach(x => x(this, args)); await deferral.WaitForDeferralsAsync().ConfigureAwait(false); e.Cancel = args.Cancel; }
public void NoDeferrals_IsCompleted() { var dm = new DeferralManager(); var task = dm.WaitForDeferralsAsync(); Assert.True(task.IsCompleted); }
private static async Task <bool> CallClassicOnNavigatingFrom(object viewmodel, NavigationMode mode, Page sourcePage, object sourceParameter, Type targetType, object targetParameter, bool suspending) { var deferral = new DeferralManager(); var navigatingEventArgs = new Classic.NavigatingEventArgs(deferral) { Page = sourcePage, PageType = sourcePage?.GetType(), Parameter = sourceParameter, NavigationMode = mode, TargetPageType = targetType, TargetPageParameter = targetParameter, Suspending = suspending, }; try { var vm = viewmodel as Classic.INavigatingAwareAsync; if (vm != null) { await vm.OnNavigatingFromAsync(navigatingEventArgs); await deferral.WaitForDeferralsAsync(); } } catch { Debugger.Break(); } return(navigatingEventArgs.Cancel); }
// before navigate (cancellable) async Task <bool> NavigatingFromAsync(bool suspending, NavigationMode mode) { DebugWrite($"Suspending: {suspending}"); var page = FrameFacadeInternal.Content as Page; if (page != null) { // force (x:bind) page bindings to update XamlUtils.UpdateBindings(page); // call navagable override (navigating) var dataContext = ResolveForPage(page); if (dataContext != null) { dataContext.NavigationService = this; dataContext.Dispatcher = this.GetDispatcherWrapper(); dataContext.SessionState = BootStrapper.Current.SessionState; var deferral = new DeferralManager(); var args = new NavigatingEventArgs(deferral) { NavigationMode = mode, PageType = FrameFacadeInternal.CurrentPageType, Parameter = FrameFacadeInternal.CurrentPageParam, Suspending = suspending, }; await deferral.WaitForDeferralsAsync(); await dataContext.OnNavigatingFromAsync(args); return(!args.Cancel); } } return(true); }
private async Task <bool> NavingFromAsync(Classic.INavigatingAwareAsync viewmodel, Page page, object currentParameter, bool suspending, NavigationMode navigationMode, Type targetPageType, object targetParameter) { var deferral = new DeferralManager(); var navigatingEventArgs = new Classic.NavigatingEventArgs(deferral) { Page = page, Parameter = currentParameter, Suspending = suspending, NavigationMode = navigationMode, TargetPageType = targetPageType, TargetPageParameter = targetParameter, }; try { await viewmodel.OnNavigatingFromAsync(navigatingEventArgs); await deferral.WaitForDeferralsAsync(); } catch { Debugger.Break(); } return(navigatingEventArgs.Cancel); }
public async Task CompletedDeferralFollowedByIncompleteDeferral_PreventsCompletion() { DeferralManager dm = new DeferralManager(); dm.DeferralSource.GetDeferral().Dispose(); IDisposable deferral = dm.DeferralSource.GetDeferral(); Task task = dm.WaitForDeferralsAsync(); await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false); }
public async Task CompletedDeferralFollowedByIncompleteDeferral_PreventsCompletion() { var dm = new DeferralManager(); dm.DeferralSource.GetDeferral().Dispose(); var deferral = dm.DeferralSource.GetDeferral(); var task = dm.WaitForDeferralsAsync(); await AsyncAssert.NeverCompletesAsync(task); }
public async Task MultipleDeferralsWithOneIncomplete_PreventsCompletion() { DeferralManager dm = new DeferralManager(); IDisposable deferral1 = dm.DeferralSource.GetDeferral(); IDisposable deferral2 = dm.DeferralSource.GetDeferral(); Task task = dm.WaitForDeferralsAsync(); deferral1.Dispose(); await AsyncAssert.NeverCompletesAsync(task).ConfigureAwait(false); }
public async Task MultipleDeferralsWithOneIncomplete_PreventsCompletion() { var dm = new DeferralManager(); var deferral1 = dm.DeferralSource.GetDeferral(); var deferral2 = dm.DeferralSource.GetDeferral(); var task = dm.WaitForDeferralsAsync(); deferral1.Dispose(); await AsyncAssert.NeverCompletesAsync(task); }
public async Task DeferralCompleted_Completes() { var dm = new DeferralManager(); var deferral = dm.DeferralSource.GetDeferral(); var task = dm.WaitForDeferralsAsync(); Assert.False(task.IsCompleted); deferral.Dispose(); await task; }
public async Task <bool> NavingFromCancelsAsync(object viewmodel, NavigationMode mode, Page sourcePage, Type sourceType, object sourceParameter, Page targetPage, Type targetType, object targetParameter, bool suspending) { Services.NavigationService.NavigationService.DebugWrite(); if (sourcePage == null) { return(false); } else if (viewmodel == null) { return(false); } else if (viewmodel is Classic.INavigatingAwareAsync) { var deferral = new DeferralManager(); var navigatingEventArgs = new Classic.NavigatingEventArgs(deferral) { Page = sourcePage, PageType = sourcePage?.GetType(), Parameter = sourceParameter, NavigationMode = mode, TargetPageType = targetType, TargetPageParameter = targetParameter, Suspending = suspending, }; try { var vm = viewmodel as Classic.INavigatingAwareAsync; await vm?.OnNavigatingFromAsync(navigatingEventArgs); await deferral.WaitForDeferralsAsync(); } catch { Debugger.Break(); } return(navigatingEventArgs.Cancel); } else if (viewmodel is Portable.IConfirmNavigationAsync) { var parameters = new Portable.NavigationParameters(); parameters.Add("NavigationMode", mode.ToPrismNavigationMode()); parameters.Add("SourceType", sourceType); parameters.Add("SourceParameter", sourceParameter); parameters.Add("TargetType", targetType); parameters.Add("TargetParameter", targetParameter); parameters.Add("Suspending", suspending); var vm = viewmodel as Portable.IConfirmNavigationAsync; return(!await vm?.CanNavigateAsync(parameters)); } else { return(true); } }
public async Task MultipleDeferralsWithAllCompleted_Completes() { var dm = new DeferralManager(); var deferral1 = dm.DeferralSource.GetDeferral(); var deferral2 = dm.DeferralSource.GetDeferral(); var task = dm.WaitForDeferralsAsync(); deferral1.Dispose(); deferral2.Dispose(); await task; }
protected async Task OnMyEventAsync() { if (MyEvent != null) { DeferralManager deferralManager = new DeferralManager(); MyEventArgs e = new MyEventArgs(deferralManager); MyEvent(this, e); await deferralManager.WaitForDeferralsAsync(); } if (e.Change) { Console.WriteLine("Change occured"); } }
private async void FacadeNavigatingCancelEventHandler(object sender, NavigatingCancelEventArgs args) { this.loggingService.WriteLine(); object parameter = null; try { parameter = this.serializationService.Deserialize(args.Parameter?.ToString()); } catch (Exception ex) { throw new Exception("Parameter must be serializable", ex); } var deferral = new DeferralManager(); var navigatingArgs = new NavigatingEventArgs( deferral, args, this.Content as Page, args.SourcePageType, parameter, args.Parameter); if (this.NavigationModeHint != NavigationMode.New) { navigatingArgs.NavigationMode = this.NavigationModeHint; } this.NavigationModeHint = NavigationMode.New; foreach (var handler in this.navigatingEventHandlers) { handler(this, navigatingArgs); } await deferral.WaitForDeferralsAsync().ConfigureAwait(false); args.Cancel = navigatingArgs.Cancel; }
// before navigate (cancellable) async Task <bool> NavigatingFromAsync(Page page, INavigable dataContext, bool suspending, NavigationMode mode) { DebugWrite($"Suspending: {suspending}"); dataContext.NavigationService = this; dataContext.Dispatcher = this.GetDispatcherWrapper(); dataContext.SessionState = BootStrapper.Current.SessionState; var deferral = new DeferralManager(); var args = new NavigatingEventArgs(deferral) { NavigationMode = mode, PageType = FrameFacadeInternal.CurrentPageType, Parameter = FrameFacadeInternal.CurrentPageParam, Suspending = suspending, }; await deferral.WaitForDeferralsAsync(); await dataContext.OnNavigatingFromAsync(args); return(!args.Cancel); }
public async Task IncompleteDeferral_PreventsCompletion() { var dm = new DeferralManager(); var deferral = dm.DeferralSource.GetDeferral(); await AsyncAssert.NeverCompletesAsync(dm.WaitForDeferralsAsync()); }
internal Task WaitForDeferralsAsync() { return(_deferrals.WaitForDeferralsAsync()); }
public async Task IncompleteDeferral_PreventsCompletion() { DeferralManager dm = new DeferralManager(); IDisposable deferral = dm.DeferralSource.GetDeferral(); await AsyncAssert.NeverCompletesAsync(dm.WaitForDeferralsAsync()).ConfigureAwait(false); }