Esempio n. 1
0
        /// <summary>
        /// Handles schema compare request
        /// </summary>
        /// <returns></returns>
        public async Task HandleSchemaCompareRequest(SchemaCompareParams parameters, RequestContext <SchemaCompareResult> requestContext)
        {
            try
            {
                ConnectionInfo sourceConnInfo;
                ConnectionInfo targetConnInfo;
                ConnectionServiceInstance.TryFindConnection(
                    parameters.SourceEndpointInfo.OwnerUri,
                    out sourceConnInfo);
                ConnectionServiceInstance.TryFindConnection(
                    parameters.TargetEndpointInfo.OwnerUri,
                    out targetConnInfo);

                CurrentSchemaCompareTask = Task.Run(async() =>
                {
                    SchemaCompareOperation operation = null;

                    try
                    {
                        operation = new SchemaCompareOperation(parameters, sourceConnInfo, targetConnInfo);
                        currentComparisonCancellationAction.Value[operation.OperationId] = operation.Cancel;
                        operation.Execute(parameters.TaskExecutionMode);

                        // add result to dictionary of results
                        schemaCompareResults.Value[operation.OperationId] = operation.ComparisonResult;

                        await requestContext.SendResult(new SchemaCompareResult()
                        {
                            OperationId  = operation.OperationId,
                            Success      = true,
                            ErrorMessage = operation.ErrorMessage,
                            AreEqual     = operation.ComparisonResult.IsEqual,
                            Differences  = operation.Differences
                        });

                        // clean up cancellation action now that the operation is complete (using try remove to avoid exception)
                        Action cancelAction = null;
                        currentComparisonCancellationAction.Value.TryRemove(operation.OperationId, out cancelAction);
                    }
                    catch (Exception e)
                    {
                        Logger.Write(TraceEventType.Error, "Failed to compare schema. Error: " + e);
                        await requestContext.SendResult(new SchemaCompareResult()
                        {
                            OperationId  = operation != null ? operation.OperationId : null,
                            Success      = false,
                            ErrorMessage = operation == null ? e.Message : operation.ErrorMessage,
                        });
                    }
                });
            }
            catch (Exception e)
            {
                await requestContext.SendError(e);
            }
        }
Esempio n. 2
0
        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 = SchemaCompareOperation.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);
        }