コード例 #1
0
        private void CleanWebControl(ref IWebBrowserWindowProvider iWebControl)
        {
            if (iWebControl == null)
            {
                return;
            }

            iWebControl.HTMLWindow.Crashed        -= Crashed;
            iWebControl.HTMLWindow.ConsoleMessage -= ConsoleMessage;
            iWebControl.Dispose();
            iWebControl = null;
        }
コード例 #2
0
        protected virtual IWindowlessHTMLEngine Tester(TestContext context = TestContext.Index)
        {
            var tester = _TestEnvironment.Build();
            var path   = _TestEnvironment.HtmlProvider.GetHtmlPath(context);

            _Logger.Debug($"Loading file: {path}");
            tester.Init(path, _Logger);
            _WebView = tester.WebView;
            _WebBrowserWindowProvider         = tester.HTMLWindowProvider;
            tester.HTMLWindow.ConsoleMessage += (_, e) => _Logger.LogBrowser(e, new Uri(path));
            return(tester);
        }
コード例 #3
0
        private void CleanWebControl(ref IWebBrowserWindowProvider WebControl)
        {
            if (WebControl == null)
            {
                return;
            }

            WebControl.HtmlWindow.Crashed        -= Crashed;
            WebControl.HtmlWindow.ConsoleMessage -= ConsoleMessage;
            WebControl.Dispose();
            WebControl = null;
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        private void Switch(Task <IHTMLBinding> binding, HTMLLogicWindow window, TaskCompletionSource <IHTMLBinding> tcs)
        {
            var oldvm         = Binding?.Root;
            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 inav = _UseINavigable ? Binding.Root as INavigable : null;

            if (inav != null)
            {
                inav.Navigation = this;
            }
            _Window.State = WindowLogicalState.Opened;

            _Window.OpenAsync().ContinueWith(t => EndAnimation(Binding.Root));

            _Navigating = false;

            FireNavigate(Binding.Root, oldvm);

            tcs?.SetResult(Binding);

            if (fireFirstLoad)
            {
                OnFirstLoad?.Invoke(this, EventArgs.Empty);
            }
        }
コード例 #6
0
        private Task <IHTMLBinding> Navigate(Uri uri, object iViewModel, JavascriptBindingMode iMode = JavascriptBindingMode.TwoWay)
        {
            if (uri == null)
            {
                throw ExceptionHelper.GetArgument($"ViewModel not registered: {iViewModel.GetType()}");
            }

            _Navigating = true;

            var oldvm = Binding?.Root as INavigable;

            if (_UseINavigable && (oldvm != null))
            {
                oldvm.Navigation = null;
            }

            var wh = new WindowHelper(new HTMLLogicWindow());

            if (_CurrentWebControl != null)
            {
                _CurrentWebControl.HTMLWindow.Crashed -= Crashed;
            }

            var closetask = (_CurrentWebControl != null) ? _Window.CloseAsync() : TaskHelper.Ended();

            _NextWebControl = _WebViewLifeCycleManager.Create();
            _NextWebControl.HTMLWindow.ConsoleMessage += ConsoleMessage;

            var moderWindow = _NextWebControl.HTMLWindow as IModernWebBrowserWindow;

            if (moderWindow != null)
            {
                var debugContext = _WebViewLifeCycleManager.DebugContext;
                EventHandler <BeforeJavascriptExcecutionArgs> before = null;
                before = (o, e) =>
                {
                    moderWindow.BeforeJavascriptExecuted -= before;
                    e.JavascriptExecutor(_javascriptFrameworkManager.GetMainScript(debugContext));
                };
                moderWindow.BeforeJavascriptExecuted += before;
            }

            var tcs = new TaskCompletionSource <IHTMLBinding>();

            EventHandler <LoadEndEventArgs> sourceupdate = null;

            sourceupdate = (o, e) =>
            {
                var injectorFactory = GetInjectorFactory(uri);
                _NextWebControl.HTMLWindow.LoadEnd -= sourceupdate;
                var engine = new HTMLViewEngine(_NextWebControl, injectorFactory, _webSessionLogger);

                HTML_Binding.Bind(engine, iViewModel, iMode, wh).WaitWith(closetask, t => Switch(t, wh.__window__, tcs));
            };

            Url = uri;
            _NextWebControl.HTMLWindow.LoadEnd += sourceupdate;
            _NextWebControl.HTMLWindow.NavigateTo(uri);

            return(tcs.Task);
        }
コード例 #7
0
        private void Switch(Task<IHTMLBinding> iBinding, HTMLLogicWindow iwindow, TaskCompletionSource<IHTMLBinding> tcs)
        {
            var oldvm = Binding?.Root;
            var fireFirstLoad = false;
            Binding = iBinding.Result;
          
            if (_CurrentWebControl!=null)
            {
                _CurrentWebControl.HTMLWindow.ConsoleMessage -= ConsoleMessage;
                _CurrentWebControl.Dispose();
            }
            else 
            {
                fireFirstLoad = true;
            }

            _CurrentWebControl = _NextWebControl;     
            _NextWebControl = null;
            _CurrentWebControl.HTMLWindow.Crashed += Crashed;

            _CurrentWebControl.Show();
    
            _Window = iwindow; 

            var inav = _UseINavigable ? Binding.Root as INavigable : null;
            if (inav != null)
                inav.Navigation = this;
            _Window.State = WindowLogicalState.Opened;

            _Window.OpenAsync().ContinueWith(t => EndAnimation(Binding.Root));

            _Navigating = false;

            if (fireFirstLoad)
                OnFirstLoad?.Invoke(this, EventArgs.Empty);

            FireNavigate(Binding.Root, oldvm);

            tcs?.SetResult(Binding);
        }    
コード例 #8
0
        private void CleanWebControl(ref IWebBrowserWindowProvider iWebControl)
        {
            if (iWebControl == null)
                return;

            iWebControl.HTMLWindow.Crashed -= Crashed;
            iWebControl.HTMLWindow.ConsoleMessage -= ConsoleMessage;
            iWebControl.Dispose();
            iWebControl = null;
        }
コード例 #9
0
        private Task<IHTMLBinding> Navigate(Uri uri, object iViewModel, JavascriptBindingMode iMode = JavascriptBindingMode.TwoWay)
        {
            if (uri == null)
                throw ExceptionHelper.GetArgument($"ViewModel not registered: {iViewModel.GetType()}");

            _Navigating = true;

            var oldvm = Binding?.Root as INavigable;

            if (_UseINavigable && (oldvm!=null))
            {
                oldvm.Navigation = null;
            }

            var wh = new WindowHelper(new HTMLLogicWindow());

            if (_CurrentWebControl != null)
                _CurrentWebControl.HTMLWindow.Crashed -= Crashed;

            var closetask = ( _CurrentWebControl!=null) ? _Window.CloseAsync() : TaskHelper.Ended();

            _NextWebControl = _WebViewLifeCycleManager.Create();
            _NextWebControl.HTMLWindow.ConsoleMessage += ConsoleMessage;

            var moderWindow = _NextWebControl.HTMLWindow as IModernWebBrowserWindow;
            if (moderWindow!=null)
            {
                var debugContext = _WebViewLifeCycleManager.DebugContext;
                EventHandler<BeforeJavascriptExcecutionArgs> before = null;
                before = (o,e) =>
                {
                    moderWindow.BeforeJavascriptExecuted -= before;
                    e.JavascriptExecutor(_javascriptFrameworkManager.GetMainScript(debugContext));
                };
                moderWindow.BeforeJavascriptExecuted += before;
            }

            var tcs = new TaskCompletionSource<IHTMLBinding>();

            EventHandler<LoadEndEventArgs> sourceupdate = null;
            sourceupdate = (o, e) =>
            {
                var injectorFactory = GetInjectorFactory(uri);
                _NextWebControl.HTMLWindow.LoadEnd -= sourceupdate;
                var engine = new HTMLViewEngine(_NextWebControl, injectorFactory, _webSessionLogger);

                HTML_Binding.Bind(engine, iViewModel, iMode, wh).WaitWith(closetask, t => Switch(t, wh.__window__, tcs));
            };

            Url = uri;
            _NextWebControl.HTMLWindow.LoadEnd += sourceupdate;
            _NextWebControl.HTMLWindow.NavigateTo(uri);

            return tcs.Task;
        }
コード例 #10
0
 public HTMLViewEngine(IWebBrowserWindowProvider hTMLWindowProvider, IJavascriptFrameworkManager frameworkManager, IWebSessionLogger logger)
 {
     _HTMLWindowProvider = hTMLWindowProvider;
     _frameworkManager   = frameworkManager;
     Logger = logger;
 }
コード例 #11
0
        private Task <IHtmlBinding> Navigate(Uri uri, object viewModel, JavascriptBindingMode mode = JavascriptBindingMode.TwoWay)
        {
            if (uri == null)
            {
                throw ExceptionHelper.GetArgument($"ViewModel not registered: {viewModel.GetType()}");
            }

            _Navigating = true;

            var oldvm = GetMainViewModel(Binding) as INavigable;

            if (_UseINavigable && (oldvm != null))
            {
                oldvm.Navigation = null;
            }

            if (_CurrentWebControl != null)
            {
                _CurrentWebControl.HtmlWindow.Crashed -= Crashed;
            }

            var closetask = (_CurrentWebControl != null) ? _Window.CloseAsync() : TaskHelper.Ended();

            _NextWebControl = _WebViewLifeCycleManager.Create();
            _NextWebControl.HtmlWindow.ConsoleMessage += ConsoleMessage;

            var moderWindow = _NextWebControl.HtmlWindow as IModernWebBrowserWindow;

            var injectorFactory = GetInjectorFactory(uri);
            var engine          = new HtmlViewEngine(_NextWebControl, injectorFactory, _webSessionLogger);

            var dataContext = new DataContextViewModel(viewModel);
            var initVm      = HtmlBinding.GetBindingBuilder(engine, dataContext, mode);

            if (moderWindow != null)
            {
                var debugContext = _WebViewLifeCycleManager.DebugContext;
                EventHandler <BeforeJavascriptExcecutionArgs> before = null;
                before = (o, e) =>
                {
                    moderWindow.BeforeJavascriptExecuted -= before;
                    e.JavascriptExecutor(_JavascriptFrameworkManager.GetMainScript(debugContext));
                };
                moderWindow.BeforeJavascriptExecuted += before;
            }
            var tcs = new TaskCompletionSource <IHtmlBinding>();

            EventHandler <LoadEndEventArgs> sourceupdate = null;

            sourceupdate = async(o, e) =>
            {
                _NextWebControl.HtmlWindow.LoadEnd -= sourceupdate;

                var builder = await initVm;
                await builder.CreateBinding(_WebViewLifeCycleManager.DebugContext).WaitWith(closetask, t => Switch(t, dataContext.Window, tcs)).ConfigureAwait(false);
            };

            Url = uri;
            _NextWebControl.HtmlWindow.LoadEnd += sourceupdate;
            _NextWebControl.HtmlWindow.NavigateTo(uri);

            return(tcs.Task);
        }
コード例 #12
0
 public HtmlViewEngine(IWebBrowserWindowProvider htmlWindowProvider, IJavascriptFrameworkManager frameworkManager, IWebSessionLogger logger)
 {
     _HtmlWindowProvider = htmlWindowProvider;
     _FrameworkManager   = frameworkManager;
     _Logger             = logger;
 }