view Agendas/trunk/src/Agendas.Google/GooglePublicador.cs @ 266:dba5d41bc7bf

BUG: Guardar persona con twitter ya existente genera error.
author juanjose.montesdeocaarbos
date Tue, 25 Oct 2011 23:22:10 -0300
parents cd96cfc8a1f5
children
line wrap: on
line source

using System;
using System.Collections.Generic;
using AltNetHispano.Agendas.Configurations;
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 AgendasConfigurationManager.Publicadores.Google.Calendar.UserName; }
        }

	    private static string GetPassword
	    {
			get { return AgendasConfigurationManager.Publicadores.Google.Calendar.Password; }
	    }

	    private static string GetCalendarId
	    {
			get { return AgendasConfigurationManager.Publicadores.Google.Calendar.CalendarId; }
	    }

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

		    foreach (var track in tracks)
		    {
		    	try
		    	{
		    		switch (track.Accion)
		    		{
		    			case Accion.Agendar:
		    				PublicarAccionAgendar(track);
		    				break;
		    			case Accion.Cancelar:
		    				PublicarAccionCancelar(track);
		    				break;
		    		}
		    	}
		    	catch (Exception ex)
		    	{
		    		track.LogAdd(new TrackLog(TrackLogPropietario.Calendario, track.Usuario, ex));
		    	}
		    }
		}

	    private void PublicarAccionCancelar(Track track)
	    {
            string message;
	        var result= _adapter.DeleteEvent(track.Evento.FechaInicio.Value, track.Evento.FechaTermino.Value, out message);
            track.LogAdd(new TrackLog(TrackLogPropietario.Calendario, message, track.Usuario, result));
	    }

		private void PublicarAccionAgendar(Track track)
		{
			_gEventDetails[track.Evento.Tipo].Generate(track.Evento);
			string message;
			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()}
	                             };
	    }
	}
}