Пример #1
0
        public async Task Stress_Vm_FromStrategy(int childrenCount, int rank, IJavascriptObjectBuilderStrategyFactory strategyFactory)
        {
            var root = new SimpleFatherTestViewModel();
            var test = new TestInContextAsync()
            {
                Bind = (win) => HtmlBinding.Bind(win, root, JavascriptBindingMode.TwoWay, strategyFactory),
                Test = async(mb) =>
                {
                    var bigVm = SimpleReadOnlyTestViewModel.BuildBigVm(childrenCount, rank);
                    var js    = mb.JsRootObject;

                    var stopWatch = new Stopwatch();
                    stopWatch.Start();

                    await DoSafeAsyncUI(() => root.Other = bigVm);

                    await Task.Delay(DelayForTimeOut);

                    var other = await _WebView.EvaluateAsync(() => GetAttribute(js, "Other"));

                    stopWatch.Stop();
                    var ts = stopWatch.ElapsedMilliseconds - DelayForTimeOut;
                    _Logger.Info($"Perf: {((double)(ts)) / 1000} sec");

                    other.IsObject.Should().BeTrue();
                }
            };

            await RunAsync(test);
        }
Пример #2
0
        public async Task Update_from_int(int value, IJavascriptObjectBuilderStrategyFactory strategyFactory)
        {
            var root = new FakeIntViewModel();
            var test = new TestInContextAsync()
            {
                Bind = (win) => HtmlBinding.Bind(win, root, JavascriptBindingMode.TwoWay, strategyFactory),
                Test = async(mb) =>
                {
                    var js = mb.JsRootObject;

                    var stopWatch = new Stopwatch();
                    stopWatch.Start();

                    await DoSafeAsyncUI(() => root.Value = value);

                    await Task.Delay(DelayForTimeOut);

                    var other = await _WebView.EvaluateAsync(() => GetAttribute(js, "Value"));

                    other.GetIntValue().Should().Be(value);

                    stopWatch.Stop();
                    var ts = stopWatch.ElapsedMilliseconds - DelayForTimeOut;
                    _Logger.Info($"Perf: {((double)(ts)) / 1000} sec");
                }
            };

            await RunAsync(test);
        }
Пример #3
0
        internal BidirectionalMapper(object root, HtmlViewEngine contextBuilder, IGlueFactory glueFactory,
                                     IJavascriptObjectBuilderStrategyFactory strategyFactory, JavascriptBindingMode mode, IWebSessionLogger logger)
        {
            _BuilderStrategyFactory = strategyFactory ?? new StandardStrategyFactory();
            Mode    = mode;
            _Logger = logger;
            var javascriptObjecChanges = (mode == JavascriptBindingMode.TwoWay) ? (IJavascriptChangesObserver)this : null;

            Context           = contextBuilder.GetMainContext(javascriptObjecChanges);
            _SessionCache     = new SessionCacher();
            _ListenerRegister = ListenToCSharp ? new FullListenerRegister(OnCSharpPropertyChanged, OnCSharpCollectionChanged): null;
            glueFactory       = glueFactory ?? GlueFactoryFactory.GetFactory(Context, _SessionCache, this, _ListenerRegister?.On);
            _JsObjectBuilder  = new CSharpToJavascriptConverter(_SessionCache, glueFactory, _Logger);
            _RootObject       = root;
        }
Пример #4
0
        internal BidirectionalMapper(object root, HTMLViewEngine contextBuilder, IGlueFactory glueFactory,
                                     IJavascriptObjectBuilderStrategyFactory strategyFactory, JavascriptBindingMode mode, IWebSessionLogger logger)
        {
            _BuilderStrategyFactory = strategyFactory ?? new StandardStrategyFactory();
            _BindingMode            = mode;
            _Logger = logger;
            var javascriptObjecChanges = (mode == JavascriptBindingMode.TwoWay) ? (IJavascriptChangesObserver)this : null;

            _Context                        = contextBuilder.GetMainContext(javascriptObjecChanges);
            _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());
            glueFactory      = glueFactory ?? GlueFactoryFactory.GetFactory(_Context, this);
            _JSObjectBuilder = new CSharpToJavascriptConverter(contextBuilder.HTMLWindow, _SessionCache, glueFactory, _Logger);
            _RootObject      = root;
        }
Пример #5
0
        internal BidirectionalMapper(object root, HtmlViewEngine contextBuilder, IGlueFactory glueFactory,
                                     IJavascriptObjectBuilderStrategyFactory strategyFactory, JavascriptBindingMode mode, IWebSessionLogger logger)
        {
            _BuilderStrategyFactory = strategyFactory ?? new StandardStrategyFactory();
            Mode    = mode;
            _Logger = logger;
            var javascriptObjectChanges = (mode == JavascriptBindingMode.TwoWay) ? (IJavascriptChangesObserver)this : null;

            Context       = contextBuilder.GetMainContext(javascriptObjectChanges);
            _SessionCache = new SessionCacher();
            var jsUpdateHelper = new JsUpdateHelper(this, Context, () => _BuilderStrategy, _SessionCache);

            _ListenerUpdater = ListenToCSharp ? new ListenerUpdater(jsUpdateHelper) : null;
            glueFactory      = glueFactory ?? GlueFactoryFactory.GetFactory(Context, _SessionCache, this, _ListenerUpdater?.On);
            _JsObjectBuilder = new CSharpToJavascriptConverter(_SessionCache, glueFactory, _Logger);
            jsUpdateHelper.JsObjectBuilder = _JsObjectBuilder;
            _JsUpdateHelper = jsUpdateHelper;
            _RootObject     = root;

            _JsUpdateHelper.CheckUiContext();
            JsValueRoot = _JsObjectBuilder.Map(_RootObject);
            JsValueRoot.AddRef();
        }
Пример #6
0
 internal BidirectionalMapper(object root, HtmlViewEngine contextBuilder, JavascriptBindingMode mode, IWebSessionLogger logger, IJavascriptObjectBuilderStrategyFactory strategyFactory) :
     this(root, contextBuilder, null, strategyFactory, mode, logger)
 {
 }
Пример #7
0
        internal static IBindingBuilder GetBindingBuilder(HtmlViewEngine viewEngine, object viewModel, JavascriptBindingMode mode, IJavascriptObjectBuilderStrategyFactory strategyFactory = null)
        {
            var mapper = viewEngine.GetMapper(viewModel, mode, strategyFactory);

            return(new BindingBuilder(mapper, viewEngine.Logger));
        }
Пример #8
0
        internal static async Task <IHtmlBinding> Bind(HtmlViewEngine viewEngine, object viewModel, JavascriptBindingMode mode, IJavascriptObjectBuilderStrategyFactory strategyFactory)
        {
            var builder = GetBindingBuilder(viewEngine, viewModel, mode, strategyFactory);

            return(await builder.CreateBinding(false));
        }
Пример #9
0
        internal BidirectionalMapper(object root, HtmlViewEngine contextBuilder, IGlueFactory glueFactory, IJavascriptObjectBuilderStrategyFactory strategyFactory,
                                     JavascriptBindingMode mode, IInternalSessionCache sessionCacher)
        {
            Mode          = mode;
            Context       = contextBuilder.GetMainContext();
            _SessionCache = sessionCacher ?? new SessionCacher();

            strategyFactory  = strategyFactory ?? new StandardStrategyFactory();
            _BuilderStrategy = new Lazy <IJavascriptObjectBuilderStrategy>(() =>
                                                                           strategyFactory.GetStrategy(Context.WebView, _SessionCache, Context.JavascriptFrameworkIsMappingObject)
                                                                           );
            _JavascriptFrameworkManager = new Lazy <IJavascriptFrameworkMapper>(() => Context.GetMapper(_SessionCache, BuilderStrategy));

            var jsUpdateHelper = new JsUpdateHelper(this, Context, _JavascriptFrameworkManager, _SessionCache);

            _JavascriptToGlueMapper = new JavascriptToGlueMapper(jsUpdateHelper, _SessionCache);

            _CSharpChangesListener    = ListenToCSharp ? new CSharpListenerJavascriptUpdater(jsUpdateHelper) : null;
            glueFactory               = glueFactory ?? GlueFactoryFactory.GetFactory(Context, _SessionCache, _JavascriptToGlueMapper, _CSharpChangesListener?.On);
            _CSharpToGlueMapper       = new CSharpToGlueMapper(_SessionCache, glueFactory, Context.Logger);
            jsUpdateHelper.GlueMapper = _CSharpToGlueMapper;

            _CSharpUnrootedObjectManager      = new CSharpUnrootedObjectManager(jsUpdateHelper, _CSharpToGlueMapper);
            glueFactory.UnrootedObjectManager = _CSharpUnrootedObjectManager;
            _JavascriptChangesListener        = (Mode == JavascriptBindingMode.TwoWay) ?
                                                new JavascriptListenerCSharpUpdater(_CSharpChangesListener, jsUpdateHelper, _JavascriptToGlueMapper) : null;

            jsUpdateHelper.CheckUiContext();
            JsValueRoot = _CSharpToGlueMapper.Map(root);
            JsValueRoot.AddRef();
        }
Пример #10
0
 internal BidirectionalMapper(object root, HtmlViewEngine engine, JavascriptBindingMode mode, IJavascriptObjectBuilderStrategyFactory strategyFactory) :
     this(root, engine, null, strategyFactory, mode, null)
 {
 }
Пример #11
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);
        }
Пример #12
0
 internal BidirectionalMapper GetMapper(object viewModel, JavascriptBindingMode mode, IJavascriptObjectBuilderStrategyFactory strategyFactory)
 {
     return(new BidirectionalMapper(viewModel, this, mode, Logger, strategyFactory));
 }