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


C# ReactiveList.AddRange方法代码示例

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


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

示例1: PersonListViewModel

 public PersonListViewModel(IScreen hostScreen, IPersonRepository personRepository = null)
 {
     HostScreen = hostScreen;
     personRepository = personRepository ?? new PersonRepository();
     Persons = new ReactiveList<PersonItemViewModel>();
     NewPersonCommand = new ReactiveCommand(null);
     NewPersonCommand.RegisterAsyncAction(_ => { }).Subscribe(_ => HostScreen.Router.Navigate.Execute(new PersonAddViewModel(HostScreen)));
     RefreshCommand = new ReactiveCommand(null);
     var refresh = RefreshCommand.RegisterAsync<List<Person>>(_ => Observable.Start(() => personRepository.RetrievePersonsAsync().
                                                                                                           Result));
     refresh.Subscribe(list =>
     {
         using (Persons.SuppressChangeNotifications())
         {
             Persons.Clear();
             Persons.AddRange(personRepository.RetrievePersonsAsync().
                                               Result.Select(d => new PersonItemViewModel(d.FirstName,
                                                                      d.LastName,
                                                                      d.Age)));
         }
     });
     MessageBus.Current.Listen<Person>().
                Subscribe(p =>
                {
                    personRepository.AddPerson(p);
                    RefreshCommand.Execute(null);
                });
 }
开发者ID:jiravanet,项目名称:Prezentace-ReactiveUI,代码行数:28,代码来源:PersonListViewModel.cs

示例2: IssueLabelsViewModel

        public IssueLabelsViewModel(
            Func<Task<IReadOnlyList<Label>>> loadAllLabelsFunc,
            Func<Task<IReadOnlyList<Label>>> loadSelectedFunc,
            Func<IEnumerable<Label>, Task> saveLabelsFunc)
	    {
            var labels = new ReactiveList<Label>();
            var selected = new ReactiveList<Label>();
            Labels = labels.CreateDerivedCollection(x => 
            {
                var vm = new IssueLabelItemViewModel(x);
                vm.IsSelected = selected.Any(y => y.Url == x.Url);
                return vm;
            });

            SaveCommand = ReactiveCommand.CreateAsyncTask(_ =>
            {
                var currentlySelected = Labels.Where(x => x.IsSelected).ToList();
                var selectedLabelsUrl = currentlySelected.Select(x => x.Label.Url).ToArray();
                var prevSelectedLabelsUrl = selected.Select(x => x.Url).ToArray();
                var intersect = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
                var different = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
                return different ? saveLabelsFunc(currentlySelected.Select(x => x.Label)) : Task.FromResult(0);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                selected.Clear();
                selected.AddRange((await loadSelectedFunc()) ?? Enumerable.Empty<Label>());
                labels.Reset(await loadAllLabelsFunc());
            });
	    }
开发者ID:runt18,项目名称:CodeHub,代码行数:30,代码来源:IssueLabelsViewModel.cs

示例3: BlogViewModel

        public BlogViewModel(string title, Uri feedAddress, IFeedService feedService = null, IBlobCache cache = null)
        {
            Title = title;
            FeedAddress = feedAddress;
            FeedService = feedService ?? Locator.Current.GetService<IFeedService>();
            Cache = cache ?? Locator.Current.GetService<IBlobCache>();

            Articles = new ReactiveList<ArticleViewModel>();

            Refresh = ReactiveCommand.CreateAsyncObservable(x => GetAndFetchLatestArticles());
            Refresh.Subscribe(articles =>
            {
                // this could be done cleaner, send a PR.
                // Refresh.ToPropertyEx(this, x => x.Articles);

                Articles.Clear();
                Articles.AddRange(articles);
            });

            
            Refresh.ThrownExceptions.Subscribe(thrownException => { this.Log().Error(thrownException); });
            _isLoading = Refresh.IsExecuting.ToProperty(this, x => x.IsLoading);

            // post-condition checks
            Condition.Ensures(FeedAddress).IsNotNull();
            Condition.Ensures(FeedService).IsNotNull();
            Condition.Ensures(Cache).IsNotNull();
        }
开发者ID:moswald,项目名称:rxui-samples,代码行数:28,代码来源:BlogViewModel.cs

示例4: HistoryViewModel

        public HistoryViewModel(IRequestHistory requests)
        {
            Requests = new ReactiveList<HttpRequest>();
            requests.GetRequestsAsync().ContinueWith(continuation => Requests.AddRange(continuation.Result));
            requests.GetRequestsObservable().Subscribe(request => Requests.Add(request));

            SelectedRequestObservable = this.ObservableForProperty(vm => vm.SelectedRequest).Select(r => r.Value);
        }
开发者ID:georgebearden,项目名称:Peticion,代码行数:8,代码来源:HistoryViewModel.cs

示例5: MainViewModel

 public MainViewModel()
 {
     People = new ReactiveList<PersonViewModel>();
     People.ActOnEveryObject(x => x.Delete.Subscribe(p => People.Remove((PersonViewModel) p)), _ => { });
     People.AddRange(new[]
     {
         new PersonViewModel("Jerry", "Seinfeld"),
         new PersonViewModel("George", "Costanza"),
         new PersonViewModel("Elaine", "Something"),
         new PersonViewModel("Newman", "Something"),
     });
 }
开发者ID:kmcginnes,项目名称:PoC.ReactiveCommandBubbling,代码行数:12,代码来源:MainViewModel.cs

示例6: ChannelViewModel

        public ChannelViewModel(string token, string teamId, IScreen screen = null)
        {
            HostScreen = screen ?? Locator.Current.GetService<IScreen>();
            Messages = new ReactiveList<Message>();

            var client = new HttpClient(NetCache.UserInitiated) {
                BaseAddress = new Uri("https://slack.com"),
            };

            var api = RestService.For<ISlackApi>(client);

            LoadChannelToDisplay = ReactiveCommand.CreateAsyncTask(async _ => {
                var channelList = await BlobCache.LocalMachine.GetOrFetchObject("channels_" + teamId, 
                    () => api.GetChannels(token),
                    RxApp.MainThreadScheduler.Now + TimeSpan.FromMinutes(5.0));

                // Try to find ReactiveUI, then general, then whatever the first one is
                var channel =
                    channelList.channels.FirstOrDefault(x => x.name.ToLowerInvariant() == "reactiveui") ??
                    channelList.channels.FirstOrDefault(x => x.name.ToLowerInvariant() == "general") ??
                    channelList.channels.First();

                return channel.id;
            });

            LoadChannelToDisplay.Subscribe(x => VisibleChannel = x);

            LoadMessages = ReactiveCommand.CreateAsyncTask(async _ => {
                var channelToLoad = VisibleChannel;
                if (channelToLoad == null) {
                    channelToLoad = await LoadChannelToDisplay.ExecuteAsync();
                }

                return await api.GetLatestMessages(token, channelToLoad);
            });

            LoadMessages.Subscribe(xs => {
                Messages.Clear();
                Messages.AddRange(xs.messages);
            });

            LoadMessages.ThrownExceptions.Subscribe(ex =>
                UserError.Throw("Couldn't load messages for room", ex));

            MessageTiles = Messages.CreateDerivedCollection(
                x => new MessageTileViewModel(x),
                x => !String.IsNullOrWhiteSpace(x.text),
                (x, y) => x.Model.date.CompareTo(y.Model.date));
        }
开发者ID:reactiveui-forks,项目名称:XamarinEvolve2014,代码行数:49,代码来源:ChannelViewModel.cs

示例7: AlbumViewModel

        public AlbumViewModel(Album album)
        {
            _events = IoC.Get<IEventAggregator>();
            _windowManager = IoC.Get<IWindowManager>();
            Model = album;
            Tracks = new ReactiveList<TrackViewModel>();
            Tracks.AddRange(album.Tracks.Select(x => new TrackViewModel(x)));

            AddAlbumToPlaylistCommand = new ReactiveCommand();
            AddAlbumToPlaylistCommand.Subscribe(param => _events.Publish(Tracks.Select(x => x.Track).ToList()));

            EditorEditAlbumsCommand = new ReactiveCommand();
            EditorEditAlbumsCommand.Subscribe(
                param => _windowManager.ShowDialog(new AlbumTagEditorViewModel(Tracks.Select(x => x.Track.Model).ToList())));
        }
开发者ID:gfdittmer,项目名称:MiSharp,代码行数:15,代码来源:AlbumViewModel.cs

示例8: ImportProgressViewModel

        public ImportProgressViewModel()
        {
            EventsToImport = new ReactiveList<RecordedEventViewModel>();

            if (Execute.InDesignMode)
            {
                CurrentIndex = 2;
                EventsToImport.AddRange(new[]
                {
                    new RecordedEventViewModel {Sequence = 1, OfficerName = "Tom Landry", Started = new DateTime(1960, 9, 14, 7, 45, 19)}, 
                    new RecordedEventViewModel {Sequence = 2, OfficerName = "Jimmy Johnson", Started = new DateTime(1989, 9, 15, 3, 04, 54)}, 
                    new RecordedEventViewModel {Sequence = 3, OfficerName = "Barry Switzer", Started = new DateTime(1994, 9, 15, 3, 04, 54)}, 
                    new RecordedEventViewModel {Sequence = 4, OfficerName = "Chan Gailey", Started = new DateTime(1998, 9, 15, 3, 04, 54)}, 
                    new RecordedEventViewModel {Sequence = 5, OfficerName = "Dave Campo", Started = new DateTime(2000, 9, 15, 3, 04, 54)}, 
                    new RecordedEventViewModel {Sequence = 6, OfficerName = "Bill Parcels", Started = new DateTime(2003, 9, 15, 3, 04, 54)}, 
                    new RecordedEventViewModel {Sequence = 7, OfficerName = "Wade Phillips", Started = new DateTime(2007, 9, 15, 3, 04, 54)}, 
                    new RecordedEventViewModel {Sequence = 8, OfficerName = "Jason Gerrett", Started = new DateTime(2010, 9, 15, 3, 04, 54)}, 
                });
            }
        }
开发者ID:JohnCastleman,项目名称:PoC.ImportList,代码行数:20,代码来源:ImportProgressViewModel.cs

示例9: FoodsViewModel

        public FoodsViewModel(INavigatableScreen screen = null)
        {
            OrderableFoods = new ReactiveList<Order>();
            OpenOrder = ReactiveCommand.Create();
            NavigationScreen = (screen ?? Locator.Current.GetService<INavigatableScreen>());
            MainViewModel = Locator.Current.GetService<MainViewModel>();

            var foods = Global.AuthenticationManager.AuthenticatedApi.GetFoods();
            foods.ToObservable()
            .Do(x =>
            {
                var orders = x.Select(f => new Order {Food = f, Id = Guid.NewGuid()});
                OrderableFoods.AddRange(orders);
            })
            .Subscribe();

            OpenOrder.Do(_ =>
                {
                    NavigationScreen.Navigation.Navigate.Execute(Locator.Current.GetService<BasketViewModel>());
                }).Subscribe();
        }
开发者ID:Jurabek,项目名称:Restaurant,代码行数:21,代码来源:FoodsViewModel.cs

示例10: NotificationsListViewModel

        public NotificationsListViewModel(INotificationsClient notificationsApi)
        {
            Notifications = new ReactiveList<NotificationTileViewModel>();
            LoadNotifications = new ReactiveCommand();

            var loadedNotifications = LoadNotifications.RegisterAsync(_ =>
                //BlobCache.LocalMachine.GetAndFetchLatest("notifications", () => Observable.Return(new List<Notification>())));
                BlobCache.LocalMachine.GetAndFetchLatest("notifications", () =>
                    notificationsApi.GetAllForCurrent()));

            loadedNotifications.Subscribe(newItems => {
                using (Notifications.SuppressChangeNotifications()) {
                    var toAdd = newItems
                        .Where(x => x.Repository.Owner.Id != 9919 && x.Repository.Owner.Id != 1089146)
                        .Select(x => new NotificationTileViewModel(x))
                        .ToArray();

                    Notifications.Clear();
                    Notifications.AddRange(toAdd);
                    //Notifications.AddRange(new[] { new NotificationTileViewModel(null) });
                }
            });
        }
开发者ID:paulcbetts,项目名称:starter-sample,代码行数:23,代码来源:NotificationsListViewModel.cs

示例11: MainWindowViewModel

        public MainWindowViewModel()
        {
            ReleasesListHint = "Type in a release location URL or path to files";
            ReleasesList = new ReactiveList<ReleaseEntryViewModel>();
            ReleasesList.ChangeTrackingEnabled = true;

            CheckRemoteUpdateInfo = ReactiveCommand.CreateAsyncTask(
                this.WhenAny(x => x.ReleaseLocation, x => !String.IsNullOrWhiteSpace(x.Value)),
                async _ => {
                    ReleasesListHint = "";

                    var releaseData = default(String);
                    if (Regex.IsMatch(ReleaseLocation, "^https?://", RegexOptions.IgnoreCase)) {
                        var wc = new WebClient();
                        releaseData = await wc.DownloadStringTaskAsync(ReleaseLocation + "/RELEASES");
                    } else {
                        releaseData = File.ReadAllText(releaseData, Encoding.UTF8);
                    }

                    var ret = releaseData.Split('\n')
                        .Select(x => ReleaseEntry.ParseReleaseEntry(x))
                        .ToList();

                    return ret;
                });

            CheckRemoteUpdateInfo.ThrownExceptions
                .Subscribe(ex => ReleasesListHint = "Failed to check for updates: " + ex.Message);

            CheckRemoteUpdateInfo
                .Subscribe(x => {
                    var vms = x
                        .Where(y => y.IsDelta == false)
                        .Select(y => new ReleaseEntryViewModel(y));

                    using (ReleasesList.SuppressChangeNotifications()) {
                        ReleasesList.Clear();
                        ReleasesList.AddRange(vms);
                    }
                });

            this.WhenAnyValue(x => x.ReleaseLocation)
                .Throttle(TimeSpan.FromMilliseconds(750), RxApp.MainThreadScheduler)
                .InvokeCommand(CheckRemoteUpdateInfo);

            ReleasesList.ItemChanged
                .Where(x => x.PropertyName == "CurrentAction")
                .Subscribe(x => updateStartsAndEnds(x.Sender));

            DoIt = ReactiveCommand.CreateAsyncTask(
                this.WhenAny(x => x.ReleasesList.Count, x => x.Value > 0),
                async _ => {
                    var releasesToApply = ReleasesList.Where(x => x.Enabled).ToList();
                    if (releasesToApply.Count < 1 || releasesToApply.All(x => x.CurrentAction == ReleaseEntryActions.None)) {
                        await UserError.Throw(new OkUserError("Nothing to do", "At least one release must have the 'Start' action"));
                        return;
                    }

                    var appName = ReleasesList[0].Name;
                    var rootAppDir = Environment.ExpandEnvironmentVariables("%LocalAppData%\\" + appName);

                    if (Directory.Exists(rootAppDir)) {
                        var result = await UserError.Throw(new YesNoUserError(
                            "App already installed",
                            String.Format("App '{0}' is already installed, remove it before running install?", appName)));

                        if (result == RecoveryOptionResult.CancelOperation) {
                            return;
                        }

                        if (result == RecoveryOptionResult.RetryOperation) {
                            using (var mgr = new UpdateManager(null, appName, Environment.ExpandEnvironmentVariables("%LocalAppData%"))) {
                                await mgr.FullUninstall();
                            }
                        }
                    }

                    foreach (var release in releasesToApply) {
                        release.ReleaseLocation = this.ReleaseLocation;
                        await release.ApplyThisRelease.ExecuteAsync(null);
                    }
                });
        }
开发者ID:Squirrel,项目名称:Squirrel.Windows.Tools,代码行数:83,代码来源:MainWindowViewModel.cs

示例12: NewGameViewModel

        public NewGameViewModel()
        {
            Players = new ReactiveList<string>();

            var canStart = this.Players.CountChanged.Select(count => count >= 3);
            StartGame = ReactiveCommand.Create(() => { }, canStart);
            RandomizeOrder = ReactiveCommand.Create(() => {
                    using (Players.SuppressChangeNotifications()) {
                        var r = new Random();
                        var newOrder = Players.OrderBy(x => r.NextDouble()).ToList();
                        Players.Clear();
                        Players.AddRange(newOrder);
                    }
                },
                canStart);

            RemovePlayer = ReactiveCommand.Create<string>(player => this.Players.Remove(player));
            var canAddPlayer = this.WhenAnyValue(x => x.Players.Count, x => x.NewPlayerName,
                (count, newPlayerName) => count < 7 && !string.IsNullOrWhiteSpace(newPlayerName) && !this.Players.Contains(newPlayerName));
            AddPlayer = ReactiveCommand.Create(() => {
                    Players.Add(NewPlayerName.Trim());
                    NewPlayerName = string.Empty;
                },
                canAddPlayer);
        }
开发者ID:reactiveui,项目名称:ReactiveUI,代码行数:25,代码来源:ObservedChangedMixinTest.cs

示例13: InstalledViewModel

        public InstalledViewModel(Guid id, string metaDataSlug, IEnumerable<InstalledItemViewModel> localContent) {
            _id = id;
            LocalContent = new ReactiveList<InstalledItemViewModel>(localContent) {ChangeTrackingEnabled = true};
            LocalContent.ItemChanged
                .Where(x => x.PropertyName == "IsEnabled")
                .ObserveOnMainThread()
                .Subscribe(x => {
                    if (x.Sender.IsEnabled)
                        EnabledItems.Add(x.Sender);
                    else
                        EnabledItems.Remove(x.Sender);
                });
            EnabledItems = new ReactiveList<InstalledItemViewModel>(LocalContent.Where(x => x.IsEnabled));

            AddContent =
                ReactiveCommand.CreateAsyncTask(
                    async x => await RequestAsync(new OpenWebLink(ViewType.Browse, metaDataSlug)).ConfigureAwait(false));
            _uninstallSelected =
                ReactiveCommand.CreateAsyncTask(async x => {
                    var r =
                        await
                            Cheat.DialogManager.MessageBoxAsync(
                                new MessageBoxDialogParams("Are you sure you wish to uninstall the selected mods?",
                                    "Uninstall items?", SixMessageBoxButton.OKCancel)).ConfigureAwait(false);
                    if (r != SixMessageBoxResult.OK)
                        return;
                    await RequestAsync(
                        new UninstallInstalledItems(id,
                            LocalContent.Where(x1 => x1.IsEnabled).Select(x2 => x2.Id).ToList()))
                        .ConfigureAwait(false);
                }).DefaultSetup("UninstallSelected");

            _playSelected =
                ReactiveCommand.CreateAsyncTask(async x => await RequestAsync(
                    new PlayInstalledItems(id,
                        LocalContent.Where(x1 => x1.IsEnabled).Select(x2 => x2.Id).ToList()))
                    .ConfigureAwait(false))
                    .DefaultSetup("PlaySelected");
            _clear =
                ReactiveCommand.CreateAsyncTask(async x => await ResetInternal().ConfigureAwait(false))
                    .DefaultSetup("Reset");

            // 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<LocalContentAdded>()
                .Where(x => _id == x.GameId)
                .Select(x => x.LocalContent.MapTo<List<InstalledItemViewModel>>())
                .ObserveOnMainThread()
                .Subscribe(x => LocalContent.AddRange(x));
            Listen<UninstallActionCompleted>()
                .Where(x => _id == x.Game.Id)
                .Select(x => x.UninstallLocalContentAction.Content.Select(u => u.Content.Id).ToArray())
                .ObserveOnMainThread()
                .Subscribe(
                    x =>
                        LocalContent.RemoveAll(
                            LocalContent.Where(
                                c => x.Contains(c.Id))
                                .ToArray()));
            /*
            this.WhenActivated(d => {
                d();
            });
            */
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:66,代码来源:InstalledViewModel.cs

示例14: LoginStartViewModel

        public LoginStartViewModel(IScreen screen = null)
        {
            HostScreen = screen ?? Locator.Current.GetService<IScreen>();
            TeamList = new ReactiveList<LoginTeamTileViewModel>();

            // CoolStuff: We're describing here, in a *declarative way*, the
            // conditions in which the LoadTeamList command is enabled. Now,
            // our Command IsEnabled is perfectly efficient, because we're only
            // updating the UI in the scenario when it should change.
            var canLoadTeamList = this.WhenAny(x => x.Email, x => !String.IsNullOrWhiteSpace(x.Value));

            // CoolStuff: ReactiveCommands have built-in support for background
            // operations. RxCmd guarantees that this block will only run exactly
            // once at a time, and that the CanExecute will auto-disable while it
            // is running.
            LoadTeamList = ReactiveCommand.CreateAsyncTask(canLoadTeamList, async _ => {
                var client = new HttpClient(NetCache.UserInitiated) {
                    BaseAddress = new Uri("https://slack.com"),
                };

                var api = RestService.For<ISlackApi>(client);
                var ret = await BlobCache.LocalMachine.GetOrFetchObject("teams_" + email,
                    async () => {
                        var teams = await api.GetTeamsForUser(this.Email);

                        if (teams.users == null || teams.users.Count == 0) {
                            throw new Exception("No teams for this account");
                        }

                        return teams;
                    },
                    RxApp.MainThreadScheduler.Now + TimeSpan.FromMinutes(5));

                return ret.users;
            });

            // CoolStuff: ReactiveCommands are themselves IObservables, whose value
            // are the results from the async method, guaranteed to arrive on the UI
            // thread. We're going to take the list of teams that the background
            // operation loaded, and put them into our TeamList.
            LoadTeamList.Subscribe(xs => {
                TeamList.Clear();
                TeamList.AddRange(xs.Select(x => new LoginTeamTileViewModel(x)));
            });

            // CoolStuff: ThrownExceptions is any exception thrown from the
            // CreateAsyncTask piped to this Observable. Subscribing to this
            // allows you to handle errors on the UI thread.
            LoadTeamList.ThrownExceptions
                .Subscribe(ex => {
                    TeamList.Clear();
                    UserError.Throw("Invalid Email for User", ex);
                });

            // CoolStuff: Whenever the Email address changes, we're going to wait
            // for one second of "dead airtime", then invoke the LoadTeamList
            // command.
            this.WhenAnyValue(x => x.Email)
                .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
                .InvokeCommand(this, x => x.LoadTeamList);
        }
开发者ID:reactiveui-forks,项目名称:XamarinEvolve2014,代码行数:61,代码来源:LoginStartViewModel.cs


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