Exemple #1
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);
                }
            }
        }
        protected override void Action()
        {
            Setup();

            Console.WriteLine("Searching for activities...");

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

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

            Console.WriteLine("Total {0} activities found.", activities.Count);
            DownloadActivities(activities);
        }
Exemple #3
0
        protected override void Action()
        {
            Console.WriteLine("Searching for activities...");

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

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

            Console.WriteLine("Total {0} activities found.", activities.Count);
            foreach (var activity in activities)
            {
                DisplayActivity(activity);
            }
        }
        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);
        }