Ejemplo n.º 1
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // NB: GrossHackAlertTiem™:
            //
            // Monotouch appears to not load assemblies when you request them
            // via Type.GetType, unlike every other platform (even
            // Xamarin.Android). So, we've got to manually do what RxUI and
            // Akavache would normally do for us
            var r = new ModernDependencyResolver();
            (new ReactiveUI.Registrations()).Register((f,t) => r.Register(f, t));
            (new ReactiveUI.Cocoa.Registrations()).Register((f,t) => r.Register(f, t));
            (new ReactiveUI.Mobile.Registrations()).Register((f,t) => r.Register(f, t));
            (new Akavache.Registrations()).Register(r.Register);
            (new Akavache.Mobile.Registrations()).Register(r.Register);
            (new Akavache.Sqlite3.Registrations()).Register(r.Register);
            RxApp.DependencyResolver = r;

            window = new UIWindow(UIScreen.MainScreen.Bounds);

            var client = new GitHubClient(new System.Net.Http.Headers.ProductHeaderValue("RxUISample", "0.1"));
            client.Credentials = new Credentials("paulcbetts", GiveMeAToken.DoIt());
            r.RegisterConstant(client.Notification, typeof(INotificationsClient));

            viewController = new NotificationsListViewController();
            window.RootViewController = viewController;
            window.MakeKeyAndVisible();

            return true;
        }
        public void ApplicationStateShouldBeRoundtrippable()
        {
            var resolver = new ModernDependencyResolver();
            resolver.InitializeResolver();
            resolver.InitializeAkavache();

            resolver.Register(() => new JsonSerializerSettings() {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                TypeNameHandling = TypeNameHandling.All,
                ObjectCreationHandling = ObjectCreationHandling.Replace,
            }, typeof(JsonSerializerSettings));

            using (resolver.WithResolver())
            {
                string path;
                var input = new DummyAppBootstrapper();
                var expected = ((DummyRoutedViewModel) input.Router.NavigationStack[0]).ARandomGuid;
                input.Router.Navigate.Execute(new DummyRoutedViewModel(input) {ARandomGuid = Guid.NewGuid()});

                Console.WriteLine("After Nav Count: {0}", input.Router.NavigationStack.Count);

                using(Utility.WithEmptyDirectory(out path))
                using (var fixture = CreateBlobCache(path))
                {
                    fixture.InsertObject("state", input).First();

                    var result = fixture.GetObjectAsync<DummyAppBootstrapper>("state").First();
                    var output = (DummyRoutedViewModel) result.Router.NavigationStack[0];
                    Assert.Equal(expected, output.ARandomGuid);
                }
            }
        }
Ejemplo n.º 3
0
        static RxApp()
        {
#if PORTABLE
            _TaskpoolScheduler = Scheduler.TaskPool;
#else
            _TaskpoolScheduler = TaskPoolScheduler.Default;
#endif
            DefaultExceptionHandler = Observer.Create <Exception>(ex => {
                // NB: If you're seeing this, it means that an
                // ObservableAsPropertyHelper or the CanExecute of a
                // ReactiveCommand ended in an OnError. Instead of silently
                // breaking, ReactiveUI will halt here if a debugger is attached.
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }

                RxApp.MainThreadScheduler.Schedule(() => {
                    throw new Exception(
                        "An OnError occurred on an object (usually ObservableAsPropertyHelper) that would break a binding or command. To prevent this, Subscribe to the ThrownExceptions property of your objects",
                        ex);
                });
            });

            var r = new ModernDependencyResolver();
            r.InitializeResolver();
            _DependencyResolver = r;

            if (InUnitTestRunner())
            {
                LogHost.Default.Warn("*** Detected Unit Test Runner, setting MainThreadScheduler to CurrentThread ***");
                LogHost.Default.Warn("If we are not actually in a test runner, please file a bug\n");
                _MainThreadScheduler = CurrentThreadScheduler.Instance;
                return;
            }
            else
            {
                LogHost.Default.Info("Initializing to normal mode");
            }

            if (_MainThreadScheduler == null)
            {
#if !ANDROID
                // NB: We can't initialize a scheduler automatically on Android
                // because it is intrinsically tied to the current Activity,
                // so devs have to set it up by hand :-/
                LogHost.Default.Error("*** ReactiveUI Platform DLL reference not added - using Default scheduler *** ");
                LogHost.Default.Error("Add a reference to ReactiveUI.{Xaml / Cocoa / etc}.");
                LogHost.Default.Error("or consider explicitly setting RxApp.MainThreadScheduler if not");
#endif
                _MainThreadScheduler = DefaultScheduler.Instance;
            }
        }
Ejemplo n.º 4
0
        static RxApp()
        {
#if PORTABLE
            _TaskpoolScheduler = Scheduler.Default;
#else
            _TaskpoolScheduler = TaskPoolScheduler.Default;
#endif
            DefaultExceptionHandler = Observer.Create<Exception>(ex => {
                // NB: If you're seeing this, it means that an 
                // ObservableAsPropertyHelper or the CanExecute of a 
                // ReactiveCommand ended in an OnError. Instead of silently 
                // breaking, ReactiveUI will halt here if a debugger is attached.
                if (Debugger.IsAttached) {
                    Debugger.Break();
                }

                RxApp.MainThreadScheduler.Schedule(() => {
                    throw new Exception(
                        "An OnError occurred on an object (usually ObservableAsPropertyHelper) that would break a binding or command. To prevent this, Subscribe to the ThrownExceptions property of your objects",
                        ex);
                });
            });

            var r = new ModernDependencyResolver();
            r.InitializeResolver();
            _DependencyResolver = r;

            if (InUnitTestRunner()) {
                LogHost.Default.Warn("*** Detected Unit Test Runner, setting MainThreadScheduler to CurrentThread ***");
                LogHost.Default.Warn("If we are not actually in a test runner, please file a bug\n");
                _MainThreadScheduler = CurrentThreadScheduler.Instance;
                return;
            } else {
                LogHost.Default.Info("Initializing to normal mode");
            }

            if (_MainThreadScheduler == null) {
#if !ANDROID
                // NB: We can't initialize a scheduler automatically on Android
                // because it is intrinsically tied to the current Activity, 
                // so devs have to set it up by hand :-/
                LogHost.Default.Error("*** ReactiveUI Platform DLL reference not added - using Default scheduler *** ");
                LogHost.Default.Error("Add a reference to ReactiveUI.{Xaml / Cocoa / etc}.");
                LogHost.Default.Error("or consider explicitly setting RxApp.MainThreadScheduler if not");
#endif
                _MainThreadScheduler = DefaultScheduler.Instance;
            }
        }
Ejemplo n.º 5
0
        static void initializeDependencyResolver()
        {
            var resolver = new ModernDependencyResolver();

            // NB: The reason that we need to do this is that logging itself
            // is set up via dependency resolution - if we try to log while
            // setting up the logger, we will end up StackOverflowException'ing
            resolver.InitializeResolver();
            _DependencyResolver = resolver;
        }