-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadOnlyLinksCollection.cs
More file actions
83 lines (73 loc) · 2.28 KB
/
ReadOnlyLinksCollection.cs
File metadata and controls
83 lines (73 loc) · 2.28 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Ipfs.CoreApi;
using OwlCore.ComponentModel;
using OwlCore.Nomad.Kubo;
using WindowsAppCommunity.Sdk.Models;
namespace WindowsAppCommunity.Sdk.Nomad;
/// <inheritdoc cref="IReadOnlyLinksCollection" />
public class ReadOnlyLinksCollection : IReadOnlyLinksCollection, IDelegable<ILinkCollection>, IReadOnlyNomadKuboRegistry<Link>
{
/// <summary>
/// The client to use for communicating with ipfs.
/// </summary>
public required ICoreApi Client { get; init; }
/// <inheritdoc/>
public required ILinkCollection Inner { get; init; }
/// <summary>
/// The links in this collection.
/// </summary>
public Link[] Links => Inner.Links.Select(link => new Link
{
Id = link.Id,
Url = link.Url,
Name = link.Name,
Description = link.Description,
}).ToArray();
/// <inheritdoc/>
public event EventHandler<Link[]>? LinksAdded;
/// <inheritdoc/>
public event EventHandler<Link[]>? LinksRemoved;
/// <inheritdoc/>
public event EventHandler<Link[]>? ItemsAdded
{
add => LinksAdded += value;
remove => LinksAdded -= value;
}
/// <inheritdoc/>
public event EventHandler<Link[]>? ItemsRemoved
{
add => LinksRemoved += value;
remove => LinksRemoved -= value;
}
/// <inheritdoc/>
public Task<Link> GetAsync(string id, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var link = Inner.Links.First(link => link.Id == id);
return Task.FromResult(new Link
{
Id = link.Id,
Name = link.Name,
Url = link.Url,
Description = link.Description
});
}
/// <inheritdoc/>
public async IAsyncEnumerable<Link> GetAsync([EnumeratorCancellation] CancellationToken cancellationToken)
{
await Task.Yield();
foreach (var link in Inner.Links)
{
cancellationToken.ThrowIfCancellationRequested();
yield return new Link
{
Id = link.Id,
Name = link.Name,
Url = link.Url,
Description = link.Description
};
}
}
}