EventGroup.cs 1.3 KB
using Model;
using System;
using System.Collections.Generic;
using System.Linq;

namespace ExtensionGroup
{
    public class EventGroup
    {
        public event IExtension.PrintDelegate Printing;

        private readonly Dictionary<string, IExtension> extEvent;
        private readonly Alcoelectro alcoelectro = new();
        private readonly Inventec inventec = new();
        private readonly PanaCIM panaCIM = new();
        private readonly Item_NanRui nanRui = new();
        private readonly KaiFa kaiFa = new();

        public EventGroup()
        {
            extEvent = new()
            {
                { "Bwit", alcoelectro },
                { "Inventec", inventec },
                { "PanaCIM", panaCIM },
                { "NanRui", nanRui },
                { "KaiFa", kaiFa }
            };

            for (int i = 0; i < extEvent.Count; i++)
                extEvent.ElementAt(i).Value.Printing += Group_Printing;
        }

        public IExtension GetEventGroup(string name)
        {
            if (extEvent.ContainsKey(name))
                return extEvent[name];
            else
                return null;
        }

        private void Group_Printing(Dictionary<string, string> content)
        {
            Printing?.Invoke(content);
        }

    }
}