Пример #1
0
        public void PushToLogDB(DateTime dt)
        {
            if (POS.IsValid())
            {
                POS.PushToBuffer(POS.Val, dt, 0);
                COG.PushToBuffer(COG.Val, dt, 0);
                SOG.PushToBuffer(SOG.Val, dt, 0);
                HDT.PushToBuffer(HDT.Val, dt, 0);
                TWD.PushToBuffer(TWD.Val, dt, 0);
                PERF.PushToBuffer(PERF.Val, dt, 0);
                DPT.PushToBuffer(DPT.Val, dt, 0);
                TWS.PushToBuffer(TWS.Val, dt, 0);
                DRIFT.PushToBuffer(DRIFT.Val, dt, 0);
                SET.PushToBuffer(SET.Val, dt, 0);
                SPD.PushToBuffer(SPD.Val, dt, 0);


                using (var context = new LionRiverDBContext())
                {
                    for (int i = 0; i < Inst.MaxBuffers; i++)
                    {
                        if (POS.AvgBufferDataAvailable(i))
                        {
                            if (POS.GetLastVal(i) != null)
                            {
                                var log = new Log()
                                {
                                    timestamp = POS.GetLastVal(i).Time,
                                    level     = i,
                                    LAT       = POS.GetLastVal(i).Val.Latitude,
                                    LON       = POS.GetLastVal(i).Val.Longitude,
                                    COG       = COG.GetLastVal(i).Val,
                                    SOG       = SOG.GetLastVal(i).Val,
                                    HDT       = HDT.GetLastVal(i).Val,
                                    TWD       = TWD.GetLastVal(i).Val,
                                    PERF      = PERF.GetLastVal(i).Val,
                                    DPT       = DPT.GetLastVal(i).Val,
                                    TWS       = TWS.GetLastVal(i).Val,
                                    DRIFT     = DRIFT.GetLastVal(i).Val,
                                    SET       = SET.GetLastVal(i).Val,
                                    SPD       = SPD.GetLastVal(i).Val
                                };
                                context.Logs.Add(log);

                                if (i == NavPlotModel.Resolution)
                                {
                                    newTrackPositionAvailable = true;
                                }

                                POS.ClearAvgBufferDataAvailable(i);
                                COG.ClearAvgBufferDataAvailable(i);
                                SOG.ClearAvgBufferDataAvailable(i);
                                HDT.ClearAvgBufferDataAvailable(i);
                                TWD.ClearAvgBufferDataAvailable(i);
                                PERF.ClearAvgBufferDataAvailable(i);
                                DPT.ClearAvgBufferDataAvailable(i);
                                TWS.ClearAvgBufferDataAvailable(i);
                                DRIFT.ClearAvgBufferDataAvailable(i);
                                SET.ClearAvgBufferDataAvailable(i);
                                SPD.ClearAvgBufferDataAvailable(i);
                            }
                        }
                    }
                    context.SaveChanges();
                }
            }
        }