Example #1
0
        public static Boolean InsertarError(SVCDocumentosElectronicos.MensajeWCFOfEstadoDocumento entidad)
        {
            try
            {
                var configurations = Configurador.Instance;

                Message msg = new Message();
                //MessageQueue queue = new MessageQueue(@"FormatName:Direct=OS:" + ConfigurationManager.AppSettings["NombreColaMSMQError"]);
                MessageQueue queue     = new MessageQueue(@"FormatName:Direct=OS:" + configurations.ErrorQueueName);
                string       queueName = configurations.ErrorQueueName; //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);
            }
        }
Example #2
0
        public void OnMessageReceived(Object source, ReceiveCompletedEventArgs e)
        {
            XmlSerializer s     = new XmlSerializer(typeof(SVCDocumentosElectronicos.EnviosPendientesEnDIAN));
            MessageQueue  queue = (MessageQueue)source;

            try
            {
                Message msg = queue.EndReceive(e.AsyncResult);
                msg.Formatter = new XmlMessageFormatter(new Type[] { typeof(SVCDocumentosElectronicos.EnviosPendientesEnDIAN) });

                SVCDocumentosElectronicos.EnviosPendientesEnDIAN documento = (SVCDocumentosElectronicos.EnviosPendientesEnDIAN)msg.Body;

                configurador.LogWriter.Write(new LogEntry()
                {
                    Message = String.Format("Mensaje recibido en la cola, consultado estado de documento en DIAN {0} ", msg.Body), Categories = new List <string> {
                        "eventLog"
                    }, Priority = 1, ProcessName = "Leyendo Queue"
                });

                SVCDocumentosElectronicos.MensajeWCFOfEstadoDocumento respuesta = client.ConsultaEstadoDocumento(documento);

                if (respuesta.CodigoError != Util.CODIGO_EXITOSO)
                {
                    Util.InsertarError(respuesta);
                    configurador.LogWriter.Write(new LogEntry()
                    {
                        Message = String.Format("Error al consultar estado de documento {0}, mensaje de error {1}", documento.Id, respuesta.MensajeError), Categories = new List <string> {
                            "eventLog"
                        }, Priority = 1, ProcessName = "Leyendo Queue"
                    });
                }
                else
                {
                    configurador.LogWriter.Write(new LogEntry()
                    {
                        Message = String.Format("Documento {0} consultado en DIAN, respuesta {1}", documento.Id, respuesta.Contenido.First().ConsultaTransaccionDocumento.First().DescripcionEstado), Categories = new List <string> {
                            "eventLog"
                        }, Priority = 1, ProcessName = "Leyendo Queue"
                    });
                }
            }
            catch (System.Exception ex)
            {
                configurador.ExceptionHandler.HandleException(ex, Util.POLITICA_ERRORES, out Exception nExption);
            }
            finally
            {
                queue.BeginReceive();
            }
        }