コード例 #1
0
        private static async Task HandleAsync(string serverUrl, string accessToken, string username, string password, string timelineKey, DateTime fromTime, DateTime toTime)
        {
            using var client = HttpClientFactory.Create(username, password, accessToken);
            serverUrl ??= await client.GetCloudServerUrlAsync();

            JsonElement home = await client.GetAsJsonAsync(serverUrl, ManicTimeMediaType.V3);

            JsonElement timelines = await client.GetAsJsonAsync(Urls.Timelines(home.GetLinkHref("manictime/timelines"), timelineKey), ManicTimeMediaType.V3);

            JsonElement timeline = timelines.GetProperty("timelines").EnumerateArray().SingleOrDefault();

            if (timeline.ValueKind == JsonValueKind.Undefined)
            {
                throw new InvalidOperationException("Timeline not found.");
            }
            JsonElement activities = await client.GetAsJsonAsync(Urls.Activities(timeline.GetLinkHref("manictime/activities"), fromTime, toTime), ManicTimeMediaType.V3);

            Console.WriteLine(activities.FormatForDisplay());
        }