예제 #1
0
        public void ExtractHistory(DateTime from, DateTime to, bool allHistory)
        {
            string logfileFormat = "{0}_log.txt";

            int countDaysDiff = to.Subtract(from).Days + 1;

            for (int i = 0; i < countDaysDiff; i++)
            {
                DateTime fromDate = from.AddDays(i);
                string   fullpath = Path.Combine(this.logPath, string.Format(logfileFormat, fromDate.ToString("ddMMyyyy")));
                var      chuncker = new LogFileChuncker(fullpath);
                logFileChunckers.Add(chuncker);
                if (allHistory)
                {
                    chuncker.GetAllSessions();
                }
                else
                {
                    chuncker.GetLastSession();
                    if (chuncker.Session != null)
                    {
                        DateTime toDate = fromDate.AddHours(24);

                        PumpEvents.AddRange(chuncker.Session.PumpDataHistory.PumpEvents.Where(e => e.EventDate.DateTime.Value >= fromDate && e.EventDate.DateTime.Value < toDate));
                        SensorEvents.AddRange(chuncker.Session.PumpDataHistory.SensorEvents.Where(e => e.EventDate.DateTime.Value >= fromDate && e.EventDate.DateTime.Value < toDate));
                    }
                }
            }
        }
예제 #2
0
        public void ExtractHistory(DateTime from, DateTime to, bool allHistory)
        {
            string logfileFormat = "{0}_log.txt";

            int countDaysDiff = to.Subtract(from).Days + 1;

            for (int i = 0; i < countDaysDiff; i++)
            {
                DateTime fromDate = from.AddDays(i);
                string   fullpath = Path.Combine(this.logPath, string.Format(logfileFormat, fromDate.ToString("ddMMyyyy")));
                if (File.Exists(fullpath))
                {
                    var chuncker = new LogFileChuncker(fullpath);
                    chuncker.MaxNumber = MaxNumber;
                    logFileChunckers.Add(chuncker);

                    chuncker.GetAllMessages();

                    if (allHistory)
                    {
                        chuncker.GetAllSessions();
                    }
                    else
                    {
                        var first = chuncker.chuncks.First(e => e.session.PumpDataHistory.MultiPacketHandlers.Count > 0);
                        var last  = chuncker.chuncks.Last(e => e.session.PumpDataHistory.MultiPacketHandlers.Count > 0);

                        first.session.PumpDataHistory.ExtractHistoryEvents();
                        last.session.PumpDataHistory.ExtractHistoryEvents();

                        var maxPumpEventDate   = first.session.PumpDataHistory.PumpEvents.Max(e => e.EventDate.DateTime.Value);
                        var maxSensorEventDate = first.session.PumpDataHistory.SensorEvents.Max(e => e.EventDate.DateTime.Value);

                        var pumpevents  = last.session.PumpDataHistory.PumpEvents.Where(e => e.EventDate.DateTime.Value > maxPumpEventDate).ToList();
                        var sensorvents = last.session.PumpDataHistory.SensorEvents.Where(e => e.EventDate.DateTime.Value > maxSensorEventDate).ToList();

                        first.session.PumpDataHistory.PumpEvents.AddRange(pumpevents);
                        first.session.PumpDataHistory.SensorEvents.AddRange(sensorvents);

                        var liststatus = chuncker.chuncks.Select(e => e.session.Status);

                        first.session.Status = new List <MiniMed.Responses.PumpStatusMessage>();

                        foreach (var statusses in liststatus)
                        {
                            foreach (var status in statusses)
                            {
                                first.session.Status.Add(status);
                            }
                        }

                        CollectedSessions.Add(first.session);
                        //chuncker.GetLastSession();
                        //if (chuncker.Session != null)
                        //{
                        //    DateTime toDate = fromDate.AddHours(24);

                        //    PumpEvents.AddRange(chuncker.Session.PumpDataHistory.PumpEvents.Where(e => e.EventDate.DateTime.Value >= fromDate && e.EventDate.DateTime.Value < toDate));
                        //    SensorEvents.AddRange(chuncker.Session.PumpDataHistory.SensorEvents.Where(e => e.EventDate.DateTime.Value >= fromDate && e.EventDate.DateTime.Value < toDate));
                        //}
                    }
                }
            }
        }