예제 #1
0
파일: HomeController.cs 프로젝트: ecm85/vph
        public async Task <ActionResult> CreateActivity(DateTime?startDate, DateTime?endDate)
        {
            if (startDate == null && endDate == null)
            {
                startDate = DateTime.Today.Date.AddDays(-13);
                endDate   = DateTime.Today;
            }

            if (endDate == null || startDate == null || endDate.Value.Date < startDate.Value.Date || startDate == DateTime.MinValue || endDate == DateTime.MinValue)
            {
                throw new InvalidOperationException("You're an idiot.");
            }
            if (endDate.Value.Date.Subtract(startDate.Value.Date).Days > 30)
            {
                throw new InvalidOperationException("Just do a month at a time.");
            }

            var currentDate = startDate.Value;
            var model       = new CreateActivityResultModel();

            while (currentDate.Date <= endDate.Value.Date)
            {
                try
                {
                    var authenticator    = CreateAuthenticator();
                    var client           = new StravaSharp.Client(authenticator);
                    var originalFilePath = Path.Combine(GetCurrentPath, "Biking-timestamped.gpx");
                    var dateStamp        = currentDate.ToString("yyyy-MM-dd");
                    var originalFileText = System.IO.File.ReadAllText(originalFilePath).Replace("YYYY-MM-DD", dateStamp);

                    using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(originalFileText)))
                    {
                        await client.Activities.Upload(ActivityType.Ride, DataType.Gpx, stream, $"BikeRide{dateStamp}.gpx",
                                                       $"Bike Ride {dateStamp}");
                    }

                    model.Successes++;
                }
                catch (Exception exception)
                {
                    model.Failures++;
                    model.Exceptions.Add(exception);
                }
                currentDate = currentDate.AddDays(1);
            }

            return(View(model));
        }
예제 #2
0
        public async Task <ActionResult> Index()
        {
            var authenticator = CreateAuthenticator();
            var viewModel     = new HomeViewModel(authenticator.IsAuthenticated);

            if (authenticator.IsAuthenticated)
            {
                var client     = new StravaSharp.Client(authenticator);
                var activities = await client.Activities.GetAthleteActivities();

                foreach (var activity in activities)
                {
                    viewModel.Activities.Add(new ActivityViewModel(activity));
                }
            }
            return(View(viewModel));
        }
예제 #3
0
파일: HomeController.cs 프로젝트: ecm85/vph
        public async Task <ActionResult> Activities()
        {
            var authenticator = CreateAuthenticator();
            var model         = new ActivitiesViewModel {
                IsAuthenticated = authenticator.IsAuthenticated
            };

            if (!authenticator.IsAuthenticated)
            {
                return(View(model));
            }
            var client     = new StravaSharp.Client(authenticator);
            var activities = await client.Activities.GetAthleteActivities();

            model.Activities = activities.Select(activity => new ActivityViewModel(activity)).ToList();
            return(View(model));
        }
예제 #4
0
 internal AthleteClient(Client client)
 {
     _client = client;
 }
예제 #5
0
 internal ClubClient(Client client)
 {
     _client = client;
 }
예제 #6
0
 internal ActivityClient(Client client)
 {
     _client = client;
 }
예제 #7
0
 internal SegmentClient(Client client)
 {
     _client = client;
 }