HamBook – Rev 12

Subversion Repositories:
Rev:
using Configuration.Annotations;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Configuration
{
    public class Notifications : INotifyPropertyChanged
    {
        
        private NotificationState[] _notificationState = new NotificationState[]
        {
            new NotificationState() { Type = NotificationType.SignalScanDetect, Enabled = false, LingerTime = 1000 },
        };

        public NotificationState[] State
        {
            get => _notificationState;
            set
            {
                if (value == _notificationState)
                {
                    return;
                }

                _notificationState = value;
                OnPropertyChanged();
            }
        }

        public Notifications()
        {
            if (_notificationStates.Count == 0)
            {
                foreach (var state in _notificationState)
                {
                    _notificationStates.TryAdd(state.Type, state);
                }
            }
        }

        public bool TryGetNotificationState(NotificationType notificationType, out NotificationState notificationState)
        {
            return _notificationStates.TryGetValue(notificationType, out notificationState);
        }

        private static ConcurrentDictionary<NotificationType, NotificationState> _notificationStates = new ConcurrentDictionary<NotificationType, NotificationState>();

        public event PropertyChangedEventHandler PropertyChanged;

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