view Agendas/trunk/src/Agendas.Blog/Impl/BlogPublicador.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 c3573defd18f
children
line wrap: on
line source

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

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

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

		public void Publicar(IEnumerable<Track> tracks)
		{
			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, ex.Message, track.Usuario, false));
				}
			}
		}
	}
}