private void RemoveAction(SessionViewModel session)
 {
     if (session != null)
     {
         bool success = App.database.DeleteWithIdentifier(SessionViewModel.TABLE_NAME, session.Identifer);
         if (success)
         {
             ViewModelController.Sessions.Remove(session);
         }
     }
 }
Ejemplo n.º 2
0
        private void SaveCurrentSession()
        {
            if (currentSession != null && currentSession.Coords != null)
            {

                currentSession.Identifer = GenerateId();
                double maxSpeed = (currentSession.AverageSpeeds != null && currentSession.AverageSpeeds.Count > 0) ? currentSession.AverageSpeeds.Max() : 0;
                double averageSpeed = (currentSession.AverageSpeeds != null && currentSession.AverageSpeeds.Count > 0) ? currentSession.AverageSpeeds.Average() : 0;
                Dictionary<string, object> dictSession = new Dictionary<string, object>();
                dictSession.Add(SessionViewModel.ID_COLUMN_NAME, currentSession.Identifer);
                dictSession.Add(SessionViewModel.TITLE_COLUMN_NAME, currentSession.Title);
                dictSession.Add(SessionViewModel.DETAILS_COLUMN_NAME, currentSession.Details);
                dictSession.Add(SessionViewModel.DISTANCE_COLUMN_NAME, currentSession.Distance);
                dictSession.Add(SessionViewModel.DURATION_COLUMN_NAME, currentSession.FormatedSpentTime);
                dictSession.Add(SessionViewModel.AVERAGE_SPEED_COLUMN_NAME, averageSpeed);
                dictSession.Add(SessionViewModel.MAX_SPEED_COLUMN_NAME, maxSpeed);
                dictSession.Add(SessionViewModel.DATE_COLUMN_NAME, string.Format("{0:00}/{1:00}/{2:0000}", currentSession.StartTime.Day, currentSession.StartTime.Month, currentSession.StartTime.Year));
                dictSession.Add(SessionViewModel.KCAL_COLUMN_NAME, currentSession.KCal);
                dictSession.Add(SessionViewModel.SPORT_COLUMN_NAME, currentSession.Sport);
                bool success = App.database.InsertWithContent(SessionViewModel.TABLE_NAME, dictSession);

                Dictionary<string, object> dictLocations = new Dictionary<string, object>();
                foreach (GeoCoordinate loc in currentSession.Coords)
                {
                    dictLocations.Clear();
                    if (loc != null)
                    {
                        dictLocations.Add(LocationService.SESSION_ID_COLUMN_NAME, currentSession.Identifer);
                        dictLocations.Add(LocationService.LAT_COLUMN_NAME, loc.Latitude);
                        dictLocations.Add(LocationService.LNG_COLUMN_NAME, loc.Longitude);
                        success = App.database.InsertWithContent(LocationService.TABLE_NAME, dictLocations);
                    }
                }
            }
            currentSession.Distance = 0.0;
            currentSession = null;
            currentSpeed = 0;
            NotifyPropertyChanged("TimeSpent");
            NotifyPropertyChanged("CurrentSpeed");
            NotifyPropertyChanged("DistanceSession");
            NotifyPropertyChanged("KCalFormated");
            NotifyPropertyChanged("KCal");
            Messenger.Default.Send<object>(null, MainViewModel.SessionLoaded);
        }
Ejemplo n.º 3
0
 public void StartSession()
 {
     Messenger.Default.Register<GeoCoordinate>(this, Location.LocationService.locationChanged, newLocation => OnLocationChanged(newLocation));
     currentSession = new SessionViewModel();
     currentSession.StartTime = DateTime.Now;
     currentSession.Sport = UserData.Get<int>(UserData.SportKey);
     timer.Start();
     this.isRunnig = true;
     DebugUtils.Log("trololo", "currentSession started");
     Messenger.Default.Send<bool>(this.isRunnig, TrackingService.SessionStatusChanged);
 }
 private void ShareAction(SessionViewModel session)
 {
     if (session != null)
     {
         string sport = "", duration = "", distance = "", kcal = "", average_speed = "";
         sport = session.SportFormated;
         duration = session.FormatedSpentTime;
         distance = session.DistanceFormated;
         kcal = session.KCalFormated;
         average_speed = session.AverageSpeedFormated;
         Uri uri = new Uri("/Views/ShareSelectionPage.xaml?sport=" + sport + "&duration=" + duration + "&distance=" + distance + "&kcal=" + kcal + "&average_speed=" + average_speed, UriKind.Relative);
         Messenger.Default.Send<Uri>(uri, MainViewModel.ShareSessionKey);
     }
 }
Ejemplo n.º 5
0
        public void FindClosestSessions(ObservableCollection<SessionViewModel> sessions)
        {
            Computing = true;

            if (!IsOpen) Open();

            cmd.CommandText = string.Format("SELECT {0}.* FROM {0} WHERE 1;", SessionViewModel.TABLE_NAME);

            int idColumnIndex = 0;
            int titleColumnIndex = 1;
            int detailsColumnIndex = 2;
            int durationColumnIndex = 4;
            int dateColumnIndex = 5;
            int maxColumnIndex = 7;
            int kcalColumnIndex = 8;
            int sportColumnIndex = 9;

            try
            {
                using (SqliteDataReader reader = cmd.ExecuteReader())
                {
                    while (reader != null && reader.Read())
                    {
                        SessionViewModel session = new SessionViewModel();
                        session.Identifer = reader.GetString(idColumnIndex);
                        string title;
                        string details;

                        try { title = reader.GetString(titleColumnIndex); }
                        catch (NullReferenceException e) { title = ""; }

                        try { details = reader.GetString(detailsColumnIndex); }
                        catch (NullReferenceException e) { details = ""; }

                        session.Title = title;
                        session.Details = details;

                        session.Distance = (double)reader[SessionViewModel.DISTANCE_COLUMN_NAME];
                        session.DurationHistory = reader.GetString(durationColumnIndex);
                        session.DateHistory = reader.GetString(dateColumnIndex);
                        session.AverageSpeedHistory = (double)reader[SessionViewModel.AVERAGE_SPEED_COLUMN_NAME];
                        session.MaxSpeed = reader.GetInt32(maxColumnIndex);
                        session.KCal = (double)reader[kcalColumnIndex];
                        session.Sport = reader.GetInt32(sportColumnIndex);

                        sessions.Add(session);
                    }
                }
            }
            catch (SqliteSyntaxException e)
            {
                DebugUtils.Log(TAG, "SqliteSyntaxException e:[" + e.Message + "]");
            }
            catch (SqliteExecutionException e)
            {
                DebugUtils.Log(TAG, "SqliteExecutionException e:[" + e.Message + "]");
            }

            DebugUtils.Log(TAG, string.Format("Find {0} session in database", sessions.Count));
            Computing = false;
        }