view Agendas/trunk/src/Agendas.Blog/Impl/BlogPublicador.cs @ 298:9bc60d166c8a

Se corrigieron los tests por el cambio de Patrocinador, para que no persista el logo en disco. Se comentó el código de PatrocinadorApiController, que no se utiliza.
author juanjose.montesdeocaarbos
date Sun, 19 Feb 2012 16:00:38 -0300
parents 2a336a6a76b5
children
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.Linq;
using AltNetHispano.Agendas.Configurations;
using AltNetHispano.Agendas.Domain;

namespace Agendas.Blog.Impl
{
	public class BlogPublicador : IPublicador
	{
		private readonly IPostWriterFactory _postWriterFactory;

		public BlogPublicador()
			: this(
				new PostWriterFactory(
					new PostWriterWebServiceAdapter(
						new BlogPublicadorConfig(AgendasConfigurationManager.Publicadores.Blog.Writer.PostWriterServiceUrl,
						                         AgendasConfigurationManager.Publicadores.Blog.Writer.BlogName,
						                         AgendasConfigurationManager.Publicadores.Blog.Writer.BlogWriterMasterKey))))
		{
		}

		public BlogPublicador(IPostWriterFactory postWriterFactory)
		{
			_postWriterFactory = postWriterFactory;
		}

		public void Publicar(IEnumerable<Track> tracks)
		{
			if (!AgendasConfigurationManager.Publicadores.Blog.Enabled) return;

			foreach (var track in tracks)
			{
				if (track.Logs.Any(l => l.Propietario == TrackLogPropietario.Blog && l.Successful)) continue;

				try
				{
					_postWriterFactory.GetPostWriter(track.Accion).WritePost(track);
					track.LogAdd(new TrackLog(TrackLogPropietario.Blog, string.Empty, track.Usuario, true));
				}
				catch (Exception ex)
				{
					track.LogAdd(new TrackLog(TrackLogPropietario.Blog, track.Usuario, ex));
				}
			}
		}
	}
}