Пример #1
0
        public List <Activity> FindAllActivities(ActivitySearchFilters filters)
        {
            filters.Start     = 0;
            filters.Limit     = 250;
            filters.SortBy    = "startLocal";
            filters.SortOrder = "asc";


            var activities = new List <Activity>();

            do
            {
                Console.WriteLine("Searching from start {0}", filters.Start);
                var pageResult = FindActivities(filters);
                if (pageResult.Count == 0)
                {
                    break;
                }
                activities.AddRange(pageResult);

                filters.Start += pageResult.Count;
            } while (true);

            return(activities);
        }
Пример #2
0
        public List <Activity> FindActivities(ActivitySearchFilters filters)
        {
            var uri      = new Uri("https://connect.garmin.com/modern/proxy/activitylist-service/activities/search/activities?" + filters.ToQueryString());
            var request  = new RestRequest(uri, Method.GET);
            var response = ConnectClient.Execute(request);

            return(Activity.ParseActivityList(response.Content));
        }
Пример #3
0
        private void SnycActivities(Options options, DateTime fromDate, Session session, DownloadService downloadService)
        {
            ActivitySearchService activitySearchService = new ActivitySearchService(session);
            var searchOptions = new ActivitySearchFilters
            {
                StartDate = fromDate
            };

            Console.WriteLine("Search for activities from " + fromDate);

            List <Activity> activities = activitySearchService.FindAllActivities(searchOptions);

            if (activities == null)
            {
                Console.WriteLine("No activities found.");
                return;
            }

            if (options.SaveActivityResult)
            {
                Console.WriteLine("Save activities json");
                foreach (Activity activity in activities)
                {
                    var    targetDirectory = FileUtils.CreateDirectoryIfNotExists(options.OutputPath + ACTIVITY_DIR);
                    var    json            = JsonConvert.SerializeObject(activity);
                    string filePath        = targetDirectory.FullName + "/" + activity.ActivityId + ".json";
                    using (FileStream streamWriter = File.Create(filePath))
                    {
                        var data = Encoding.ASCII.GetBytes(json);
                        streamWriter.Write(data, 0, data.Length);
                    }
                    FileInfo fileInfo = new FileInfo(filePath);
                    fileInfo.CreationTime  = activity.StartTimeLocal;
                    fileInfo.LastWriteTime = activity.StartTimeLocal;
                }
            }

            foreach (var activity in activities)
            {
                try
                {
                    if (options.Origin)
                    {
                        downloadService.DownloadActivity("http://connect.garmin.com/proxy/download-service/files/activity/" + activity.ActivityId, options.OutputPath + ACTIVITY_DIR, activity.StartTimeLocal);
                    }
                    else
                    {
                        downloadService.DownloadGpxActivity("http://connect.garmin.com/proxy/download-service/export/gpx/activity/" + activity.ActivityId, activity.ActivityId, options.OutputPath + ACTIVITY_DIR, activity.StartTimeLocal);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Download activity failed:" + ex.Message);
                }
            }
        }
        private IEnumerable <Activity> GetAllActivities()
        {
            Console.WriteLine("Search for activities in the past month...");
            var searchOptions = new ActivitySearchFilters
            {
                FromDate = DateTime.Today.AddMonths(-1)
            };

            List <Activity> activities = ActivitySearchService.FindAllActivities(searchOptions);

            if (activities == null)
            {
                Console.WriteLine("No activities found.");
                return(null);
            }

            Console.WriteLine("Total {0} activities found.", activities.Count);
            foreach (var activity in activities)
            {
                DisplayActivity(activity);
            }

            return(activities);
        }