public ConfigUnitLoader(CeilidhStartOptions options) { HomePath = options.UserDataPath ?? DefaultHomePath; Directory.CreateDirectory(HomePath); var configPath = options.ConfigFile ?? Path.Combine(HomePath, "config.xml"); if (File.Exists(configPath)) { using (var configFile = File.OpenRead(configPath)) { var serializer = new XmlSerializer(typeof(CeilidhConfig)); Config = (CeilidhConfig)serializer.Deserialize(configFile); } } else { Config = CeilidhConfig.DefaultConfig; } Config.HomePath = HomePath; if (Config.Culture != null) { CultureInfo.DefaultThreadCurrentUICulture = Thread.CurrentThread.CurrentUICulture = Config.Culture; } // TODO: A config controller is necessary to allow extension and saving }
public static async Task <CobbleContext> LoadCeilidhAsync(CeilidhStartOptions startOptions, Action <CobbleContext> loaderCallback) { if (Instance != null) { throw new NotSupportedException(); } var loaderContext = new CobbleContext(); foreach (var loader in typeof(IUnitLoader).Assembly.GetExportedTypes() .Where(x => x != typeof(IUnitLoader) && typeof(IUnitLoader).IsAssignableFrom(x))) { loaderContext.AddManaged(loader); } foreach (var loader in typeof(CeilidhLoader).Assembly.GetExportedTypes() .Where(x => typeof(IUnitLoader).IsAssignableFrom(x))) { loaderContext.AddManaged(loader); } loaderCallback?.Invoke(loaderContext); loaderContext.AddUnmanaged(startOptions); await loaderContext.ExecuteAsync(); var mainContext = new CobbleContext(); if (!loaderContext.TryGetImplementations(out IEnumerable <IUnitLoader> loaders)) { return(mainContext); } foreach (var loader in loaders) { loader.RegisterUnits(mainContext); } await mainContext.ExecuteAsync(); Instance = mainContext; if (mainContext.TryGetSingleton(out IWindowProvider provider)) { var window = provider.CreateWindow(new MainPage(), 0); window.Size = (640, 480); window.Title = "Ceilidh"; window.IsVisible = true; window.Closing += (sender, args) => Environment.Exit(0); } return(mainContext); }
private static async Task <int> Main(string[] args) { var startOptions = new CeilidhStartOptions(); var help = false; var options = new OptionSet { { "c|config=", "the path to the config file.", path => startOptions.ConfigFile = path }, { "u|user="******"the path to the user data folder.", path => startOptions.UserDataPath = path }, { "h|help", "show this message and exit.", _ => help = true } }; try { options.Parse(args); } catch (OptionException e) { Console.WriteLine("Argument error: {0}", e.Message); Console.WriteLine($"Try '{Path.GetFileName(Environment.GetCommandLineArgs()[0])} --help' for more information."); return(-1); } if (help) { Console.WriteLine($"Ceilidh Console Shell Version {typeof(ConsoleShell).Assembly.GetName().Version}"); Console.WriteLine($"Ceilidh Standard Version {typeof(IUnitLoader).Assembly.GetName().Version}"); Console.WriteLine("Usage:"); options.WriteOptionDescriptions(Console.Out); return(0); } using (var loadContext = new CobbleContext()) { loadContext.AddUnmanaged(startOptions); foreach (var unit in typeof(IUnitLoader).Assembly.GetExportedTypes() .Where(x => x != typeof(IUnitLoader) && typeof(IUnitLoader).IsAssignableFrom(x))) { loadContext.AddManaged(unit); } await loadContext.ExecuteAsync(); if (!loadContext.TryGetImplementations <IUnitLoader>(out var impl)) { return(0); } using (var ceilidhContext = new CobbleContext()) { foreach (var register in impl) { register.RegisterUnits(ceilidhContext); } ceilidhContext.AddManaged <ConsoleOutputConsumer>(); await ceilidhContext.ExecuteAsync(); } } return(0); }
public SelfUnitLoader(ConfigUnitLoader configUnit, CeilidhStartOptions startOptions) { _config = configUnit.Config; _startOptions = startOptions; }