-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathTransaction.cs
71 lines (56 loc) · 2.24 KB
/
Transaction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Todoist.Net.Models;
namespace Todoist.Net.Services
{
/// <summary>
/// Represents a Transaction
/// </summary>
/// <seealso cref="Todoist.Net.Services.ITransaction" />
internal class Transaction : ITransaction
{
private readonly LinkedList<Command> _commands;
private readonly IAdvancedTodoistClient _todoistClient;
/// <summary>
/// Initializes a new instance of the <see cref="Transaction"/> class.
/// </summary>
/// <param name="todoistClient">The client.</param>
internal Transaction(IAdvancedTodoistClient todoistClient)
{
_todoistClient = todoistClient;
_commands = new LinkedList<Command>();
Project = new ProjectsCommandService(_commands);
Notes = new NotesCommandService(_commands);
Items = new ItemsCommandService(_commands);
Labels = new LabelsCommandService(_commands);
Notifications = new NotificationsCommandService(_commands);
Filters = new FiltersCommandService(_commands);
Reminders = new RemindersCommandService(_commands);
Users = new UsersCommandService(_commands);
Sharing = new SharingCommandService(_commands);
}
public IFiltersCommandService Filters { get; set; }
public IItemsCommandService Items { get; }
public ILabelsCommandService Labels { get; }
public INotesCommandServices Notes { get; }
public INotificationsCommandService Notifications { get; }
public IProjectCommandService Project { get; }
public IRemindersCommandService Reminders { get; }
public ISharingCommandService Sharing { get; }
public IUsersCommandService Users { get; }
/// <inheritdoc/>
public async Task<string> CommitAsync(CancellationToken cancellationToken = default)
{
try
{
return await _todoistClient.ExecuteCommandsAsync(cancellationToken, _commands.ToArray()).ConfigureAwait(false);
}
finally
{
_commands.Clear();
}
}
}
}