public static Config Load(IniData iniData) { Config cfg = new Config(); cfg.ApiKey = iniData.GetKey("main.apiKey"); cfg.AuthType = iniData.GetKey("main.auth"); return(cfg); }
protected string GetProductIniValue(string SectionName, string Key) { var parser = new FileIniDataParser(); parser.Parser.Configuration.CommentString = ";"; var FilePath = Assembly.GetEntryAssembly().Location; IniData data = parser.ReadFile(Path.Combine(Directory.GetParent(FilePath).FullName, "TestProgramConfigProductInfo.ini")); var FormatKey = string.Format("{0}.{1}", SectionName, Key); Console.WriteLine(data.GetKey(FormatKey)); return(data.GetKey(FormatKey)); }
public frmMainScreen() { InitializeComponent(); var parser = new FileIniDataParser(); IniData data = parser.ReadFile("db.ini"); database.server = data.GetKey("host"); database.dbName = data.GetKey("name"); database.username = data.GetKey("user"); database.password = data.GetKey("pass"); dh = new DataHandler(); bis = new BindingSource(); }
public static string GetStringKey(string FilePath, string key, string defaultValue = "") { try { var parser = new FileIniDataParser(); IniData data = parser.ReadFile(FilePath, Encoding.ASCII); var s = data.GetKey(key); if (s == null) { return(defaultValue); } if (s.Length == 0) { return(defaultValue); } return(s); } catch (Exception e) { //Helper.WriteLog(e.Message); //todo error log return(defaultValue); } }
public ConfigureWindow(IniData data) { InitializeComponent(); mData = data; if (mData.GetKey("debug")?.ToLowerInvariant() == "on") { enableDebugModeCheckbox.Checked = true; } if (mData.GetKey("anonymous")?.ToLowerInvariant() == "on") { enableAnonymousModeCheckbox.Checked = true; } }
private bool ContainsTaikoBeatmap(ZipArchiveEntry file) { IniData data = this.GetIniData(file); return(string.Equals( data.GetKey("general.mode"), taikoMode.ToString(), StringComparison.InvariantCultureIgnoreCase)); }
static string GetIniValue(string Key) { try { var parser = new FileIniDataParser(); parser.Parser.Configuration.CommentString = "#"; IniData data = parser.ReadFile("config.ini"); var SectionName = data.Sections.FirstOrDefault().SectionName; var FormatKey = string.Format("{0}.{1}", SectionName, Key); Console.WriteLine(data.GetKey(FormatKey)); return(data.GetKey(FormatKey)); } catch (Exception ex) { Error(ex); return(string.Empty); } }
public string GetIniValue(string Key) { try { var parser = new FileIniDataParser(); parser.Parser.Configuration.CommentString = "#"; var FilePath = Assembly.GetEntryAssembly().Location; IniData data = parser.ReadFile(Path.Combine(Directory.GetParent(FilePath).FullName, "config.ini")); var SectionName = data.Sections.FirstOrDefault().SectionName; var FormatKey = string.Format("{0}.{1}", SectionName, Key); Console.WriteLine("{0} {1}", Key, data.GetKey(FormatKey)); return(data.GetKey(FormatKey)); } catch (Exception ex) { Error(ex); return(string.Empty); } }
private async void Login(String username, String password) { HttpClient httpClient = new HttpClient(); string body = await httpClient.GetStringAsync(data.GetKey("server") + "/api/v1/login?username="******"&password="******"cache_dir") + "/" + rep.body).Create(); new System.IO.DirectoryInfo(data.GetKey("data_dir") + "/" + rep.body).Create(); new System.IO.DirectoryInfo(data.GetKey("log_dir") + "/" + rep.body).Create(); Workspace workspace = new Workspace(); workspace.Show(); this.Hide(); } else { MessageBox.Show(rep.msg); } }
public void ConfigureServices(IServiceCollection services) { var parser = new FileIniDataParser(); var iniPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "pttBeauty.ini"); IniData data = parser.ReadFile(iniPath); var config = ConfigurationOptions.Parse(data.GetKey("RedisConnectionString")); var redisConnection = ConnectionMultiplexer.Connect(config); redisDatabase = redisConnection.GetDatabase(); redisServer = redisConnection.GetServer(config.EndPoints.First()); }
/// <summary> /// 读取或更改站点设置 /// </summary> /// <param name="siteShortName">站点短名</param> /// <param name="siteConfig">设置参数表</param> /// <param name="configType">设置方法</param> public static string SiteConfig(string siteShortName, SiteConfigArgs siteConfig, SiteConfigType configType = SiteConfigType.Read) { if (string.IsNullOrWhiteSpace(siteShortName)) { return(string.Empty); } IniData iniData = new IniData(); if (inis.ContainsKey(siteShortName)) { iniData = inis[siteShortName]; } switch (configType) { case SiteConfigType.Change: if (string.IsNullOrWhiteSpace(siteConfig.Section) || string.IsNullOrWhiteSpace(siteConfig.Key)) { return(string.Empty); } iniData[siteConfig.Section][siteConfig.Key] = siteConfig.Value; inis[siteShortName] = iniData; break; case SiteConfigType.Save: SaveSiteConfig(siteShortName); break; default: if (string.IsNullOrWhiteSpace(siteConfig.Section) || string.IsNullOrWhiteSpace(siteConfig.Key)) { return(string.Empty); } if (string.IsNullOrWhiteSpace(iniData.GetKey(siteConfig.Section))) { try { LoadSiteConfig(siteShortName); iniData = inis[siteShortName]; } catch { } } return(iniData[siteConfig.Section][siteConfig.Key] ?? string.Empty); } return(string.Empty); }
public string Read(string key) { var parts = key.Split(':'); // Global key if (parts.Length is 1) { return(_ini.GetKey(parts[0])); } // Local key else if (parts.Length is 2) { return(_ini[parts[0]][parts[1]]); } throw new InvalidKeyFormatException($"Key {key} has an incorrect format."); }
private Song GetSongData(IniData data) { Song song = new Song { Id = id, CategoryId = categoryId, Order = id, Offset = 0, Volume = 1, Type = SongTypeEnum.Osu.ToString().ToLower() }; if (!data.Sections.ContainsSection("general")) { ConsoleHelper.WriteError("Could not find general data!"); return(null); } if (data.TryGetKey("general.mode", out string modeString)) { if (int.TryParse(modeString, out int mode)) { if (mode != taikoMode) { ConsoleHelper.WriteError("Not an Osu!Taiko beatmap!!"); return(null); } } } else { ConsoleHelper.WriteError("Could not determine mode!"); return(null); } if (data.TryGetKey("general.previewtime", out string previewTime)) { if (double.TryParse(previewTime, out double previewTimeAsDbl)) { song.Preview = previewTimeAsDbl / 1000; } } if (!data.Sections.ContainsSection("metadata")) { ConsoleHelper.WriteError("Could not find metadata!"); return(null); } if (data.TryGetKey("metadata.title", out string title)) { song.Title = title; } else { ConsoleHelper.WriteError("Could not find title!"); return(null); } if (!string.IsNullOrWhiteSpace(data.GetKey("metadata.artist")) && !string.IsNullOrWhiteSpace(data.GetKey("metadata.source"))) { song.Subtitle = $"{data.GetKey("metadata.artist")} - {data.GetKey("metadata.source")}"; } else if (data.GetKey("metadata.artist") != null) { song.Subtitle = data.GetKey("metadata.artist"); } return(song); }
public string GetKeyValue(string valueKey) => Data?.GetKey(valueKey);
private void ValidSettingsCheck() { if (bedrockServers.Count() < 1) { throw new Exception("No Servers Configured"); } else { var exeLocations = bedrockServers.GroupBy(t => t.ServerConfig.BedrockServerExeLocation); if (exeLocations.Count() != bedrockServers.Count()) { throw new Exception("Duplicate Server Paths defined"); } foreach (var server in bedrockServers) { if (!File.Exists(server.ServerConfig.BedrockServerExeLocation)) { throw new FileNotFoundException("The bedrock server file is not accessible or does not exist", server.ServerConfig.BedrockServerExeLocation); } else { FileInfo inf = new FileInfo(server.ServerConfig.BedrockServerExeLocation); FileInfo configfile = inf.Directory.GetFiles(serverProperties).ToList().Single(); IniDataParser parser = new IniDataParser(); parser.Configuration.AllowKeysWithoutSection = true; parser.Configuration.CommentString = "#"; FileIniDataParser fp = new FileIniDataParser(parser); IniData data = fp.ReadFile(configfile.FullName); server.ServerConfig.ServerName = data.GetKey(serverName); server.ServerConfig.ServerPort4 = data.GetKey(ipv4port); server.ServerConfig.ServerPort6 = data.GetKey(ipv6port); } } var duplicateV4 = bedrockServers.GroupBy(x => x.ServerConfig.ServerPort4) .Where(g => g.Count() > 1) .Select(y => new ServerConfig() { ServerPort4 = y.Key }) .ToList(); var duplicateV4Servers = bedrockServers.Where(t => duplicateV4.Select(r => r.ServerPort4).Contains(t.ServerConfig.ServerPort4)).ToList(); if (duplicateV4Servers.Count() > 0) { throw new Exception("Duplicate server IPv4 ports detected for: " + string.Join(", ", duplicateV4Servers.Select(t => t.ServerConfig.BedrockServerExeLocation))); } var duplicateV6 = bedrockServers.GroupBy(x => x.ServerConfig.ServerPort6) .Where(g => g.Count() > 1) .Select(y => new ServerConfig() { ServerPort6 = y.Key }) .ToList(); var duplicateV6Servers = bedrockServers.Where(t => duplicateV6.Select(r => r.ServerPort6).Contains(t.ServerConfig.ServerPort6)).ToList(); if (duplicateV6Servers.Count() > 0) { throw new Exception("Duplicate server IPv6 ports detected for: " + string.Join(", ", duplicateV6Servers.Select(t => t.ServerConfig.BedrockServerExeLocation))); } var duplicateName = bedrockServers.GroupBy(x => x.ServerConfig.ServerName) .Where(g => g.Count() > 1) .Select(y => new ServerConfig() { ServerName = y.Key }) .ToList(); var duplicateNameServers = bedrockServers.Where(t => duplicateName.Select(r => r.ServerName).Contains(t.ServerConfig.ServerName)).ToList(); if (duplicateNameServers.Count() > 0) { throw new Exception("Duplicate server names detected for: " + string.Join(", ", duplicateV6Servers.Select(t => t.ServerConfig.BedrockServerExeLocation))); } if (bedrockServers.Count > 1) { if (!bedrockServers.Exists(t => t.ServerConfig.ServerPort4 == primaryipv4port && t.ServerConfig.ServerPort6 == primaryipv6port)) { throw new Exception("No server defined with default ports " + primaryipv4port + " and " + primaryipv6port); } bedrockServers.Single(t => t.ServerConfig.ServerPort4 == primaryipv4port && t.ServerConfig.ServerPort6 == primaryipv6port).ServerConfig.Primary = true; } else { bedrockServers.ForEach(t => t.ServerConfig.Primary = true); } } }