internal void OnNodeAdded(NodeShareInfo ninfo, string nodename, long pctimeStamp) { var newinf = new NodeInfoForPC { NodeGuid = ninfo.NodeId, PCVersion = ninfo.PCVersion, PCTimeStamp = pctimeStamp, Url = ninfo.Url, Name = nodename }; lock (CachedNodes) { CachedNodes.Add(newinf); } OnCachedNodesChange(); }
internal async Task OnNodeUpdate(NodeInfo ninfo, List <SSDPPCInfo> ssdpinfo) { bool updated = false; bool deleted = false; lock (CachedNodes) { var ssdpin = ssdpinfo.FirstOrDefault(x => x.Id == Id); if (ssdpin != null) { var name = DecryptName(ssdpin.EN); if (name == null) { logger.LogError($"Invalid node from {ninfo.Url}"); return; } NodeInfoForPC info = CachedNodes.FirstOrDefault(x => x.NodeGuid == ninfo.NodeGuid); if (info != null) { if (info.PCTimeStamp < ssdpin.TimeStamp) { CachedNodes.Remove(info); } else { return; } } var newinf = new NodeInfoForPC { NodeGuid = ninfo.NodeGuid, PCVersion = ninfo.PCVersion, PCTimeStamp = ssdpin.TimeStamp, Url = ninfo.Url, Name = name }; CachedNodes.Add(newinf); OnCachedNodesChange(); updated = true; } else { int nremoved = 0; if (CachedNodes.FirstOrDefault(x => x.NodeGuid == ninfo.NodeGuid) != null) { nremoved = CachedNodes.RemoveAll(x => x.NodeGuid == ninfo.NodeGuid); } if (nremoved > 0) { OnCachedNodesChange(); deleted = true; } } } if (updated || deleted) { if (!deleted) { var pci = await GetPeerPCInfo(this, ninfo).ConfigureAwait(false); if ((pci != null) && (pci.StorageProviders != null)) { bool needResync = false; foreach (var sp in pci.StorageProviders) { if (sp.Visibility != StorageProviderVisibility.Public) { continue; } if (sp.Type == StorageProviderInstance.TypeAliYun) { lock (StorageProviderInstances) { if (!StorageProviderInstances.Any(x => sp.Id.Equals(x.RuntimeId))) { var instance = new StorageProviderInstance_AliyunOSS(new StorageProviderInfo { Id = sp.Id, Type = StorageProviderInstance.TypeAliYun, Name = sp.Name, Visibility = sp.Visibility, Settings = sp.Settings }); StorageProviderInstances.Add(instance); needResync = true; } } } if (sp.Type == StorageProviderInstance.TypeAzure) { lock (StorageProviderInstances) { if (!StorageProviderInstances.Any(x => sp.Id.Equals(x.RuntimeId))) { var instance = new StorageProviderInstance_AzureBlob(new StorageProviderInfo { Id = sp.Id, Type = StorageProviderInstance.TypeAzure, Name = sp.Name, Visibility = sp.Visibility, Settings = sp.Settings }); StorageProviderInstances.Add(instance); needResync = true; } } } } if (needResync) { ResyncClientListToStorageProviderInstances(); } } if ((pci != null) && (pci.Apps != null)) { foreach (var ai in pci.Apps) { NodeInfoForPC n = null; lock (CachedNodes) { n = CachedNodes.FirstOrDefault(x => x.NodeGuid == ai.NodeId); } if (n == null) { return; } var a = Apps.FirstOrDefault(x => (x.NodeId == ai.NodeId) && (x.AppId == ai.AppId) && (x.Name == ai.Name)); if (a == null) { lock (Apps) { Apps.Add(ai); } } } } } _ = Task.Run(() => { try { OnNodeChangedEvent?.Invoke(this, EventArgs.Empty); } catch { } }); } }