private static IServiceLocator Setup() { var config = ConfigHelper.LoadConfigSettingFromAssemblies(typeof(ServiceLocator).Assembly, null, null, null); StartupSetting setting = null; if (config != null) { config = config["htb.devfx"]; if (config != null) { setting = ConfigSetting.ToSetting <StartupSetting>(config, "startup"); } } ServiceLocatorSetting locatorSetting = null; if (setting != null && setting.CoreSetting != null) { locatorSetting = setting.CoreSetting.ServiceLocatorSetting; } IServiceLocator instance = null; if (locatorSetting != null && !string.IsNullOrEmpty(locatorSetting.TypeName)) { var typeName = locatorSetting.TypeName; instance = (IServiceLocator)TypeHelper.CreateObject(typeName, typeof(IServiceLocator), false); } if (instance == null) { instance = new ServiceLocatorInternal(); } if (instance is IServiceLocatorInternal) { ((IServiceLocatorInternal)instance).Init(locatorSetting); } return(instance); }
public void Load(string directoryPath) { // Init { { var startupSetting = new StartupSetting(); startupSetting.ProcessSettings.Add(new ProcessSetting() { Path = @"Assemblies/Tor/tor.exe", Arguments = "-f torrc DataDirectory " + @"../../../Work/Tor", WorkingDirectory = @"Assemblies/Tor", }); startupSetting.ProcessSettings.Add(new ProcessSetting() { Path = @"Assemblies/Polipo/polipo.exe", Arguments = "-c polipo.conf", WorkingDirectory = @"Assemblies/Polipo", }); this.Startup = startupSetting; } { var catharsisSettings = new CatharsisSetting(); catharsisSettings.Ipv4AddressFilters.Add(new Ipv4AddressFilter("tcp:127.0.0.1:18118", null, new string[] { @"Catharsis_Ipv4.txt" })); this.Catharsis = catharsisSettings; } { var cacheSettings = new CacheSetting(); cacheSettings.Path = Path.Combine(directoryPath, "Cache.blocks"); this.Cache = cacheSettings; } { var colorsSetting = new ColorsSetting(); colorsSetting.Tree_Hit = System.Windows.Media.Colors.LightPink; colorsSetting.Link = System.Windows.Media.Colors.SkyBlue; colorsSetting.Link_New = System.Windows.Media.Colors.LightPink; colorsSetting.Message_Trust = System.Windows.Media.Colors.SkyBlue; colorsSetting.Message_Untrust = System.Windows.Media.Colors.LightPink; this.Colors = colorsSetting; } } // Config { var startupConfigPath = Path.Combine(directoryPath, "Startup.config"); var catharsisConfigPath = Path.Combine(directoryPath, "Catharsis.config"); var cacheConfigPath = Path.Combine(directoryPath, "Cache.config"); var colorsConfigPath = Path.Combine(directoryPath, "Colors.config"); if (!File.Exists(startupConfigPath)) { this.SaveObject(startupConfigPath, this.Startup); } if (!File.Exists(catharsisConfigPath)) { this.SaveObject(catharsisConfigPath, this.Catharsis); } if (!File.Exists(cacheConfigPath)) { this.SaveObject(cacheConfigPath, this.Cache); } if (!File.Exists(colorsConfigPath)) { this.SaveObject(colorsConfigPath, this.Colors); } this.Startup = this.LoadObject <StartupSetting>(startupConfigPath); this.Catharsis = this.LoadObject <CatharsisSetting>(catharsisConfigPath); this.Cache = this.LoadObject <CacheSetting>(cacheConfigPath); this.Colors = this.LoadObject <ColorsSetting>(colorsConfigPath); } }