Пример #1
0
 public CatalogSynchronizer(
     ICatalogCategoryRepo categoryRepo       = null,
     ICatalogItemRepoFactory itemRepoFactory = null,
     IAdminVarRepo adminVarRepo = null)
 {
     _categoryRepo    = categoryRepo ?? Locator.Current.GetService <ICatalogCategoryRepo>();
     _itemRepoFactory = itemRepoFactory ?? Locator.Current.GetService <ICatalogItemRepoFactory>();
     _adminVarRepo    = adminVarRepo ?? Locator.Current.GetService <IAdminVarRepo>();
 }
Пример #2
0
        public CatalogItemListViewModel(
            string categoryId,
            ICatalogItemRepoFactory itemRepoFactory = null,
            IViewStackService viewStackService      = null)
        {
            itemRepoFactory  = itemRepoFactory ?? Locator.Current.GetService <ICatalogItemRepoFactory>();
            viewStackService = viewStackService ?? Locator.Current.GetService <IViewStackService>();

            var itemRepo = itemRepoFactory.Create(categoryId);

            LoadItems = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(itemRepo
                       .GetItems()
                       .SelectMany(x => x)
                       .Select(x => new CatalogItemCellViewModel(x, itemRepo))
                       .ToList()
                       .Select(x => x as IReadOnlyList <ICatalogItemCellViewModel>));
            });

            _items = LoadItems.ToProperty(this, x => x.Items);

            var firebaseStorageService = Locator.Current.GetService <GameCtor.FirebaseStorage.DotNet.IFirebaseStorageService>();

            DownloadImages = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(Items
                       .ToObservable()
                       .SelectMany(
                           itemCell =>
                {
                    return firebaseStorageService
                    .GetDownloadUrl("catalogPhotos/" + itemCell.Id + ".jpg")
                    .Catch <string, Exception>(ex => Observable.Return <string>(null))
                    .Where(x => x != null)
                    .Do(imageUrl => itemCell.ImageUrl = imageUrl)
                    .Select(_ => itemCell);
                })
                       .SelectMany(
                           itemCell =>
                {
                    return itemRepo
                    .Upsert(itemCell.Model);
                }));
            });
        }
Пример #3
0
        public CatalogCategoryViewModel(
            string categoryId,
            ICatalogItemRepoFactory catalogItemRepoFactory = null,
            IViewStackService viewStackService             = null)
            : base(viewStackService)
        {
            catalogItemRepoFactory = catalogItemRepoFactory ?? Locator.Current.GetService <ICatalogItemRepoFactory>();
            ICatalogItemRepo catalogItemRepo = catalogItemRepoFactory.Create(categoryId);

            CatalogItems = new List <ICatalogItemCellViewModel>();

            LoadCatalogItems = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(catalogItemRepo.GetItems()
                       .SelectMany(x => x)
                       .Select(x => new CatalogItemCellViewModel(x) as ICatalogItemCellViewModel)
                       .Do(x => CatalogItems.Add(x)));
            });

            LoadCatalogItems
            .ThrownExceptions
            .Subscribe(
                ex =>
            {
                this.Log().Debug(ex.Message);
            });

            this
            .WhenAnyValue(vm => vm.SelectedItem)
            .Where(x => x != null)
            .SelectMany(x => LoadSelectedPage(x))
            .Subscribe();

            //this
            //    .WhenAnyValue(vm => vm.ItemAppearing)
            //    .Where(item => item != null && item.Id == CatalogItems[CatalogItems.Count - 1].Id)
            //    .Select(_ => Unit.Default)
            //    .InvokeCommand(LoadCatalogItems)
            //    .DisposeWith(disposables);

            //_isRefreshing = LoadCatalogItems
            //    .IsExecuting
            //    .ToProperty(this, vm => vm.IsRefreshing, true);
        }