예제 #1
0
        public void Receive()
        {
            var dto = new LogEntryDTO("MyApp", "SomeTarget", new LogEntry
            {
                CreatedAt  = DateTime.Now,
                Exception  = new Exception("Something awful"),
                LoggedType = typeof(LogEntryDTO),
                MethodName = "Some",
                LogLevel   = LogLevel.Info,
                Message    = "No no",
                ThreadId   = 20,
                UserName   = "******"
            });
            var queue = new MessageQueue(Queue.Name)
            {
                Formatter = new XmlMessageFormatter(new[] { typeof(LogEntryDTO) })
            };

            queue.Send(new Message(dto));

            var receiver = new Receiver();
            var listenr  = new QueueReader(Queue.Name, receiver);

            receiver.Event.WaitOne(1000);

            Assert.NotEmpty(receiver.Entries);
            var entry = receiver.Entries.First();

            Assert.Equal("Arnwe", entry.UserName);
            Assert.Equal("No no", entry.Message);
        }
예제 #2
0
        public void Send100()
        {
            Queue.Reset();

            SimpleLogManager.Instance.AddMessageQueue("MyApp", Queue.Name);
            var logger = SimpleLogManager.Instance.GetLogger(GetType());

            for (int i = 0; i < 100; i++)
            {
                logger.Warning("Hello world :" + i);
            }


            var messages = new LogEntryDTO[100];
            var queue    = new MessageQueue(Queue.Name)
            {
                Formatter = new XmlMessageFormatter(new[] { typeof(LogEntryDTO) })
            };

            for (int i = 0; i < 100; i++)
            {
                var msg = queue.Receive(TimeSpan.FromSeconds(10));
                Assert.NotNull(msg);

                var dto    = (LogEntryDTO)msg.Body;
                var pos    = dto.Message.IndexOf(':');
                var number = int.Parse(dto.Message.Substring(pos + 1));
                messages[number] = dto;
            }

            for (int i = 100 - 1; i >= 0; i--)
            {
                Assert.NotNull(messages[i]);
            }
        }
예제 #3
0
 private static LogEntryDTO CreateEntry()
 {
     var entry = new LogEntryDTO()
         {
             ApplicationName = "arne",
             ComputerName = "Mamma",
             CreatedAt = DateTime.Now,
             Exception = new ExceptionDTO(new InvalidOperationException("SomeOp"))
         };
     return entry;
 }
예제 #4
0
        private static LogEntryDTO CreateEntry()
        {
            var entry = new LogEntryDTO()
            {
                ApplicationName = "arne",
                ComputerName    = "Mamma",
                CreatedAt       = DateTime.Now,
                Exception       = new ExceptionDTO(new InvalidOperationException("SomeOp"))
            };

            return(entry);
        }
예제 #5
0
        /// <summary>
        /// Enqueue to be written
        /// </summary>
        /// <param name="entry"></param>
        /// <remarks>
        /// The entry might be written directly in the same thread or enqueued to be written
        /// later. It's up to each implementation to decide. Keep in mind that a logger should not
        /// introduce delays in the thread execution. If it's possible that it will delay the thread,
        /// enqueue entries instead and write them in a seperate thread.
        /// </remarks>
        public void Enqueue(LogEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            if (_filters.Any(filter => !filter.CanLog(entry)))
            {
                return;
            }

            var dto     = new LogEntryDTO(_applicationName, _module, entry);
            var message = new Message(dto);

            _queue.Send(message);
        }
예제 #6
0
 /// <summary>
 /// Received a new log entry.
 /// </summary>
 /// <param name="dto">Log entry</param>
 public void ReceivedLogEntry(LogEntryDTO dto)
 {
     Entries.Add(dto);
     Event.Set();
 }
예제 #7
0
        private List <LogEntryDTO> ExtractDives(string id, SQLiteConnection sqliteConnection)
        {
            List <LogEntryDTO> dives = new List <LogEntryDTO>();

            try
            {
                sqliteConnection.Open();

                if (DiveParsed != null)
                {
                    string countSql     = "SELECT COUNT(id) FROM dive_logs";
                    var    countCommand = new SQLiteCommand(countSql, sqliteConnection);
                    _totalDives = int.Parse(countCommand.ExecuteScalar().ToString());

                    DiveParsed(id, new ParserProgess(0, _totalDives));
                }

                var sql = "SELECT id, datetime(startTimeStamp,'unixepoch') as stringStartDate, maxTime, maxDepth FROM dive_logs";
                using (var command = new SQLiteCommand(sql, sqliteConnection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var dive = new LogEntryDTO();
                            dive.ExternalId = reader["id"].ToString();

                            var date = reader["stringStartDate"];

                            dive.DiveDate   = DateTime.Parse(date.ToString());
                            dive.MaxDepth   = Convert.ToDecimal(reader["maxDepth"]);
                            dive.DiveLength = TimeSpan.FromMinutes(Convert.ToInt32(reader["maxTime"]));
                            dive.Outcome    = DTO.Types.DiveOutcome.Unknown;

                            dive.DataPoints = new List <DataPointDTO>();
                            dives.Add(dive);
                        }
                    }
                }

                string sqllog = "SELECT id, diveLogId, currentTime, currentDepth, fractionO2, fractionHe, waterTemp, averagePPO2, CNSPercent, currentCircuitSetting FROM dive_log_records WHERE diveLogId =";
                foreach (var dive in dives)
                {
                    using (var command = new SQLiteCommand(sqllog + dive.ExternalId, sqliteConnection))
                    {
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var dataPoint = new DataPointDTO();
                                dataPoint.AveragePPO2 = Convert.ToDecimal(reader["averagePPO2"]);
                                dataPoint.Depth       = Convert.ToDecimal(reader["currentDepth"]);
                                dataPoint.Time        = Convert.ToInt32(reader["currentTime"]);
                                dataPoint.WaterTemp   = Convert.ToInt16(reader["waterTemp"]);
                                dataPoint.CNS         = Convert.ToInt16(reader["CNSPercent"]);

                                if (dataPoint.Time == 0)
                                {
                                    dive.FractionO2 = Convert.ToDecimal(reader["fractionO2"]);
                                    dive.FractionHe = Convert.ToDecimal(reader["fractionHe"]);
                                    var startCircuitSetting = Convert.ToInt16(reader["currentCircuitSetting"]);
                                    switch (startCircuitSetting)
                                    {
                                    case 0:
                                        dive.DiveType = DTO.Types.DiveType.CCR;
                                        break;

                                    case 1:
                                        dive.DiveType = DTO.Types.DiveType.OC;
                                        break;

                                    default:
                                        dive.DiveType = DTO.Types.DiveType.Unknown;
                                        break;
                                    }
                                }

                                dive.DataPoints.Add(dataPoint);
                            }
                        }
                    }

                    DiveParsed?.Invoke(id, new ParserProgess(dives.IndexOf(dive) + 1, _totalDives));
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
            finally
            {
                sqliteConnection.Close();
            }

            return(dives);
        }