private void PerformTransformations( ConcurrentDictionary <string, object> objectCache, IIncludeContext includeContext, ServerDefinition server, string role, StageDefinition stage) { _logMessageSink.EnterBlock(sink => { string environmentPath = Path.Combine(server.OutputPath, $"{role}.json"); try { sink.Message($"------------------------------------------------------------------------------------------------------\nStarting {environmentPath}"); TargetingInformation targetingInformation = new TargetingInformation { Replication = server.Replication, Role = role, Stage = stage.Stage, Server = server.Server }; // This needs to be created per file creation thread TransformationContext transformationContext = new TransformationContext(); // use the shared cache created in the wrapping service method to share resource reads. transformationContext.Cache = objectCache; PatchingTemplate template = _templateProvider.GetTemplate(transformationContext, targetingInformation.Role); JArray runtimeTemplate = JArray.Parse(template.String); transformationContext.SetPluginPolicy(includeContext); transformationContext.SetPluginPolicy(targetingInformation); transformationContext.SetPluginPolicy(sink); _transformationEngine.EvaluateMakros(transformationContext, runtimeTemplate); File.WriteAllText(environmentPath, JsonConvert.SerializeObject(runtimeTemplate, Formatting.Indented)); sink.Message($"Finished {environmentPath}\n------------------------------------------------------------------------------------------------------"); } catch (Exception e) { sink.Error($"Error while generating {environmentPath}...\n{e.ToString()}"); } }); }