Using JobQueue

Topics: Writing modules
Jun 25, 2015 at 6:40 PM
Hi, im trying to queque a job in orchard jobqueue to run it asyncronously, i manage to do that but when the job is processed I am getting an castExcpetion, i checked and i dont know what could be the problem, i based my code on the emailactivity provided by orchard.

i have this interface:
public interface IEmailService : IEventHandler
{
    void SendDisabledPatientMail(string email);
    void SendEmail(int action, string email);
}
with it default implementation:
public class EmailService : Component, IEmailService
{
    public  const int DESHABILITAR_EMAIL =1;

    private readonly IOrchardServices _orchardServices;
    private readonly ISmtpChannel _smtpChannel;
    public EmailService(ISmtpChannel smtpChannel,
                        IOrchardServices orchardServices)
    {
        _smtpChannel = smtpChannel;
        _orchardServices = orchardServices;

    }
    public void SendDisabledPatientMail(string email)
    {
        var asunto = _orchardServices.WorkContext.CurrentSite.As<EmailSettings>().DeshabilitarPacienteAsunto;
        var body = _orchardServices.WorkContext.CurrentSite.As<EmailSettings>().DeshabilitarPacienteMessage;
         ConfigureAndSend(asunto, body, email);
    }

    /// <summary>
    /// Metodo mas generico, recibe el ide de paciente y que tipode mail enviar y lo delega solo manda emial
    /// </summary>
    /// <param name="pacienteId"></param>
    /// <param name="action"></param>
    public void SendEmail(int action, string email)
    {
        Console.WriteLine("hola");

        switch (action) { 
           case DESHABILITAR_EMAIL:
              var asunto = _orchardServices.WorkContext.CurrentSite.As<EmailSettings>().DeshabilitarPacienteAsunto;
              var body = _orchardServices.WorkContext.CurrentSite.As<EmailSettings>().DeshabilitarPacienteMessage;
                 var parameters = new Dictionary<string, object> {
            {"Subject", asunto+DateTime.Now.ToShortTimeString()},
            {"Body", body} ,
            {"Recipients", email}
        };
        _smtpChannel.Process(parameters);
                break;


        }
    }

    /// <summary>
    /// Metodo que efectivamente configura el mail a mandar, solo manda email a uno solo!!
    /// </summary>
    /// <param name="asunto"></param>
    /// <param name="cuerpo"></param>
    private void ConfigureAndSend(string asunto, string cuerpo, string email) {

        var parameters = new Dictionary<string, object> {
            {"Subject", asunto+DateTime.Now.ToShortTimeString()},
            {"Body", cuerpo} ,
            {"Recipients", email}
        };
        Parallel.Invoke(() => _smtpChannel.Process(parameters));



    }
}

and here its how I enqueue the job
_jobsQueue.Enqueue("IEmailService.SendEmail", new { action = EmailService.DESHABILITAR_EMAIL, email = user.As<UserPart>().Email }, 0);
I would appreciat any indication.