public void Execute(TaskExecutionMode mode) { if (this.CancellationToken.IsCancellationRequested) { throw new OperationCanceledException(this.CancellationToken); } try { SchemaCompareEndpoint sourceEndpoint = SchemaCompareUtils.CreateSchemaCompareEndpoint(this.Parameters.SourceEndpointInfo, this.SourceConnectionInfo); SchemaCompareEndpoint targetEndpoint = SchemaCompareUtils.CreateSchemaCompareEndpoint(this.Parameters.TargetEndpointInfo, this.TargetConnectionInfo); SchemaComparison comparison = new SchemaComparison(sourceEndpoint, targetEndpoint); if (this.Parameters.DeploymentOptions != null) { comparison.Options = SchemaCompareUtils.CreateSchemaCompareOptions(this.Parameters.DeploymentOptions); } // for testing schemaCompareStarted?.Invoke(this, new EventArgs()); this.ComparisonResult = comparison.Compare(this.CancellationToken); // try one more time if it didn't work the first time if (!this.ComparisonResult.IsValid) { this.ComparisonResult = comparison.Compare(this.CancellationToken); } // Since DacFx does not throw on schema comparison cancellation, throwing here explicitly to ensure consistency of behavior if (!this.ComparisonResult.IsValid && this.CancellationToken.IsCancellationRequested) { throw new OperationCanceledException(this.CancellationToken); } this.Differences = new List <DiffEntry>(); if (this.ComparisonResult.Differences != null) { foreach (SchemaDifference difference in this.ComparisonResult.Differences) { DiffEntry diffEntry = SchemaCompareUtils.CreateDiffEntry(difference, null); this.Differences.Add(diffEntry); } } } catch (Exception e) { ErrorMessage = e.Message; Logger.Write(TraceEventType.Error, string.Format("Schema compare operation {0} failed with exception {1}", this.OperationId, e.Message)); throw; } }
private bool IsEqual(SchemaDifference difference, DiffEntry diffEntry) { bool result = true; // Create a diff entry from difference and check if it matches the diff entry passed DiffEntry entryFromDifference = SchemaCompareUtils.CreateDiffEntry(difference, null); System.Reflection.PropertyInfo[] properties = diffEntry.GetType().GetProperties(); foreach (var prop in properties) { result = result && ((prop.GetValue(diffEntry) == null && prop.GetValue(entryFromDifference) == null) || prop.GetValue(diffEntry).SafeToString().Equals(prop.GetValue(entryFromDifference).SafeToString())); } return(result); }
private bool IsEqual(SchemaDifference difference, DiffEntry diffEntry) { bool result = true; // Create a diff entry from difference and check if it matches the diff entry passed DiffEntry entryFromDifference = SchemaCompareUtils.CreateDiffEntry(difference, null); System.Reflection.PropertyInfo[] properties = diffEntry.GetType().GetProperties(); foreach (var prop in properties) { // Don't need to check if included is the same when verifying if the difference is equal if (prop.Name != "Included") { if (!((prop.GetValue(diffEntry) == null && prop.GetValue(entryFromDifference) == null) || prop.GetValue(diffEntry).SafeToString().Equals(prop.GetValue(entryFromDifference).SafeToString()))) { return(false); } } } return(result); }
/// <summary> /// Exclude will return false if included dependencies are found. Include will also include dependencies that need to be included. /// This is the same behavior as SSDT /// </summary> /// <param name="mode"></param> public void Execute(TaskExecutionMode mode) { this.CancellationToken.ThrowIfCancellationRequested(); try { SchemaDifference node = this.FindDifference(this.ComparisonResult.Differences, this.Parameters.DiffEntry); if (node == null) { throw new InvalidOperationException(SR.SchemaCompareExcludeIncludeNodeNotFound); } this.Success = this.Parameters.IncludeRequest ? this.ComparisonResult.Include(node) : this.ComparisonResult.Exclude(node); // if include request (pass or fail), send dependencies that might have been affected by this request, given by GetIncludeDependencies() if (this.Parameters.IncludeRequest) { IEnumerable <SchemaDifference> affectedDependencies = this.ComparisonResult.GetIncludeDependencies(node); this.AffectedDependencies = affectedDependencies.Select(difference => SchemaCompareUtils.CreateDiffEntry(difference: difference, parent: null)).ToList(); } else { // if exclude was successful, the possible affected dependencies are given by GetIncludedDependencies() if (this.Success) { IEnumerable <SchemaDifference> affectedDependencies = this.ComparisonResult.GetIncludeDependencies(node); this.AffectedDependencies = affectedDependencies.Select(difference => SchemaCompareUtils.CreateDiffEntry(difference: difference, parent: null)).ToList(); } // if not successful, send back the exclude dependencies that caused it to fail else { IEnumerable <SchemaDifference> blockingDependencies = this.ComparisonResult.GetExcludeDependencies(node); blockingDependencies = blockingDependencies.Where(difference => difference.Included == node.Included); this.BlockingDependencies = blockingDependencies.Select(difference => SchemaCompareUtils.CreateDiffEntry(difference: difference, parent: null)).ToList(); } } } catch (Exception e) { ErrorMessage = e.Message; Logger.Write(TraceEventType.Error, string.Format("Schema compare publish changes operation {0} failed with exception {1}", this.OperationId, e.Message)); throw; } }