当前位置: 首页>>代码示例>>C#>>正文


C# ReactiveCommand.Do方法代码示例

本文整理汇总了C#中ReactiveCommand.Do方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveCommand.Do方法的具体用法?C# ReactiveCommand.Do怎么用?C# ReactiveCommand.Do使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReactiveCommand的用法示例。


在下文中一共展示了ReactiveCommand.Do方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PasteViewModel

        public PasteViewModel(ClipboardItem clipboardItem, IRoom room, IMessageBus bus)
        {
            if (clipboardItem.IsImage)
            {
                _imageSource = clipboardItem.LocalPath;
            }
            else
            {
                _imageSource = DependencyProperty.UnsetValue;
            }

            Caption = "Upload this " + (clipboardItem.IsImage ? "image" : "file") + "?";
            LocalPath = clipboardItem.LocalPath;
            ShowLocalPath = !clipboardItem.IsImage;
            ContentType = clipboardItem.ContentType;
            Size = clipboardItem.Size;

            PasteCommand = new ReactiveCommand();

            Subscribe(bus.Listen<FileUploadedMessage>().Where(msg => msg.CorrelationId == _currentCorrelation)
                .SubscribeUI(_ => IsFinished = true));

            Subscribe(bus.Listen<FileUploadProgressChangedMessage>().Where(msg => msg.CorrelationId == _currentCorrelation)
                .SubscribeUI(
                    msg =>
                    {
                        ProgressCurrent = msg.Progress.Current;
                        ProgressTotal = msg.Progress.Total;
                        Debug.WriteLine("Current, total" + ProgressCurrent + ", " + ProgressTotal);
                    }));

            Subscribe(bus.Listen<CorrelatedExceptionMessage>().Where(msg => msg.CorrelationId == _currentCorrelation)
                .SubscribeUI(msg =>
                    {
                        IsErrored = true;
                        IsUploading = false;
                        LastException = msg.Exception;
                    }));

            ProgressCurrent = 0;
            ProgressTotal = 100;

            Subscribe(bus.RegisterMessageSource(
                PasteCommand.Do(_ =>
                    {
                        IsUploading = true;
                        IsErrored = false;
                    })
                .Select(_ => new RequestUploadFileMessage(room.Id, clipboardItem.LocalPath, clipboardItem.ContentType))
                .Do(msg => _currentCorrelation = msg.CorrelationId)));

            CancelCommand = new ReactiveCommand();
            Subscribe(CancelCommand.Subscribe(_ => IsFinished = true));
        }
开发者ID:Doomblaster,项目名称:MetroFire,代码行数:54,代码来源:PasteViewModel.cs

示例2: RoomListViewModel

        public RoomListViewModel(Room room, IMessageBus bus)
        {
            _room = room;
            _bus = bus;

            bus.Listen<RoomPresenceMessage>().SubscribeUI(msg => IsActive = msg.IsPresentIn(_room.Id));

            _bus.Listen<RoomActivatedMessage>().Where(msg => msg.RoomId == _room.Id)
                .Do(_ => IsJoiningRoom = false)
                .SubscribeUI(_ => IsCurrentRoom = true);

            _bus.Listen<RoomDeactivatedMessage>().Where(msg => msg.RoomId == _room.Id)
                .SubscribeUI(_ => IsCurrentRoom = false);

            _bus.Listen<RoomActivityMessage>().Where(msg => msg.RoomId == _room.Id)
                .SubscribeUI(msg => RoomActivityCount += msg.Count);

            JoinCommand = new ReactiveCommand();
            JoinCommand.Do(_ => IsJoiningRoom = true).SubscribeUI(HandleJoinCommand);
        }
开发者ID:Doomblaster,项目名称:MetroFire,代码行数:20,代码来源:RoomListViewModel.cs

示例3: SettingsVM

        public SettingsVM(
            ISettingsService Settings,
            ICleanupData Cleanup,
            IConnectivityService Connectivity
            ) {
            this.Cleanup = Cleanup;
            this.Settings = Settings;
            this.Connectivity = Connectivity;

            this.WhenAny(x => x.Model, x => x.Value)
                .Where(x => x != null)
                .Select(m => m.UseGPS)
                .Subscribe(x => UseGPS = x);

            Reset = new ReactiveAsyncCommand(Connectivity.WifiAvailable());

            Reset.RegisterAsyncTask(OnReset);

            var setting_changed =
                this.WhenAny(x => x.UseGPS, x => x.Model,
                    (gps, model) => (model.Value != null) ? model.Value.UseGPS != gps.Value : false);

            Save = new ReactiveCommand(setting_changed);
            Messenger.RegisterMessageSource(
                Save
                .Do(_ => saveModel())
                .Select(_ => Page.Previous)
                );

            RefreshVocabulary = new ReactiveCommand(Connectivity.WifiAvailable());
            RefreshVocabulary
                .Subscribe(_ => {
                    Messenger.SendMessage(Page.SetupVocabulary);
                });





            ManageTaxa = new ReactiveCommand();
            Messenger.RegisterMessageSource(
                ManageTaxa
                .Select(_ => Page.TaxonManagement)
                );

            UploadData = new ReactiveCommand();
            Messenger.RegisterMessageSource(
                UploadData
                .Select(_ => Page.Upload)
                );

            DownloadData = new ReactiveCommand();
            Messenger.RegisterMessageSource(
                DownloadData
                .Select(_ => Page.Download)
                );

            Info = new ReactiveCommand();
            Messenger.RegisterMessageSource(
                Info
                .Select(_ => Page.Info)
                );

            ImportExport = new ReactiveCommand();
            Messenger.RegisterMessageSource(
                ImportExport
                .Select(_ => Page.ImportExport)
                );

            Settings
                .SettingsObservable()
                .Subscribe(x => Model = x);
        }
开发者ID:rollingthunder,项目名称:DiversityMobile,代码行数:73,代码来源:SettingsVM.cs

示例4: MapManagementVM

        public MapManagementVM(
            IConnectivityService Network,
            IMapTransferService MapService,
            IMapStorageService MapStorage,
            INotificationService Notifications,
            [Dispatcher] IScheduler Dispatcher
            ) {
            Contract.Requires(Network != null);
            Contract.Requires(MapService != null);
            Contract.Requires(MapStorage != null);
            Contract.Requires(Notifications != null);
            this.Network = Network;
            this.MapService = MapService;
            this.MapStorage = MapStorage;



            this.FirstActivation()
                .Subscribe(_ => getMaps.Execute(null));

            MapList = getMaps.RegisterAsyncFunction(_ => MapStorage.getAllMaps().Select(m => new MapVM(m)))
                      .SelectMany(vms => vms.ToList())
                      .ObserveOn(Dispatcher)
                      .CreateCollection();
            MapList.ItemsAdded
                .Subscribe(item => _local_map_register.Add(item.ServerKey, Unit.Default));

            MapList.ItemsRemoved
                .Subscribe(item => _local_map_register.Remove(item.ServerKey));

            SelectMap = new ReactiveCommand<MapVM>(vm => !vm.IsDownloading);
            SelectMap
                .Select(vm => vm as IElementVM<Map>)
                .ToMessage(Messenger, MessageContracts.VIEW);

            SelectMap
                .Select(_ => Page.Previous)
                .ToMessage(Messenger);

            DeleteMap = new ReactiveCommand<MapVM>(vm => !vm.IsDownloading);
            DeleteMap
                .Do(vm => MapList.Remove(vm))
                .Select(vm => vm.Model)
                .Where(map => map != null)
                .Subscribe(map => MapStorage.deleteMap(map));

            _IsOnlineAvailable = this.ObservableToProperty(
                this.OnActivation()
                .SelectMany(Network.WifiAvailable().TakeUntil(this.OnDeactivation()))
                .Do(x => { })
                , x => x.IsOnlineAvailable, false);

            SearchMaps = new ReactiveAsyncCommand(_IsOnlineAvailable);

            _SearchResults = this.ObservableToProperty<MapManagementVM, IReactiveCollection<MapVM>>(
                SearchMaps.RegisterAsyncFunction(s => searchMapsImpl(s as string))
                .ObserveOn(Dispatcher)
                .Select(result => {
                    try {
                        return new ReactiveCollection<MapVM>(result.Select(x => new MapVM(null) { ServerKey = x })) as IReactiveCollection<MapVM>;
                    }
                    catch (Exception) {
                        return null;
                    }
                }),
                x => x.SearchResults);

            DownloadMap = new ReactiveCommand<MapVM>(vm => canBeDownloaded(vm as MapVM), Observable.Empty<Unit>());
            DownloadMap
                .Where(downloadMap.CanExecute)
                .CheckConnectivity(Network, Notifications)
                .Do(vm => vm.IsDownloading = true)
                .Do(_ => CurrentPivot = Pivot.Local)
                .Do(vm => MapList.Add(vm))
                .Subscribe(downloadMap.Execute);

            downloadMap.RegisterAsyncObservable(vm => {
                var vm_t = vm as MapVM;
                if (vm_t == null)
                    return Observable.Empty<System.Tuple<MapVM, Map>>();
                else
                    return MapService.downloadMap(vm_t.ServerKey)
                        .ShowServiceErrorNotifications(Notifications)
                        .Catch((WebException ex) => {
                            Notifications.showNotification(DiversityResources.MapManagement_Message_NoPermissions);

                            return Observable.Empty<Map>();
                        })
                        .Select(map => System.Tuple.Create(vm_t, map));
            })
            .ObserveOn(Dispatcher)
            .Select(t => {
                if (t.Item1 != null) // VM
                    {
                    if (t.Item2 != null) // Map
                        {
                        t.Item1.SetModel(t.Item2);
                    }
                    else {
                        MapList.Remove(t.Item1);
//.........这里部分代码省略.........
开发者ID:rollingthunder,项目名称:DiversityMobile,代码行数:101,代码来源:MapManagementVM.cs


注:本文中的ReactiveCommand.Do方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。