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


C# ReactiveList.FirstOrDefault方法代码示例

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


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

示例1: RecentViewModel

        public RecentViewModel(Guid id, string metaDataSlug, IEnumerable<RecentItemViewModel> recentItems) {
            _id = id;
            RecentItems = new ReactiveList<RecentItemViewModel>(recentItems);

            // TODO: This is a tab, and tabs are only active while shown
            // but we want to receive these events regardless of being active or not, otherwise we are not uptodate when the user switches to us.
            // Or we need to find a different approach!
            Listen<ContentUsed>()
                .Where(x => {
                    var contentId = GetId(x.Content);
                    lock (RecentItems)
                        return _id == x.Content.GameId && RecentItems.All(r => r.Id != contentId);
                })
                .Select(x => {
                    var ri = x.Content.MapTo<RecentItemViewModel>();
                    if (x.Token != null)
                        ri.UpdateExecute(x.Token);
                    return ri;
                })
                .ObserveOnMainThread()
                .Subscribe(x => {
                    lock (RecentItems)
                        RecentItems.Insert(0, x);
                });

            Listen<RecentItemRemoved>()
                .ObserveOnMainThread()
                .Subscribe(x => {
                    lock (RecentItems) {
                        RecentItems.RemoveAll(r => r.Id == x.Content.Id);
                    }
                });

            // TODO: Stop manually moving, start auto sorting in View (ICollectionView or ReactiveDerivedCollection)...
            // Then remove this event
            Listen<ContentUsed>()
                .Select(x => {
                    var contentId = GetId(x.Content);
                    lock (RecentItems)
                        return RecentItems.FirstOrDefault(r => r.Id == contentId);
                })
                .Where(x => x != null)
                .ObserveOnMainThread()
                .Subscribe(x => {
                    lock (RecentItems)
                        RecentItems.Move(RecentItems.IndexOf(x), 0);
                });

            AddContent =
                ReactiveCommand.CreateAsyncTask(
                    async x => await RequestAsync(new OpenWebLink(ViewType.Browse, metaDataSlug)).ConfigureAwait(false));


            this.WhenActivated(d => {
                RefreshUpdated();
                d(new TimerWithoutOverlap(TimeSpan.FromMinutes(1),
                    () => RxApp.MainThreadScheduler.Schedule(RefreshUpdated)));
            });
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:59,代码来源:RecentViewModel.cs

示例2: RepositoryPublishViewModel

        public RepositoryPublishViewModel(
            IRepositoryHosts hosts,
            IRepositoryPublishService repositoryPublishService,
            IVSServices vsServices,
            IConnectionManager connectionManager)
        {
            this.vsServices = vsServices;
            this.hosts = hosts;

            title = this.WhenAny(
                x => x.SelectedHost,
                x => x.Value != null ?
                    string.Format(CultureInfo.CurrentCulture, "Publish repository to {0}", x.Value.Title) :
                    "Publish repository"
            )
            .ToProperty(this, x => x.Title);

            Connections = new ReactiveList<IConnection>(connectionManager.Connections);
            this.repositoryPublishService = repositoryPublishService;

            if (Connections.Any())
            {
                SelectedConnection = Connections.FirstOrDefault(x => x.HostAddress.IsGitHubDotCom()) ?? Connections[0];
            }

            accounts = this.WhenAny(x => x.SelectedConnection, x => x.Value != null ? hosts.LookupHost(x.Value.HostAddress) : RepositoryHosts.DisconnectedRepositoryHost)
                .Where(x => !(x is DisconnectedRepositoryHost))
                .SelectMany(host => host.ModelService.GetAccounts())
                .ObserveOn(RxApp.MainThreadScheduler)
                .ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection<IAccount>(new IAccount[] {}));

            this.WhenAny(x => x.Accounts, x => x.Value)
                .WhereNotNull()
                .Where(accts => accts.Any())
                .Subscribe(accts => {
                    var selectedAccount = accts.FirstOrDefault();
                    if (selectedAccount != null)
                    {
                        SelectedAccount = accts.FirstOrDefault();
                    }
                });

            isHostComboBoxVisible = this.WhenAny(x => x.Connections, x => x.Value)
                .WhereNotNull()
                .Select(h => h.Count > 1)
                .ToProperty(this, x => x.IsHostComboBoxVisible);

            InitializeValidation();

            PublishRepository = InitializePublishRepositoryCommand();

            canKeepPrivate = CanKeepPrivateObservable.CombineLatest(PublishRepository.IsExecuting,
                (canKeep, publishing) => canKeep && !publishing)
                .ToProperty(this, x => x.CanKeepPrivate);

            isPublishing = PublishRepository.IsExecuting
                .ToProperty(this, x => x.IsPublishing);

            var defaultRepositoryName = repositoryPublishService.LocalRepositoryName;
            if (!string.IsNullOrEmpty(defaultRepositoryName))
            {
                DefaultRepositoryName    = defaultRepositoryName;
            }

            this.WhenAny(x => x.SelectedConnection, x => x.SelectedAccount,
                (a,b) => true)
                .Where(x => RepositoryNameValidator.ValidationResult != null && SafeRepositoryNameWarningValidator.ValidationResult != null)
                .Subscribe(async _ =>
                {
                    var name = RepositoryName;
                    RepositoryName = null;
                    await RepositoryNameValidator.ResetAsync();
                    await SafeRepositoryNameWarningValidator.ResetAsync();
                    RepositoryName = name;
                });
        }
开发者ID:nulltoken,项目名称:VisualStudio,代码行数:76,代码来源:RepositoryPublishViewModel.cs


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