public async Task RefreshConfigFileAsync(bool force = false) { CreateConfigDirectory(); bool requireRefresh = force || File.Exists(HasChangesFile); if (!requireRefresh) { return; } Logger.LogInformation("Reloading config..."); var newGlobalConfig = await LoadGlobalConfigAsync(); if (newGlobalConfig != StickyConfig) { StickyConfig = newGlobalConfig; } var newServerConfigs = await LoadServerConfigsAsync(); var addedConfigs = newServerConfigs.Except(Configs); var removedConfigs = Configs.Except(newServerConfigs); var duplicates = newServerConfigs.GroupBy(x => x.Port) .Where(x => x.Count() > 1) .ToList(); foreach (var duplicate in duplicates) { int port = duplicate.Key; Logger.LogError($"There are multiple StickyNets registered for port {port}! Please remove the duplicates!"); Logger.LogWarning("Ignoring duplicates!"); newServerConfigs.RemoveAll(x => x.Port == port); newServerConfigs.Add(duplicate.First()); } foreach (var config in removedConfigs) { if (ServerRemoved != null) { await ServerRemoved.Invoke(config); } } foreach (var config in addedConfigs) { if (ServerAdded != null) { await ServerAdded.Invoke(config); } } Configs = newServerConfigs.ToList(); File.Delete(HasChangesFile); }
private void ServiceLost(DNSSDService browser, DNSSDFlags flags, uint ifIndex, string serviceName, string regType, string domain) { Log("Service " + serviceName + " lost"); Server server = null; Mutex.WaitOne(); foreach (Server item in servers) { if (item.Name == serviceName) { server = item; break; } } if (server != null) { servers.Remove(server); ServerRemoved?.Invoke(server); } Mutex.ReleaseMutex(); }