public async void Execute_OnSearchClick() { if (Searching) { return; } Searching = true; DispatcherService.InvokeIfRequired(() => _tweets.Clear()); if (_tweetSearchService != null && !string.IsNullOrEmpty(SearchString)) { await _tweetSearchService.GetMeSomeTweets <LinqTweet>(newTweets => { if (newTweets != null) { DispatcherService.InvokeIfRequired(() => _tweets.AddRange(newTweets)); } Searching = false; if (OnSearchComplete != null) { OnSearchComplete(); } }, SearchString); } }
void ActiveEvents_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: foreach (IEvent ev in e.NewItems) { if (_filter.Apply(ev.Definition)) { _events.Insert(0, new EventViewModel(ev)); } } break; case NotifyCollectionChangedAction.Remove: foreach (IEvent ev in e.OldItems) { foreach (EventViewModel evm in _events) { if (evm.Definition.Id == ev.Definition.Id) { _events.Remove(evm); break; } } } break; case NotifyCollectionChangedAction.Reset: _events.Clear(); break; } }
private void Update() { this.NotifyPropertyChanged(nameof(this.Name)); { var tempList = new List <SignatureTreeViewModel>(); foreach (var item in _value.Children) { tempList.Add(new SignatureTreeViewModel(this, item)); } tempList.Sort((x, y) => { int c = x.Value.LinkItem.Signature.CompareTo(y.Value.LinkItem.Signature); if (c != 0) { return(c); } return(x.GetHashCode().CompareTo(y.GetHashCode())); }); _children.Clear(); _children.AddRange(tempList); } }
private void ClearMediaContainer() { MediaContainer = null; ConnectionStatus = ConnectionStatus.NotConnected; _nowPlaying.Clear(); _clients.Clear(); }
public void ObsCollExConstructorTest() { ObservableCollectionEx <string> target = new ObservableCollectionEx <string>(); target.Add("Jesse Pinkman"); Assert.AreEqual(1, target.Count); target.Clear(); Assert.AreEqual(0, target.Count); }
public void removeSelected() { foreach (var selectedItem in selectedItems) { allItems.Remove(selectedItem); } selectedItems.Clear(); }
public void InterpolateSpline(double resolution = 0.25, double weight = 1) { if (Points.Count < 3) { return; } if (_Spline == null) { _Spline = new BezierSpline(Points.Select(p => p.ToVector()), weight); } var finalPoints = new List <PointM>(); var splinePoints = _Spline.Interpolate(resolution); finalPoints.AddRange(splinePoints.Select(v => PointM.FromVector(v, Points[0].Unit))); if (finalPoints.Count > 1) { _Points.Clear(); _Points.AddRange(finalPoints); } }
private static void TestCase3() { ObservableCollectionEx <Person> coll = new ObservableCollectionEx <Person>(); coll.CollectionChanged += OnCollectionChanged2; var eric = new Person("Eric"); var charles = new Person("Charles"); coll.Add(eric); coll.Add(charles); coll.Remove(eric); coll.Clear(); // Will Charles say 'goodbye' to us? }
public void ClearTest() { var wasExecuted = false; var collection = new ObservableCollectionEx <string> { "One", "Two" }; collection.CollectionChanged += (sender, args) => { if (args.Action == NotifyCollectionChangedAction.Remove && args.OldItems.Count == 2) { wasExecuted = true; } }; collection.Clear(); CollectionAssert.IsEmpty(collection); Assert.IsTrue(wasExecuted); }
public void BUG__0002__BulkUpdateFailsWhenCalledFromMultipleThreads() { var col = new ObservableCollectionEx<int>(); var t1 = Task.Factory.StartNew(() => { using (col.BeginBulkUpdate()) { col.Add(1); Thread.Sleep(10); } }); using (col.BeginBulkUpdate()) { col.Clear(); } // code above would normally fail by now. }
private void ShowDownloadItem() { try { for (;;) { var informaitonDic = new Dictionary <int, Information>(); { string[] words = null; { string searchText = null; this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { searchText = _searchTextBox.Text; })); if (!string.IsNullOrWhiteSpace(searchText)) { words = searchText.ToLower().Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries); } } foreach (var item in _amoebaManager.DownloadingInformation.ToArray()) { if (words != null) { var text = ((string)item["Path"] ?? "").ToLower(); if (!words.All(n => text.Contains(n))) { continue; } } informaitonDic[(int)item["Id"]] = item; } } var listViewModelDic = new Dictionary <int, DownloadListViewModel>(); var removeList = new List <DownloadListViewModel>(); this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { foreach (var item in _listViewModelCollection.ToArray()) { listViewModelDic[item.Id] = item; if (!informaitonDic.ContainsKey(item.Id)) { removeList.Add(item); } } })); var resultList = new List <DownloadListViewModel>(); var updateDic = new Dictionary <DownloadListViewModel, Information>(); bool clearFlag = false; var selectItems = new List <DownloadListViewModel>(); if (removeList.Count > 100) { clearFlag = true; removeList.Clear(); updateDic.Clear(); foreach (var information in informaitonDic.Values) { resultList.Add(new DownloadListViewModel(information)); } var hid = new HashSet <int>(); this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { hid.UnionWith(_listView.SelectedItems.OfType <DownloadListViewModel>().Select(n => n.Id)); })); foreach (var item in resultList) { if (hid.Contains(item.Id)) { selectItems.Add(item); } } } else { foreach (var information in informaitonDic.Values) { DownloadListViewModel item; if (listViewModelDic.TryGetValue((int)information["Id"], out item)) { updateDic[item] = information; } else { resultList.Add(new DownloadListViewModel(information)); } } } this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { bool sortFlag = false; if (resultList.Count != 0) { sortFlag = true; } if (removeList.Count != 0) { sortFlag = true; } if (updateDic.Count != 0) { sortFlag = true; } if (clearFlag) { _listViewModelCollection.Clear(); } foreach (var item in resultList) { _listViewModelCollection.Add(item); } foreach (var item in removeList) { _listViewModelCollection.Remove(item); } foreach (var item in updateDic) { item.Key.Information = item.Value; } if (clearFlag) { _listView.SelectedItems.Clear(); _listView.SetSelectedItems(selectItems); } if (sortFlag) { this.Sort(); } })); for (int i = 0; i < 10; i++) { Thread.Sleep(1000 * 3); if (_mainWindow.SelectedTab == MainWindowTabType.Download) { break; } } } } catch (Exception) { } }
public void Update() { _treeView.Items.Clear(); _trustSignatureCollection.Clear(); _untrustSignatureCollection.Clear(); if (_cache_LinkItems.Count == 0) { return; } string[] words = null; { string searchText = _searchTextBox.Text; if (!string.IsNullOrWhiteSpace(searchText)) { words = searchText.ToLower().Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries); } } foreach (var leaderSignature in Settings.Instance.Global_TrustSignatures.ToArray()) { var item = this.GetSignatureTreeViewItem(leaderSignature); if (words != null) { foreach (var word in words) { if (item == null) { break; } item = item.Search(n => n.LinkItem.Signature.Contains(word, StringComparison.CurrentCultureIgnoreCase)); } } if (item == null) { continue; } _treeView.Items.Add(new SignatureTreeViewModel(null, item)); } foreach (var path in Settings.Instance.LinkControl_ExpandedPaths.ToArray()) { if (path.Count == 0) { goto End; } var treeViewModel = _treeView.Items.OfType <SignatureTreeViewModel>() .FirstOrDefault(n => n.Value.LinkItem.Signature == path[0]); if (treeViewModel == null) { goto End; } foreach (var name in path.Skip(1)) { treeViewModel = treeViewModel.Children.OfType <SignatureTreeViewModel>() .FirstOrDefault(n => n.Value.LinkItem.Signature == name); if (treeViewModel == null) { goto End; } } treeViewModel.IsExpanded = true; continue; End :; if (words == null) { Settings.Instance.LinkControl_ExpandedPaths.Remove(path); } } }
private void ShowDownloadItem() { try { for (; ;) { Thread.Sleep(100); if (_mainWindow.SelectedTab != MainWindowTabType.Download) { continue; } var downloadingInformation = _amoebaManager.DownloadingInformation.ToArray(); Dictionary <int, Information> dic = new Dictionary <int, Information>(); foreach (var item in downloadingInformation.ToArray()) { dic[(int)item["Id"]] = item; } Dictionary <int, DownloadListViewItem> dic2 = new Dictionary <int, DownloadListViewItem>(); this.Dispatcher.Invoke(DispatcherPriority.ContextIdle, new Action(() => { foreach (var item in _listViewItemCollection.ToArray()) { dic2[item.Id] = item; } })); List <DownloadListViewItem> removeList = new List <DownloadListViewItem>(); this.Dispatcher.Invoke(DispatcherPriority.ContextIdle, new Action(() => { foreach (var item in _listViewItemCollection.ToArray()) { if (!dic.ContainsKey(item.Id)) { removeList.Add(item); } } })); List <DownloadListViewItem> newList = new List <DownloadListViewItem>(); Dictionary <DownloadListViewItem, Information> updateDic = new Dictionary <DownloadListViewItem, Information>(); bool clearFlag = false; var selectItems = new List <DownloadListViewItem>(); if (removeList.Count > 100) { clearFlag = true; removeList.Clear(); updateDic.Clear(); foreach (var information in downloadingInformation) { newList.Add(new DownloadListViewItem(information)); } HashSet <int> hid = new HashSet <int>(); this.Dispatcher.Invoke(DispatcherPriority.ContextIdle, new Action(() => { hid.UnionWith(_listView.SelectedItems.OfType <DownloadListViewItem>().Select(n => n.Id)); })); foreach (var item in newList) { if (hid.Contains(item.Id)) { selectItems.Add(item); } } } else { foreach (var information in downloadingInformation) { DownloadListViewItem item = null; if (dic2.ContainsKey((int)information["Id"])) { item = dic2[(int)information["Id"]]; } if (item != null) { if (!CollectionUtilities.Equals(item.Information, information)) { updateDic[item] = information; } } else { newList.Add(new DownloadListViewItem(information)); } } } this.Dispatcher.Invoke(DispatcherPriority.ContextIdle, new Action(() => { bool sortFlag = false; if (newList.Count != 0) { sortFlag = true; } if (removeList.Count != 0) { sortFlag = true; } if (updateDic.Count != 0) { sortFlag = true; } if (clearFlag) { _listViewItemCollection.Clear(); } foreach (var item in newList) { _listViewItemCollection.Add(item); } foreach (var item in removeList) { _listViewItemCollection.Remove(item); } foreach (var item in updateDic) { item.Key.Information = item.Value; } if (clearFlag) { _listView.SelectedItems.Clear(); _listView.SetSelectedItems(selectItems); } if (sortFlag) { this.Sort(); } })); Thread.Sleep(1000 * 3); } } catch (Exception) { } }
private void ClearMediaContainer() { MediaContainer = null; _nowPlaying.Clear(); _clients.Clear(); }
/// <summary> ///A test for GetDelayedNotifier ///</summary> public void DelayedNotificationTestHelper <T>() where T : new() { ObservableCollectionEx <T> target = CreateTargetHelper <T>(); T item0 = new T(); T item1 = new T(); T item2 = new T(); T item3 = new T(); T item4 = new T(); // Testing Add this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); using (ObservableCollectionEx <T> iTarget = target.DelayNotifications()) { iTarget.Add(item0); iTarget.Add(item1); iTarget.Add(item2); iTarget.Add(item3); iTarget.Add(item4); Assert.IsTrue(5 == target.Count, "Count is incorrect"); Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); } Assert.IsTrue(5 == target.Count, "Count is incorrect"); Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); // Testing Replace this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); using (ObservableCollectionEx <T> iTarget = target.DelayNotifications()) { iTarget[1] = item0; iTarget[2] = item1; iTarget[3] = item2; iTarget[4] = item3; iTarget[0] = item4; using (ObservableCollectionEx <T> iNested = iTarget.DelayNotifications()) { iNested.Add(item4); iNested.Add(item4); Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); } Assert.IsTrue(7 == target.Count, "Count is incorrect"); Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); } Assert.IsTrue(7 == target.Count, "Count is incorrect"); Assert.IsTrue(3 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(2 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); // Testing Remove this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); using (ObservableCollectionEx <T> iTarget = target.DelayNotifications()) { iTarget.Remove(item0); iTarget.Remove(item1); iTarget.Remove(item2); iTarget.Remove(item3); iTarget.Remove(item4); Assert.IsTrue(2 == target.Count, "Count is incorrect"); Assert.IsTrue(0 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(0 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); try { iTarget.Add(item0); Assert.Fail("Mixed operation is not handled"); } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(InvalidOperationException)); } } Assert.IsTrue(3 == target.Count, "Count is incorrect"); Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); this._firedCollectionEvents.Clear(); this._firedPropertyEvents.Clear(); using (ObservableCollectionEx <T> iTarget = target.DelayNotifications()) { iTarget.Clear(); } Assert.IsTrue(0 == target.Count, "Count is incorrect"); Assert.IsTrue(2 == this._firedPropertyEvents.Count, "Incorrect number of PropertyChanged notifications"); Assert.IsTrue(1 == this._firedCollectionEvents.Count, "Incorrect number of CollectionChanged notifications"); }
private void ClearRedoHistory() { _UndoHistory.Clear(); _Redo.Clear(); _RedoHistory.Clear(); }
public async Task RefreshContainerAsync() { Guid token; lock (_tokenSyncObj) { token = Guid.NewGuid(); _refreshToken = token; } try { var container = await _restConnection.MakeRequestAsync <MediaContainer, string>(Method.Get, ResponseType.Xml, PlexResources.MyPlexBaseUrl, PlexResources.MyPlexDevices, headers : PlexHeaders.CreatePlexRequest(User)); if (container != null && container.ResponseObject != null) { bool updated; lock (_deviceSyncObj) { if (token != _refreshToken) { return; } updated = _devices.UpdateToMatch(container.ResponseObject.Devices, d => d.ClientIdentifier, UpdateDevice); _servers.UpdateToMatch(GetByProvides(container.ResponseObject, "server"), d => d.ClientIdentifier); _players.UpdateToMatch(GetByProvides(container.ResponseObject, "player"), d => d.ClientIdentifier); } if (updated) { OnDevicesUpdated(); } } } catch { var updated = false; lock (_deviceSyncObj) { if (token != _refreshToken) { return; } // lost connection, so clear everything if (_devices.Any()) { _devices.Clear(); _servers.Clear(); _players.Clear(); updated = true; } } if (updated) { OnDevicesUpdated(); } } }
public async Task RefreshContainerAsync() { Guid token; lock (_tokenSyncObj) { token = Guid.NewGuid(); _refreshToken = token; } try { var container = await _connectionHelper.MakeRequestAsync <MediaContainer>(Method.Get, PlexResources.MyPlexBaseUrl, PlexResources.MyPlexDevices, user : User); bool updated; lock (_deviceSyncObj) { if (token != _refreshToken) { return; } updated = _devices.UpdateToMatch(container.Devices, d => d.ClientIdentifier, UpdateDevice); _servers.UpdateToMatch(GetByProvides(container, "server"), d => d.ClientIdentifier); _players.UpdateToMatch(GetByProvides(container, "player"), d => d.ClientIdentifier); } if (updated) { OnDevicesUpdated(); } } catch { var updated = false; lock (_deviceSyncObj) { if (token != _refreshToken) { return; } // lost connection, so clear everything if (_devices.Any()) { _devices.Clear(); _servers.Clear(); _players.Clear(); updated = true; } } if (updated) { OnDevicesUpdated(); } } }
public void ObsCollExConstructorTest() { ObservableCollectionEx<string> target = new ObservableCollectionEx<string>(); target.Add("Jesse Pinkman"); Assert.AreEqual(1, target.Count); target.Clear(); Assert.AreEqual(0, target.Count); }
private void ShowConnectionInfomation() { try { for (;;) { var connectionInformation = _amoebaManager.ConnectionInformation.ToArray(); var dic = new Dictionary <int, Information>(); foreach (var item in connectionInformation.ToArray()) { dic[(int)item["Id"]] = item; } var dic2 = new Dictionary <int, ConnectionListViewModel>(); this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { foreach (var item in _listViewModelCollection.ToArray()) { dic2[item.Id] = item; } })); var removeList = new List <ConnectionListViewModel>(); this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { foreach (var item in _listViewModelCollection.ToArray()) { if (!dic.ContainsKey(item.Id)) { removeList.Add(item); } } })); var newList = new List <ConnectionListViewModel>(); var updateDic = new Dictionary <ConnectionListViewModel, Information>(); bool clearFlag = false; var selectItems = new List <ConnectionListViewModel>(); if (removeList.Count > 100) { clearFlag = true; removeList.Clear(); updateDic.Clear(); foreach (var information in connectionInformation) { newList.Add(new ConnectionListViewModel(information)); } var hid = new HashSet <int>(); this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { hid.UnionWith(_listView.SelectedItems.OfType <ConnectionListViewModel>().Select(n => n.Id)); })); foreach (var item in newList) { if (hid.Contains(item.Id)) { selectItems.Add(item); } } } else { foreach (var information in connectionInformation) { ConnectionListViewModel item = null; if (dic2.ContainsKey((int)information["Id"])) { item = dic2[(int)information["Id"]]; } if (item != null) { updateDic[item] = information; } else { newList.Add(new ConnectionListViewModel(information)); } } } this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { bool sortFlag = false; if (newList.Count != 0) { sortFlag = true; } if (removeList.Count != 0) { sortFlag = true; } if (updateDic.Count != 0) { sortFlag = true; } if (clearFlag) { _listViewModelCollection.Clear(); } foreach (var item in newList) { _listViewModelCollection.Add(item); } foreach (var item in removeList) { _listViewModelCollection.Remove(item); } foreach (var item in updateDic) { item.Key.Information = item.Value; } if (clearFlag) { _listView.SelectedItems.Clear(); _listView.SetSelectedItems(selectItems); } if (sortFlag) { this.Sort(); } })); Thread.Sleep(1000 * 3); } } catch (Exception) { } }