HamBook – Rev 10

Subversion Repositories:
Rev:
using Configuration.Annotations;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;
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 RJCP.IO.Ports.Parity _parity = RJCP.IO.Ports.Parity.None;
        private RJCP.IO.Ports.StopBits _stopBits = RJCP.IO.Ports.StopBits.One;
        private Definitions _definitions = new Definitions();
        private RJCP.IO.Ports.Handshake _handshake = RJCP.IO.Ports.Handshake.None;
        private SerialPortTimeout _serialPortTimeout = new SerialPortTimeout();
        private int _scanDetectPause = 10;
        private Audio _audio = new Audio();

        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 int ScanDetectPause
        {
            get => _scanDetectPause;
            set
            {
                if (value == _scanDetectPause)
                {
                    return;
                }

                _scanDetectPause = value;
                OnPropertyChanged();
            }
        }

        public RJCP.IO.Ports.Parity Parity
        {
            get => _parity;
            set
            {
                if (value == _parity)
                {
                    return;
                }

                _parity = value;
                OnPropertyChanged();
            }
        }

        public RJCP.IO.Ports.StopBits StopBits
        {
            get => _stopBits;
            set
            {
                if (value == _stopBits)
                {
                    return;
                }

                _stopBits = value;
                OnPropertyChanged();
            }
        }

        public RJCP.IO.Ports.Handshake Handshake
        {
            get => _handshake;
            set
            {
                if (value == _handshake)
                {
                    return;
                }

                _handshake = value;
                OnPropertyChanged();
            }
        }

        public SerialPortTimeout SerialPortTimeout
        {
            get => _serialPortTimeout;
            set
            {
                if (value == _serialPortTimeout)
                {
                    return;
                }

                _serialPortTimeout = value;
                OnPropertyChanged();
            }
        }

        public Definitions Definitions
        {
            get => _definitions;
            set
            {
                if (value == _definitions)
                {
                    return;
                }

                _definitions = value;
                OnPropertyChanged();
            }
        }

        public Audio Audio
        {
            get => _audio;
            set
            {
                if (value == _audio)
                {
                    return;
                }

                _audio = value;
                OnPropertyChanged();
            }
        }

        public Configuration()
        {
        }

        public event PropertyChangedEventHandler PropertyChanged;

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