public static void DigestSession(Models.SessionModel session, ref Queue <NewRemoteFrameArgs> localFrames, ref Queue <NewRemoteFrameArgs> remoteFrames)
        {
            StringBuilder stringBuilder = new StringBuilder();

            DateTime firstInstant = Math.Max(localFrames.First().TimeStamp.ToDate().AddSeconds(1).Ticks, remoteFrames.First().TimeStamp.ToDate().AddSeconds(1).Ticks).ToDate();
            DateTime lastInstant  = Math.Min(localFrames.Last().TimeStamp.ToDate().Ticks, remoteFrames.Last().TimeStamp.ToDate().Ticks).ToDate();

            localFrames = new Queue <NewRemoteFrameArgs>(localFrames.SkipWhile(x => x.TimeStamp.ToDate().Second != firstInstant.Second)
                                                         .TakeWhile(x => x.TimeStamp.ToDate().Minute != lastInstant.Minute || x.TimeStamp.ToDate().Second != lastInstant.Second));
            remoteFrames = new Queue <NewRemoteFrameArgs>(remoteFrames.SkipWhile(x => x.TimeStamp.ToDate().Second != firstInstant.Second)
                                                          .TakeWhile(x => x.TimeStamp.ToDate().Minute != lastInstant.Minute || x.TimeStamp.ToDate().Second != lastInstant.Second));

            DBHelper.InsertFrames(session.GetHash(), DBHelper.DigestFrames(true, ref localFrames, ref stringBuilder), true);
            DBHelper.InsertFrames(session.GetHash(), DBHelper.DigestFrames(false, ref remoteFrames, ref stringBuilder), false);
            File.WriteAllBytes(session.GetPath(), stringBuilder.ToString().Zip());
        }
        public PlaySessionViewModel(PlaySession window, Models.SessionModel session)
        {
            SessionGaits = new Dictionary <string, List <Gait> >();
            Right        = new Graphics();
            Left         = new Graphics();
            this.session = session;
            Window       = window;
            Timer.Tick  += Timer_Tick;

            SessionFrames = System.IO.File.ReadAllBytes(session.GetPath()).Unzip()
                            .Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                            .GroupBy(x => x.Split('@')[0])
                            .ToDictionary
                            (
                x => x.Key == "1" ? "LOCAL" : "REMOTE",
                y => y.Select(x => x.Split('@')[1]).ToList()
                            );
            IndexTotal             = Math.Min(SessionFrames["LOCAL"].Count, SessionFrames["REMOTE"].Count);
            SessionGaits["LOCAL"]  = DBAccessor.GetGaits(session.GetHash(), true);
            SessionGaits["REMOTE"] = DBAccessor.GetGaits(session.GetHash(), false);
        }
 public static bool SaveSession(Models.SessionModel session, string athleteHash)
 {
     try
     {
         using (DBEntities db = new DBEntities())
         {
             string  hash            = session.GetHash();
             Session sessionToUpdate = db.Session.FirstOrDefault(x => x.session_hash == hash);
             sessionToUpdate.footwear        = session.Footwear ? 1 : 0;
             sessionToUpdate.height          = session.Height;
             sessionToUpdate.treadmill_speed = session.TreadmillSpeed;
             sessionToUpdate.weight          = session.Weight;
             sessionToUpdate.athlete_hash    = athleteHash;
             sessionToUpdate.duration        = session.Duration;
             sessionToUpdate.saved           = 1;
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }