Mercurial > altnet-hispano
changeset 127:3700b77ed455
Configuracion de publicadores
author | jorge.rowies |
---|---|
date | Sat, 02 Jul 2011 21:50:05 -0300 |
parents | 6012f2becf97 |
children | 1e47bf408073 |
files | Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj Agendas/trunk/src/Agendas.Tests/App.config Agendas/trunk/src/Agendas.Tests/PublicadoresConfigTests.cs Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj Agendas/trunk/src/Agendas.Web/PublicadoresConfig.cs Agendas/trunk/src/Agendas.Web/Web.config |
diffstat | 6 files changed, 153 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj Tue Jun 28 23:35:22 2011 -0400 +++ b/Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj Sat Jul 02 21:50:05 2011 -0300 @@ -83,6 +83,7 @@ <Compile Include="Cruds\EventoTests.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="AgendarTests.cs" /> + <Compile Include="PublicadoresConfigTests.cs" /> <Compile Include="TestBase.cs" /> <Compile Include="TrackTests.cs" /> <Compile Include="Workflows\Workflow.cs" /> @@ -113,6 +114,10 @@ <Project>{0973DF44-3B90-4D2A-B579-C64C93B6C853}</Project> <Name>Agendas.Repositories.NHibernate</Name> </ProjectReference> + <ProjectReference Include="..\Agendas.Web\Agendas.Web.csproj"> + <Project>{319A8E3D-C61E-455F-A1BF-A6B1B1636BAB}</Project> + <Name>Agendas.Web</Name> + </ProjectReference> </ItemGroup> <ItemGroup> <None Include="App.config">
--- a/Agendas/trunk/src/Agendas.Tests/App.config Tue Jun 28 23:35:22 2011 -0400 +++ b/Agendas/trunk/src/Agendas.Tests/App.config Sat Jul 02 21:50:05 2011 -0300 @@ -1,6 +1,19 @@ <?xml version="1.0" encoding="utf-8" ?> <configuration> + + <configSections> + <section name="publicadoresSection" type="AltNetHispano.Agendas.Web.PublicadorConfigurationSection, AltNetHispano.Agendas.Web"/> + </configSections> + <connectionStrings> <add name="AltNetHispano" connectionString="Data Source=.\sqlexpress;Initial Catalog=AltNetHispano_Test;Integrated Security=SSPI"/> </connectionStrings> + + <publicadoresSection> + <publicadores> + <add name="Blog" type="Agendas.Blog.Impl.BlogPublicador, Agendas.Blog" enabled="false"/> + <add name="Twitter" type="AltNetHispano.Agendas.Twitter.TwitterPublicador, AltNetHispano.Agendas.Twitter" enabled="true"/> + </publicadores> + </publicadoresSection> + </configuration> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Tests/PublicadoresConfigTests.cs Sat Jul 02 21:50:05 2011 -0300 @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using AltNetHispano.Agendas.Web; +using NUnit.Framework; + +namespace AltNetHispano.Agendas.Tests +{ + [TestFixture] + public class PublicadoresConfigTests + { + [Test] + public void TestConfig() + { + var cfg = ConfigurationManager.GetSection("publicadoresSection") as PublicadorConfigurationSection; + + Assert.IsNotNull(cfg); + Assert.AreEqual(2, cfg.Publicadores.Count); + Assert.AreEqual("Agendas.Blog.Impl.BlogPublicador", cfg.Publicadores["Blog"].GetPublicadorType().FullName); + Assert.AreEqual(false, cfg.Publicadores["Blog"].Enabled); + Assert.AreEqual("AltNetHispano.Agendas.Twitter.TwitterPublicador", cfg.Publicadores["Twitter"].GetPublicadorType().FullName); + Assert.AreEqual(true, cfg.Publicadores["Twitter"].Enabled); + } + } +}
--- a/Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj Tue Jun 28 23:35:22 2011 -0400 +++ b/Agendas/trunk/src/Agendas.Web/Agendas.Web.csproj Sat Jul 02 21:50:05 2011 -0300 @@ -82,6 +82,7 @@ <Compile Include="Models\PerfilModel.cs" /> <Compile Include="Models\PropuestaModel.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="PublicadoresConfig.cs" /> <Compile Include="Services\AccountMembershipService.cs" /> <Compile Include="Services\FormsAuthenticationService.cs" /> <Compile Include="Services\IFormsAuthenticationService.cs" /> @@ -165,6 +166,10 @@ <Content Include="Views\Evento\Proponer.cshtml" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\Agendas.Blog\Agendas.Blog.csproj"> + <Project>{DDD605FF-EF42-428A-AEB6-F3496A46A82B}</Project> + <Name>Agendas.Blog</Name> + </ProjectReference> <ProjectReference Include="..\Agendas.Domain\Agendas.Domain.csproj"> <Project>{A14907DF-02E4-4FA7-BE27-4292AF50AA22}</Project> <Name>Agendas.Domain</Name>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Web/PublicadoresConfig.cs Sat Jul 02 21:50:05 2011 -0300 @@ -0,0 +1,88 @@ +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("type", IsRequired = true)] + public string Type + { + get + { + return (string)this["type"]; + } + } + + public Type GetPublicadorType() + { + return System.Type.GetType((string) this["type"]); + } + + [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; + } + } + } +} \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Web/Web.config Tue Jun 28 23:35:22 2011 -0400 +++ b/Agendas/trunk/src/Agendas.Web/Web.config Sat Jul 02 21:50:05 2011 -0300 @@ -1,10 +1,14 @@ <?xml version="1.0"?> <!-- - For more information on how to configure your ASP.NET application, please visit - http://go.microsoft.com/fwlink/?LinkId=152368 - --> + For more information on how to configure your ASP.NET application, please visit + http://go.microsoft.com/fwlink/?LinkId=152368 + --> <configuration> + <configSections> + <section name="publicadoresSection" type="AltNetHispano.Agendas.Web.PublicadorConfigurationSection, AltNetHispano.Agendas.Web"/> + </configSections> + <connectionStrings> <add name="ApplicationServices" connectionString="Data Source=.\sqlexpress;Initial Catalog=AltNetHispano;Integrated Security=SSPI" providerName="System.Data.SqlClient" /> <add name="AltNetHispano" connectionString="Data Source=.\sqlexpress;Initial Catalog=AltNetHispano;Integrated Security=SSPI"/> @@ -90,4 +94,12 @@ </dependentAssembly> </assemblyBinding> </runtime> + + <publicadoresSection> + <publicadores> + <add name="Blog" type="Agendas.Blog.Impl.BlogPublicador, Agendas.Blog" enabled="false"/> + <add name="Twitter" type="AltNetHispano.Agendas.Twitter.TwitterPublicador, AltNetHispano.Agendas.Twitter" enabled="false"/> + </publicadores> + </publicadoresSection> + </configuration> \ No newline at end of file