예제 #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);
                }
            }
        }
예제 #2
0
        private void SnycWellness(Options options, DateTime fromDate, DownloadService downloadService)
        {
            while (fromDate <= DateTime.Now)
            {
                string dateString = fromDate.ToString("yyyy-MM-dd");
                string url        = "https://connect.garmin.com/modern/proxy/download-service/files/wellness/" + dateString;

                try
                {
                    downloadService.DownloadActivity(url, options.OutputPath + WELLNESS_DIR, fromDate);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Download welness failed:" + ex.Message);
                }

                fromDate = fromDate.AddDays(1);
            }
        }