view Agendas/trunk/src/Agendas.Google/GooglePublicador.cs @ 133:6f1041301797

Se agregan los estados Cancelado y Descartado con las acciones Cancelar, Reagendar, Descartar, Reproponer, según ticket 146. Falta solucionar problema con flujo, ver más información en el ticket de assembla. http://www.assembla.com/spaces/altnet-hispano/tickets/146-implementar-estado-descartar-y-cancelar-de-eventos
author alabra
date Sun, 10 Jul 2011 23:59:19 -0400
parents 0ea32a748453
children 80156ae1493f
line wrap: on
line source

using System.Collections.Generic;
using System.Configuration;
using AltNetHispano.Agendas.Domain;
using AltNetHispano.Agendas.Google.DetailsEvents;

namespace AltNetHispano.Agendas.Google
{
	public class GooglePublicador : IPublicador
	{
	    private readonly IGCalendarAdapter _adapter;
        private readonly IDictionary<TipoEvento, IGEventDetail> _gEventDetails;
        
        private static string GetUserName
        {
            get { return ConfigurationManager.AppSettings["userNameGoogleCalendar"]; }
        }

	    private static string GetPassword
	    {
            get { return ConfigurationManager.AppSettings["passwordGoogleCalendar"]; }
	    }

	    private static string GetCalendarId
	    {
            get { return ConfigurationManager.AppSettings["calendarIdGoogleCalendar"]; }
	    }

	    public void Publicar(IEnumerable<Track> tracks)
		{
		    foreach (var track in tracks)
		    {
		        if (track.Accion == Accion.Agendar)
                    PublicarAccionAgendar(track);
		    }
		}

        private void PublicarAccionAgendar(Track track)
        {
            string message;
            _gEventDetails[track.Evento.Tipo].Generate(track.Evento);
            var result = _adapter.CreateEvent(_gEventDetails[track.Evento.Tipo], out message);
            track.LogAdd(new TrackLog(TrackLogPropietario.Calendario, message, track.Usuario, result));
        }

        public GooglePublicador()
            : this(new GCalendarAdapter("VAN", GetUserName, GetPassword, GetCalendarId))
        {
        }

	    public GooglePublicador(IGCalendarAdapter gCalendarAdapter)
	    {
	        _adapter = gCalendarAdapter;

	        _gEventDetails = new Dictionary<TipoEvento, IGEventDetail>
	                             {
	                                 {TipoEvento.Van, new VanGEventDetail()},
	                                 {TipoEvento.Cafe, new CafeGEventDetail()},
	                                 {TipoEvento.GrupoEstudio, new EstudioGEventDetail()}
	                             };
	    }
	}
}