public void Collection() { Observable.Add(Fixture.Create <string>(), Fixture.Create <TestItem>()); Observable.Add(Fixture.Create <string>(), Fixture.Create <TestItem>()); Observable.Add(Fixture.Create <string>(), Fixture.Create <TestItem>()); _testCases.CollectionTest(Observable); }
public ObservableSortedList <PollResponseGroup <UserModel> > GetGroupedPollResponses() { ObservableSortedList <PollResponseGroup <UserModel> > groupedResponses = new ObservableSortedList <PollResponseGroup <UserModel> >(); Dictionary <string, PollResponseGroup <UserModel> > responseToGroup = new Dictionary <string, PollResponseGroup <UserModel> >(); this.LoadPollResponses(); if (this.PollOptions != null) { foreach (string option in this.PollOptions) { PollResponseGroup <UserModel> group = new PollResponseGroup <UserModel>(option); responseToGroup.Add(option, group); groupedResponses.Add(group); } } if (this.IsCalendarMessage) { PollResponseGroup <UserModel> acceptGroup = new PollResponseGroup <UserModel>(Strings.CalendarAcceptMessage); responseToGroup.Add(Strings.CalendarAcceptMessage, acceptGroup); groupedResponses.Add(acceptGroup); PollResponseGroup <UserModel> declineGroup = new PollResponseGroup <UserModel>(Strings.CalendarDeclineMessage); responseToGroup.Add(Strings.CalendarDeclineMessage, declineGroup); groupedResponses.Add(declineGroup); } foreach (KeyValuePair <string, int> response in this.Responses) { PollResponseGroup <UserModel> group = null; string key = response.Key; if (this.IsCalendarMessage) { if (string.Compare(response.Key, MessageModel.CalendarAcceptStringNonLocalized, StringComparison.OrdinalIgnoreCase) == 0) { key = Strings.CalendarAcceptMessage; } if (string.Compare(response.Key, MessageModel.CalendarDeclineStringNonLocalized, StringComparison.OrdinalIgnoreCase) == 0) { key = Strings.CalendarDeclineMessage; } } if (!responseToGroup.TryGetValue(key, out group)) { group = new PollResponseGroup <UserModel>(response.Key); groupedResponses.Add(group); responseToGroup.Add(response.Key, group); } group.Add(DataSync.Instance.GetUser(response.Value)); } return(groupedResponses); }
public void SetGrid(Interop.Grid grid) { GridItemViewModel vm = CreateGridViewModel(grid); _Grid.Clear(); _Grid.Add(vm); }
public void AddCollide() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyRecords = new ObservableSortedList <CollideStruct, int>(); var MyDictionary = new Dictionary <CollideStruct, int>(64); //**************************************** for (var Index = 0; Index < 64; Index++) { CollideStruct Key; int Value; do { Key = new CollideStruct(MyRandom.Next()); } while (MyDictionary.ContainsKey(Key)); Value = MyRandom.Next(); MyDictionary.Add(Key, Value); MyRecords.Add(Key, Value); } //**************************************** Assert.AreEqual(64, MyRecords.Count, "Count incorrect. Bad Seed was {0}", MySeed); CollectionAssert.AreEquivalent(MyDictionary, MyRecords, "Collections don't match. Bad Seed was {0}", MySeed); Thread.Sleep(1); }
public void Replace() { //**************************************** var MyRecords = new ObservableSortedList <int, int>(); //**************************************** MyRecords.Add(9, 1); MyRecords.Add(12, 2); MyRecords.Add(10, 3); MyRecords.Add(11, 4); MyRecords[10] = 84; //**************************************** Assert.AreEqual(84, MyRecords[10]); }
public void AddCapacity() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyRecords = new ObservableSortedList <int, int>(1024); var MyDictionary = new Dictionary <int, int>(1024); var MySortedList = new SortedList <int, int>(1024); //**************************************** while (MyDictionary.Count < 1024) { MyDictionary[MyRandom.Next()] = MyRandom.Next(); } foreach (var MyPair in MyDictionary) { MySortedList.Add(MyPair.Key, MyPair.Value); MyRecords.Add(MyPair.Key, MyPair.Value); } //**************************************** Assert.AreEqual(1024, MyRecords.Count, "Count incorrect. Bad Seed was {0}", MySeed); CollectionAssert.AreEqual(MySortedList, MyRecords, "Collections don't match. Bad Seed was {0}", MySeed); Thread.Sleep(1); }
public MemorizationViewController() : base("Memorization") { verses = VersesTableViewController.Current.Verses; verses.CollectionChanged += delegate(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (tableView != null) { var newItems = e.NewItems; var oldItems = e.OldItems; if (newItems != null) { foreach (Verse verse in newItems) { if (verse.Category == categoryToFilter) { filteredVerses.Add(verse); Console.WriteLine(verse.Title); } } } if (oldItems != null) { foreach (Verse verse in oldItems) { if (filteredVerses.Any(item => item.Id == verse.Id)) { filteredVerses.Remove(verse); Console.WriteLine(verse.Title); } } } } }; }
public void EventReplace() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyRecords = new ObservableSortedList <int, int>(1); NotifyCollectionChangedEventArgs MyEventArgs = null, MyKeyEventArgs = null, MyValueEventArgs = null; //**************************************** MyRecords.Add(42, 10); MyRecords.CollectionChanged += (sender, e) => MyEventArgs = e; MyRecords.Keys.CollectionChanged += (sender, e) => MyKeyEventArgs = e; MyRecords.Values.CollectionChanged += (sender, e) => MyValueEventArgs = e; MyRecords[42] = 84; //**************************************** Assert.AreEqual(1, MyRecords.Count, "Item count does not match"); Assert.IsNotNull(MyEventArgs, "No Event Raised"); Assert.AreEqual(NotifyCollectionChangedAction.Replace, MyEventArgs.Action); Assert.IsNotNull(MyEventArgs.OldItems, "No Old Items"); Assert.AreEqual(0, MyEventArgs.OldStartingIndex, "Starting Index incorrect"); Assert.AreEqual(1, MyEventArgs.OldItems.Count, "Old Items Count incorrect"); Assert.AreEqual(new KeyValuePair <int, int>(42, 10), MyEventArgs.OldItems[0], "Old Items Value incorrect"); Assert.IsNotNull(MyEventArgs.NewItems, "No New Items"); Assert.AreEqual(0, MyEventArgs.NewStartingIndex, "Starting Index incorrect"); Assert.AreEqual(1, MyEventArgs.NewItems.Count, "New Items Count incorrect"); Assert.AreEqual(new KeyValuePair <int, int>(42, 84), MyEventArgs.NewItems[0], "New Items Value incorrect"); }
public void EventAddMany() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyRecords = new ObservableSortedList <int, int>(1024); var EventCount = 0; //**************************************** MyRecords.CollectionChanged += (sender, e) => { if (e.Action == NotifyCollectionChangedAction.Add) { EventCount++; } }; for (var Index = 0; Index < 1024; Index++) { MyRecords.Add(MyRandom.Next(), MyRandom.Next()); } //**************************************** Assert.AreEqual(1024, MyRecords.Count, "Item count does not match"); Assert.AreEqual(1024, EventCount, "Event Count does not match"); }
public void ReplaceCollide() { //**************************************** var MyRecords = new ObservableSortedList <CollideStruct, int>(); var MyKey = new CollideStruct(10); //**************************************** MyRecords.Add(new CollideStruct(9), 1); MyRecords.Add(new CollideStruct(12), 2); MyRecords.Add(new CollideStruct(10), 3); MyRecords.Add(new CollideStruct(11), 4); MyRecords[MyKey] = 84; //**************************************** Assert.AreEqual(84, MyRecords[MyKey]); }
public void AddExists() { //**************************************** var MyRecords = new ObservableSortedList <int, int>(); //**************************************** MyRecords.Add(10, 84); //**************************************** try { MyRecords.Add(10, 84); Assert.Fail("Add succeeded"); } catch (ArgumentException) { } }
public void Search() { var contacts = new Contacts(); contacts.SearchCompleted += (s, args) => { ObservableSortedList <ContactGroup <ContactItem> > tempItems = new ObservableSortedList <ContactGroup <ContactItem> >(); var groups = new Dictionary <char, ContactGroup <ContactItem> >(); foreach (var contact in args.Results) { if (!contact.PhoneNumbers.Any(number => number.Kind == PhoneNumberKind.Mobile)) { continue; } if (IsContactRegisteredUser(contact)) { continue; } char firstLetter = char.ToLower(contact.DisplayName[0]); // show # for numbers if (firstLetter >= '0' && firstLetter <= '9') { firstLetter = '#'; } // create group for letter if it doesn't exist if (!groups.ContainsKey(firstLetter)) { var group = new ContactGroup <ContactItem>(firstLetter); tempItems.Add(group); groups[firstLetter] = group; } // create a contact for item and add it to the relevant group var contactItem = new ContactItem(contact); groups[firstLetter].Add(contactItem); } this.items = tempItems; Deployment.Current.Dispatcher.BeginInvoke(() => { this.NotifyPropertyChanged("Items"); }); IsInitialized = true; NotifyPropertyChanged("IsContactsEmpty"); NotifyPropertyChanged("IsContactsNotEmpty"); NotifyPropertyChanged("IsLoading"); }; // get all contacts contacts.SearchAsync(null, FilterKind.None, null); }
private void StartTree() { ClassItemViewModel root = new ClassItemViewModel(new Models.ClassItem() { Name = "Classes", Type = Models.ClassItemType.Root }); _First.Add(root); _First[0].IsExpanded = true; }
public void SetRootItem(ProjectItem root) { if (root == null) { _RootItem = null; _First.Clear(); return; } SetProject(root, this); _RootItem = new ProjectItemViewModel(root); _First.Clear(); _First.Add(_RootItem); }
public void AddRangePrePopulated() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyRecords = new ObservableSortedList <int, int>(1024); var MyDictionary = new Dictionary <int, int>(1024); var MySortedList = new SortedList <int, int>(1024); var MySecondSet = new List <KeyValuePair <int, int> >(512); //**************************************** while (MyDictionary.Count < 512) { MyDictionary[MyRandom.Next()] = MyRandom.Next(); } foreach (var MyPair in MyDictionary) { MySortedList.Add(MyPair.Key, MyPair.Value); MyRecords.Add(MyPair.Key, MyPair.Value); } while (MyDictionary.Count < 1024) { MyDictionary[MyRandom.Next()] = MyRandom.Next(); } MySecondSet.AddRange(MyDictionary.Except(MySortedList)); foreach (var MyPair in MySecondSet) { MySortedList.Add(MyPair.Key, MyPair.Value); } MyRecords.AddRange(MySecondSet); //**************************************** Assert.AreEqual(1024, MyRecords.Count, "Count incorrect. Bad Seed was {0}", MySeed); CollectionAssert.AreEqual(MySortedList, MyRecords, "Collections don't match. Bad Seed was {0}", MySeed); Thread.Sleep(1); }
public void EventAdd() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyRecords = new ObservableSortedList <int, int>(1); NotifyCollectionChangedEventArgs MyEventArgs = null, MyKeyEventArgs = null, MyValueEventArgs = null; //**************************************** MyRecords.CollectionChanged += (sender, e) => MyEventArgs = e; MyRecords.Keys.CollectionChanged += (sender, e) => MyKeyEventArgs = e; MyRecords.Values.CollectionChanged += (sender, e) => MyValueEventArgs = e; var Pair = new KeyValuePair <int, int>(MyRandom.Next(), MyRandom.Next()); MyRecords.Add(Pair); //**************************************** Assert.AreEqual(1, MyRecords.Count, "Item count does not match"); Assert.IsNotNull(MyEventArgs, "No Event Raised"); Assert.AreEqual(NotifyCollectionChangedAction.Add, MyEventArgs.Action); Assert.IsNotNull(MyEventArgs.NewItems, "No New Items"); Assert.AreEqual(0, MyEventArgs.NewStartingIndex, "Starting Index incorrect"); Assert.AreEqual(1, MyEventArgs.NewItems.Count, "New Items Count incorrect"); Assert.AreEqual(Pair, MyEventArgs.NewItems[0], "New Items Value incorrect"); Assert.IsNotNull(MyKeyEventArgs, "No Key Event Raised"); Assert.AreEqual(NotifyCollectionChangedAction.Add, MyKeyEventArgs.Action); Assert.IsNotNull(MyKeyEventArgs.NewItems, "No Key New Items"); Assert.AreEqual(0, MyKeyEventArgs.NewStartingIndex, "Key Starting Index incorrect"); Assert.AreEqual(1, MyKeyEventArgs.NewItems.Count, "New Key Items Count incorrect"); Assert.AreEqual(Pair.Key, MyKeyEventArgs.NewItems[0], "New Key Items Value incorrect"); Assert.IsNotNull(MyValueEventArgs, "No Value Event Raised"); Assert.AreEqual(NotifyCollectionChangedAction.Add, MyEventArgs.Action); Assert.IsNotNull(MyValueEventArgs.NewItems, "No Value New Items"); Assert.AreEqual(0, MyValueEventArgs.NewStartingIndex, "Value Starting Index incorrect"); Assert.AreEqual(1, MyValueEventArgs.NewItems.Count, "New Value Items Count incorrect"); Assert.AreEqual(Pair.Value, MyValueEventArgs.NewItems[0], "New Value Items Value incorrect"); }
public void EventAddUpdate() { //**************************************** var MySeed = Environment.TickCount; var MyRandom = new Random(MySeed); var MyRecords = new ObservableSortedList <int, int>(1); NotifyCollectionChangedEventArgs MyEventArgs = null, MyKeyEventArgs = null, MyValueEventArgs = null; //**************************************** MyRecords.CollectionChanged += (sender, e) => MyEventArgs = e; MyRecords.Keys.CollectionChanged += (sender, e) => MyKeyEventArgs = e; MyRecords.Values.CollectionChanged += (sender, e) => MyValueEventArgs = e; var Pair = new KeyValuePair <int, int>(MyRandom.Next(), MyRandom.Next()); MyRecords.BeginUpdate(); MyRecords.Add(Pair); //**************************************** Assert.IsNull(MyEventArgs, "Event Raised"); Assert.IsNull(MyKeyEventArgs, "Event Raised"); Assert.IsNull(MyValueEventArgs, "Event Raised"); //**************************************** MyRecords.EndUpdate(); Assert.AreEqual(1, MyRecords.Count, "Item count does not match"); Assert.IsNotNull(MyEventArgs, "No Event Raised"); Assert.AreEqual(NotifyCollectionChangedAction.Reset, MyEventArgs.Action); Assert.IsNotNull(MyKeyEventArgs, "No Key Event Raised"); Assert.AreEqual(NotifyCollectionChangedAction.Reset, MyKeyEventArgs.Action); Assert.IsNotNull(MyValueEventArgs, "No Value Event Raised"); Assert.AreEqual(NotifyCollectionChangedAction.Reset, MyEventArgs.Action); }
public static ObservableSortedList<ContactGroup<UserModel>> GroupUsers(IList<UserModel> users) { ObservableSortedList<ContactGroup<UserModel>> groups = new ObservableSortedList<ContactGroup<UserModel>>(); var groupsDict = new Dictionary<char, ContactGroup<UserModel>>(); foreach (UserModel user in users) { if (user.UserType == UserType.Group) { if (!user.Name.Contains("(G)")) { user.Name += " (G)"; } } char firstLetter = char.ToLower(user.Name[0]); // show # for numbers if (firstLetter >= '0' && firstLetter <= '9') { firstLetter = '#'; } // create group for letter if it doesn't exist if (!groupsDict.ContainsKey(firstLetter)) { var group = new ContactGroup<UserModel>(firstLetter); groups.Add(group); groupsDict[firstLetter] = group; } // create a contact for item and add it to the relevant groupsDict[firstLetter].Add(user); } return groups; }
public void Search() { var contacts = new Contacts(); contacts.SearchCompleted += (s, args) => { ObservableSortedList<ContactGroup<ContactItem>> tempItems = new ObservableSortedList<ContactGroup<ContactItem>>(); var groups = new Dictionary<char, ContactGroup<ContactItem>>(); foreach (var contact in args.Results) { if (!contact.PhoneNumbers.Any(number => number.Kind == PhoneNumberKind.Mobile)) { continue; } if (IsContactRegisteredUser(contact)) { continue; } char firstLetter = char.ToLower(contact.DisplayName[0]); // show # for numbers if (firstLetter >= '0' && firstLetter <= '9') { firstLetter = '#'; } // create group for letter if it doesn't exist if (!groups.ContainsKey(firstLetter)) { var group = new ContactGroup<ContactItem>(firstLetter); tempItems.Add(group); groups[firstLetter] = group; } // create a contact for item and add it to the relevant group var contactItem = new ContactItem(contact); groups[firstLetter].Add(contactItem); } this.items = tempItems; Deployment.Current.Dispatcher.BeginInvoke(() => { this.NotifyPropertyChanged("Items"); }); IsInitialized = true; NotifyPropertyChanged("IsContactsEmpty"); NotifyPropertyChanged("IsContactsNotEmpty"); NotifyPropertyChanged("IsLoading"); }; // get all contacts contacts.SearchAsync(null, FilterKind.None, null); }
public void AddVerse(Verse verse) { Verses.Add(verse); AppDelegate.Current.Database.AddVerse(verse); }
/// <summary> /// Creates a list of incidents types to be displayed to the user. /// </summary> /// <param name="searchText"> /// An optional search parameter. /// If left blank, all incident types are returned. /// If specified, both the incident type name and any associtated keywords are matched.</param> /// <returns>A list of incident types.</returns> internal void BuildIncidentTypesList(string searchText = "") { //first search through the filtered list and remove any incident types that don't have a matching name or keyword List <IncidentType> toDelete = new List <IncidentType>(); foreach (IncidentType type in IncidentTypes) { bool matching = false; if (type.Name.ToUpper().Contains(searchText.ToUpper())) { matching = true; } foreach (string keyword in type.Keywords) { if (keyword.ToUpper().Contains(searchText.ToUpper())) { matching = true; } } if (!matching) { toDelete.Add(type); } } foreach (IncidentType type in toDelete) { filteredIncidentTypes.Remove(type); } //then search through the full list and add any incident types that DO have a matching name or keyword List <IncidentType> toAdd = new List <IncidentType>(); foreach (IncidentType type in fullList) { bool matching = false; if (type.Name.ToUpper().Contains(searchText.ToUpper())) { matching = true; } foreach (string keyword in type.Keywords) { if (keyword.ToUpper().Contains(searchText.ToUpper())) { matching = true; } } if (matching) { toAdd.Add(type); } } foreach (IncidentType type in toAdd) { if (!filteredIncidentTypes.Contains(type)) { filteredIncidentTypes.Add(type); } } }
public void AddItem(PoeItem item) { ItemsList.Add(item); OnPropertyChanged("ItemCountDisplay"); }