Beispiel #1
0
        public SplashViewModel2(IServiceDispatcher serviceDispatcher, IPlatformProvider platformProvider)
        {
            HasNavigationBar = false;

            Title = "SplashViewModel2";

            this.serviceDispatcher = serviceDispatcher;
            this.platformProvider  = platformProvider;

            Task.Delay(1500).ContinueWith(t => platformProvider.ExecuteOnUIThread(() =>
            {
                serviceDispatcher.Dispatch <IShellNavigationService>(n => n.Push <StackShellViewModel>(new { Name = ShellNames.Stack }));
                serviceDispatcher.Dispatch <INavigationService>(ShellNames.Stack, n => n.Push <ViewModel1>(replace: true));
            }));
        }
        private void Dispatch(DispatchData data)
        {
            for (int i = 0; i < data.Arguments.Length; i++)
            {
                if (data.Arguments[i] is JArray)
                {
                    data.Arguments[i] = (data.Arguments[i] as JArray).ToObject <object[]>();
                }
                else if (data.Arguments[i] is JObject)
                {
                    data.Arguments[i] = (data.Arguments[i] as JObject).ToObject <Dictionary <string, object> >();
                }
            }

            string result = string.IsNullOrEmpty(data.InstanceName)
                ? JsonConvert.SerializeObject(serviceDispatcher.Dispatch(data.ServiceName, data.MethodName, data.Arguments))
                : JsonConvert.SerializeObject(serviceDispatcher.Dispatch(data.ServiceName, data.InstanceName, data.MethodName, data.Arguments));

            if (data.CallbackId != null)
            {
                webBrowser.InvokeScript("eval", string.Format("serviceDispatcher._dispatchCallback('{0}', {1})", data.CallbackId, result));
            }
        }
Beispiel #3
0
 private void OpenDetail()
 {
     serviceDispatcher.Dispatch <INavigationService>(ShellNames.MasterDetail, n => n.Push <DetailViewModel>());
 }
Beispiel #4
0
        public SplashViewModel1(IServiceDispatcher serviceDispatcher, IPlatformProvider platformProvider)
        {
            HasNavigationBar = false;

            Title = "SplashViewModel1";

            this.serviceDispatcher = serviceDispatcher;
            this.platformProvider  = platformProvider;

            Task.Delay(1500).ContinueWith(t => platformProvider.ExecuteOnUIThread(() => serviceDispatcher.Dispatch <INavigationService>(ShellNames.SplashScreen, n => n.Push <SplashViewModel2>(replace: true))));
        }
Beispiel #5
0
 public void OpenMasterDetailViewModel()
 {
     serviceDispatcher.Dispatch <IShellNavigationService>(n => n.Push <MasterDetailShellViewModel>(new { Name = ShellNames.MasterDetail, Master = new NavigationMasterViewModel(serviceDispatcher) }));
     serviceDispatcher.Dispatch <INavigationService>(ShellNames.MasterDetail, n => n.Push <ViewModel3>());
 }
Beispiel #6
0
 public void OpenViewModel2()
 {
     serviceDispatcher.Dispatch <INavigationService>(ShellNames.Stack, n => n.Push <ViewModel2>());
 }
Beispiel #7
0
        public WebBrowserPage(IServiceDispatcher serviceDispatcher, IPlatformProvider platformProvider)
        {
            webView            = new ShellWebView();
            eventRegistrations = new ConcurrentDictionary <string, EventRegistration>();

            webView.RegisterCallback("initialize", args =>
            {
                platformProvider.ExecuteOnUIThread(() => webView.InjectJavaScript(string.Format("serviceDispatcher._initializeCallback({0});", JsonConvert.SerializeObject(serviceDispatcher.Services))));
            });

            webView.RegisterCallback("dispatch", args =>
            {
                DispatchData dispatchData = JsonConvert.DeserializeObject <DispatchData>(args);

                string result = string.IsNullOrEmpty(dispatchData.InstanceName)
                    ? JsonConvert.SerializeObject(serviceDispatcher.Dispatch(dispatchData.ServiceName, dispatchData.MethodName, dispatchData.Arguments))
                    : JsonConvert.SerializeObject(serviceDispatcher.Dispatch(dispatchData.ServiceName, dispatchData.InstanceName, dispatchData.MethodName, dispatchData.Arguments));

                if (dispatchData.CallbackId != null)
                {
                    platformProvider.ExecuteOnUIThread(() => webView.InjectJavaScript(string.Format("serviceDispatcher._dispatchCallback('{0}', {1});", dispatchData.CallbackId, result)));
                }
            });

            webView.RegisterCallback("subscribeEvent", args =>
            {
                SubscribeEventData subscribeEventData = JsonConvert.DeserializeObject <SubscribeEventData>(args);

                EventRegistration eventRegistration = serviceDispatcher.SubscribeEvent(subscribeEventData.ServiceName, subscribeEventData.EventName, this, (s, e) =>
                {
                    if (subscribeEventData.CallbackId != null)
                    {
                        platformProvider.ExecuteOnUIThread(() => webView.InjectJavaScript(string.Format("serviceDispatcher._eventCallback('{0}', '{1}');", subscribeEventData.CallbackId, JsonConvert.SerializeObject(e))));
                    }
                });

                eventRegistrations.AddOrUpdate(subscribeEventData.CallbackId, eventRegistration, (k, e) => e);
            });

            webView.RegisterCallback("unsubscribeEvent", args =>
            {
                UnsubscribeEventData unsubscribeEventData = JsonConvert.DeserializeObject <UnsubscribeEventData>(args);

                EventRegistration eventRegistration = null;
                if (eventRegistrations.TryRemove(unsubscribeEventData.CallbackId, out eventRegistration))
                {
                    serviceDispatcher.UnsubscribeEvent(unsubscribeEventData.ServiceName, eventRegistration);
                }
            });

            Content = webView;

            SetBinding(UrlProperty, new Binding("Url"));
            SetBinding(HtmlProperty, new Binding("Html"));

            webView.NavigationCompleted += (s, e) =>
            {
                if (webView.Source is UrlWebViewSource)
                {
                    Url = e;
                }
            };
        }
Beispiel #8
0
 private void Close()
 {
     serviceDispatcher.Dispatch <INavigationService>(ShellNames.MasterDetail, n => n.Pop());
 }
Beispiel #9
0
 public override void Execute(IServiceDispatcher serviceDispatcher)
 {
     serviceDispatcher.Dispatch <IMasterDetailNavigationService>(n => n.PushRoot(TypeConfiguration.Type, TypeConfiguration.Data));
 }