public Task DeleteServerConfigAsync(StickyServerConfig config) { File.Delete(config.FilePath); Configs.Remove(config); Logger.LogInformation($"Removed the following StickyNet:\r\n{config}"); return(Task.CompletedTask); }
public async Task AddServerConfigAsync(StickyServerConfig config) { CreateConfigDirectory(); config.FilePath = GenerateFilePath(config); string json = JsonConvert.SerializeObject(config, Formatting.Indented); await File.WriteAllTextAsync(config.FilePath, json); Logger.LogInformation("Successfully saved config file!"); Configs.Add(config); }
private string GenerateFilePath(StickyServerConfig config) { string path = Path.Combine(ConfigFolderPath, $"{config.Port}-{config.Protocol}.cfg"); int i = 0; while (File.Exists(path)) { path = Path.Combine(ConfigFolderPath, $"{config.Port}-{config.Protocol}-{i}.cfg"); i++; } return(path); }
public bool Equals(StickyServerConfig other) => other == null ? false : Port == other.Port;