private void UpdateDataAndFilters_Execute() { try { var newFilters = new List <CanIdTraceFilter>(); foreach (var el in currentTraceProvider.CanHeaders.ToList()) { if (newFilters.Count(x => x.CanId == el.CanId && x.IsExtId == el.IsExtId) == 0) { CanIdTraceFilter entity = new CanIdTraceFilter(el.CanId, el.IsExtId); entity.PropertyChanged += FilterIsActive_PropertyChanged; newFilters.Add(entity); } } Filters = newFilters.OrderBy(x => x.CanId).ToList(); UpdateDataCommand.Execute(); } catch (Exception e) { MessageBox.Show(e.ToString(), (string)Manager <LanguageCultureInfo> .StaticInstance.GetResource("#ErrorMsgBoxTitle"), MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Channel_ReceivedData(object sender, CANAnalyzerDevices.Devices.DeviceChannels.Events.ChannelDataReceivedEventArgs e) { if (RecieveState != RecieveState.Recieving || sender != Channel || currentTraceProvider == null) { return; } TraceModel model = new TraceModel() { Time = e.Data.Time, Payload = e.Data.Payload }; //проверка на существование такого же CanHeader'a List <CanHeaderModel> canHeaders; int filtersCount; lock (currentTraceProvider) { canHeaders = currentTraceProvider.CanHeaders.Where(x => (x.IsExtId == e.Data.IsExtId) && (x.CanId == e.Data.CanId) && (x.DLC == e.Data.DLC)).Take(1).ToList(); filtersCount = currentTraceProvider.CanHeaders.Where(x => (x.IsExtId == e.Data.IsExtId) && (x.CanId == e.Data.CanId)).Count(); //если такого CanHeader'a нет, то создаем, добавляем в БД if (canHeaders.Count == 0) { canHeaders.Add(new CanHeaderModel() { IsExtId = e.Data.IsExtId, CanId = e.Data.CanId, DLC = e.Data.DLC }); currentTraceProvider.Add(canHeaders[0]); lock (currentTraceProvider) { currentTraceProvider.SaveChanges(); } } //если появился новый CAN ID if (filtersCount == 0) { CanIdTraceFilter filter = new CanIdTraceFilter(e.Data.CanId, e.Data.IsExtId); filter.PropertyChanged += FilterIsActive_PropertyChanged; _context.Post((s) => { Filters.Add(filter); Filters = new BindingList <ITraceFilter>(Filters.OrderBy(x => x.ToString()).ToList()); }, null); } } model.CanHeader = canHeaders[0]; currentTraceProvider.Add(model); _context.Post((s) => { Items.Add(model); }, null); }