view Agendas/trunk/src/Agendas.Web/PublicadoresConfig.cs @ 128:1e47bf408073

Asignacion de los publicadores configurados en web.config al factory de agenda (mediante CompositePublicador)
author jorge.rowies
date Mon, 04 Jul 2011 20:00:51 -0300
parents 3700b77ed455
children
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Reflection;

namespace AltNetHispano.Agendas.Web
{
	public class PublicadorConfigurationElement : ConfigurationElement
	{
		[ConfigurationProperty("name", IsRequired = true)]
		public string Name
		{
			get { return (string)this["name"]; }
		}

		[ConfigurationProperty("componentKey", IsRequired = true)]
		public string ComponentKey
		{
			get
			{
				return (string)this["componentKey"];
			}
		}

		[ConfigurationProperty("enabled", IsRequired = true)]
		public bool Enabled
		{
			get { return (bool)this["enabled"]; }
		}
	}

	[ConfigurationCollection(typeof(PublicadorConfigurationElement))]
	public class PublicadorConfigurationCollection : ConfigurationElementCollection
	{
		protected override ConfigurationElement CreateNewElement()
		{
			return new PublicadorConfigurationElement();
		}

		protected override object GetElementKey(ConfigurationElement element)
		{
			var value = element as PublicadorConfigurationElement;
			return value != null ? value.Name : null;
		}

		public PublicadorConfigurationElement this[int index]
		{
			get
			{
				return BaseGet(index) as PublicadorConfigurationElement;
			}
			set
			{
				if (BaseGet(index) != null)
					BaseRemoveAt(index);
				BaseAdd(index, value);
			}
		}

		public new PublicadorConfigurationElement this[string name]
		{
			get
			{
				return BaseGet(name) as PublicadorConfigurationElement;
			}
		}
	}

	public class PublicadorConfigurationSection : ConfigurationSection
	{
		[ConfigurationProperty("publicadores", IsRequired = true)]
		public PublicadorConfigurationCollection Publicadores
		{
			get
			{
				return this["publicadores"]
					 as PublicadorConfigurationCollection;
			}
		}
	}
}