/// <summary> /// Retrieve all applicable values from the DHT. /// </summary> /// <param name="key">The key of the value to retrieve.</param> /// <returns>All the list of resources found on network, ordered by semantic affinity</returns> public IList <KademliaResource> GetAll(string key) { IList <KademliaResource> found = dhtNode.Get(key); if (found.Count > 0) { return(found.AsParallel().OrderByDescending( d => QualityCalculator.calculateQualityCoefficient( key, new string[3] { d.Tag.Album, d.Tag.Artist, d.Tag.Title }, 0, 0, d.Tag.Bitrate, d.Tag.Channels, d.Tag.SampleRate) ).ToList()); } else { return(found); } }
/// <summary> /// Retrieve a value from the DHT. /// </summary> /// <param name="key">The key of the value to retrieve.</param> /// <returns>the best semantically matching value stored for the key, or null if no values are found</returns> public KademliaResource Get(string key) { IList <KademliaResource> found = dhtNode.Get(key); if (found.Count > 0) { IList <KademliaResource> ordered = found.AsParallel().OrderByDescending( d => QualityCalculator.calculateQualityCoefficient( key, new string[3] { d.Tag.Album, d.Tag.Artist, d.Tag.Title }, 0, 0, d.Tag.Bitrate, d.Tag.Channels, d.Tag.SampleRate) ).ToList(); return(ordered[0]); // An arbitrary value } else { return(null); // Nothing there } }