Example #1
0
        /// <summary>
        ///   List all the objects pinned to local storage.
        /// </summary>
        /// <param name="mode">
        ///   The <see cref="PinMode">type</see> of pinned objects to return.
        ///   Defaults to <see cref="PinMode.All"/>.
        /// </param>
        /// <param name="cancel">
        ///   Is used to stop the task.  When cancelled, the <see cref="TaskCanceledException"/> is raised.
        /// </param>
        public async Task <PinnedObject[]> ListAsync(PinMode mode = PinMode.All, CancellationToken cancel = default(CancellationToken))
        {
            var filter = "type=" + mode.ToString().ToLowerInvariant();
            var json   = await ipfs.DoCommandAsync("pin/ls", cancel, null, filter);

            var keys = (JObject)(JObject.Parse(json)["Keys"]);

            return(keys
                   .Properties()
                   .Select(p => new PinnedObject
            {
                Id = p.Name,
                Mode = (PinMode)Enum.Parse(typeof(PinMode), (string)keys[p.Name]["Type"], true)
            })
                   .ToArray());
        }
Example #2
0
        public void PinMode(int pinNumber, PinMode pinMode)
        {
            CheckConnected();

            if (IsDebug)
            {
                Console.WriteLine("Setting pin mode...");
                Console.WriteLine("  Pin number: " + pinNumber);
                Console.WriteLine("  Pin mode: " + pinMode.ToString());
            }

            var cmd = String.Format("M{0}:{1}", pinNumber, (int)pinMode);

            if (IsDebug)
            {
                Console.WriteLine("Sending command: " + cmd);
            }

            Client.WriteLine(cmd);
        }
Example #3
0
 /// <summary>
 /// Sets the basic mode for a particular pin.
 /// </summary>
 /// <param name="pin">The pin to set the mode on.</param>
 /// <param name="mode">The mode.</param>
 public void PinMode(int pin, PinMode mode)
 {
     Debug.WriteLine(string.Format("Sending pin mode {0} to pin {1}", mode.ToString(), pin));
     SerialConnector.Send(
         new Command(CommandMap.PinMode, pin, (int)mode));
 }