@@ -48,7 +48,30 @@ public void Add(PinnedObject obj)
4848 if ( obj == null )
4949 throw new ArgumentNullException ( ) ;
5050
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+ } ) ;
5275 }
5376
5477 /// <summary>
@@ -68,6 +91,11 @@ public bool Contains(PinnedObject item)
6891 return Pins . Contains ( item ) ;
6992 }
7093
94+ public bool Contains ( string id )
95+ {
96+ return Pins . Any ( pin => pin . Id == id ) ;
97+ }
98+
7199 /// <inheritdoc />
72100 public void CopyTo ( PinnedObject [ ] array , int index )
73101 {
@@ -90,17 +118,42 @@ public bool IsReadOnly
90118 }
91119
92120 /// <summary>
93- /// Remove the trusted peer .
121+ /// Remove the pinned object .
94122 /// </summary>
95123 /// <remarks>
96- /// Equivalent to <c>ipfs bootstrap rm <i>peer </i></c>.
124+ /// Equivalent to <c>ipfs pin rm <i>id </i></c>.
97125 /// </remarks>
98- public bool Remove ( PinnedObject peer )
126+ public bool Remove ( PinnedObject obj )
99127 {
100- if ( peer == null )
128+ if ( obj == null )
101129 throw new ArgumentNullException ( ) ;
102130
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+ } ) ;
104157 }
105158
106159 /// <inheritdoc />
0 commit comments