示例#1
0
        /// <summary>
        /// Add strava activity to database.
        /// </summary>
        /// <param name="athleteId">Strava Athlete Id</param>
        /// <param name="item">Strava Summary infomation</param>
        /// <returns></returns>
        private Activity InsertActivity(StravaDotNetActivities.ActivitySummary item)
        {
            Models.Activity s = new Models.Activity();

            try
            {
                s.AthleteId = _fvAthlete.Id;

                UpdateActivityDetails(item, s);

                s.DetailsDownloaded = false;

                // get the weight on the activty date on/before activity.
                ActivityWeight w = new ActivityWeight(_userId, item.Id);
                s.Weight = w.GetActivityWeight();
            }
            catch (Exception ex)
            {
                // catches event types (i.e. watersport) which aren't handled.  Ignoring these activities for now
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }

            return(s);
        }
示例#2
0
        /// <summary>
        /// Update details on an existing activity so that we pick up any amendments made on Strava since original download.
        /// </summary>
        /// <param name="item">Strava summary activity details</param>
        private void CheckActivityDetailsForChanges(StravaDotNetActivities.ActivitySummary item)
        {
            // Activity fvActivity = _unitOfWork.Activity.GetActivity(item.Id);


            Activity fvActivity = _unitOfWork.CRUDRepository.GetByKey <Activity>(item.Id, o => o.ActivityType, o => o.Athlete);

            if (fvActivity == null)
            {
                return;
            }

            UpdateActivityDetails(item, fvActivity);

            //        _unitOfWork.Activity.UpdateActivity(fvActivity);
            _unitOfWork.CRUDRepository.Update <Activity>(fvActivity);
        }
示例#3
0
 /// <summary>
 /// Adds the activity to the list of activities.
 /// </summary>
 /// <param name="other">The activity to add.</param>
 public void AddActivity(ActivitySummary other)
 {
     OtherActivities.Add(other);
 }
示例#4
0
 /// <summary>
 /// Adds a ride to the list of rides.
 /// </summary>
 /// <param name="activity">The ride to add.</param>
 public void AddRide(ActivitySummary activity)
 {
     Rides.Add(activity);
 }
示例#5
0
 /// <summary>
 /// Adds a run to the list of runs.
 /// </summary>
 /// <param name="activity">The run to add.</param>
 public void AddRun(ActivitySummary activity)
 {
     Runs.Add(activity);
 }
示例#6
0
 /// <summary>
 /// Adds the activity to the list of activities.
 /// </summary>
 /// <param name="other">The activity to add.</param>
 public void AddActivity(ActivitySummary other)
 {
     OtherActivities.Add(other);
 }
示例#7
0
 /// <summary>
 /// Adds a ride to the list of rides.
 /// </summary>
 /// <param name="activity">The ride to add.</param>
 public void AddRide(ActivitySummary activity)
 {
     Rides.Add(activity);
 }
示例#8
0
 /// <summary>
 /// Adds a run to the list of runs.
 /// </summary>
 /// <param name="activity">The run to add.</param>
 public void AddRun(ActivitySummary activity)
 {
     Runs.Add(activity);
 }
示例#9
0
        private static void UpdateActivityDetails(StravaDotNetActivities.ActivitySummary item, Activity s)
        {
            s.Id                 = item.Id;
            s.Name               = item.Name;
            s.ExternalId         = item.ExternalId;
            s.ActivityTypeId     = item.Type.ToString();
            s.SufferScore        = item.SufferScore;
            s.EmbedToken         = item.EmbedToken;
            s.Distance           = Convert.ToDecimal(item.Distance);
            s.TotalPhotoCount    = item.TotalPhotoCount;
            s.ElevationGain      = Convert.ToDecimal(item.ElevationGain);
            s.HasKudoed          = item.HasKudoed;
            s.AverageHeartrate   = Convert.ToDecimal(item.AverageHeartrate);
            s.MaxHeartrate       = Convert.ToDecimal(item.MaxHeartrate);
            s.Truncated          = item.Truncated;
            s.GearId             = item.GearId;
            s.AverageSpeed       = Convert.ToDecimal(item.AverageSpeed);
            s.MaxSpeed           = Convert.ToDecimal(item.MaxSpeed);
            s.AverageCadence     = Convert.ToDecimal(item.AverageCadence);
            s.AverageTemperature = Convert.ToDecimal(item.AverageTemperature);
            s.AveragePower       = Convert.ToDecimal(item.AveragePower);
            s.Kilojoules         = Convert.ToDecimal(item.Kilojoules);
            s.IsTrainer          = item.IsTrainer;
            s.IsCommute          = item.IsCommute;
            s.IsManual           = item.IsManual;
            s.IsPrivate          = item.IsPrivate;
            s.IsFlagged          = item.IsFlagged;
            s.AchievementCount   = item.AchievementCount;
            s.KudosCount         = item.KudosCount;
            s.CommentCount       = item.CommentCount;
            s.AthleteCount       = item.AthleteCount;
            s.PhotoCount         = item.PhotoCount;
            s.StartDate          = item.DateTimeStart;
            s.StartDateLocal     = item.DateTimeStartLocal;
            s.MovingTime         = item.MovingTimeSpan;

            if (item.ElapsedTimeSpan.Days >= 1)
            {
                if (s.MovingTime.Value.Days == 0)
                {
                    s.MovingTime = item.MovingTimeSpan;
                }
                else
                {
                    s.MovingTime = null;
                }
            }
            else
            {
                s.ElapsedTime = item.ElapsedTimeSpan;
            }

            s.TimeZone             = item.TimeZone;
            s.StartLatitude        = item.StartLatitude;
            s.StartLongitude       = item.StartLongitude;
            s.WeightedAverageWatts = item.WeightedAverageWatts;

            s.EndLatitude   = item.EndLatitude;
            s.EndLongitude  = item.EndLongitude;
            s.HasPowerMeter = item.HasPowerMeter;

            s.MapId              = item.Map.Id;
            s.MapPolyline        = item.Map.Polyline;
            s.MapPolylineSummary = item.Map.SummaryPolyline;
        }