public SaveSessionViewModel(SaveSession window, Models.SessionModel session)
 {
     this.sessionModel = session;
     Window            = window;
     Genders           = new ObservableCollection <string>()
     {
         "Man", "Woman"
     };
 }
        //#################################################################################################
        public IActionResult LoadSessionFromFile(Models.SessionModel sessionModel)
        {
            Program.sessionModel.validationMessage = String.Empty;
            Program.sessionModel.valError          = false;

            if ((sessionModel.file != null && !sessionModel.file.FileName.EndsWith(".xml")) ||
                (!String.IsNullOrEmpty(sessionModel.fileName) && !sessionModel.fileName.EndsWith(".xml")))
            {
                Program.sessionModel.validationMessage = HelperController.GetMessage("Session.Err.WrongType").txt;
                Program.sessionModel.valError          = true;
                return(Session());
            }


            if (sessionModel.file != null)
            {
                try
                {
                    var result = new StringBuilder();
                    using (var reader = new StreamReader(sessionModel.file.OpenReadStream()))
                    {
                        while (reader.Peek() >= 0)
                        {
                            result.AppendLine(reader.ReadLine());
                        }
                    }

                    var filestring = result.ToString();
                    Program.indexModel.FilterList = GetFiltersFromXml(Controllers.XmlController.GetXml(filestring));
                }
                catch (Exception ex)
                {
                    LogController.LogError(String.Format(HelperController.GetMessage("SessionController.Err.LoadSessionFromFile(Model)1").txt, ex.ToString()));
                    Program.sessionModel.validationMessage = HelperController.GetMessage("SessionController.Err.LoadSessionFromFile(Model)1").ext;
                    Program.sessionModel.valError          = true;
                    return(Session());
                }
            }
            else
            {
                try
                {
                    Program.indexModel.FilterList = GetFiltersFromXml(Controllers.XmlController.GetXml(HelperController.ConvertBase64ToUtf8(sessionModel.fileString)));
                }
                catch (Exception ex)
                {
                    LogController.LogError(String.Format(HelperController.GetMessage("SessionController.Err.LoadSessionFromFile(Model)2").txt, ex.ToString()));
                    Program.sessionModel.validationMessage = HelperController.GetMessage("SessionController.Err.LoadSessionFromFile(Model)2").ext;
                    Program.sessionModel.valError          = true;
                    return(Session());
                }
            }

            Program.sessionModel.validationMessage = HelperController.GetMessage("SessionController.Inf.LoadSessionFromFile(Model)").txt;

            return(Session());
        }
Example #3
0
        public ViewModel()
        {
            var session = HttpContext.Current.Session;

            this.SessionModel = new Models.SessionModel()
            {
                ID     = Convert.ToInt32(session["ID"]),
                RoleID = Convert.ToInt32(session["RoleID"])
            };
        }
        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);
     }
 }
Example #7
0
 public async Task PostAsync([FromBody] Models.SessionModel session)
 {
     await DoNothing(); //- Shushing warnings
 }
 public SaveSession(Models.SessionModel session)
 {
     InitializeComponent();
     DataContext = new SaveSessionViewModel(this, session);
 }