示例#1
0
        public static void Execute()
        {
            var notifications = new List <Notification>
            {
                new(NotificationType.Email, "Email A"),
                new(NotificationType.ConnectDirect, "File X"),
                new(NotificationType.Nexxera, "File Y")
            };

            notifications.ForEach(notification => NotifierFactory.Create(notification).Send());
        }
示例#2
0
        private static IEnumerable <INotifier> GenerateNotifiers(ILogger logger, IConfiguration configuration)
        {
            logger.LogInformation("Processing notifier config.");

            List <INotifier> notifiers = new List <INotifier>();

            IConfigurationSection section = configuration.GetSection("Notifiers");

            foreach (IConfigurationSection child in section.GetChildren())
            {
                string type = child.GetValue <string>("Type");

                if (!Enum.TryParse(type, out NotifierType notifier))
                {
                    logger.LogError($"Notifier Type '{ type }' is not supported.");
                    throw new NotImplementedException(type);
                }

                notifiers.Add(NotifierFactory.Create(notifier, logger, child));
            }

            return(notifiers);
        }