public static AppRuntime AppRuntime(this AppRegistry registry) { //框架不负责初始化逻辑,由扩展程序决定 var appRuntime = registry.GetOrCreate <AppRuntime>().WithTitle("应用运行时信息").ValueAs <AppRuntime>(); return(appRuntime); }
public static string CreateItemId <T>(this AppRegistry registry) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } return(typeof(T).GetFriendlyName()); }
public static AppRegistryItem GetOrCreate <T>(this AppRegistry registry) where T : new() { var itemId = registry.CreateItemId <T>(); var itemValue = registry.TryFindItemValue <T>(itemId); if (itemValue != null) { return(itemValue); } itemValue = AppRegistryItem.Create(itemId, new T()).Register(registry); return(itemValue); }
public static AppRegistryItem LoadFromFile(this AppRegistry registry, string id) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } var fileDbHelper = FileDbHelper.Instance; var filePath = fileDbHelper.MakeAppDataFilePath("AppRegistry", $"{id}.json"); var theOne = fileDbHelper.Read <AppRegistryItem>(filePath).SingleOrDefault(); return(theOne); }
public static AppRegistryItem Register(this AppRegistryItem theItem, AppRegistry registry) { if (theItem == null) { throw new ArgumentNullException(nameof(theItem)); } if (registry == null) { throw new ArgumentNullException(nameof(registry)); } registry.Register(theItem); return(theItem); }
public static void SaveToFile(this AppRegistry registry, AppRegistryItem item) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } if (item == null) { throw new ArgumentNullException(nameof(item)); } var fileDbHelper = FileDbHelper.Instance; var filePath = fileDbHelper.MakeAppDataFilePath("AppRegistry", $"{item.Id}.json"); fileDbHelper.Save(filePath, item); }
public static AppRegistryItem TryFindItemValue <T>(this AppRegistry registry, string itemId) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } if (itemId == null) { throw new ArgumentNullException(nameof(itemId)); } var theItem = registry.TryFind(itemId); return(theItem); }
public static AppRegistry SetupSingletons(this AppRegistry registry, IServiceCollection services) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } //把注册表和包含的项目,全部注册成Singleton services.AddSingleton(registry); foreach (var item in registry.Items) { var theType = item.Value.GetType(); registry.Logger.Log($"AppRegistry Items Singleton Setup => {theType.GetFriendlyName()}"); services.AddSingleton(theType, item.Value); } return(registry); }
public static AppRegistryItem LoadFromFile <T>(this AppRegistry registry, bool updateSelf) where T : new() { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } var itemId = registry.CreateItemId <T>(); var theSource = registry.LoadFromFile(itemId); if (theSource != null) { var item = registry.GetOrCreate <T>(); if (updateSelf) { item.Id = theSource.Id; item.Title = theSource.Title; item.Group = theSource.Group; item.Value = theSource.Value; return(item); } } return(theSource); }
public static List <AppRegistryItem> LoadFromFile(this AppRegistry registry) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } var fileDbHelper = FileDbHelper.Instance; var ids = registry.Items.Select(x => x.Id).ToList(); var items = new List <AppRegistryItem>(); foreach (var id in ids) { var filePath = fileDbHelper.MakeAppDataFilePath("AppRegistry", $"{id}.json"); var theOne = fileDbHelper.Read <AppRegistryItem>(filePath).SingleOrDefault(); if (theOne != null) { items.Add(theOne); } } return(items); }