public async Task Navigate(object viewModel, string id = null) { var oldBinding = _CurrentBinding; _CurrentBinding = await _NavigationSolver.NavigateAsync(viewModel, id); oldBinding?.Dispose(); }
public void Dispose() { _Disposed = true; Binding = null; UseINavigable = false; CleanWebControl(ref _CurrentWebControl); CleanWebControl(ref _NextWebControl); }
private void Crashed(object sender, BrowserCrashedArgs e) { var dest = _CurrentWebControl.HtmlWindow.Url; var vm = GetMainViewModel(Binding); var mode = Binding.Mode; _webSessionLogger.Error("WebView crashed trying recover"); CleanWebControl(ref _CurrentWebControl); Binding = null; Navigate(dest, vm, mode); }
private void Switch(Task <IHtmlBinding> binding, HtmlLogicWindow window, TaskCompletionSource <IHtmlBinding> tcs) { var oldvm = GetMainViewModel(Binding); var fireFirstLoad = false; Binding = binding.Result; if (_CurrentWebControl != null) { _CurrentWebControl.HtmlWindow.ConsoleMessage -= ConsoleMessage; _CurrentWebControl.Dispose(); } else { fireFirstLoad = true; } _CurrentWebControl = _NextWebControl; _NextWebControl = null; _CurrentWebControl.HtmlWindow.Crashed += Crashed; _CurrentWebControl.Show(); _Window = window; var rootVm = GetMainViewModel(Binding); var inav = _UseINavigable ? rootVm as INavigable : null; if (inav != null) { inav.Navigation = this; } _Window.State = WindowLogicalState.Opened; _Window.OpenAsync().ContinueWith(t => EndAnimation(rootVm)); _Navigating = false; FireNavigate(rootVm, oldvm); tcs?.SetResult(Binding); if (!fireFirstLoad) { return; } OnFirstLoad?.Invoke(this, new FirstLoadEvent(_CurrentWebControl.HtmlWindow)); }
private void Reload(bool forceClean) { var dest = _CurrentWebControl.HtmlWindow.Url; var vm = GetMainViewModel(Binding); var mode = Binding.Mode; if (forceClean) { CleanWebControl(ref _CurrentWebControl); } Binding = null; Navigate(dest, vm, mode); }
private async Task StressVm(SimpleFatherTestViewModel root, IHtmlBinding mb, SimpleReadOnlyTestViewModel bigVm) { var js = mb.JsRootObject; IJavascriptObject other; using (var perf = GetPerformanceCounter("Perf to bind Vm")) { await DoSafeAsyncUI(() => root.Other = bigVm); await WaitAnotherUiCycleAsync(); await Task.Delay(DelayForTimeOut); perf.DiscountTime = DelayForTimeOut; other = await _WebView.EvaluateAsync(() => GetAttribute(js, "Other")); } other.IsObject.Should().BeTrue(); var rootJs = mb.JsBrideRootObject; ISet <IJsCsGlue> allChildren = new HashSet <IJsCsGlue>(); using (GetPerformanceCounter("Perf to VisitAllChildren")) { await DoSafeAsyncUI(() => rootJs.VisitDescendantsSafe(glue => true)); } using (GetPerformanceCounter("Perf to VisitAllChildren Collect")) { await DoSafeAsyncUI(() => rootJs.VisitDescendantsSafe(glue => allChildren.Add(glue))); } _TestOutputHelper.WriteLine($"Objects created {allChildren.Count}"); using (GetPerformanceCounter("Perf Foreach GetAllChildren")) { await DoSafeAsyncUI(() => allChildren.ForEach(_ => { })); } List <object> basics = null; using (GetPerformanceCounter("Perf Collecting basics")) { basics = allChildren.Where(g => g.Type == JsCsGlueType.Basic && g.CValue != null).Select(g => g.CValue).ToList(); } string string1, string2, string3, string4; using (GetPerformanceCounter("Creating string")) { string1 = $"[{string.Join(",", basics.Select(JavascriptNamer.GetCreateExpression))}]"; } using (GetPerformanceCounter("Creating string parralel")) { var builder = new StringBuilder("["); var first = true; Parallel.ForEach(basics, () => new Builder(), (basic, _, sb) => { if (!sb.First) { sb.String.Append(","); } sb.String.Append(basic); sb.First = false; return(sb); }, (sb) => { lock (builder) { if (!first) { builder.Append(","); } first = false; builder.Append(sb.String); } }); builder.Append("]"); string2 = builder.ToString(); } var array = basics.ToArray(); using (GetPerformanceCounter("Creating JSON string")) { string3 = JsonConvert.SerializeObject(array); } using (GetPerformanceCounter("Creating JSON string bigVm")) { string4 = JsonConvert.SerializeObject(bigVm); } }
private static object GetMainViewModel(IHtmlBinding binding) { return(((DataContextViewModel)(binding?.Root))?.ViewModel); }
public BindingInContext(IHtmlBinding binding, ISessionCache cache) { Binding = binding; Cache = cache; }