/// <summary> /// Applies applicable transforms in order of sequenced patches. /// </summary> /// <param name="throwOnError">Whether to throw an exception if an error occurs.</param> internal void Apply(bool throwOnError = false) { // Need to make a copy of the database since exclusivity is required. IEnumerable <string> applicable = null; using (var copy = Copy(this.db)) { // Copy the items to a list so they are enumerated immediately and the temporary database can be closed. applicable = this.sequencer.GetApplicablePatches(copy.FilePath).Select(patch => patch.Patch).ToList(); } foreach (var path in applicable) { using (var patch = new PatchPackage(path)) { var transforms = patch.GetValidTransforms(this.db); foreach (var transform in transforms) { // GetValidTransforms does not return the patch transform so assume it too is valid. foreach (var prefix in PatchApplicator.TransformPrefixes) { var temp = Path.ChangeExtension(Path.GetTempFileName(), ".mst"); patch.ExtractTransform(prefix + transform, temp); // Apply and commit the authored transform so further transforms may apply. this.db.ApplyTransform(temp, PatchApplicator.IgnoreErrors); this.db.ApplyTransform(temp, PatchApplicator.IgnoreErrors | TransformErrors.ViewTransform); this.db.Commit(); // Attempt to delete the temporary transform. TryDelete(temp); } } } } }