Exemple #1
0
 private void MainWindow_OnClosing(object sender, CancelEventArgs e)
 {
     pollingThread?.CancelAsync();
     Settings.Default.PollData = new PollSaveDataParallelArrays {
         PollCommand = PollDataCollection.Select(data => data.PollCommand).ToArray(),
         IsPolling   = PollDataCollection.Select(data => data.IsPolling).ToArray(),
         Name        = PollDataCollection.Select(data => data.Name).ToArray()
     };
     ComCommand[] comCommands = ComCommandsPanel.Children.OfType <ComCommand>().ToArray();
     Settings.Default.ComCommands = new ComCommandSaveDataParallelArrays {
         Command = comCommands.Select(command => command.Command).ToArray(),
         Title   = comCommands.Select(command => command.Title).ToArray()
     };
     Settings.Default.IndividualPollInterval = IndividualPollInterval;
     foreach (PollData pollData in PollDataCollection)
     {
         pollData.Dispose();
     }
 }
Exemple #2
0
        public MainWindow()
        {
            PollSaveDataParallelArrays pollDataPArray = Settings.Default.PollData;

            for (var i = 0; i < pollDataPArray.Name.Length; i++)
            {
                PollDataCollection.Add(new PollData {
                    PollCommand = pollDataPArray.PollCommand[i],
                    IsPolling   = pollDataPArray.IsPolling[i],
                    Name        = pollDataPArray.Name[i]
                });
            }

            individualPollInterval = IndividualPollInterval = Settings.Default.IndividualPollInterval;
            DependencyPropertyDescriptor.FromProperty(IndividualPollIntervalProperty, typeof(MainWindow))
            .AddValueChanged(this,
                             (_, a) =>
                             individualPollInterval = IndividualPollInterval);

            InitializeComponent();

            ComCommandSaveDataParallelArrays cmdSavePArray = Settings.Default.ComCommands;

            for (var i = 0; i < cmdSavePArray.Title.Length; i++)
            {
                ComCommandsPanel.Children.Add(InitComCommand(new ComCommand {
                    Title   = cmdSavePArray.Title[i],
                    Command = cmdSavePArray.Command[i]
                }));
            }


            DependencyPropertyDescriptor isPollingPropdpDesc =
                DependencyPropertyDescriptor.FromProperty(PollData.IsPollingProperty, typeof(PollData));

            void PollDataIsPollingChanged(object _, EventArgs __) => OnPropertyChanged(nameof(AreAllPolling));

            foreach (PollData pollData in PollDataCollection)
            {
                isPollingPropdpDesc.AddValueChanged(pollData, PollDataIsPollingChanged);
            }

            PollDataCollection.CollectionChanged += (sender, args) => {
                if ((args.Action == NotifyCollectionChangedAction.Remove) ||
                    (args.Action == NotifyCollectionChangedAction.Replace) ||
                    (args.Action == NotifyCollectionChangedAction.Reset))
                {
                    foreach (PollData pollData in args.OldItems)
                    {
                        isPollingPropdpDesc.RemoveValueChanged(pollData, PollDataIsPollingChanged);
                        pollData.Dispose();
                    }
                }

                if (args.NewItems != null)
                {
                    foreach (PollData pollData in args.NewItems)
                    {
                        isPollingPropdpDesc.AddValueChanged(pollData, PollDataIsPollingChanged);
                    }
                }

                OnPropertyChanged(nameof(AreAllPolling));
            };

            ComConnection.I.DataReceived += OnComDataReceived;
        }
Exemple #3
0
 private void AddPollDataRow_OnClick(object sender, RoutedEventArgs e) => PollDataCollection.Add(new PollData());