public void Test_CreateComparer() { var coll = new SortedObservableCollection <int>(Comparer <int> .Create((x, y) => x - y)); Assert.AreEqual(0, coll.Count); Assert.IsFalse(coll.IsReadOnly); }
public void SortedCollection001CanSort() { var sc = new SortedObservableCollection <TestSortable>(); TestSortable t2 = new TestSortable(); t2.Name = "t2"; sc.Add(t2); TestSortable t1 = new TestSortable(); t1.Name = "t1"; sc.Add(t1); TestSortable t3 = new TestSortable(); t3.Name = "t3"; sc.Add(t3); TestSortable t31 = new TestSortable(); t31.Name = "t3"; sc.Add(t31, 1); TestSortable t22 = new TestSortable(); t22.Name = "t2"; sc.Add(t22, 2); Assert.IsTrue(sc[0].Name == t1.Name); Assert.IsTrue(sc[1].Name == t2.Name); Assert.IsTrue(sc[2].Name == t3.Name); Assert.IsTrue(sc[3].Name == t31.Name); Assert.IsTrue(sc[4].Name == t22.Name); }
public void Test_Add() { var listener = new EventListener(); var coll = new SortedObservableCollection <int>(); coll.PropertyChanged += listener.Consume; coll.CollectionChanged += listener.Consume; listener.Expect <PropertyChangedEventArgs>(x => x.PropertyName == "Count"); listener.Expect <NotifyCollectionChangedEventArgs>(x => ValidateCollectionEvent(x, NotifyCollectionChangedAction.Add, newIndex: 0, newItem: 3)); coll.Add(3); listener.MakeAssert(); listener.Expect <PropertyChangedEventArgs>(x => x.PropertyName == "Count"); listener.Expect <NotifyCollectionChangedEventArgs>(x => ValidateCollectionEvent(x, NotifyCollectionChangedAction.Add, newIndex: 0, newItem: 1)); coll.Add(1); listener.MakeAssert(); listener.Expect <PropertyChangedEventArgs>(x => x.PropertyName == "Count"); listener.Expect <NotifyCollectionChangedEventArgs>(x => ValidateCollectionEvent(x, NotifyCollectionChangedAction.Add, newIndex: 2, newItem: 5)); coll.Add(5); listener.MakeAssert(); CollectionAssert.AreEqual(new int[] { 1, 3, 5 }, coll); }
public void AddTests() { var collection = new SortedObservableCollection <string>(); collection.Add("item 1"); Assert.AreEqual <int>(1, collection.Count); Assert.AreEqual <int>(0, collection.IndexOf("item 1")); collection.Add("item 0"); Assert.AreEqual <int>(2, collection.Count); Assert.AreEqual <int>(0, collection.IndexOf("item 0")); Assert.AreEqual <int>(1, collection.IndexOf("item 1")); collection.Add("item 9"); Assert.AreEqual <int>(3, collection.Count); Assert.AreEqual <int>(0, collection.IndexOf("item 0")); Assert.AreEqual <int>(1, collection.IndexOf("item 1")); Assert.AreEqual <int>(2, collection.IndexOf("item 9")); collection.Add("item 5"); Assert.AreEqual <int>(4, collection.Count); Assert.AreEqual <int>(0, collection.IndexOf("item 0")); Assert.AreEqual <int>(1, collection.IndexOf("item 1")); Assert.AreEqual <int>(2, collection.IndexOf("item 5")); Assert.AreEqual <int>(3, collection.IndexOf("item 9")); }
private async void Load(bool epoch) { using (await _loadMoreLock.WaitAsync()) { var response = await ProtoService.SendAsync(new GetContacts()); if (response is Telegram.Td.Api.Users users) { var items = new List <User>(); foreach (var id in users.UserIds) { var user = ProtoService.GetUser(id); if (user != null) { items.Add(user); } } Items = new SortedObservableCollection <User>(new UserComparer(epoch)); Items.ReplaceWith(items); RaisePropertyChanged(() => Items); } } }
public ContactsViewModel(IProtoService protoService, ICacheService cacheService, IEventAggregator aggregator, IContactsService contactsService) : base(protoService, cacheService, aggregator) { _contactsService = contactsService; Items = new SortedObservableCollection <User>(new UserComparer(true)); }
public ValidationConfigVisitor(CancellationToken cancellationToken, ILogger logger = null) { this._cancellationToken = cancellationToken; this._logger = logger; this.Result = new SortedObservableCollection <ValidationMessage>(); this.Result.SortDirection = SortDirection.Descending; }
public pageGameSetup() { fTskHolders = new SortedObservableCollection <TTskHolder>(new THolderComparer()); InitializeComponent(); setSource.DataContext = this; this.Loaded += new RoutedEventHandler(pageGameSetup_Loaded); }
public void SetterTest() { SortedObservableCollection <string> mySortedCollection = new SortedObservableCollection <string>() { "ddeddd", "bbbb", "aaaaa", "eeeee", "ccacaccc", "ffafasfdsd", }; Assert.AreEqual(6, mySortedCollection.Count); Assert.AreEqual("aaaaa", mySortedCollection[0]); Assert.AreEqual("bbbb", mySortedCollection[1]); Assert.AreEqual("ccacaccc", mySortedCollection[2]); Assert.AreEqual("ddeddd", mySortedCollection[3]); Assert.AreEqual("eeeee", mySortedCollection[4]); Assert.AreEqual("ffafasfdsd", mySortedCollection[5]); mySortedCollection[0] = "zzzz"; mySortedCollection[0] = "babababa"; mySortedCollection[4] = "caaaa"; Assert.AreEqual(6, mySortedCollection.Count); Assert.AreEqual("babababa", mySortedCollection[0]); Assert.AreEqual("caaaa", mySortedCollection[1]); Assert.AreEqual("ccacaccc", mySortedCollection[2]); Assert.AreEqual("ddeddd", mySortedCollection[3]); Assert.AreEqual("eeeee", mySortedCollection[4]); Assert.AreEqual("zzzz", mySortedCollection[5]); }
public SortedViewModel() { Items = new SortedObservableCollection <string>(); SelectedItems = new ObservableCollection <string>(); SelectedItems.CollectionChanged += (s, e) => { if (SelectedItems.Count == 0) { IsSelectionEnabled = false; } if (RemoveSelectionCommand != null) { RemoveSelectionCommand.RaiseCanExecuteChanged(); } }; AddCommand = new RelayCommand(() => { Items.Add(NewItem); NewItem = string.Empty; }, () => !string.IsNullOrWhiteSpace(NewItem)); ToggleSelectionCommand = new RelayCommand(() => IsSelectionEnabled = !IsSelectionEnabled); RemoveSelectionCommand = new RelayCommand(() => { foreach (var item in SelectedItems) { Items.Remove(item); } SelectedItems.Clear(); }, () => SelectedItems.Count > 0); }
public UsersSelectionViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator) : base(protoService, cacheService, aggregator) { Items = new SortedObservableCollection <TLUser>(new TLUserComparer(false)); SelectedItems = new ObservableCollection <TLUser>(); SelectedItems.CollectionChanged += OnCollectionChanged; }
public void Test_Create() { var coll = new SortedObservableCollection <int>(); Assert.AreEqual(0, coll.Count); Assert.IsFalse(coll.IsReadOnly); }
public void Test_Remove() { var listener = new EventListener(); var coll = new SortedObservableCollection <int>() { 1, 2, 3, 4, 5 }; coll.PropertyChanged += listener.Consume; coll.CollectionChanged += listener.Consume; listener.Expect <PropertyChangedEventArgs>(x => x.PropertyName == "Count"); listener.Expect <NotifyCollectionChangedEventArgs>(x => ValidateCollectionEvent(x, NotifyCollectionChangedAction.Remove, oldIndex: 1, oldItem: 2)); Assert.IsTrue(coll.Remove(2)); listener.MakeAssert(); Assert.AreEqual(4, coll.Count); CollectionAssert.AreEqual(new int[] { 1, 3, 4, 5 }, coll); Assert.IsFalse(coll.Remove(8)); listener.Expect <PropertyChangedEventArgs>(x => x.PropertyName == "Count"); listener.Expect <NotifyCollectionChangedEventArgs>(x => ValidateCollectionEvent(x, NotifyCollectionChangedAction.Remove, oldIndex: 2, oldItem: 4)); coll.RemoveAt(2); listener.MakeAssert(); Assert.AreEqual(3, coll.Count); CollectionAssert.AreEqual(new int[] { 1, 3, 5 }, coll); }
private void SearchEntries(string search, SortedObservableCollection <EntryModel> myList) { int cachedCount; do { cachedCount = _entryLookup.Count; if (myList.Count != 0) { _dispatchService.CheckBeginInvokeOnUi(myList.Clear); } foreach (var entryLookupKey in _entryLookup.Keys) { if ( //if entry contains search parameter entryLookupKey.Contains(search) || //if search parameter contains entry search.Contains(entryLookupKey) ) { _dispatchService.CheckBeginInvokeOnUi( () => myList.Add(_entryLookup[entryLookupKey]) ); } //can make search arbitrary complex! try with weighting etc } } while (cachedCount != _entryLookup.Count); }
public SettingsWebSessionsViewModel(IProtoService protoService, ICacheService cacheService, ISettingsService settingsService, IEventAggregator aggregator) : base(protoService, cacheService, settingsService, aggregator) { Items = new SortedObservableCollection <ConnectedWebsite>(new TLAuthorizationComparer()); TerminateCommand = new RelayCommand <ConnectedWebsite>(TerminateExecute); TerminateOthersCommand = new RelayCommand(TerminateOtherExecute); }
public SettingsSessionsViewModel(IProtoService protoService, ICacheService cacheService, IEventAggregator aggregator) : base(protoService, cacheService, aggregator) { Items = new SortedObservableCollection <Session>(new SessionComparer()); TerminateCommand = new RelayCommand <Session>(TerminateExecute); TerminateOthersCommand = new RelayCommand(TerminateOtherExecute); }
public Updates() { matches = new SortedObservableCollection <Match>(); blocks = new List <string>(); lists = new List <string>(); deleted_lists = new List <string>(); last_activity_date = ""; }
public ContactsViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator, IContactsService contactsService) : base(protoService, cacheService, aggregator) { _contactsService = contactsService; Items = new SortedObservableCollection <TLUser>(new TLUserComparer(true)); Search = new ObservableCollection <KeyedList <string, TLObject> >(); }
public FileSystemTracker( SortedObservableCollection <FileData> root, ConcurrentDictionary <string, FileData> files) { this._root = root; this._files = files; this._dispatcher = Dispatcher.CurrentDispatcher; this._root.CollectionChanged += this.FileData_CollectionChanged; }
public SettingsSessionsViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator) : base(protoService, cacheService, aggregator) { _cachedItems = new Dictionary <long, TLAuthorization>(); Items = new SortedObservableCollection <TLAuthorization>(new TLAuthorizationComparer()); TerminateCommand = new RelayCommand <TLAuthorization>(TerminateExecute); TerminateOthersCommand = new RelayCommand(TerminateOtherExecute); }
public FileSystemTracker( SortedObservableCollection<FileData> root, ConcurrentDictionary<string, FileData> files) { this._root = root; this._files = files; this._dispatcher = Dispatcher.CurrentDispatcher; this._root.CollectionChanged += this.FileData_CollectionChanged; }
public ObservableCollection <EntryModel> SearchEntry(string searchTerm) { var list = new SortedObservableCollection <EntryModel>(new BaseModelComparator <EntryModel>()); if (searchTerm.Length >= 2) { Task.Run(() => SearchEntries(searchTerm, list)).ConfigureAwait(false); } return(list); }
public UsersSelectionViewModel(IMTProtoService protoService, ICacheService cacheService, ITelegramEventAggregator aggregator) : base(protoService, cacheService, aggregator) { Items = new SortedObservableCollection <TLUser>(new TLUserComparer(false)); Search = new ObservableCollection <KeyedList <string, TLObject> >(); SelectedItems = new ObservableCollection <TLUser>(); SelectedItems.CollectionChanged += OnCollectionChanged; SendCommand = new RelayCommand(SendExecute, () => Minimum <= SelectedItems.Count && Maximum >= SelectedItems.Count); }
public void Test_CreateFull() { var source = Enumerable.Range(0, 6); var coll = new SortedObservableCollection <int>(source, Comparer <int> .Create((x, y) => y - x)); Assert.AreEqual(6, coll.Count); Assert.IsFalse(coll.IsReadOnly); CollectionAssert.AreEqual(source.Reverse(), coll); }
public void Test_CreateFromSource() { var source = Enumerable.Range(0, 6); var coll = new SortedObservableCollection <int>(source); Assert.AreEqual(6, coll.Count); Assert.IsFalse(coll.IsReadOnly); CollectionAssert.AreEqual(source, coll); }
public UsersSelectionViewModel(IProtoService protoService, ICacheService cacheService, IEventAggregator aggregator) : base(protoService, cacheService, aggregator) { Items = new SortedObservableCollection <User>(new UserComparer(false)); SelectedItems = new MvxObservableCollection <User>(); SelectedItems.CollectionChanged += OnCollectionChanged; SendCommand = new RelayCommand(SendExecute, () => Minimum <= SelectedItems.Count && Maximum >= SelectedItems.Count); SingleCommand = new RelayCommand <User>(SendExecute); }
public ContactSyncViewModel() { Account account = AccountManager.GetAccount(); if (account == null) return; _store = SmartStore.GetSmartStore(account); _syncManager = SyncManager.GetInstance(account); Contacts = new SortedObservableCollection<ContactObject>(); FilteredContacts = new SortedObservableCollection<ContactObject>(); IndexReference = new ObservableCollection<string>(); }
public void TestComplexAdd() { var list = new SortedObservableCollection <string>(Comparer <string> .Default) { "b", "c", "a" }; Assert.IsTrue(list[0] == "a"); Assert.IsTrue(list[1] == "b"); Assert.IsTrue(list[2] == "c"); }
public void Test_Contains() { var coll = new SortedObservableCollection <int> { 3, 1, 2, 5, 4 }; Assert.IsTrue(coll.Contains(1)); Assert.IsTrue(coll.Contains(2)); Assert.IsTrue(coll.Contains(5)); Assert.IsFalse(coll.Contains(15)); }
public void Ctor_FillWithValuesFromAnotherCollection() { //Arrange AddIdRange(new Range(2, 5)); //Act var collection = new SortedObservableCollection <DomainEntityViewModel <TestModel> >(comparer, ClassUnderTest); //Assert collection.Count.Should().Be(ClassUnderTest.Count); }
public ContactsViewModel(IProtoService protoService, ICacheService cacheService, ISettingsService settingsService, IEventAggregator aggregator, IContactsService contactsService) : base(protoService, cacheService, settingsService, aggregator) { _contactsService = contactsService; _loadMoreLock = new DisposableMutex(); Items = new SortedObservableCollection <User>(new UserComparer(Settings.IsContactsSortedByEpoch)); Initialize(); }
public static object CreateNewObject(SortedObservableCollection <PluginGeneratorNodeSettings> lst) { Contract.Requires(lst != null); var myType = CompileResultType(lst); var myObject = Activator.CreateInstance(myType); foreach (var field in lst) { myType.InvokeMember(field.Name, BindingFlags.SetProperty, null, myObject, new object[] { field }); } return(myObject); }
public void TestSortedObservableCollection() { var collection = new SortedObservableCollection<int> { 5, 13, 2, 9, 0, 8, 5, 11, 1, 7, 14, 12, 4, 10, 3, 6 }; collection.Remove(5); for (int i = 0; i < collection.Count; ++i) { Assert.That(collection[i] == i); Assert.That(collection.BinarySearch(i) == i); } Assert.Throws<InvalidOperationException>(() => collection[4] = 10); Assert.Throws<InvalidOperationException>(() => collection.Move(4, 5)); }
public void TestAdd() { var collection = new SortedObservableCollection<int>(Comparer<int>.Default); collection.ShouldEqual(new int[0]); collection.Add(5); collection.ShouldEqual(new[] { 5 }); collection.Add(4); collection.ShouldEqual(new[] { 4, 5 }); collection.Add(3); collection.ShouldEqual(new[] { 3, 4, 5 }); collection.Add(10); collection.ShouldEqual(new[] { 3, 4, 5, 10 }); var exception = BddTestHelper.Catch(() => { collection.Add(10); }); exception.ShouldNotBeNull(); exception.ShouldBeOfType<ArgumentException>(); collection.ShouldEqual(new[] { 3, 4, 5, 10 }); }
/// <summary> /// Instantiates a new Model /// </summary> public SystemComponentData() { JobQueue = new SortedObservableCollection<Job>(i => i.ArrivalTime); }
/// <summary> /// Sets the lambda for the ObservableCollection to sort based on Job.ArrivalTime. /// </summary> public ExitNodeData() { JobQueue = new SortedObservableCollection<Job>(i => i.ArrivalTime); }
public void Cleanup() { if (this.AreChildrenLoaded) { this.Children.ForEach(x => x.Cleanup()); } var settings = Factory.Resolve<Settings>(); if (settings.OpenFolders.Contains(this._fullPath)) { settings.OpenFolders.Remove(this._fullPath); } FileData outs; Factory.Resolve<FolderService>().Files.TryRemove(this._fullPath, out outs); this._children = null; }
public CommandBar() { Items = new SortedObservableCollection<ICommandItem>(); }
public Updates() { matches = new SortedObservableCollection<Match>(); blocks = new List<string>(); lists = new List<string>(); deleted_lists = new List<string>(); last_activity_date = ""; }
/// <summary> /// This removes an item from the view model and local storage without actually calling the API. /// </summary> public void RemoveItem(BookmarkViewModel bookmarkViewModel, SortedObservableCollection<BookmarkViewModel> bookmarksCollection) { var bookmarkToDelete = bookmarksCollection.Where(b => b.BookmarkId == bookmarkViewModel.BookmarkId).FirstOrDefault(); if (bookmarkToDelete != null) bookmarksCollection.Remove(bookmarkToDelete); var bookmarkDbItem = App.DbDataContext.Bookmarks.Where(b => b.BookmarkId == bookmarkViewModel.BookmarkId).FirstOrDefault(); if (bookmarkDbItem != null) { App.DbDataContext.Bookmarks.DeleteOnSubmit(bookmarkDbItem); App.DbDataContext.SubmitChanges(); } }
public Buffer() { Messages = new SortedObservableCollection<Message>(); SeenMessages = new Dictionary<long, Message>(); }
/// <summary> /// The serialization for these threads is the minimum required information needed to show them /// in the history and watchlists. That is, the board they are from, and the first post, this information /// is described by a ThreadID. We represent these as single post threads in the cache, opening the thread /// will load the remaining posts again from the net. /// </summary> private void Rebuild() { if (_isRebuilt) { return; } _isRebuilt = true; Restore().Wait(); List<string> boards = GetSetting<List<string>>("Boards", BoardList.Boards.Values.Where(x => !x.IsNSFW).Select(x => x.Name).ToList()); _boards = new SortedObservableCollection<Board>(boards.Where(x => BoardList.Boards.ContainsKey(x)) .Select(x => ThreadCache.Current.EnforceBoard(x))); List<string> favorites = GetSetting<List<string>>("Favorites", new List<string>() { "a", "fa", "fit" }); _favorites = new ObservableCollection<Board>(favorites.Where(x => BoardList.Boards.ContainsKey(x)) .Select(x => ThreadCache.Current.EnforceBoard(x))); _boards.CollectionChanged += (sender, e) => { SetSetting<List<string>>("Boards", _boards.Select(x => x.Name).ToList()); }; _favorites.CollectionChanged += (sender, e) => { SetSetting<List<string>>("Favorites", _favorites.Select(x => x.Name).ToList()); }; }
public MainViewModel() { Locations = new SortedObservableCollection<LocationData>(); CreateData(); }
public Server() { Buffers = new Dictionary<int, Buffer>(); Channels = new Dictionary<String, Channel>(); SortedBuffers = new SortedObservableCollection<Buffer>(); }