Beispiel #1
0
 public LogViewModel(SampleSqliteConnection conn,
                     MsgBus messageBus,
                     IDialogs dialogs) : base(dialogs)
 {
     this.conn       = conn;
     this.messageBus = messageBus;
 }
Beispiel #2
0
        public MainViewModel(IDataSyncManager manager,
                             SampleDataSyncDelegate sdelegate,
                             INavigationService navigator,
                             IDialogs dialogs,
                             Shiny.IMessageBus messageBus)
        {
            this.manager   = manager;
            this.navigator = navigator;

            var faker = new Faker <MyEntity>()
                        .RuleFor(x => x.FirstName, (f, _) => f.Name.FirstName())
                        .RuleFor(x => x.LastName, (f, _) => f.Name.LastName());

            this.IsSyncEnabled = manager.Enabled;
            this.AllowOutgoing = sdelegate.AllowOutgoing;

            this.GenerateTestItem = ReactiveCommand.CreateFromTask(async() =>
            {
                var entity = faker.Generate(1).First();
                await manager.Save(entity, SyncOperation.Create);
                await this.BindList();
            });

            this.ForceRun = ReactiveCommand.CreateFromTask(() =>
                                                           //dialogs.LoadingTask(() => manager.ForceRun())
                                                           manager.ForceRun()
                                                           );

            this.Clear = ReactiveCommand.CreateFromTask(async() =>
            {
                var result = await dialogs.Confirm("Are you sure you wish to clear the data sync pending queue?");
                if (result)
                {
                    await this.manager.ClearPending();
                    await this.BindList();
                }
            });

            this.WhenAnyValue(x => x.AllowOutgoing)
            .Skip(1)
            .Subscribe(x => sdelegate.AllowOutgoing = x)
            .DisposeWith(this.DestroyWith);

            this.WhenAnyValue(x => x.IsSyncEnabled)
            .Skip(1)
            .Subscribe(x => manager.Enabled = x)
            .DisposeWith(this.DestroyWith);

            messageBus
            .Listener <SyncItem>()
            .SubOnMainThread(x => this.Remove(x.Id))
            .DisposeWith(this.DestroyWith);
        }