public void HandlesChangesOfSuspendedFastObservableCollectionCorrectly() { var collection = new FastObservableCollection <TestModel>(); TestModel model = null; for (int i = 0; i < 10; i++) { var randomModel = new TestModel(); collection.Add(randomModel); } var wrapper = new ChangeNotificationWrapper(collection); var collectionItemPropertyChanged = false; wrapper.CollectionItemPropertyChanged += (sender, e) => collectionItemPropertyChanged = true; var newModel = new TestModel(); using (collection.SuspendChangeNotifications()) { collection.Clear(); collection.Add(newModel); } newModel.FirstName = "Geert"; Assert.IsTrue(collectionItemPropertyChanged); }
public void MultipleActionsWithoutSuspendingNotifications() { var counter = 0; var fastCollection = new FastObservableCollection <int>(); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => counter++; fastCollection.Add(0); fastCollection.Add(1); fastCollection.Remove(0); fastCollection.Remove(1); fastCollection.AddRange(new[] { 1, 2 }); fastCollection[0] = 5; fastCollection.Move(0, 1); fastCollection.Clear(); Assert.AreEqual(9, counter); }
public void HandlesChangesOfSuspendedFastObservableCollectionCorrectly() { var collection = new FastObservableCollection <TestModel> { AutomaticallyDispatchChangeNotifications = false }; for (var i = 0; i < 10; i++) { var randomModel = new TestModel(); collection.Add(randomModel); } var wrapper = new ChangeNotificationWrapper(collection); var collectionItemPropertyChanged = false; wrapper.CollectionItemPropertyChanged += (sender, e) => collectionItemPropertyChanged = true; var newModel = new TestModel(); using (collection.SuspendChangeNotifications()) { collection.Clear(); collection.Add(newModel); } newModel.FirstName = "Geert"; Assert.IsTrue(collectionItemPropertyChanged, "Collection item property should have changed"); }
public void AddingItemsInAddingMode() { var counter = 0; var eventArgs = (NotifyCollectionChangedEventArgs)null; var fastCollection = new FastObservableCollection <int>(); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => { counter++; eventArgs = e; }; using (fastCollection.SuspendChangeNotifications(SuspensionMode.Adding)) { fastCollection.Add(1); fastCollection.Add(2); fastCollection.Add(3); fastCollection.Add(4); fastCollection.Add(5); } Assert.AreEqual(1, counter); Assert.AreEqual(NotifyCollectionChangedAction.Add, eventArgs.Action); CollectionAssert.AreEqual(eventArgs.NewItems, new[] { 1, 2, 3, 4, 5 }); }
public void SuspendsValidationWhileAddingAndRemovingItems() { int counter = 0; var fastCollection = new FastObservableCollection<int>(); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => counter++; using (fastCollection.SuspendChangeNotifications()) { fastCollection.Add(1); fastCollection.Add(2); fastCollection.Add(3); fastCollection.Add(4); fastCollection.Add(5); fastCollection.Remove(5); fastCollection.Remove(4); fastCollection.Remove(3); fastCollection.Remove(2); fastCollection.Remove(1); } Assert.AreEqual(1, counter); }
public void CascadedAddingItemsInAddingModeWithInterceptingDisposing() { var counter = 0; var eventArgs = (NotifyCollectionChangedEventArgs)null; var fastCollection = new FastObservableCollection <int>(); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => { counter++; eventArgs = e; }; var firstToken = fastCollection.SuspendChangeNotifications(SuspensionMode.Adding); var secondToken = fastCollection.SuspendChangeNotifications(SuspensionMode.Adding); fastCollection.Add(1); fastCollection.Add(2); secondToken.Dispose(); Assert.AreEqual(0, counter); Assert.IsNull(eventArgs); fastCollection.Add(3); fastCollection.Add(4); fastCollection.Add(5); firstToken.Dispose(); Assert.AreEqual(1, counter); // ReSharper disable PossibleNullReferenceException Assert.AreEqual(NotifyCollectionChangedAction.Add, eventArgs.Action); CollectionAssert.AreEqual(eventArgs.NewItems, new[] { 1, 2, 3, 4, 5 }); // ReSharper restore PossibleNullReferenceException }
public void SuspendsValidationWhileAddingAndRemovingItems() { var counter = 0; var fastCollection = new FastObservableCollection <int>(); fastCollection.AutomaticallyDispatchChangeNotifications = false; fastCollection.CollectionChanged += (sender, e) => counter++; using (fastCollection.SuspendChangeNotifications()) { fastCollection.Add(1); fastCollection.Add(2); fastCollection.Add(3); fastCollection.Add(4); fastCollection.Add(5); fastCollection.Remove(5); fastCollection.Remove(4); fastCollection.Remove(3); fastCollection.Remove(2); fastCollection.Remove(1); } Assert.AreEqual(0, counter); }
public void TestAddTwiceShouldRaiseCollectionChangedEventTwice() { var timesRaised = 0; _collection.CollectionChanged += (s, e) => timesRaised++; _collection.Add(_item1); _collection.Add(_item2); Assert.That(timesRaised, Is.EqualTo(2)); }
/// <summary> /// /// </summary> public void OnInit(IEnumerable <PluginInfo> catalog) { var currentCatalog = catalog.ToArray(); var genPlugin = _resolverService.Resolve <GeneralPluginsConfigurationSectionViewModel>(); genPlugin.OnInit(currentCatalog); _sections.Add(genPlugin); var plugins = _resolverService.Resolve <SpecificPluginsConfigurationSectionViewModel>(); plugins.OnInit(currentCatalog); _sections.Add(plugins); }
private void updateEntries(params VM[] viewModels) { FastObservableCollection <VM> all = All as FastObservableCollection <VM>; all.SuspendCollectionChangeNotification(); var removeItems = all.Where(vm => !viewModels.Contains(vm)).ToList(); var addItems = viewModels.Where(vm => !all.Contains(vm)).ToList(); if (addItems.Count == 0 && removeItems.Count == 0) { return; //nothing to do here } foreach (var vm in removeItems) { all.Remove(vm); } foreach (var vm in addItems) { all.Add(vm); } _subItemList = all.ToArray().ToList(); all.NotifyChanges(); EntriesChanged?.Invoke(this, EventArgs.Empty); }
public ManageFontModel() { Fonts = new FastObservableCollection <string>(); FontStyles = new FastObservableCollection <string>(); FontSizes = new FastObservableCollection <string>(); using (var installedFontCollection = new InstalledFontCollection()) { var fonts = installedFontCollection.Families; foreach (var font in fonts) { Fonts.Add(font.Name); } } using (FontStyles.SuspendChangeNotifications()) { foreach (var propertyInfo in typeof(FontStyles).GetProperties()) { FontStyles.Add(propertyInfo.Name); } } using (FontSizes.SuspendChangeNotifications()) { for (var i = MinFontSize; i < MaxFontSize; i = i + FontSizeStep) { FontSizes.Add($"{i}"); } } }
public void HandlesClearOfSuspendedFastObservableCollectionCorrectly() { var collection = new FastObservableCollection <TestModel> { AutomaticallyDispatchChangeNotifications = false }; TestModel model = null; for (var i = 0; i < 10; i++) { var randomModel = new TestModel(); collection.Add(randomModel); } model = collection[0]; var wrapper = new ChangeNotificationWrapper(collection); var collectionItemPropertyChanged = false; wrapper.CollectionItemPropertyChanged += (sender, e) => collectionItemPropertyChanged = true; using (collection.SuspendChangeNotifications()) { collection.Clear(); } model.FirstName = "Geert"; Assert.IsFalse(collectionItemPropertyChanged); }
/// <summary> /// Updates the entries (via Remove and Add) in the ALL items collection /// with the entries in the <param name="viewModels"/> array parameter. /// </summary> /// <param name="viewModels"></param> private void UpdateAllEntries(params VM[] viewModels) { Logger.InfoFormat("_"); _All.SuspendCollectionChangeNotification(); try { var removeItems = _All.Where(vm => !viewModels.Contains(vm)).ToList(); var addItems = viewModels.Where(vm => !_All.Contains(vm)).ToList(); foreach (var vm in removeItems) { _All.Remove(vm); } foreach (var vm in addItems) { _All.Add(vm); } } finally { _All.NotifyChanges(); if (this.EntriesChanged != null) { this.EntriesChanged(this, EventArgs.Empty); } } }
public EntriesHelper(Func <bool, object, Task <IEnumerable <VM> > > loadSubEntryFunc) { _loadSubEntryFunc = loadSubEntryFunc; All = new FastObservableCollection <VM>(); All.Add(default(VM)); }
private void updateEntries(params VM[] viewModels) { FastObservableCollection <VM> all = All as FastObservableCollection <VM>; all.SuspendCollectionChangeNotification(); var removeItems = all.Where(vm => !viewModels.Contains(vm)).ToList(); var addItems = viewModels.Where(vm => !all.Contains(vm)).ToList(); foreach (var vm in removeItems) { all.Remove(vm); } foreach (var vm in addItems) { all.Add(vm); } _subItemList = all.ToArray().ToList(); all.NotifyChanges(); if (EntriesChanged != null) { EntriesChanged(this, EventArgs.Empty); } }
public void ReturnsFalseWhenNoPendingNotificationsAreListed() { var fastCollection = new FastObservableCollection <int>(); fastCollection.Add(1); Assert.IsFalse(fastCollection.IsDirty); }
public void ReturnsFalseWhenNoPendingNotificationsAreListed() { var fastCollection = new FastObservableCollection<int>(); fastCollection.Add(1); Assert.IsFalse(fastCollection.IsDirty); }
public void ThrowsInvalidOperationExceptionForAddingInRemovingMode() { var fastCollection = new FastObservableCollection <int>(); using (fastCollection.SuspendChangeNotifications(SuspensionMode.Removing)) { Assert.Throws <InvalidOperationException>(() => fastCollection.Add(0)); } }
public void TestFastObservableCollectionSpeed() { var foo = new FastObservableCollection <Company>(); for (int i = 0; i < 10000; i++) { foo.Add(new Company()); } }
/// <summary> /// /// </summary> public void OnInit(IEnumerable <PluginInfo> catalog) { foreach (var plugin in catalog.Select(x => x.Plugin).OrderBy(x => x.Name)) { if (plugin is ISimplyAWpfPlugin wpfPlugin && wpfPlugin.CustomConfigControl != null) { var section = _resolverService.Resolve <SpecialWpfConfigPluginsConfigurationSectionViewModel>(); section.OnInit(wpfPlugin); _sections.Add(section); }
private void AddLogEntries(IEnumerable <LogEntry> entries, bool bypassClearingLog = false) { if (!bypassClearingLog && _isClearingLog) { return; } lock (_lock) { var typeNames = TypeNames; var requireSorting = false; using (SuspendChangeNotifications()) { using (_logEntries.SuspendChangeNotifications()) { foreach (var entry in entries) { _logEntries.Add(entry); if (!typeNames.Contains(entry.Log.TargetType.Name)) { try { typeNames.Add(entry.Log.TargetType.Name); requireSorting = true; } catch (Exception) { // we don't have time for this, let it go... } } UpdateEntriesCount(entry); } } if (requireSorting) { using (typeNames.SuspendChangeNotifications()) { typeNames.Sort(); typeNames.Remove(defaultComboBoxItem); typeNames.Insert(0, defaultComboBoxItem); } } } RaisePropertyChanged(string.Empty); } LogMessage.SafeInvoke(this, new LogEntryEventArgs(entries)); }
public void ReturnsTrueWhenPendingNotificationsAreListed() { var fastCollection = new FastObservableCollection <int>(); using (fastCollection.SuspendChangeNotifications()) { fastCollection.Add(1); Assert.IsTrue(fastCollection.IsDirty); } Assert.IsFalse(fastCollection.IsDirty); }
public void ReturnsTrueWhenPendingNotificationsAreListed() { var fastCollection = new FastObservableCollection<int>(); using (fastCollection.SuspendChangeNotifications()) { fastCollection.Add(1); Assert.IsTrue(fastCollection.IsDirty); } Assert.IsFalse(fastCollection.IsDirty); }
public void CleanedUpSuspensionContextAfterAdding() { var fastCollection = new FastObservableCollection <int>(); using (fastCollection.SuspendChangeNotifications(SuspensionMode.Adding)) { fastCollection.Add(1); } var context = this.GetSuspensionContext(fastCollection); Assert.IsNull(context); }
public void ReturnsFalseAfterDisposing() { var fastCollection = new FastObservableCollection <int>(); using (fastCollection.SuspendChangeNotifications()) { fastCollection.Add(1); Assert.IsTrue(fastCollection.NotificationsSuspended); } Assert.IsFalse(fastCollection.NotificationsSuspended); }
public void ReturnsSingleElementUsingLinq() { var fastCollection = new FastObservableCollection <int>(); for (var i = 0; i < 43; i++) { fastCollection.Add(i); } var allInts = (from x in fastCollection where x == 42 select x).FirstOrDefault(); Assert.AreEqual(42, allInts); }
public void HandlesCollectionChangesCorrectlyInSuspensionModeMixedConsolidate() { var collection = new FastObservableCollection <TestModel> { AutomaticallyDispatchChangeNotifications = false }; var wrapper = new ChangeNotificationWrapper(collection); var itemsReset = false; var itemsAdded = false; var itemsRemoved = false; var model = new TestModel(); collection.Add(model); wrapper.CollectionChanged += (sender, e) => { if (e.OldItems != null) { itemsRemoved = true; } if (e.Action == NotifyCollectionChangedAction.Reset) { itemsReset = true; } if (e.NewItems != null) { itemsAdded = true; } }; using (collection.SuspendChangeNotifications(SuspensionMode.MixedConsolidate)) { collection.ReplaceRange(new [] { new TestModel() }); } Assert.IsTrue(itemsAdded, "Items should be added"); Assert.IsTrue(itemsRemoved, "Items should be removed"); Assert.IsFalse(itemsReset, "Items should not be reset"); }
public void AddDishIntoOrderedDishes(Dish dish) { // проверяем, есть ли уже в списке такое блюдо var orderedDish = _dishes.FirstOrDefault(cur => cur.DishId == dish.Id); if (orderedDish != null) { orderedDish.Quantity++; } else { orderedDish = new OrderedDish { DishId = dish.Id, Quantity = 1, OrderedPrice = GetRealPrice(dish) }; _dishes.Add(orderedDish); } }
public void HandlesCollectionChangesByResetCorrectly() { var collection = new FastObservableCollection <TestModel>(); var wrapper = new ChangeNotificationWrapper(collection); var itemsReset = false; var itemsAdded = false; var itemsRemoved = false; var model = new TestModel(); collection.Add(model); wrapper.CollectionChanged += (sender, e) => { if (e.OldItems != null) { itemsRemoved = true; } if (e.Action == NotifyCollectionChangedAction.Reset) { itemsReset = true; } if (e.NewItems != null) { itemsAdded = true; } }; using (collection.SuspendChangeNotifications()) { collection.ReplaceRange(new [] { new TestModel() }); } Assert.IsFalse(itemsAdded); Assert.IsFalse(itemsRemoved); Assert.IsTrue(itemsReset); }
protected override async Task InitializeAsync() { await base.InitializeAsync(); var ranges = new FastObservableCollection <DateRange>(); using (ranges.SuspendChangeNotifications()) { ranges.Add(PredefinedDateRanges.Today); ranges.Add(PredefinedDateRanges.Yesterday); ranges.Add(PredefinedDateRanges.ThisWeek); ranges.Add(PredefinedDateRanges.LastWeek); ranges.Add(PredefinedDateRanges.ThisMonth); ranges.Add(PredefinedDateRanges.LastMonth); } Ranges = ranges; StartDate = ranges[0].Start; EndDate = ranges[0].End; Span = ranges[0].Duration; SelectedRange = ranges[0]; }
private async Task SubAddData(ItemTreeItemViewModel item, string conditionWave, string conditionAlarm, object[] objectWave, object[] objectAlarm, bool showmessagbox = true) { List <IBaseAlarmSlot> result = new List <IBaseAlarmSlot>(); if (item.T_Item.ItemType == (int)ChannelType.WirelessVibrationChannelInfo) { result = await _databaseComponent.GetUniformHistoryData(item.T_Item.ItemType, item.ServerIP, item.T_Item.Guid, new string[] { "ACQDatetime", "Result", "Unit", "AlarmGrade" }, StartTime.Value, EndTime.Value, conditionWave, objectWave); } else if (item.T_Item.ItemType == (int)ChannelType.WirelessScalarChannelInfo) { result = await _databaseComponent.GetUniformHistoryData(item.T_Item.ItemType, item.ServerIP, item.T_Item.Guid, new string[] { "ACQDatetime", "Result", "Unit", "AlarmGrade" }, StartTime.Value, EndTime.Value, conditionAlarm, objectAlarm); } if (result == null || result.Count == 0) { if (showmessagbox == true) { #if XBAP MessageBox.Show("没有数据,请重新选择条件", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); #else Xceed.Wpf.Toolkit.MessageBox.Show("没有数据,请重新选择条件", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); #endif } return; } for (int i = 0; i < result.Count; i++) { RMSObject amsObj = new RMSObject(); if (item.BaseAlarmSignal != null) { amsObj.OrganizationName = item.BaseAlarmSignal.OrganizationName; amsObj.DeviceName = item.BaseAlarmSignal.DeviceName; amsObj.ItemName = item.BaseAlarmSignal.ItemName; } else if (item.Parent is OrganizationTreeItemViewModel)//回收站 { amsObj.OrganizationName = "回收站"; amsObj.DeviceName = item.ServerIP; amsObj.ItemName = item.Name; } amsObj.ACQDatetime = result[i].ACQDatetime; amsObj.Result = result[i].Result.Value; amsObj.Unit = result[i].Unit; amsObj.AlarmGrade = (AlarmGrade)(result[i].AlarmGrade & 0x00ffff00); if (item.T_Item.ItemType == (int)ChannelType.WirelessVibrationChannelInfo) { if (vInfoCollection.Where(p => p.OrganizationName == amsObj.OrganizationName && p.DeviceName == amsObj.DeviceName && p.ItemName == amsObj.ItemName && p.ACQDatetime == amsObj.ACQDatetime).Count() == 0) //去重 { vInfoCollection.Add(amsObj); } } else if (item.T_Item.ItemType == (int)ChannelType.WirelessScalarChannelInfo) { if (anInfoCollection.Where(p => p.OrganizationName == amsObj.OrganizationName && p.DeviceName == amsObj.DeviceName && p.ItemName == amsObj.ItemName && p.ACQDatetime == amsObj.ACQDatetime).Count() == 0) //去重 { anInfoCollection.Add(amsObj); } } } }
private async void AddData(object para) { if (SelectedTreeItem == null) { #if XBAP MessageBox.Show("请选中要查询的组织机构", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); #else Xceed.Wpf.Toolkit.MessageBox.Show("请选中要查询的组织机构", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); #endif return; } if (Unit == null || Unit == "") { #if XBAP MessageBox.Show("请选择要查询的测点的数据类型", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); #else Xceed.Wpf.Toolkit.MessageBox.Show("请选择要查询的测点的数据类型", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); #endif return; } if (SelectedTreeItem is ItemTreeItemViewModel) { if ((SelectedTreeItem as ItemTreeItemViewModel).T_Item != null && (SelectedTreeItem as ItemTreeItemViewModel).T_Item.ItemType == (int)ChannelType.WirelessScalarChannelInfo) { AnInfoSelected = true; } if ((SelectedTreeItem as ItemTreeItemViewModel).T_Item != null && (SelectedTreeItem as ItemTreeItemViewModel).T_Item.ItemType == (int)ChannelType.WirelessVibrationChannelInfo) { VInfoSelected = true; } } string conditionWave; string conditionAlarm; object[] objectWave; object[] objectAlarm; ConditionClass.GetConditionStr(out conditionWave, out conditionAlarm, out objectWave, out objectAlarm, AllowNormal, AllowPreWarning, AllowWarning, AllowDanger, AllowInvalid, AllowRPMFilter, Unit, DownRPMFilter, UpRPMFilter); string selectedip = _cardProcess.GetOrganizationServer(SelectedTreeItem); #region 分频 var divfre = SelectedTreeItem as DivFreTreeItemViewModel; if (divfre != null) { try { WaitInfo = "获取数据中"; Status = ViewModelStatus.Querying; var item_parent = divfre.Parent as ItemTreeItemViewModel; var divfreinfo = divfre.T_DivFreInfo; if (divfreinfo == null) { return; } //var channel = _cardProcess.GetChannel(_hardwareService.ServerTreeItems, item_parent.T_Item); //if (channel == null || channel.IChannel == null) //{ // return; //} var result = await _databaseComponent.GetHistoryData <D1_DivFreInfo>(selectedip, divfreinfo.Guid, null, StartTime.Value, EndTime.Value, null, null); if (result.Count == 0) { #if XBAP MessageBox.Show("没有数据,请重新选择条件", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); #else Xceed.Wpf.Toolkit.MessageBox.Show("没有数据,请重新选择条件", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); #endif return; } List <IBaseDivfreSlot> slotdata = null; switch (item_parent.T_Item.ItemType) { case (int)ChannelType.IEPEChannelInfo: { var resultslot = await _databaseComponent.GetHistoryData <D_IEPESlot>(selectedip, item_parent.T_Item.Guid, null, StartTime.Value, EndTime.Value, null, null); if (resultslot.Count == 0) { return; } slotdata = resultslot.Select(p => p as IBaseDivfreSlot).ToList(); break; } case (int)ChannelType.EddyCurrentDisplacementChannelInfo: { var resultslot = await _databaseComponent.GetHistoryData <D_EddyCurrentDisplacementSlot>(selectedip, item_parent.T_Item.Guid, null, StartTime.Value, EndTime.Value, null, null); if (resultslot.Count == 0) { return; } slotdata = resultslot.Select(p => p as IBaseDivfreSlot).ToList(); break; } case (int)ChannelType.WirelessVibrationChannelInfo: { string unit = Unit; var resultslot = await _databaseComponent.GetHistoryData <D_WirelessVibrationSlot>(selectedip, item_parent.T_Item.Guid, null, StartTime.Value, EndTime.Value, conditionWave, new object[] { unit, DownRPMFilter, UpRPMFilter }); if (resultslot.Count == 0) { return; } slotdata = resultslot.Select(p => p as IBaseDivfreSlot).ToList(); break; } default: return; } if (slotdata == null) { return; } for (int i = 0; i < result.Count; i++) { DivFreObject divFreObj = new DivFreObject(); divFreObj.OrganizationName = item_parent.BaseAlarmSignal.OrganizationName; divFreObj.DeviceName = item_parent.BaseAlarmSignal.DeviceName; divFreObj.ItemName = item_parent.BaseAlarmSignal.ItemName; divFreObj.DivFreName = divfre.Name; var data = (from p in slotdata where p.RecordLab == result[i].RecordLab select new { p.ACQDatetime, p.Unit }).SingleOrDefault(); if (data == null) { return; } divFreObj.ACQDatetime = data.ACQDatetime; divFreObj.DescriptionFre = result[i].DescriptionFre; divFreObj.Result = result[i].Result.Value; //divFreObj.Phase = result[i].Phase; divFreObj.Unit = data.Unit; if (divFreCollection.Where(p => p.OrganizationName == divFreObj.OrganizationName && p.DeviceName == divFreObj.DeviceName && p.ItemName == divFreObj.ItemName && p.DivFreName == divFreObj.DivFreName && p.ACQDatetime == divFreObj.ACQDatetime).Count() == 0) //去重 { divFreCollection.Add(divFreObj); } } } catch (Exception ex) { _eventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-分频查询", ex)); } finally { Status = ViewModelStatus.None; } return; } #endregion #region 测点 var item = SelectedTreeItem as ItemTreeItemViewModel; if (item != null) { if (item.T_Item != null && item.T_Item.ItemType != 0) { try { WaitInfo = "获取数据中"; Status = ViewModelStatus.Querying; await SubAddData(item, conditionWave, conditionAlarm, objectWave, objectAlarm); } catch (Exception ex) { _eventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-测点查询", ex)); } finally { Status = ViewModelStatus.None; } return; } else { #if XBAP MessageBox.Show("该测点没绑定或无信息", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); #else Xceed.Wpf.Toolkit.MessageBox.Show("该测点无信息", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); #endif return; } } #endregion #region 组织机构 if (SelectedTreeItem != null) { try { WaitInfo = "获取数据中"; Status = ViewModelStatus.Querying; var items = _cardProcess.GetItems(SelectedTreeItem).Where(p => p.IsPaired); foreach (var subitem in items) { await SubAddData(subitem, conditionWave, conditionAlarm, objectWave, objectAlarm, false); } } catch (Exception ex) { _eventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-测点批量查询", ex)); } finally { Status = ViewModelStatus.None; } return; } #endregion }
//A More exact Mouse In PolygonCheck public static bool MouseIsInPolygon(FastObservableCollection<INode> poly, PolyPoint point) { Vector3 vecPoint = new Vector3(point.X, point.Y,0); var tempList = new FastObservableCollection<INode>(); foreach (var node in poly) { tempList.Add(node); } //Copy the list so we can add the last two verts into the start so we can get a full circle check easy. tempList.Insert(0,tempList[tempList.Count-2]); tempList.Insert(0,tempList[tempList.Count-1]); for (int i = 1; i < tempList.Count - 2; i++) { //we'll feed 3 verts at a time to PointInTriangle to see if it returns true or not. If one time returns true then we can stop calculating Vector3 A = new Vector3((tempList[0] as PolyPoint).X, (tempList[0] as PolyPoint).Y ,0); Vector3 B = new Vector3((tempList[i + 1] as PolyPoint).X, (tempList[i + 1] as PolyPoint).Y,0); Vector3 C = new Vector3((tempList[i + 2] as PolyPoint).X, (tempList[i + 2] as PolyPoint).Y,0); if (PointInTriangle(ref A, ref B, ref C, ref vecPoint)) { return true; } } return false; }
public void HandlesClearOfSuspendedFastObservableCollectionCorrectly() { var collection = new FastObservableCollection<TestModel>(); TestModel model = null; for (int i = 0; i < 10; i++) { var randomModel = new TestModel(); collection.Add(randomModel); } model = collection[0]; var wrapper = new ChangeNotificationWrapper(collection); var collectionItemPropertyChanged = false; wrapper.CollectionItemPropertyChanged += (sender, e) => collectionItemPropertyChanged = true; using (collection.SuspendChangeNotifications()) { collection.Clear(); } model.FirstName = "Geert"; Assert.IsFalse(collectionItemPropertyChanged); }
public void HandlesCollectionChangesByResetCorrectly() { var collection = new FastObservableCollection<TestModel>(); var wrapper = new ChangeNotificationWrapper(collection); var itemsReset = false; var itemsAdded = false; var itemsRemoved = false; var model = new TestModel(); collection.Add(model); wrapper.CollectionChanged += (sender, e) => { if (e.OldItems != null) { itemsRemoved = true; } if (e.Action == NotifyCollectionChangedAction.Reset) { itemsReset = true; } if (e.NewItems != null) { itemsAdded = true; } }; using (collection.SuspendChangeNotifications()) { collection.ReplaceRange(new [] { new TestModel() }); } Assert.IsFalse(itemsAdded); Assert.IsFalse(itemsRemoved); Assert.IsTrue(itemsReset); }
private FastObservableCollection<AgentViewModel> CreateSimulatedField(Landscape landscape) { var columnsCount = landscape.GetColumnsCount(); var rowsCount = landscape.GetRowsCount(); var cells = new FastObservableCollection<AgentViewModel>(); for (int i = 0; i < columnsCount * rowsCount; i++) { cells.Add(new AgentViewModel(VisualAgentType.None)); } foreach (var plant in landscape.Plants) { if (plant == null) { continue; } var cellIndex = GetCellIndex(plant, columnsCount); cells[cellIndex] = new AgentViewModel(VisualAgentType.Plant); } var agents = new List<AgentViewModel>(landscape.Agents.Length); foreach (var agent in landscape.Agents) { if (agent == null) { continue; } var cellIndex = GetCellIndex(agent, columnsCount); var type = VisualAgentType.None; switch (agent.Type) { case AgentType.Herbivore: type = VisualAgentType.Herbivore; break; case AgentType.Carnivore: type = VisualAgentType.Carnivore; break; } var agentViewModel = new AgentViewModel(type, agent); cells[cellIndex] = agentViewModel; agents.Add(agentViewModel); } AliveAgents.ReplaceRange(agents); return cells; }
public void ReturnsSingleElementUsingLinq() { var fastCollection = new FastObservableCollection<int>(); for (int i = 0; i < 43; i++) { fastCollection.Add(i); } var allInts = (from x in fastCollection where x == 42 select x).FirstOrDefault(); Assert.AreEqual(42, allInts); }
private void AddLogEntries(List <LogEntry> entries, bool bypassClearingLog = false) { if (!bypassClearingLog && _isClearingLog) { return; } _dispatcherService.BeginInvoke(() => { var filteredLogEntries = new List <LogEntry>(); var typeNames = TypeNames; var requireSorting = false; lock (_lock) { using (SuspendChangeNotifications()) { using (_logEntries.SuspendChangeNotifications()) { foreach (var entry in entries) { _logEntries.Add(entry); if (IsValidLogEntry(entry)) { filteredLogEntries.Add(entry); } var targetTypeName = entry?.Log?.TargetType?.Name ?? string.Empty; if (typeNames.Contains(targetTypeName)) { continue; } try { typeNames.Add(targetTypeName); requireSorting = true; } catch (Exception) { // we don't have time for this, let it go... } } } } } UpdateEntriesCount(entries); if (requireSorting) { lock (_lock) { using (typeNames.SuspendChangeNotifications()) { typeNames.Sort(); typeNames.Remove(_defaultComboBoxItem); typeNames.Insert(0, _defaultComboBoxItem); } } } LogMessage?.Invoke(this, new LogEntryEventArgs(entries, filteredLogEntries)); }); }