示例#1
0
        public static async Task Run([QueueTrigger(QueueNames.RefreshAthletesDetails)] RefreshAthletesDetailsRequest request,
                                     [Table(TableNames.AthletesTable, "{AthleteId}", "")] AthleteTableEntity athlete,
                                     [Table(TableNames.AthletesTable)] CloudTable athletesTable,
                                     ILogger log)
        {
            var client = new LittleStravaClient();

            var result = await client.GetAuthenticatedAthlete(athlete);

            athlete.FirstName = result.Firstname;
            athlete.LastName  = result.Lastname;

            await athletesTable.ExecuteAsync(TableOperation.InsertOrReplace(athlete));
        }
示例#2
0
        public static async Task Run(
            [QueueTrigger(QueueNames.SyncDay)] SyncDayRequest request,
            [Table(TableNames.AthletesTable, "{AthleteId}", "")] AthleteTableEntity athlete,
            [Table(TableNames.AthletesTable)] CloudTable athletesTable,
            [Table(TableNames.SyncedActivitiesTable)] CloudTable syncedActivitiesTable,
            ILogger log)
        {
            var client = new LittleStravaClient();

            var date   = request.DateTime.Date;
            var before = new DateTimeOffset(date.AddDays(1)).ToUnixTimeSeconds();
            var after  = new DateTimeOffset(date).ToUnixTimeSeconds();

            var activities = await client.GetLoggedInAthleteActivities(athlete, before, after);

            var types            = athlete.TypesToSync.Split(",").Select(Enum.Parse <LittleStravaClient.ActivityType>).ToArray();
            var activitiesToSync = activities.Where(x => types.Contains(x.Type))
                                   .Select(x => new { x.Id, x.Type, Meters = x.Distance, Miles = ConvertToMiles(x.Distance) })
                                   .ToArray();

            var totalDaysMiles = activitiesToSync.Sum(x => x.Miles);

            if (totalDaysMiles > 0)
            {
                var landsEnd3FireBaseAppClient = new LandsEnd3FireBaseAppClient();
                await landsEnd3FireBaseAppClient.SubmitData(athlete, date, totalDaysMiles);

                var tableBatchOperation = new TableBatchOperation();
                foreach (var sycnedActivity in activitiesToSync)
                {
                    tableBatchOperation.InsertOrReplace(new SyncedActivitiesTableEntity
                    {
                        PartitionKey = request.AthleteId.ToString(),
                        RowKey       = sycnedActivity.Id.ToString(),
                        ActivityType = sycnedActivity.Type.ToString(),
                        Meters       = sycnedActivity.Meters,
                        Miles        = sycnedActivity.Miles,
                    });
                }

                if (tableBatchOperation.Any())
                {
                    syncedActivitiesTable.ExecuteBatch(tableBatchOperation);
                }
            }

            await athletesTable.ExecuteAsync(TableOperation.InsertOrReplace(athlete));
        }
        public static async Task Run(
            [QueueTrigger(QueueNames.ActivityUpdated)] ActivityUpdatedMessage message,
            [Table(TableNames.AthletesTable, "{AthleteId}", "")] AthleteTableEntity athlete,
            [Table(TableNames.AthletesTable)] CloudTable athletesTable,
            [Queue(QueueNames.SyncDay)] IAsyncCollector <SyncDayRequest> syncDayRequests,
            ILogger log)
        {
            var littleStravaClient = new LittleStravaClient();
            var activity           = await littleStravaClient.GetActivityById(athlete, message.ActivityId);

            await syncDayRequests.AddAsync(new SyncDayRequest
            {
                DateTime  = activity.StartDate.Date,
                AthleteId = athlete.GetAthleteId()
            });

            await athletesTable.ExecuteAsync(TableOperation.InsertOrReplace(athlete));
        }