HamBook – Rev 1

Subversion Repositories:
Rev:
using Configuration.Annotations;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO.Ports;
using System.Runtime.CompilerServices;
using System.Xml.Serialization;

namespace Configuration
{
    [XmlRoot(Namespace = "urn:hambook-configuration-schema", ElementName = "Configuration")]
    public class Configuration : INotifyPropertyChanged
    {
        private bool _launchOnBoot = false;

        private string _radio = "Yaesu FT-891";
        private string _port = "COM1";
        private int _speed = 38400;
        private int _dataBits = 8;
        private Parity _parity = Parity.None;
        private StopBits _stopBits = StopBits.One;

        public bool LaunchOnBoot
        {
            get => _launchOnBoot;
            set
            {
                if (value == _launchOnBoot)
                {
                    return;
                }

                _launchOnBoot = value;
                OnPropertyChanged();
            }
        }

        public string Radio
        {
            get => _radio;
            set
            {
                if (value == _radio)
                {
                    return;
                }

                _radio = value;
                OnPropertyChanged();
            }
        }

        public string Port
        {
            get => _port;
            set
            {
                if (value == _port)
                {
                    return;
                }

                _port = value;
                OnPropertyChanged();
            }
        }

        public int Speed
        {
            get => _speed;
            set
            {
                if (value == _speed)
                {
                    return;
                }

                _speed = value;
                OnPropertyChanged();
            }
        }

        public int DataBits
        {
            get => _dataBits;
            set
            {
                if (value == _dataBits)
                {
                    return;
                }

                _dataBits = value;
                OnPropertyChanged();
            }
        }

        public Parity Parity
        {
            get => _parity;
            set
            {
                if (value == _parity)
                {
                    return;
                }

                _parity = value;
                OnPropertyChanged();
            }
        }

        public StopBits StopBits
        {
            get => _stopBits;
            set
            {
                if (value == _stopBits)
                {
                    return;
                }

                _stopBits = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}