private LeprechaunConfigurationBuilder BuildConfiguration(IRuntimeArgs args) { XmlDocument config = new XmlDocument(); args.ConfigFilePath = EnsureAbsoluteConfigPath(args.ConfigFilePath); if (Path.GetExtension(args.ConfigFilePath) == ".json") { config = JsonConvert.DeserializeXmlNode(File.ReadAllText(args.ConfigFilePath)); } else { config.Load(args.ConfigFilePath); } var replacer = GetVariablesReplacer(args); XmlElement configsElement = config.DocumentElement["configurations"]; XmlElement baseConfigElement = config.DocumentElement["defaults"]; XmlElement sharedConfigElement = config.DocumentElement["shared"]; var configObject = new LeprechaunConfigurationBuilder(replacer, configsElement, baseConfigElement, sharedConfigElement, args.ConfigFilePath, new ConfigurationImportPathResolver(new ConsoleLogger())); return(configObject); }
public void Watch(LeprechaunConfigurationBuilder configuration, ILogger logger, Action rebuildAction) { const int debounceInMs = 500; Timer debouncer = new Timer(Rebuild); void RebuildFromItemChange(IItemMetadata item, string database) { logger.Info($"{item?.SerializedItemId ?? "Unknown"} was altered."); debouncer.Change(debounceInMs, Timeout.Infinite); } void RebuildFromConfigChange(string configPath, TreeWatcher.TreeWatcherChangeType changeType) { if (changeType == TreeWatcher.TreeWatcherChangeType.Delete) { logger.Error($"Config file {configPath} was deleted. Terminating watch."); Environment.Exit(1); } logger.Info($"{configPath} was changed."); debouncer.Change(debounceInMs, Timeout.Infinite); } void Rebuild(object ignored) { var timer = new Stopwatch(); timer.Start(); rebuildAction(); timer.Stop(); logger.Info(string.Empty); logger.Info($"Regeneration complete in {timer.ElapsedMilliseconds}ms."); } foreach (var config in configuration.Configurations) { config.Resolve <IDataStore>().RegisterForChanges(RebuildFromItemChange); } foreach (var configPath in configuration.ImportedConfigFilePaths) { new TreeWatcher(Path.GetDirectoryName(configPath), Path.GetFileName(configPath), RebuildFromConfigChange); } }
private void GenerateWatch(IOrchestrator orchestrator, LeprechaunConfigurationBuilder configuration) { try { var metadata = GenerateMetadata(orchestrator, configuration); GenerateCode(metadata); } catch (Exception ex) { // during watch we don't want errors to terminate the application Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(ex.StackTrace); Console.ResetColor(); } }
private static LeprechaunConfigurationBuilder BuildConfiguration(ConsoleArgs args) { var config = new XmlDocument(); config.Load(args.ConfigFilePath); var replacer = new ChainedVariablesReplacer( new ConfigurationNameVariablesReplacer(), new HelixConventionVariablesReplacer(), new ConfigPathVariableReplacer(Path.GetDirectoryName(args.ConfigFilePath))); var configObject = new LeprechaunConfigurationBuilder(replacer, config.DocumentElement["configurations"], config.DocumentElement["defaults"], config.DocumentElement["shared"], args.ConfigFilePath, new ConfigurationImportPathResolver(new ConsoleLogger())); // configure Rainbow RainbowSettings.Current = (RainbowSettings)configObject.Shared.Resolve <ILeprechaunRainbowSettings>(); return(configObject); }
public void Watch(LeprechaunConfigurationBuilder configuration, ILogger logger, Action rebuildAction) { logger.Warn("Watch is currently not supported for Sitecore Serialization."); }
private IReadOnlyList <ConfigurationCodeGenerationMetadata> GenerateMetadata(IOrchestrator orchestrator, LeprechaunConfigurationBuilder configuration) { var metadataTimer = new Stopwatch(); metadataTimer.Start(); // we generate template data that will feed code generation var metadata = orchestrator.GenerateMetadata(configuration.Configurations); metadataTimer.Stop(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine( $"Loaded metadata for {metadata.Count} configurations ({metadata.Sum(m => m.Metadata.Count)} total templates) in {metadataTimer.ElapsedMilliseconds}ms."); Console.ResetColor(); return(metadata); }
public void Initialize(LeprechaunConfigurationBuilder config) { // configure Rainbow RainbowSettings.Current = (RainbowSettings)config.Shared.Resolve <ILeprechaunRainbowSettings>(); }
public void Initialize(LeprechaunConfigurationBuilder config) { }