public static void SendMessage(string queueName, CorreoMessage msg) { MessageQueue messageQueue = null; if (!MessageQueue.Exists(queueName)) { messageQueue = MessageQueue.Create(queueName); } else { messageQueue = new MessageQueue(queueName); } try { messageQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(CorreoMessage) }); messageQueue.Send(msg, "Activacion"); } catch (Exception) { throw; //Write code here to do the necessary error handling. } finally { messageQueue.Close(); } }
public static int ConfirmarLinea(String ruc, String nroLinea) { List <Linea> ls = new List <Linea>(); CorreoMessage cMsg = new CorreoMessage(); DataTable dt = new DataTable(); try { using (SqlConnection cn = new SqlConnection(Util.CN)) { cn.Open(); using (SqlCommand cm = new SqlCommand("usp_activarLinea", cn)) { cm.CommandType = CommandType.StoredProcedure; cm.Parameters.AddWithValue("@ruc", ruc); cm.Parameters.AddWithValue("@nroTelefono", nroLinea); dt.Load(cm.ExecuteReader()); ls = dt.DataTableToList2 <Linea>(); if (ls != null) { Linea lin = ls[0]; cMsg.NroLinea = lin.nroLinea; cMsg.Ruc = lin.rucEmpresa; cMsg.Destinatario = Util.CC; cMsg.Monto = lin.precioPlan; cMsg.Nombre = lin.nombreEmpresa; cMsg.Mensaje = "Estimado cliente, se activo la linea: " + lin.nroLinea + " para: " + lin.nombreReferencia; Mensajeria.SendMessage(Mensajeria.COLA, cMsg); Mensajeria.ReceiveMessageActivacion(Mensajeria.COLA); return(1); } else { return(-1); } } } } catch (Exception) { return(-1); } }
public static CorreoMessage ReceiveMessageActivacion(string queueName) { if (!MessageQueue.Exists(queueName)) { return(null); } MessageQueue messageQueue = new MessageQueue(queueName); CorreoMessage emailMessage = null; try { messageQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(CorreoMessage) }); Message Mymessage = messageQueue.Receive(); emailMessage = (CorreoMessage)Mymessage.Body; List <String> to = emailMessage.Destinatario.Split(';').ToList <String>(); List <String> cc = new List <String>(); List <String> co = new List <String>(); StringBuilder sb = new StringBuilder(); String html = File.ReadAllText(@"c:\inetpub\wwwroot\WsSoapClaro\Template\template.html"); sb.Append(html); sb.Replace("[CLIENTE]", emailMessage.Nombre); sb.Replace("[MENSAJE]", emailMessage.Mensaje); sb.Replace("[MONTO]", emailMessage.Monto); sb.Replace("[LINEA]", emailMessage.NroLinea); MailingAnonymous.SendMail(to, cc, co, "Test-MSMQ - Confirmación de línea: " + emailMessage.NroLinea, sb); } catch { throw; } finally { messageQueue.Close(); } return(emailMessage); }