internal static async Task<IHTMLBinding> Bind(HTMLViewEngine viewEngine, object iViewModel, JavascriptBindingMode iMode, object additional = null)
 {
     var mapper = viewEngine.GetMapper(iViewModel, iMode );
     var res = new HTML_Binding(mapper, viewEngine.Logger);
     await mapper.Init(additional);
     return res;
  }
Beispiel #2
0
        internal static async Task <IHTMLBinding> Bind(HTMLViewEngine viewEngine, object iViewModel, JavascriptBindingMode iMode, object additional = null)
        {
            var mapper = viewEngine.GetMapper(iViewModel, iMode);
            var res    = new HTML_Binding(mapper, viewEngine.Logger);
            await mapper.Init(additional);

            return(res);
        }
 protected override IWindowlessHTMLEngine Tester(TestContext context = TestContext.Index) 
 {
     var tester = base.Tester(context);
     var frameworkHelper = _WindowLessHTMLEngineProvider.FrameworkTestContext;
     _ViewEngine = new HTMLViewEngine(tester.HTMLWindowProvider, frameworkHelper.FrameworkManager, _Logger);
     _JavascriptFrameworkExtractor = frameworkHelper.JavascriptFrameworkExtractorBuilder(_WebView);
     return tester;
 }
Beispiel #4
0
        internal static async Task <IBindingBuilder> GetBindingBuilder(HTMLViewEngine viewEngine, object viewModel, JavascriptBindingMode mode, object additional = null, IJavascriptObjectBuilderStrategyFactory strategyFactory = null)
        {
            var mapper         = viewEngine.GetMapper(viewModel, mode, strategyFactory);
            var bindingBuilder = new BindingBuilder(mapper, viewEngine.Logger, additional);
            await bindingBuilder.Init();

            return(bindingBuilder);
        }
Beispiel #5
0
        protected override IWindowlessHTMLEngine Tester(TestContext context = TestContext.Index)
        {
            var tester          = base.Tester(context);
            var frameworkHelper = _WindowLessHTMLEngineProvider.FrameworkTestContext;

            _ViewEngine = new HTMLViewEngine(tester.HTMLWindowProvider, frameworkHelper.FrameworkManager, _Logger);
            _JavascriptFrameworkExtractor = frameworkHelper.JavascriptFrameworkExtractorBuilder(_WebView);
            return(tester);
        }
        public static async Task<IHTMLBinding> Bind(HTMLViewEngine engine, string iViewModel)
        {
            var context = engine.GetMainContext(null);
            var mainView = context.WebView;

            var root = await mainView.EvaluateAsync(() =>
                {
                    var json = mainView.GetGlobal().GetValue("JSON");
                    return json.Invoke("parse", mainView, mainView.Factory.CreateString(iViewModel));
                });

            var injector = context.JavascriptSessionInjector;
            //TODO improve context management or remove this functionality
            var mappedroot = await mainView.EvaluateAsync( () => injector.Inject(root, null));
            await injector.RegisterMainViewModel(mappedroot);

            return new StringBinding(context, mappedroot);
        }
Beispiel #7
0
        public static async Task <IHTMLBinding> Bind(HTMLViewEngine engine, string iViewModel)
        {
            var context  = engine.GetMainContext(null);
            var mainView = context.WebView;

            var root = await mainView.EvaluateAsync(() =>
            {
                var json = mainView.GetGlobal().GetValue("JSON");
                return(json.Invoke("parse", mainView, mainView.Factory.CreateString(iViewModel)));
            });

            var injector = context.JavascriptSessionInjector;
            //TODO improve context management or remove this functionality
            var mappedroot = await mainView.EvaluateAsync(() => injector.Inject(root, null));

            await injector.RegisterMainViewModel(mappedroot);

            return(new StringBinding(context, mappedroot));
        }
 internal BidirectionalMapper(object iRoot, HTMLViewEngine contextBuilder, JavascriptBindingMode iMode, object addicionalObject, IWebSessionLogger logger)
 {        
     _BindingMode = iMode;
     _Logger = logger;
     var javascriptObjecChanges = (iMode == JavascriptBindingMode.TwoWay) ? (IJavascriptChangesObserver)this : null;
     _Context = contextBuilder.GetMainContext(javascriptObjecChanges);
     _sessionInjector = _Context.JavascriptSessionInjector;  
     _SessionCache = new SessionCacher();
     _ListenerRegister = new FullListenerRegister(
                                 (n) => n.PropertyChanged += CSharpPropertyChanged,
                                 (n) => n.PropertyChanged -= CSharpPropertyChanged,
                                 (n) => n.CollectionChanged += CSharpCollectionChanged,
                                 (n) => n.CollectionChanged -= CSharpCollectionChanged,
                                 (c) => c.ListenChanges(),
                                 (c) => c.UnListenChanges());
     var commandFactory = new CommandFactory(_Context, this);
     RegisterJavascriptHelper();
     _JSObjectBuilder = new CSharpToJavascriptConverter(_Context, _SessionCache, commandFactory, _Logger) ;
     _Root = _JSObjectBuilder.Map(iRoot, addicionalObject); 
 }
        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);
        }
        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;
        }
Beispiel #11
0
        internal static async Task <IHTMLBinding> Bind(HTMLViewEngine viewEngine, object viewModel, JavascriptBindingMode mode, IJavascriptObjectBuilderStrategyFactory strategyFactory)
        {
            var builder = await GetBindingBuilder(viewEngine, viewModel, mode, null, strategyFactory);

            return(await builder.CreateBinding(false));
        }
Beispiel #12
0
        internal static async Task <IHTMLBinding> Bind(HTMLViewEngine viewEngine, object viewModel, JavascriptBindingMode mode, object additional = null)
        {
            var builder = await GetBindingBuilder(viewEngine, viewModel, mode, additional);

            return(await builder.CreateBinding(false));
        }