public List <Guid> ApplyVirtualHosts(Guid settingId, BinaryReader inputStreamReader) //Return affected virtual hosts { var count = (int)inputStreamReader.ReadUInt16LittleEndian(); if (count == 0) { throw new InvalidDataException(); } var affectedVirtualHosts = new List <Guid>(); var newHosts = new Dictionary <Guid, VirtualHostSetting>(); for (int index = 0; index < count; index++) { var virtualHostId = inputStreamReader.ReadGuid(); var priority = inputStreamReader.ReadInt32LittleEndian(); var weight = inputStreamReader.ReadInt32LittleEndian(); VirtualHostSetting virtualHost = new VirtualHostSetting(priority, weight); newHosts.Add(virtualHostId, virtualHost); } lock (virtualHostLock) { VirtualHostSettingId = settingId; foreach (var item in newHosts) { var virtualHostId = item.Key; var virtualHost = item.Value; if (VirtualHosts.TryGetValue(virtualHostId, out var oldVirtualHost)) { if (oldVirtualHost != virtualHost) { affectedVirtualHosts.Add(virtualHostId);//changed } VirtualHosts.Remove(virtualHostId); } else { affectedVirtualHosts.Add(virtualHostId);//added } } affectedVirtualHosts.AddRange(VirtualHosts.Keys);//removed VirtualHosts = newHosts; } return(affectedVirtualHosts); }
public Dictionary <Guid, VirtualHostSetting> ApplyVirtualHosts(Guid settingId, string value, out List <Guid> affectedVirtualHosts) //from redis { affectedVirtualHosts = new List <Guid>(); var newHosts = new Dictionary <Guid, VirtualHostSetting>(); var texts = value.Split(','); foreach (var text in texts) { var setting = text.Split('-'); var virtualHostId = Guid.Parse(setting[0]); var priority = int.Parse(setting[1]); var weight = int.Parse(setting[2]); VirtualHostSetting virtualHost = new VirtualHostSetting(priority, weight); newHosts.Add(virtualHostId, virtualHost); } lock (virtualHostLock) { VirtualHostSettingId = settingId; foreach (var item in newHosts) { var virtualHostId = item.Key; var virtualHost = item.Value; if (VirtualHosts.TryGetValue(virtualHostId, out var oldVirtualHost)) { if (oldVirtualHost != virtualHost) { affectedVirtualHosts.Add(virtualHostId);//changed } VirtualHosts.Remove(virtualHostId); } else { affectedVirtualHosts.Add(virtualHostId);//added } } affectedVirtualHosts.AddRange(VirtualHosts.Keys);//deleted VirtualHosts = newHosts; } return(newHosts); }