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")); }
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 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); }
void pageGameSetup_Loaded(object sender, RoutedEventArgs e) { if (System.ComponentModel.DesignerProperties.IsInDesignTool) { return; //HACK BUG VS Designer } fTskHolders.Clear(); foreach (TTskSet tsk in game.cfg.tskSets) { fTskHolders.Add(new TTskHolder(tsk)); } fTskHolders.Add(new TTskHolder()); }
public void MoveTest() { var collection = new SortedObservableCollection <TestModel>(); var item1 = new TestModel { Value = 1 }; var item2 = new TestModel { Value = 42 }; var item3 = new TestModel { Value = 10 }; var item4 = new TestModel { Value = 50 }; collection.ItemHasChanged = property => property == "Value"; collection.Add(item1); collection.Add(item2); collection.Add(item3); collection.Add(item4); item2.Value = 2; item3.Value = 3; item4.Value = 4; Assert.AreEqual <int>(0, collection.IndexOf(item1)); Assert.AreEqual <int>(1, collection.IndexOf(item2)); Assert.AreEqual <int>(2, collection.IndexOf(item3)); Assert.AreEqual <int>(3, collection.IndexOf(item4)); item2.Value = 2; item3.Value = 3; item4.Value = 0; Assert.AreEqual <int>(1, collection.IndexOf(item1)); Assert.AreEqual <int>(2, collection.IndexOf(item2)); Assert.AreEqual <int>(3, collection.IndexOf(item3)); Assert.AreEqual <int>(0, collection.IndexOf(item4)); item3.Value = 2; Assert.AreEqual <int>(1, collection.IndexOf(item1)); Assert.AreEqual <int>(2, collection.IndexOf(item2)); Assert.AreEqual <int>(3, collection.IndexOf(item3)); Assert.AreEqual <int>(0, collection.IndexOf(item4)); }
public SolutionFolder GetOrCreateSubfolder(string folderName) { var folder = _items.OfType <SolutionFolder>().SingleOrDefault(p => p.Name == folderName); if (folder == null) { folder = new SolutionFolder(this) { Guid = Guid.NewGuid(), Name = folderName }; _items.Add(folder); } return(folder); }
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 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 void ReverseIntTest() { SortedObservableCollection <int> mySortedCollection = new SortedObservableCollection <int>(); mySortedCollection.Add(9); mySortedCollection.Add(7); mySortedCollection.Add(5); mySortedCollection.Add(3); mySortedCollection.Add(2); Assert.AreEqual(5, mySortedCollection.Count); Assert.AreEqual(2, mySortedCollection[0]); Assert.AreEqual(3, mySortedCollection[1]); Assert.AreEqual(5, mySortedCollection[2]); Assert.AreEqual(7, mySortedCollection[3]); Assert.AreEqual(9, mySortedCollection[4]); }
private async Task LoadServiceConfigurationAsync() { var predefinedNetworkServices = await GetPredefinedNetworkServicesAsync(); foreach (var networkService in predefinedNetworkServices) { networkService.IsEnabledChanged += OnPredefinedServiceSelectionIsEnabledChanged; } PredefinedNetworkServices = predefinedNetworkServices; var userNetworkServices = await GetUserNetworkServicesAsync(); m_userNetworkServices.Clear(); foreach (var networkService in userNetworkServices) { networkService.IsEnabledChanged += OnUserServiceSelectionIsEnabledChanged; m_userNetworkServices.Add(networkService); } }
public PackageViewModel(SessionViewModel session, PackageContainer packageContainer, bool packageAlreadyInSession) : base(session) { PackageContainer = packageContainer; Package = PackageContainer.Package; HasBeenUpgraded = Package.IsDirty; DependentProperties.Add(nameof(PackagePath), new[] { nameof(Name), nameof(RootDirectory) }); Dependencies = new DependencyCategoryViewModel(nameof(Dependencies), this, session, Package.RootAssets); AssetMountPoint = new AssetMountPointViewModel(this); content.Add(AssetMountPoint); content.Add(Dependencies); RenameCommand = new AnonymousCommand(ServiceProvider, () => IsEditing = true); IsLoaded = Package.State >= PackageState.AssetsReady; // IsDeleted will make the package added to Session.LocalPackages, so let's do it last InitialUndelete(!packageAlreadyInSession); DeletedAssets.CollectionChanged += DeletedAssetsChanged; }
public MainViewModel(IMessenger messenger) : base(messenger) { ShowCases = new SortedObservableCollection <ShowCase>(); ShowCases.Add(new ShowCase { Title = "SortedObservableCollection", Description = "Shows how to use the SortedObservableCollection", TargetPage = "SortedView" }); ShowCases.Add(new ShowCase { Title = "TextBox Behaviors", Description = "Shows how to use the behaviors for the TextBox control", TargetPage = "BehaviorsView" }); ShowCases.Add(new ShowCase { Title = "ProgressIndicator Behavior", Description = "Shows how to use the behaviors for progress indicator (Windows Phone only)", TargetPage = "ProgressIndicatorView" }); ShowCases.Add(new ShowCase { Title = "OpenFlyoutAction", Description = "Shows how to use the OpenFlyoutAction", TargetPage = "FlyoutView" }); OpenShowCaseCommand = new RelayCommand <ShowCase>(sc => Messenger.Send <NavigateMessage>(new NavigateMessage { TargetPage = sc.TargetPage })); }
internal LauncherViewModel(IViewModelServiceProvider serviceProvider, NugetStore store) : base(serviceProvider) { if (store == null) { throw new ArgumentNullException(nameof(store)); } DependentProperties.Add("ActiveVersion", new[] { "ActiveDocumentationPages" }); this.store = store; store.Logger = this; DisplayReleaseAnnouncement(); VsixPackage = new VsixVersionViewModel(this, store); // Commands InstallLatestVersionCommand = new AnonymousTaskCommand(ServiceProvider, InstallLatestVersion) { IsEnabled = false }; OpenUrlCommand = new AnonymousTaskCommand <string>(ServiceProvider, OpenUrl); ReconnectCommand = new AnonymousTaskCommand(ServiceProvider, async() => { // We are back online (or so we think) IsOffline = false; await FetchOnlineData(); }); StartStudioCommand = new AnonymousTaskCommand(ServiceProvider, StartStudio) { IsEnabled = false }; foreach (var devVersion in LauncherSettings.DeveloperVersions) { var version = new XenkoDevVersionViewModel(this, store, null, devVersion, false); xenkoVersions.Add(version); } FetchOnlineData().Forget(); LoadRecentProjects(); uninstallHelper = new UninstallHelper(serviceProvider, store); GameStudioSettings.RecentProjectsUpdated += (sender, e) => Dispatcher.InvokeAsync(LoadRecentProjects).Forget(); }
public void Add(PathBase child) { if (Childs.IndexOf(child) < 0) { Childs.Add(child); child.PropertyChanged += Child_PropertyChanged; } else { throw new System.Exception("Path allready exists."); } }
private void Update() { try { var we = new List <WhereExpression.IWhereOption>(); foreach (var w in _whereOptions) { if (w.PropertyPath != LastUpdateTimePropertyName) { we.Add(w); } } we.Add(new WhereExpression.WhereOptionLong() { Predicate = WhereExpression.GreaterThan, PropertyPath = LastUpdateTimePropertyName, Value = _lastUpdate }); var result = DataService.GetUpdate <T, T1>(we); _lastUpdate = result.LastUpdateTime; foreach (var item in result.Items) { switch (item.State) { case DtoState.Add: _processDtoBeforeAddToSortedCollectionAction?.Invoke(item); _datas.Add(item); break; case DtoState.Update: _datas.UpdateFirst(p => p.ID == item.ID, p => { p.Update(item); _processDtoBeforeAddToSortedCollectionAction?.Invoke(p); }); break; case DtoState.Delete: _datas.RemoveFirst(p => p.ID == item.ID); break; } } } catch (System.Exception ex) { Load(); } }
protected TreeViewItemViewModel(TreeViewItemViewModel parent, IMessenger messenger, bool lazyLoadChildren) { Parent = parent; MessengerInstance = messenger; Children = new SortedObservableCollection <TreeViewItemViewModel>(Comparer); messenger.Register <RemoveNodeMessage>(this, OnRemoveNodeMessage); if (lazyLoadChildren) { Children.Add(DummyChild); } }
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> /// Calculate exponential smoothed values for the current data series. /// </summary> public override void CalculateFilterValues() { base.CalculateFilterValues(); var fittedSamples = new SortedObservableCollection <XYSample>(); for (var i = 1; i < this.WertY.Count; i++) { var smoothValue = this.SmoothingFactor * this.WertY[i] + (1 - this.SmoothingFactor) * this.WertY[i - 1]; fittedSamples.Add(new XYSample(this.WertX[i], smoothValue)); } Viana.Project.CurrentFilterData.InterpolationSeries = fittedSamples; }
private void UpdateAdvertisementView() { AdvertisementsView = new SortedObservableCollection <ObservableBluetoothLEAdvertisement>(new ObservableBluetoothLEAdvertisement.RssiComparer(), "Rssi"); foreach (var advertisement in Context.Advertisements) { if (IsContentFilterMatch(ContentFilter, advertisement.Value)) { AdvertisementsView.Add(advertisement.Value); } } RaisePropertyChanged("AdvertisementsView"); }
internal void AddChild(IObservableNode node) { if (node == null) { throw new ArgumentNullException("node"); } if (children.Contains(node)) { throw new InvalidOperationException("The node is already in the children list of its parent."); } NotifyPropertyChanging(node.Name); children.Add(node); NotifyPropertyChanged(node.Name); }
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 }); }
PathPart AddNodes(PathPart current, IList <string> pathParts) { var res = current; var i = 0; if (current == null) { res = Drives[Drives.Add(new DriveContainer(pathParts[i++]))]; } for (; i < pathParts.Count; i++) { res = new DirectoryContainer(res, pathParts[i]); } return(res); }
/// <summary> /// Calculate moving average values for the current data series. /// </summary> public override void CalculateFilterValues() { base.CalculateFilterValues(); var fittedSamples = new SortedObservableCollection <XYSample>(); var startIndex = (int)(this.NumberOfSamplesToInterpolate / 2f); // Calculate interpolation for (int i = startIndex; i < this.WertX.Count - startIndex; i++) { var samplesForInterpolation = this.GetRangeAtPosition(i - startIndex, this.NumberOfSamplesToInterpolate); fittedSamples.Add(new XYSample(this.WertX[i], samplesForInterpolation.Sum() / this.NumberOfSamplesToInterpolate)); } Viana.Project.CurrentFilterData.InterpolationSeries = fittedSamples; }
private void SearchFolders(string search, SortedObservableCollection <FolderModel> myList) { foreach (var folderLookupKey in _folderLookup.Keys) { if ( //if entry contains search parameter folderLookupKey.Contains(search) || //if search parameter contains entry search.Contains(folderLookupKey) ) { _dispatchService.CheckBeginInvokeOnUi( () => myList.Add(_folderLookup[folderLookupKey]) ); } //can make search arbitrary complex! try with weighting etc } }
public void ConstructorTests() { var list = new string[] { "item 4", "item 2", "item 5", "item 9" }; var collection = new SortedObservableCollection <string>(list); var collection2 = new SortedObservableCollection <string>(); foreach (var item in list) { collection2.Add(item); } Assert.AreEqual <int>(4, collection.Count); Assert.AreEqual <int>(collection.Count, collection2.Count); Assert.AreEqual <int>(0, collection.IndexOf("item 2")); Assert.AreEqual <int>(1, collection.IndexOf("item 4")); Assert.AreEqual <int>(2, collection.IndexOf("item 5")); Assert.AreEqual <int>(3, collection.IndexOf("item 9")); }
public void StressTest() { List <KeyValuePair <int, string> > items = new List <KeyValuePair <int, string> >(); SortedObservableCollection <KeyValuePair <int, string>, int> mySortedCollection = new SortedObservableCollection <KeyValuePair <int, string>, int>(x => x.Key); Random random = new Random(); for (int i = 0; i < 10000; i++) { var item = new KeyValuePair <int, string>(random.Next(), random.Next().ToString()); items.Add(item); mySortedCollection.Add(item); } // Sort list, sorted list should be the same items.Sort((x, y) => x.Key - y.Key); Assert.AreEqual(items.Count, mySortedCollection.Count); for (int i = 0; i < items.Count; i++) { Assert.AreEqual(items[i].Key, mySortedCollection[i].Key); } }
public ShoppingListBlock(string label, string tooltip, List <Tuple <Blueprint, int> > composition, BlueprintCategory category, bool showAllGrades) { Label = label; Tooltip = tooltip; Composition = new SortedObservableCollection <Tuple <Blueprint, int> >((b1, b2) => b1.Item1.Grade.GetValueOrDefault().CompareTo(b2.Item1.Grade.GetValueOrDefault())); foreach (var blueprint in composition) { Composition.Add(blueprint); } ShowAllGrades = showAllGrades; Category = category; foreach (var blueprint in Composition) { blueprint.Item1.PropertyChanged += (o, e) => { if (e.PropertyName == "ShoppingListHighlighted") { this.Highlighted = ((Blueprint)o).ShoppingListHighlighted; } }; } }
public static void Initialize() { Countries.Add(new CountryClass("United Kingdom", "GB")); Countries.Add(new CountryClass("Argentina", "AR")); Countries.Add(new CountryClass("Australia", "AU")); Countries.Add(new CountryClass("Austria", "AT")); Countries.Add(new CountryClass("Belgium", "BE")); Countries.Add(new CountryClass("Brazil", "BR")); Countries.Add(new CountryClass("Canada", "CA")); Countries.Add(new CountryClass("Croatia", "HR")); Countries.Add(new CountryClass("Bosnia", "BA")); Countries.Add(new CountryClass("Cyprus", "CY")); Countries.Add(new CountryClass("Czech", "CZ")); Countries.Add(new CountryClass("Denmark", "DK")); Countries.Add(new CountryClass("Finland", "FI")); Countries.Add(new CountryClass("France", "FR")); Countries.Add(new CountryClass("Georgia", "GE")); Countries.Add(new CountryClass("Germany", "DE")); Countries.Add(new CountryClass("Greece", "GR")); Countries.Add(new CountryClass("Hongkong", "HK")); Countries.Add(new CountryClass("Hungary", "HU")); Countries.Add(new CountryClass("Iceland", "IS")); Countries.Add(new CountryClass("India", "IN")); Countries.Add(new CountryClass("Indonesia", "ID")); Countries.Add(new CountryClass("Iran", "IR")); Countries.Add(new CountryClass("Iraq", "IQ")); Countries.Add(new CountryClass("Ireland", "IE")); Countries.Add(new CountryClass("Israel", "IL")); Countries.Add(new CountryClass("Italy", "IT")); Countries.Add(new CountryClass("Japan", "JP")); Countries.Add(new CountryClass("Liechtenstein", "LI")); Countries.Add(new CountryClass("Luxembourg", "LU")); Countries.Add(new CountryClass("Malaysia", "MY")); Countries.Add(new CountryClass("Malta", "MT")); Countries.Add(new CountryClass("Mexico", "MX")); Countries.Add(new CountryClass("Morocco", "MA")); Countries.Add(new CountryClass("Netherlands", "NL")); Countries.Add(new CountryClass("Newzealand", "NZ")); Countries.Add(new CountryClass("Norway", "NO")); Countries.Add(new CountryClass("Poland", "PL")); Countries.Add(new CountryClass("Portugal", "PT")); Countries.Add(new CountryClass("Puertorico", "PR")); Countries.Add(new CountryClass("Romania", "RO")); Countries.Add(new CountryClass("Russia", "RU")); Countries.Add(new CountryClass("Singapore", "SG")); Countries.Add(new CountryClass("South Africa", "ZA")); Countries.Add(new CountryClass("Spain", "ES")); Countries.Add(new CountryClass("Sweden", "SE")); Countries.Add(new CountryClass("Switzerland", "CH")); Countries.Add(new CountryClass("Turkey", "TR")); Countries.Add(new CountryClass("USA", "US")); Countries.Add(new CountryClass("Unknown", "UN")); Countries.Add(new CountryClass("Blank 1", "B1")); Countries.Add(new CountryClass("Blank 2", "B2")); Countries.Add(new CountryClass("Blank 3", "B3")); Countries.Add(new CountryClass("Chile", "CL")); Countries.Add(new CountryClass("Serbia", "RS")); Countries.Add(new CountryClass("Slovenia", "SI")); Countries.Add(new CountryClass("Lebanon", "LB")); Countries.Add(new CountryClass("Moldova", "MO")); Countries.Add(new CountryClass("Ukraine", "UA")); Countries.Add(new CountryClass("Latvia", "LV")); Countries.Add(new CountryClass("Slovakia", "SK")); Countries.Add(new CountryClass("Costa Rica", "CR")); Countries.Add(new CountryClass("Estonia", "EE")); Countries.Add(new CountryClass("China", "CN")); Countries.Add(new CountryClass("Colombia", "CO")); Countries.Add(new CountryClass("Ecuador", "EC")); Countries.Add(new CountryClass("Uruguay", "UY")); Countries.Add(new CountryClass("Venezuela", "VE")); Countries.Add(new CountryClass("Lithuania", "LT")); Countries.Add(new CountryClass("Bulgaria", "BG")); Countries.Add(new CountryClass("Egypt", "EG")); Countries.Add(new CountryClass("Saudi Arabia", "SA")); Countries.Add(new CountryClass("South Korea", "KR")); Countries.Add(new CountryClass("Belarus", "BY")); Countries.Add(new CountryClass("Peru", "PE")); Countries.Add(new CountryClass("Algeria", "DZ")); Countries.Add(new CountryClass("Kazakhstan", "KZ")); Countries.Add(new CountryClass("El Salvador", "SV")); Countries.Add(new CountryClass("Taiwan", "TW")); Countries.Add(new CountryClass("Jamaica", "JM")); Countries.Add(new CountryClass("Guatemala", "GT")); Countries.Add(new CountryClass("Marshall Islands", "MH")); Countries.Add(new CountryClass("Macedonia", "MK")); Countries.Add(new CountryClass("United Arab Emirates", "AE")); DefaultCountry = GetCountryByID(49); }