public static string GetString(this ConfigFileFormat format) { switch (format) { case ConfigFileFormat.Properties: return("properties"); case ConfigFileFormat.Xml: return("xml"); case ConfigFileFormat.Json: return("json"); case ConfigFileFormat.Yml: return("yml"); case ConfigFileFormat.Yaml: return("yaml"); case ConfigFileFormat.Txt: return("txt"); default: return("unknown"); } }
/// <summary> /// 設定を保存します /// </summary> private void SaveConfig() { ConfigFileFormat data = new ConfigFileFormat() { rules = this.rules }; var jsonStr = JsonUtility.ToJson(data); System.IO.File.WriteAllText(ConfigFile, jsonStr); isDirtyForSave = false; }
public static string GetString(this ConfigFileFormat format) { return(format switch { ConfigFileFormat.Properties => "properties", ConfigFileFormat.Xml => "xml", ConfigFileFormat.Json => "json", ConfigFileFormat.Yml => "yml", ConfigFileFormat.Yaml => "yaml", ConfigFileFormat.Txt => "txt", _ => "unknown", });
public static string GetString(this ConfigFileFormat format) { switch (format) { case ConfigFileFormat.Properties: return("properties"); case ConfigFileFormat.Xml: return("xml"); default: return("unknown"); } }
public LocalFileConfigRepository(string @namespace, IApolloOptions configUtil, IConfigRepository?upstream = null) : base(@namespace) { _upstream = upstream; _options = configUtil; var ext = Path.GetExtension(@namespace); if (ext != null && ext.Length > 1 && Enum.TryParse(ext.Substring(1), true, out ConfigFileFormat format)) { Format = format; } PrepareConfigCacheDir(); }
/// <summary> /// 設定から読み込みます /// </summary> private void LoadConfig() { if (!System.IO.File.Exists(ConfigFile)) { rules = new List <Rule>(); return; } string jsonStr = System.IO.File.ReadAllText(ConfigFile); ConfigFileFormat data = JsonUtility.FromJson <ConfigFileFormat>(jsonStr); this.rules = data.rules; foreach (var rule in rules) { rule.gameObject = AssetDatabase.LoadAssetAtPath <GameObject>(rule.attachPrefabPath); } isDirtyForSave = false; isDirtyForEdit = true; }
/// <summary>添加其他namespace。如果sectionKey为null则添加到root中,可以直接读取,否则使用Configuration.GetSection(sectionKey)读取</summary> public static IApolloConfigurationBuilder AddNamespaceSurgingApollo(this IApolloConfigurationBuilder builder, string @namespace, string?sectionKey, ConfigFileFormat format = ConfigFileFormat.Json) { if (string.IsNullOrWhiteSpace(@namespace)) { throw new ArgumentNullException(nameof(@namespace)); } if (format < ConfigFileFormat.Properties || format > ConfigFileFormat.Txt) { throw new ArgumentOutOfRangeException(nameof(format), format, $"最小值{ConfigFileFormat.Properties},最大值{ConfigFileFormat.Txt}"); } if (format != ConfigFileFormat.Properties) { @namespace += "." + format.GetString(); } var configRepository = builder.ConfigRepositoryFactory.GetConfigRepository(@namespace); var previous = builder.Sources.FirstOrDefault(source => source is SurgingApolloConfigurationProvider apollo && apollo.SectionKey == sectionKey && apollo.ConfigRepository == configRepository); if (previous != null) { builder.Sources.Remove(previous); builder.Sources.Add(previous); } else { builder.Add(new SurgingApolloConfigurationProvider(sectionKey, configRepository)); #pragma warning disable 618 ApolloConfigurationManager.Manager.Registry.Register(@namespace, new DefaultConfigFactory(builder.ConfigRepositoryFactory)); #pragma warning restore 618 } return(builder); }
/// <summary>添加其他namespace</summary> public static IApolloConfigurationBuilder AddNamespaceSurgingApollo(this IApolloConfigurationBuilder builder, string @namespace, ConfigFileFormat format = ConfigFileFormat.Json) => builder.AddNamespaceSurgingApollo(@namespace, null, format);
/// <summary> /// 添加其他namespace /// </summary> /// <param name="builder">The builder.</param> /// <param name="namespace">The namespace.</param> /// <param name="format">The format.</param> /// <returns>IApolloConfigurationBuilder.</returns> public static IApolloConfigurationBuilder AddNamespaceApollo(this IApolloConfigurationBuilder builder, string @namespace, ConfigFileFormat format = ConfigFileFormat.Json) { return(builder.AddNamespaceApollo(@namespace, null, format)); }
/// <summary>添加其他namespace</summary> public static IApolloConfigurationBuilder AddNamespace(this IApolloConfigurationBuilder builder, string @namespace, ConfigFileFormat format = ConfigFileFormat.Properties) => builder.AddNamespace(@namespace, null, format);
/// <summary>添加默认namespace: application,等价于AddNamespace(ConfigConsts.NamespaceApplication)</summary> public static IApolloConfigurationBuilder AddDefault(this IApolloConfigurationBuilder builder, ConfigFileFormat format = ConfigFileFormat.Properties) => builder.AddNamespace(ConfigConsts.NamespaceApplication, null, format);
internal static bool TryGetAdapter(ConfigFileFormat format, out IConfigAdapter adapter) => Dic.TryGetValue(format, out adapter);
public static void AddAdapter(ConfigFileFormat format, IConfigAdapter adapter) => Dic[format] = adapter ?? throw new ArgumentNullException(nameof(adapter));