/// <summary> /// Constructor used for unit tests. /// </summary> /// <param name="project">User configuration influencing the execution plan.</param> /// <param name="cloningContext">Cloning task</param> /// <param name="executionContext">ExecutionContext</param> internal ExecutionPlanBuilder(Project project, CloningContext cloningContext, ExecutionContext executionContext) : this() { if (executionContext == null) { throw new ArgumentNullException(nameof(executionContext)); } ExecutionContext = executionContext; ExecutionContext.Initialize(project, cloningContext); }
/// <summary> /// Verify if the last build of the container's metadata still match with the current cloning context. /// </summary> private void LoadCache(Project project, CloningContext context = null) { if (project == null) { throw new ArgumentNullException(nameof(project)); } if (project.ConnectionStrings == null || !project.ConnectionStrings.Any()) { throw new NullReferenceException(nameof(project.ConnectionStrings)); } Behavior behavior = null; Configuration.Environment source = null; Configuration.Environment destination = null; if (project.Name == null) { project.Name = Guid.NewGuid().ToString(); } var containerFileName = project.Name; //Hash the selected map, connnectionStrings and the cloner //configuration to see if it match the lasted builded container var configData = new MemoryStream(); SerializationHelper.Serialize(configData, project.ConnectionStrings); //Append context data if (context != null) { if (context.SourceEnvironment != null) { //Map source = project.Environments.FirstOrDefault(e => e.Name == context.SourceEnvironment); if (source == null) { throw new Exception($"Source environment name '{context.SourceEnvironment}' not found in configuration file for application '{project.Name}'!"); } destination = project.Environments.FirstOrDefault(e => e.Name == context.DestinationEnvironment); if (destination == null) { throw new Exception($"Destination environment name '{context.DestinationEnvironment}' not found in configuration file for application '{project.Name}'!"); } containerFileName += "_" + context.SourceEnvironment + "_" + context.DestinationEnvironment; SerializationHelper.Serialize(configData, source); //Behavior if (!string.IsNullOrWhiteSpace(context.Behaviour)) { behavior = project.BuildBehavior(context.Behaviour); SerializationHelper.Serialize(configData, behavior); SerializationHelper.Serialize(configData, project.ExtractionTemplates); containerFileName += "_" + context.Behaviour; } } else { containerFileName += "_noMap"; } } containerFileName += ".cache"; //Hash user config configData.Position = 0; string currentHash; using (var md5Hash = MD5.Create()) currentHash = Encoding.UTF8.GetString(md5Hash.ComputeHash(configData)); //If in-memory container is good, we use it if (ExecutionContextCacheHash == currentHash) { return; } Metadatas metadatas = null; //If we can load cache from disk if ((context == null || !context.UseInMemoryCacheOnly)) { //If container on disk is good, we use it if (TryLoadContainerFromFile(containerFileName, currentHash, ref metadatas)) { InitExecutionContext(project, source, destination, currentHash, metadatas); return; } } //Else we rebuild the container HashSet <SchemaVar> schemas = null; if (source != null && source.Schemas != null) { schemas = new HashSet <SchemaVar>(source.Schemas); } metadatas = MetadataBuilder.BuildMetadata(project.ConnectionStrings, behavior, schemas); InitExecutionContext(project, source, destination, currentHash, metadatas); if ((context == null || !context.UseInMemoryCacheOnly)) { Save(containerFileName); } }
/// <summary> /// Constructor used for unit tests. /// </summary> /// <param name="project">User configuration influencing the execution plan.</param> /// <param name="cloningContext">Cloning task</param> public ExecutionPlanBuilder(Project project, CloningContext cloningContext) : this() { ExecutionContext = new ExecutionContext(); ExecutionContext.Initialize(project, cloningContext); }
/// <summary> /// Verify if the last build of the container's metadata still match with the current cloning context. /// </summary> public void Initialize(Project project, CloningContext context = null) { LoadCache(project, context); }