Ejemplo n.º 1
0
        private void ShotCommand_Execute()
        {
            TransmitData data = new TransmitData()
            {
                CanId   = (int)this.CanId,
                IsExtId = this.IsExtId,
                DLC     = (int)this.DLC,
                Payload = this.Payload.ToArray()
            };

            var results = new List <ValidationResult>();

            if (!Validator.TryValidateObject(data, new ValidationContext(data), results, true))
            {
                foreach (var error in results)
                {
                    MessageBox.Show(error.ErrorMessage, (string)Manager <LanguageCultureInfo> .StaticInstance.GetResource("#WarningMsgBoxTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
                }

                if (Status == TransmitState.Transmiting)
                {
                    RunCommand.Execute();
                }

                return;
            }

            Task.Run(() => { TransmitToSelectedChannels?.Invoke(data); });
        }
Ejemplo n.º 2
0
        private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (sender != Items)
            {
                return;
            }

            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                foreach (var el in e.NewItems)
                {
                    //filtering
                    if (el is TraceModel model)
                    {
                        bool isFiltered = false;

                        foreach (var filter in Filters)
                        {
                            if (filter.FilterOne(model))
                            {
                                isFiltered = true;
                                break;
                            }
                        }


                        if (!isFiltered)
                        {
                            _context.Post((s) =>
                            {
                                ShowedItems.Add(model);
                            }, null);
                        }

                        TransmitToSelectedChannels?.Invoke(new TransmitData()
                        {
                            CanId = model.CanHeader.CanId, DLC = model.CanHeader.DLC, IsExtId = model.CanHeader.IsExtId, Payload = model.Payload
                        });
                    }
                }
            }

            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
            {
                lock (currentTraceProvider)
                {
                    currentTraceProvider.RemoveAll();
                    currentTraceProvider.SaveChanges();
                }



                _context.Post((s) =>
                {
                    ShowedItems.Clear();
                }, null);
            }
        }
        public void Shot()
        {
            Task.Run(() =>
            {
                if (TransmitToSelectedChannels == null)
                {
                    return;
                }

                var dataToTrasmit = new TransmitData()
                {
                    CanId = (int)Model.CanId, DLC = Model.DLC, IsExtId = Model.IsExtId, Payload = Model.Payload.ToByteArray()
                };
                if (!Validator.TryValidateObject(dataToTrasmit, new ValidationContext(dataToTrasmit), null, true))
                {
                    StopTransmiting();
                    return;
                }

                TransmitToSelectedChannels.Invoke(dataToTrasmit);

                Count++;
            });
        }