@@ -48,7 +48,30 @@ public void Add(PinnedObject obj)
48
48
if ( obj == null )
49
49
throw new ArgumentNullException ( ) ;
50
50
51
- throw new NotImplementedException ( ) ;
51
+ var recursive = "recursive=" + ( obj . Mode == PinMode . Recursive ) . ToString ( ) . ToLowerInvariant ( ) ;
52
+ ipfs . DoCommand ( "pin/add" , obj . Id , recursive ) ;
53
+ pins = null ;
54
+ }
55
+
56
+ /// <summary>
57
+ /// Pin an object.
58
+ /// </summary>
59
+ /// <param name="id">
60
+ /// The string representation of the object's <see cref="MultiHash"/>.
61
+ /// </param>
62
+ /// <param name="recursive">
63
+ /// True to also pin the object's links; False to just pin the object. Defaults to true.
64
+ /// </param>
65
+ /// <remarks>
66
+ /// Equivalent to <c>ipfs pin add <i>id</i></c>.
67
+ /// </remarks>
68
+ public void Add ( string id , bool recursive = true )
69
+ {
70
+ Add ( new PinnedObject
71
+ {
72
+ Id = id ,
73
+ Mode = recursive ? PinMode . Recursive : PinMode . Direct
74
+ } ) ;
52
75
}
53
76
54
77
/// <summary>
@@ -68,6 +91,11 @@ public bool Contains(PinnedObject item)
68
91
return Pins . Contains ( item ) ;
69
92
}
70
93
94
+ public bool Contains ( string id )
95
+ {
96
+ return Pins . Any ( pin => pin . Id == id ) ;
97
+ }
98
+
71
99
/// <inheritdoc />
72
100
public void CopyTo ( PinnedObject [ ] array , int index )
73
101
{
@@ -90,17 +118,42 @@ public bool IsReadOnly
90
118
}
91
119
92
120
/// <summary>
93
- /// Remove the trusted peer .
121
+ /// Remove the pinned object .
94
122
/// </summary>
95
123
/// <remarks>
96
- /// Equivalent to <c>ipfs bootstrap rm <i>peer </i></c>.
124
+ /// Equivalent to <c>ipfs pin rm <i>id </i></c>.
97
125
/// </remarks>
98
- public bool Remove ( PinnedObject peer )
126
+ public bool Remove ( PinnedObject obj )
99
127
{
100
- if ( peer == null )
128
+ if ( obj == null )
101
129
throw new ArgumentNullException ( ) ;
102
130
103
- throw new NotImplementedException ( ) ;
131
+ var recursive = "recursive=" + ( obj . Mode == PinMode . Recursive ) . ToString ( ) . ToLowerInvariant ( ) ;
132
+ ipfs . DoCommand ( "pin/rm" , obj . Id , recursive ) ;
133
+ pins = null ;
134
+
135
+ return true ;
136
+ }
137
+
138
+ /// <summary>
139
+ /// Unpin an object.
140
+ /// </summary>
141
+ /// <param name="id">
142
+ /// The string representation of the object's <see cref="MultiHash"/>.
143
+ /// </param>
144
+ /// <param name="recursive">
145
+ /// True to also unpin the object's links; False to just unpin the object. Defaults to true.
146
+ /// </param>
147
+ /// <remarks>
148
+ /// Equivalent to <c>ipfs pin rm <i>id</i></c>.
149
+ /// </remarks>
150
+ public bool Remove ( string id , bool recursive = true )
151
+ {
152
+ return Remove ( new PinnedObject
153
+ {
154
+ Id = id ,
155
+ Mode = recursive ? PinMode . Recursive : PinMode . Direct
156
+ } ) ;
104
157
}
105
158
106
159
/// <inheritdoc />
0 commit comments