Exemplo n.º 1
0
 public LogEntry(Model.LogEntry entry)
 {
     Message   = entry.Message;
     Severity  = entry.Severity.ToString();
     Category  = entry.Category.ToString();
     Timestamp = entry.Timestamp;
 }
        public async Task <Guid> Save(Model.LogEntry log)
        {
            var result = Guid.Empty;

            var entity = new Entities.LogEntry()
            {
                Id          = log.Id,
                Timestamp   = log.Timestamp,
                Application = log.Application,
                Source      = log.Source,
                Level       = log.Level,
                Event       = log.Event,
                Message     = log.Message
            };

            entity.Properties = new List <Entities.LogProperty>();

            foreach (var i in log.Properties)
            {
                entity.Properties.Add(new Entities.LogProperty()
                {
                    Key   = i.Key,
                    Value = i.Value
                });
            }

            entity.Tags = new List <Entities.LogTag>();

            foreach (var i in log.Tags)
            {
                entity.Tags.Add(new Entities.LogTag()
                {
                    Value = i
                });
            }

            await db.Logs.AddAsync(entity);

            if (await db.SaveChangesAsync() > 0)
            {
                result = entity.Id;
            }

            return(result);
        }
        public Model.LogEntry AddEntry(Model.LogEntry entry)
        {
            context.LogEntries.Add(entry);

            if (lastCleanupRun.AddHours(3) < System.DateTime.Now)
            {
                // Delete old logentries
                context.Database.ExecuteSqlCommand("DELETE FROM LogEntries WHERE TimeStamp < @DateOffset", new System.Data.SqlClient.SqlParameter("DateOffset", entry.Timestamp.AddDays(-1)));

                lastCleanupRun = System.DateTime.Now;
            }

            context.SaveChanges();

            ProcessUsages(entry);

            return(entry);
        }
        private void PopulateUsage(Model.Usage usage, Model.LogEntry entry)
        {
            usage.E1Current       = entry.E1;
            usage.E2Current       = entry.E2;
            usage.E1RetourCurrent = entry.E1Retour;
            usage.E2RetourCurrent = entry.E2Retour;

            if (entry.PvCounter > 0 && entry.Timestamp.Hour >= 3)
            {
                var refDate            = entry.Timestamp.Date;
                var minDailyProduction = context.Usages.Where(x => x.Timestamp >= refDate).Min(x => x.PvProductionStart);
                usage.PvProductionCurrent = minDailyProduction + entry.PvCounter;
            }
            else
            {
                usage.PvProductionCurrent = usage.PvProductionStart;
            }
        }
        private void ProcessUsages(Model.LogEntry entry)
        {
            // Process Usage values
            var hourlyUsage = GetUsage(entry);

            PopulateUsage(hourlyUsage, entry);

            context.SaveChanges();

            // Process gas usage
            var hourlyGasUsage = GetGasUsage(entry);

            if (hourlyGasUsage != null)
            {
                hourlyGasUsage.GasCurrent = entry.GasMeasurementValue;
            }

            context.SaveChanges();
        }
Exemplo n.º 6
0
        public async Task Load(string fileName, ProgressUtility progress)
        {
            flights.Clear();
            // CSV doesn't have realtime clock, so go with the file date instead.
            this.startTime = File.GetLastWriteTime(fileName);

            // time (ms)
            long min = long.MaxValue;
            long max = long.MinValue;

            await Task.Run(() =>
            {
                timeElementName = null;
                using (Stream s = File.OpenRead(fileName))
                {
                    Dictionary <string, LogItemSchema> map = new Dictionary <string, LogItemSchema>();
                    XmlNameTable nametable = new NameTable();
                    using (XmlCsvReader reader = new XmlCsvReader(s, System.Text.Encoding.UTF8, new Uri(fileName), nametable))
                    {
                        reader.FirstRowHasColumnNames = true;
                        reader.ColumnsAsAttributes    = true;
                        while (reader.Read())
                        {
                            progress.ShowProgress(0, s.Length, s.Position);
                            if (this.schema == null)
                            {
                                // create the schema
                                this.schema = new LogItemSchema()
                                {
                                    Name = "CsvLog", Type = "Root"
                                };
                                LogItemSchema row = null;

                                foreach (String name in reader.ColumnNames)
                                {
                                    if (timeElementName == null && (name.ToLower().Contains("time") || name.ToLower().Contains("ticks")))
                                    {
                                        timeElementName = name;
                                    }

                                    if (name.Contains(":"))
                                    {
                                        // then we have sub-parts.
                                        int pos             = name.IndexOf(":");
                                        string key          = name.Substring(0, pos);
                                        string field        = name.Substring(pos + 1);
                                        LogItemSchema group = null;
                                        if (!map.ContainsKey(key))
                                        {
                                            group = new LogItemSchema()
                                            {
                                                Name = key, Type = key
                                            };
                                            this.schema.AddChild(group);
                                            map[key] = group;
                                        }
                                        else
                                        {
                                            group = map[key];
                                        }
                                        var leaf = new LogItemSchema()
                                        {
                                            Name = field, Type = "Double"
                                        };
                                        group.AddChild(leaf);
                                        map[name] = leaf;
                                    }
                                    else
                                    {
                                        if (row == null)
                                        {
                                            row = new LogItemSchema()
                                            {
                                                Name = "Other", Type = "Other"
                                            };
                                            this.schema.AddChild(row);
                                        }
                                        var leaf = new LogItemSchema()
                                        {
                                            Name = name, Type = "Double"
                                        };
                                        row.AddChild(leaf);
                                        map[name] = leaf;
                                    }
                                }
                            }

                            if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "row")
                            {
                                // read a row
                                long time    = GetTicks(reader);
                                min          = Math.Min(min, time);
                                max          = Math.Max(max, time);
                                LogEntry row = new Model.LogEntry()
                                {
                                    Name = "Other", Timestamp = (ulong)time
                                };
                                log.Add(row);
                                Dictionary <string, LogEntry> groups = new Dictionary <string, LogEntry>();

                                if (reader.MoveToFirstAttribute())
                                {
                                    do
                                    {
                                        string name = XmlConvert.DecodeName(reader.LocalName);
                                        LogItemSchema itemSchema = map[name];
                                        LogEntry e = row;
                                        if (name.Contains(":"))
                                        {
                                            // then we have sub-parts.
                                            int pos      = name.IndexOf(":");
                                            string key   = name.Substring(0, pos);
                                            string field = name.Substring(pos + 1);
                                            if (!groups.ContainsKey(key))
                                            {
                                                e = new LogEntry()
                                                {
                                                    Name = key, Timestamp = (ulong)time
                                                };
                                                groups[key] = e;
                                                log.Add(e);
                                            }
                                            else
                                            {
                                                e = groups[key];
                                            }
                                            name = field;
                                        }

                                        string value = reader.Value;
                                        double d     = 0;
                                        if (double.TryParse(value, out d))
                                        {
                                            e.SetField(name, d);
                                        }
                                        else
                                        {
                                            if (!string.IsNullOrEmpty(value))
                                            {
                                                // not a number.
                                                itemSchema.Type = "String";
                                                e.SetField(name, value);
                                            }
                                        }
                                    }while (reader.MoveToNextAttribute());
                                    reader.MoveToElement();
                                }
                            }
                        }
                    }
                }
            });

            // this log has no absolute UTC time, only ticks since board was booted, so we make up a start time.
            DateTime end    = this.startTime.AddMilliseconds((max - min) / 1000);
            var      flight = new Flight()
            {
                Log = this, StartTime = this.startTime, Duration = end - this.startTime
            };

            this.duration = end - this.startTime;
            this.flights.Add(flight);
        }
Exemplo n.º 7
0
        public Model.LogEntry ConvertToModel(Entities.LogEntry entity)
        {
            var result = new Model.LogEntry();

            return(result);
        }
Exemplo n.º 8
0
        public Entities.LogEntry ConvertToEntity(Model.LogEntry model)
        {
            var result = new Entities.LogEntry();

            return(result);
        }