public static async Task <PeerListing> Load() { PeerListing returnValue = new PeerListing(); try { string filenameHashIpnsEntry = await IpfsApiWrapper.GetAdditionalInformation("salus"); string listingFileHash = await IpfsApiWrapper.ResolveAsync(filenameHashIpnsEntry); if (!string.IsNullOrEmpty(listingFileHash) && await IpfsApiWrapper.Get(listingFileHash, Path.Combine(FileSystemConstants.PswmgrConfigFolder, "peers.json"))) { using (StreamReader reader = new StreamReader(File.OpenRead(ListingFilename))) { string json = reader.ReadToEnd(); returnValue = JsonConvert.DeserializeObject <PeerListing>(json); } } returnValue.Dirty = false; } catch { } await returnValue.Sync(); return(returnValue); }
private async Task Sync() { _FilenameHash = await IpfsApiWrapper.GetAdditionalInformation("salus"); string peerId = IpfsApiWrapper.GetPeerId(); if (!_Peers.Contains(peerId)) { _Peers.Add(peerId); Dirty = true; } await Save(); }
public async Task Save() { if (Dirty) { using (StreamWriter writer = new StreamWriter(ListingFilename)) { writer.Write(JsonConvert.SerializeObject(this, Formatting.Indented)); } string hashFilename = await IpfsApiWrapper.AddAsync(ListingFilename); string filenameHashIpnsEntry = await IpfsApiWrapper.GetAdditionalInformation("salus"); await IpfsApiWrapper.PublishAsync(hashFilename, filenameHashIpnsEntry); Dirty = false; } }