public static Boolean InsertarError(SVCDocumentosElectronicos.MensajeWCFOfEnviosDeDocumentosPendiente entidad) { try { Message msg = new Message(); MessageQueue queue = new MessageQueue(@"FormatName:Direct=OS:" + ConfigurationManager.AppSettings["NombreColaMSMQError"]); string queueName = ConfigurationManager.AppSettings["NombreColaMSMQError"]; if (!MessageQueue.Exists(queueName)) { MessageQueue.Create(queueName, true); } msg.Body = entidad; using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { queue.Send(msg, MessageQueueTransactionType.Automatic); scope.Complete(); } return(true); } catch (Exception) { return(false); } }
private void OnBeginSendDocuments(object source, ElapsedEventArgs e) { SVCDocumentosElectronicos.MensajeWCFOfEnviosDeDocumentosPendiente respuesta = null; try { respuesta = client.ObtenerEnviosCorreoPendiente(); if (respuesta.CodigoError != Util.CODIGO_EXITOSO) { Util.InsertarError(respuesta); } if (respuesta.Contenido.Length > 0) { configurador.LogWriter.Write(new LogEntry() { Message = String.Format("Documentos pedientes de enviar al cliente {0}", respuesta.Contenido.Length.ToString()), Categories = new List <string> { "eventLog" }, Priority = 1, ProcessName = "Alimentando Queue" }); if (queue.GetAllMessages().Length > 0) { queue.Purge(); } foreach (SVCDocumentosElectronicos.EnviosDeDocumentosPendiente entidad in respuesta.Contenido) { Message msg = new Message(entidad); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { queue.Send(msg, MessageQueueTransactionType.Automatic); scope.Complete(); configurador.LogWriter.Write(new LogEntry() { Message = String.Format("Se mandó a la cola {0}, el documento {1} pendiente de envío al cliente", queue.QueueName, entidad.DocumentoId), Categories = new List <string> { "eventLog" }, Priority = 1, ProcessName = "Alimentando Queue" }); } msg = null; } } } catch (Exception ex) { configurador.ExceptionHandler.HandleException(ex, Util.POLITICA_ERRORES, out Exception nExption); } finally { respuesta = null; } }