示例#1
0
 public Task DeleteServerConfigAsync(StickyServerConfig config)
 {
     File.Delete(config.FilePath);
     Configs.Remove(config);
     Logger.LogInformation($"Removed the following StickyNet:\r\n{config}");
     return(Task.CompletedTask);
 }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
 public bool Equals(StickyServerConfig other)
 => other == null
         ? false
         : Port == other.Port;