public static Boolean InsertarError(SVCDocumentosElectronicos.MensajeWCFOfEnviosPendientesPosteoDIAN 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) { try { SVCDocumentosElectronicos.MensajeWCFOfEnviosPendientesPosteoDIAN respuesta = client.ObtenerDocumentosPendientesEnvio(); if (respuesta.CodigoError != Util.CODIGO_EXITOSO) { Util.InsertarError(respuesta); } if (respuesta.Contenido.Length > 0) { configurador.LogWriter.Write(new LogEntry() { Message = String.Format("Documentos pediente de posteo {0}", respuesta.Contenido.Length.ToString()), Categories = new List <string> { "eventLog" }, Priority = 1, ProcessName = "Alimentando Queue" }); if (queue.GetAllMessages().Length > 0) { queue.Purge(); } foreach (SVCDocumentosElectronicos.EnviosPendientesPosteoDIAN 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 posteo", queue.QueueName, entidad.Id), Categories = new List <string> { "eventLog" }, Priority = 1, ProcessName = "Alimentando Queue" }); } } } } catch (Exception ex) { configurador.ExceptionHandler.HandleException(ex, Util.POLITICA_ERRORES, out Exception nExption); } }