private void AddAssociatedMenuConfigurationDifference(FormatTextTableHandler table, string name, AssociatedMenuConfiguration config1, AssociatedMenuConfiguration config2)
        {
            if (config1 != null && config2 == null)
            {
                table.AddLineIfNotEqual(name, "not null", "null");
            }
            else if (config1 == null && config2 != null)
            {
                table.AddLineIfNotEqual(name, "null", "not null");
            }
            else if (config1 != null && config2 != null)
            {
                if (config1.Label != null && config2.Label == null)
                {
                    table.AddLineIfNotEqual(name + ".Label", "not null", "null");
                }
                else if (config1.Label == null && config2.Label != null)
                {
                    table.AddLineIfNotEqual(name + ".Label", "null", "not null");
                }
                else if (config1.Label != null && config2.Label != null)
                {
                    var isDifferentLabel = LabelComparer.GetDifference(config1.Label, config2.Label);

                    if (!isDifferentLabel.IsEmpty)
                    {
                        table.AddLine(name + ".Label");

                        if (isDifferentLabel.LabelsOnlyIn1.Count > 0)
                        {
                            table.AddLine(string.Format("Labels ONLY in {0}: {1}", _connectionName1, isDifferentLabel.LabelsOnlyIn1.Count));
                            table.AddLine("LanguageCode", "Value");
                            isDifferentLabel.LabelsOnlyIn1.ForEach(e => table.AddLine(e.Locale, e.Value));
                        }

                        if (isDifferentLabel.LabelsOnlyIn2.Count > 0)
                        {
                            table.AddLine(string.Format("Labels ONLY in {0}: {1}", _connectionName2, isDifferentLabel.LabelsOnlyIn2.Count));
                            table.AddLine("LanguageCode", "Value");
                            isDifferentLabel.LabelsOnlyIn2.ForEach(e => table.AddLine(e.Locale, e.Value));
                        }

                        if (isDifferentLabel.LabelDifference.Count > 0)
                        {
                            table.AddLine(string.Format("Labels DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentLabel.LabelDifference.Count));
                            table.AddLine("LanguageCode", "Organization", "Value");
                            isDifferentLabel.LabelDifference.ForEach(e => table.AddLine(e.Locale, e.Value1, e.Value2));
                        }
                    }
                }
            }
        }
        private List <string> GetDifferenceKey(EntityKeyMetadata key1, EntityKeyMetadata key2)
        {
            List <string> strDifference = new List <string>();

            {
                FormatTextTableHandler tableFormatter = new FormatTextTableHandler(true);

                tableFormatter.CalculateLineLengths("LanguageCode", "Value");
                tableFormatter.CalculateLineLengths("LanguageCode", "Organization", "Value");

                var isDifferentDisplayName = LabelComparer.GetDifference(key1.DisplayName, key2.DisplayName);

                isDifferentDisplayName.LabelsOnlyIn1.ForEach(i => tableFormatter.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelsOnlyIn2.ForEach(i => tableFormatter.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelDifference.ForEach(i =>
                {
                    tableFormatter.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    tableFormatter.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                if (!isDifferentDisplayName.IsEmpty)
                {
                    if (isDifferentDisplayName.LabelsOnlyIn1.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName1, isDifferentDisplayName.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + tableFormatter.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelsOnlyIn2.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName2, isDifferentDisplayName.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + tableFormatter.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelDifference.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDisplayName.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDisplayName.LabelDifference.ForEach(i =>
                        {
                            strDifference.Add(_tabSpacer + tableFormatter.FormatLine(i.Locale, _connectionName1, i.Value1));
                            strDifference.Add(_tabSpacer + tableFormatter.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }
            }

            return(strDifference);
        }
        private void CompareTranslations(StringBuilder content, Translation translation1, Translation translation2)
        {
            {
                FormatTextTableHandler displayStringsOnlyExistsIn1 = new FormatTextTableHandler();
                displayStringsOnlyExistsIn1.SetHeader("EntityName", "StringKey", "LanguageCode", "Label");

                FormatTextTableHandler displayStringsOnlyExistsIn2 = new FormatTextTableHandler();
                displayStringsOnlyExistsIn2.SetHeader("EntityName", "StringKey", "LanguageCode", "Label");

                FormatTextTableHandler displayStringsDifference = new FormatTextTableHandler();
                displayStringsDifference.SetHeader("EntityName", "StringKey", "LanguageCode", "Connection", "Label");

                foreach (var displayString1 in translation1.DisplayStrings)
                {
                    {
                        var displayString2 = translation2.DisplayStrings.FirstOrDefault(d =>
                                                                                        string.Equals(displayString1.EntityName, d.EntityName, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                        string.Equals(displayString1.StringKey, d.StringKey, StringComparison.InvariantCultureIgnoreCase)
                                                                                        );

                        if (displayString2 != null)
                        {
                            continue;
                        }
                    }

                    foreach (var label in displayString1.Labels)
                    {
                        displayStringsOnlyExistsIn1.AddLine(displayString1.EntityName, displayString1.StringKey, LanguageLocale.GetLocaleName(label.LanguageCode), label.Value);
                    }
                }

                foreach (var displayString2 in translation2.DisplayStrings)
                {
                    {
                        var displayString1 = translation1.DisplayStrings.FirstOrDefault(d =>
                                                                                        string.Equals(displayString2.EntityName, d.EntityName, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                        string.Equals(displayString2.StringKey, d.StringKey, StringComparison.InvariantCultureIgnoreCase)
                                                                                        );

                        if (displayString1 != null)
                        {
                            continue;
                        }
                    }

                    foreach (var label in displayString2.Labels)
                    {
                        displayStringsOnlyExistsIn2.AddLine(displayString2.EntityName, displayString2.StringKey, LanguageLocale.GetLocaleName(label.LanguageCode), label.Value);
                    }
                }

                foreach (var displayString1 in translation1.DisplayStrings)
                {
                    var displayString2 = translation2.DisplayStrings.FirstOrDefault(d =>
                                                                                    string.Equals(displayString1.EntityName, d.EntityName, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                    string.Equals(displayString1.StringKey, d.StringKey, StringComparison.InvariantCultureIgnoreCase)
                                                                                    );

                    if (displayString2 == null)
                    {
                        continue;
                    }

                    var diff = LabelComparer.GetDifference(displayString1, displayString2);

                    if (!diff.IsEmpty)
                    {
                        foreach (var item in diff.LabelsOnlyIn1)
                        {
                            displayStringsDifference.AddLine(displayString1.EntityName, displayString1.StringKey, LanguageLocale.GetLocaleName(item.LanguageCode), Connection1.Name, item.Value);
                        }

                        foreach (var item in diff.LabelsOnlyIn2)
                        {
                            displayStringsDifference.AddLine(displayString1.EntityName, displayString1.StringKey, LanguageLocale.GetLocaleName(item.LanguageCode), Connection2.Name, item.Value);
                        }

                        foreach (var item in diff.LabelDifference)
                        {
                            displayStringsDifference.AddLine(displayString1.EntityName, displayString1.StringKey, LanguageLocale.GetLocaleName(item.LanguageCode), Connection1.Name, item.Value1);
                            displayStringsDifference.AddLine(displayString1.EntityName, displayString1.StringKey, LanguageLocale.GetLocaleName(item.LanguageCode), Connection2.Name, item.Value2);
                        }
                    }
                }

                if (displayStringsOnlyExistsIn1.Count > 0)
                {
                    content
                    .AppendLine()
                    .AppendLine()
                    .AppendLine()
                    .AppendLine(new string('-', 150))
                    .AppendLine()
                    .AppendLine();

                    content.AppendLine().AppendLine().AppendFormat("Display Strings ONLY EXISTS in {0}: {1}", Connection1.Name, displayStringsOnlyExistsIn1.Count);

                    displayStringsOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd()));
                }

                if (displayStringsOnlyExistsIn2.Count > 0)
                {
                    content
                    .AppendLine()
                    .AppendLine()
                    .AppendLine()
                    .AppendLine(new string('-', 150))
                    .AppendLine()
                    .AppendLine();

                    content.AppendLine().AppendLine().AppendFormat("Display Strings ONLY EXISTS in {0}: {1}", Connection2.Name, displayStringsOnlyExistsIn2.Count);

                    displayStringsOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd()));
                }

                if (displayStringsDifference.Count > 0)
                {
                    content
                    .AppendLine()
                    .AppendLine()
                    .AppendLine()
                    .AppendLine(new string('-', 150))
                    .AppendLine()
                    .AppendLine();

                    content.AppendLine().AppendLine().AppendFormat("Display Strings DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, displayStringsDifference.Count);

                    displayStringsDifference.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd()).AppendLine());
                }

                if (displayStringsOnlyExistsIn2.Count == 0 &&
                    displayStringsOnlyExistsIn1.Count == 0 &&
                    displayStringsDifference.Count == 0
                    )
                {
                    content.AppendLine("No difference in Display Strings.");
                }
            }

            {
                FormatTextTableHandler localizedLabelsOnlyExistsIn1 = new FormatTextTableHandler();
                localizedLabelsOnlyExistsIn1.SetHeader("EntityName", "ObjectId", "ColumnName", "LanguageCode", "Label");

                FormatTextTableHandler localizedLabelsOnlyExistsIn2 = new FormatTextTableHandler();
                localizedLabelsOnlyExistsIn2.SetHeader("EntityName", "ObjectId", "ColumnName", "LanguageCode", "Label");

                FormatTextTableHandler localizedLabelsDifference = new FormatTextTableHandler();
                localizedLabelsDifference.SetHeader("EntityName", "ObjectId", "ColumnName", "LanguageCode", "Connection", "Label");

                foreach (var locLabel1 in translation1.LocalizedLabels)
                {
                    {
                        var locLabel2 = translation2.LocalizedLabels.FirstOrDefault(d =>
                                                                                    string.Equals(locLabel1.EntityName, d.EntityName, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                    string.Equals(locLabel1.ColumnName, d.ColumnName, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                    locLabel1.ObjectId == d.ObjectId
                                                                                    );

                        if (locLabel2 != null)
                        {
                            continue;
                        }
                    }

                    foreach (var label in locLabel1.Labels)
                    {
                        localizedLabelsOnlyExistsIn1.AddLine(locLabel1.EntityName, locLabel1.ObjectId.ToString(), locLabel1.ColumnName, LanguageLocale.GetLocaleName(label.LanguageCode), label.Value);
                    }
                }

                foreach (var locLabel2 in translation2.LocalizedLabels)
                {
                    {
                        var locLabel1 = translation1.LocalizedLabels.FirstOrDefault(d =>
                                                                                    string.Equals(locLabel2.EntityName, d.EntityName, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                    string.Equals(locLabel2.ColumnName, d.ColumnName, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                    locLabel2.ObjectId == d.ObjectId
                                                                                    );

                        if (locLabel1 != null)
                        {
                            continue;
                        }
                    }

                    foreach (var label in locLabel2.Labels)
                    {
                        localizedLabelsOnlyExistsIn2.AddLine(locLabel2.EntityName, locLabel2.ObjectId.ToString(), locLabel2.ColumnName, LanguageLocale.GetLocaleName(label.LanguageCode), label.Value);
                    }
                }

                foreach (var locLabel1 in translation1.LocalizedLabels)
                {
                    var locLabel2 = translation2.LocalizedLabels.FirstOrDefault(d =>
                                                                                string.Equals(locLabel1.EntityName, d.EntityName, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                string.Equals(locLabel1.ColumnName, d.ColumnName, StringComparison.InvariantCultureIgnoreCase) &&
                                                                                locLabel1.ObjectId == d.ObjectId
                                                                                );

                    if (locLabel2 == null)
                    {
                        continue;
                    }

                    var diff = LabelComparer.GetDifference(locLabel1, locLabel2);

                    if (!diff.IsEmpty)
                    {
                        foreach (var item in diff.LabelsOnlyIn1)
                        {
                            localizedLabelsDifference.AddLine(locLabel1.EntityName, locLabel1.ObjectId.ToString(), locLabel1.ColumnName, LanguageLocale.GetLocaleName(item.LanguageCode), Connection1.Name, item.Value);
                        }

                        foreach (var item in diff.LabelsOnlyIn2)
                        {
                            localizedLabelsDifference.AddLine(locLabel1.EntityName, locLabel1.ObjectId.ToString(), locLabel1.ColumnName, LanguageLocale.GetLocaleName(item.LanguageCode), Connection2.Name, item.Value);
                        }

                        foreach (var item in diff.LabelDifference)
                        {
                            localizedLabelsDifference.AddLine(locLabel1.EntityName, locLabel1.ObjectId.ToString(), locLabel1.ColumnName, LanguageLocale.GetLocaleName(item.LanguageCode), Connection1.Name, item.Value1);
                            localizedLabelsDifference.AddLine(locLabel1.EntityName, locLabel1.ObjectId.ToString(), locLabel1.ColumnName, LanguageLocale.GetLocaleName(item.LanguageCode), Connection2.Name, item.Value2);
                        }
                    }
                }

                if (localizedLabelsOnlyExistsIn1.Count > 0)
                {
                    content
                    .AppendLine()
                    .AppendLine()
                    .AppendLine()
                    .AppendLine(new string('-', 150))
                    .AppendLine()
                    .AppendLine();

                    content.AppendLine().AppendLine().AppendFormat("Localized Labels ONLY EXISTS in {0}: {1}", Connection1.Name, localizedLabelsOnlyExistsIn1.Count);

                    localizedLabelsOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd()));
                }

                if (localizedLabelsOnlyExistsIn2.Count > 0)
                {
                    content
                    .AppendLine()
                    .AppendLine()
                    .AppendLine()
                    .AppendLine(new string('-', 150))
                    .AppendLine()
                    .AppendLine();

                    content.AppendLine().AppendLine().AppendFormat("Localized Labels ONLY EXISTS in {0}: {1}", Connection2.Name, localizedLabelsOnlyExistsIn2.Count);

                    localizedLabelsOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd()));
                }

                if (localizedLabelsDifference.Count > 0)
                {
                    content
                    .AppendLine()
                    .AppendLine()
                    .AppendLine()
                    .AppendLine(new string('-', 150))
                    .AppendLine()
                    .AppendLine();

                    content.AppendLine().AppendLine().AppendFormat("Localized Labels DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, localizedLabelsDifference.Count);

                    localizedLabelsDifference.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd()).AppendLine());
                }

                if (localizedLabelsOnlyExistsIn2.Count == 0 &&
                    localizedLabelsOnlyExistsIn1.Count == 0 &&
                    localizedLabelsDifference.Count == 0
                    )
                {
                    content.AppendLine("No difference in Localized Labels.");
                }
            }
        }
        private async Task <List <string> > GetDifferenceAttribute(AttributeMetadata attr1, AttributeMetadata attr2)
        {
            List <string> strDifference = new List <string>();

            {
                FormatTextTableHandler table = new FormatTextTableHandler(true);

                table.CalculateLineLengths("LanguageCode", "Value");
                table.CalculateLineLengths("LanguageCode", "Organization", "Value");

                var isDifferentDisplayName = LabelComparer.GetDifference(attr1.DisplayName, attr2.DisplayName);
                var isDifferentDescription = LabelComparer.GetDifference(attr1.Description, attr2.Description);

                isDifferentDisplayName.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                isDifferentDescription.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                if (!isDifferentDisplayName.IsEmpty)
                {
                    if (isDifferentDisplayName.LabelsOnlyIn1.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName1, isDifferentDisplayName.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelsOnlyIn2.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName2, isDifferentDisplayName.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelDifference.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDisplayName.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDisplayName.LabelDifference.ForEach(i =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName1, i.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }

                if (!isDifferentDescription.IsEmpty)
                {
                    if (isDifferentDescription.LabelsOnlyIn1.Count > 0)
                    {
                        strDifference.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName1, isDifferentDescription.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelsOnlyIn2.Count > 0)
                    {
                        strDifference.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName2, isDifferentDescription.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelDifference.Count > 0)
                    {
                        strDifference.Add(string.Format("Descriptions DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDescription.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDescription.LabelDifference.ForEach(i =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName1, i.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }
            }

            {
                var table = new FormatTextTableHandler(true);
                table.SetHeader("Property", _connectionName1, _connectionName2);

                List <string> additionalDifference = new List <string>();

                if (attr1.GetType().Name == attr2.GetType().Name)
                {
                    if (attr1 is Microsoft.Xrm.Sdk.Metadata.EnumAttributeMetadata)
                    {
                        var enumAttributeMetadata1 = attr1 as Microsoft.Xrm.Sdk.Metadata.EnumAttributeMetadata;
                        var enumAttributeMetadata2 = attr2 as Microsoft.Xrm.Sdk.Metadata.EnumAttributeMetadata;

                        if (enumAttributeMetadata1.OptionSet != null && enumAttributeMetadata2.OptionSet != null)
                        {
                            if (!CreateFileHandler.IgnoreAttribute(enumAttributeMetadata1.EntityLogicalName, enumAttributeMetadata1.LogicalName))
                            {
                                var diffenrenceOptionSet = await _optionSetComparer.GetDifference(enumAttributeMetadata1.OptionSet, enumAttributeMetadata2.OptionSet, attr1.EntityLogicalName, attr1.LogicalName);

                                if (diffenrenceOptionSet.Count > 0)
                                {
                                    additionalDifference.Add(string.Format("Difference in OptionSet {0} and {1}"
                                                                           , enumAttributeMetadata1.OptionSet.Name + (enumAttributeMetadata1.OptionSet.IsGlobal.GetValueOrDefault() ? "(Global)" : "(Local)")
                                                                           , enumAttributeMetadata2.OptionSet.Name + (enumAttributeMetadata2.OptionSet.IsGlobal.GetValueOrDefault() ? "(Global)" : "(Local)")
                                                                           )
                                                             );
                                    diffenrenceOptionSet.ForEach(s => additionalDifference.Add(_tabSpacer + s));
                                }
                            }
                        }
                    }
                }

                if (table.Count > 0)
                {
                    strDifference.AddRange(table.GetFormatedLines(true));
                }

                if (additionalDifference.Count > 0)
                {
                    strDifference.AddRange(additionalDifference);
                }
            }

            return(strDifference);
        }
        public async Task <List <string> > GetDifference(OrganizationDifferenceImageBuilder imageBuilder, EntityMetadata entityMetadata1, EntityMetadata entityMetadata2)
        {
            List <string> strDifference = new List <string>();

            {
                FormatTextTableHandler table = new FormatTextTableHandler(true);

                table.CalculateLineLengths("LanguageCode", "Value");
                table.CalculateLineLengths("LanguageCode", "Organization", "Value");

                var isDifferentDisplayName = LabelComparer.GetDifference(entityMetadata1.DisplayName, entityMetadata2.DisplayName);
                var isDifferentDescription = LabelComparer.GetDifference(entityMetadata1.Description, entityMetadata2.Description);

                isDifferentDisplayName.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                isDifferentDescription.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                if (!isDifferentDisplayName.IsEmpty)
                {
                    if (isDifferentDisplayName.LabelsOnlyIn1.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName1, isDifferentDisplayName.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelsOnlyIn2.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName2, isDifferentDisplayName.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelDifference.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDisplayName.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDisplayName.LabelDifference.ForEach(e =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, _connectionName1, e.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, _connectionName2, e.Value2));
                        });
                    }
                }

                if (!isDifferentDescription.IsEmpty)
                {
                    if (isDifferentDescription.LabelsOnlyIn1.Count > 0)
                    {
                        strDifference.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName1, isDifferentDescription.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelsOnlyIn2.Count > 0)
                    {
                        strDifference.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName2, isDifferentDescription.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelDifference.Count > 0)
                    {
                        strDifference.Add(string.Format("Descriptions DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDescription.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDescription.LabelDifference.ForEach(e =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, _connectionName1, e.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, _connectionName2, e.Value2));
                        });
                    }
                }
            }

            {
                FormatTextTableHandler table = new FormatTextTableHandler(true);

                table.CalculateLineLengths("LanguageCode", "Value");
                table.CalculateLineLengths("LanguageCode", "Organization", "Value");

                var isDifferentDisplayCollectionName = LabelComparer.GetDifference(entityMetadata1.DisplayCollectionName, entityMetadata2.DisplayCollectionName);

                isDifferentDisplayCollectionName.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayCollectionName.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayCollectionName.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                if (!isDifferentDisplayCollectionName.IsEmpty)
                {
                    if (isDifferentDisplayCollectionName.LabelsOnlyIn1.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayCollectionNames ONLY in {0}: {1}", _connectionName1, isDifferentDisplayCollectionName.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayCollectionName.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayCollectionName.LabelsOnlyIn2.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayCollectionNames ONLY in {0}: {1}", _connectionName2, isDifferentDisplayCollectionName.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayCollectionName.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayCollectionName.LabelDifference.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayCollectionNames DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDisplayCollectionName.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDisplayCollectionName.LabelDifference.ForEach(e =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, _connectionName1, e.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, _connectionName2, e.Value2));
                        });
                    }
                }
            }

            await CompareAttributes(imageBuilder, strDifference, entityMetadata1.LogicalName, entityMetadata1.Attributes, entityMetadata2.Attributes);

            CompareKeys(imageBuilder, strDifference, entityMetadata1.LogicalName, entityMetadata1.Keys ?? Enumerable.Empty <EntityKeyMetadata>(), entityMetadata2.Keys ?? Enumerable.Empty <EntityKeyMetadata>());

            CompareOneToMany(imageBuilder, strDifference, entityMetadata1.LogicalName, "N:1", "ManyToOne", entityMetadata1.ManyToOneRelationships, entityMetadata2.ManyToOneRelationships);

            CompareOneToMany(imageBuilder, strDifference, entityMetadata1.LogicalName, "1:N", "OneToMany", entityMetadata1.OneToManyRelationships, entityMetadata2.OneToManyRelationships);

            CompareManyToMany(imageBuilder, strDifference, entityMetadata1.LogicalName, entityMetadata1.ManyToManyRelationships, entityMetadata2.ManyToManyRelationships);

            return(strDifference);
        }
Esempio n. 6
0
        private async Task <List <string> > GetDifferenceOptionSetValue(OptionMetadata optionMetadata1, OptionMetadata optionMetadata2, string entityName1, string attributeName1, string entityName2 = null, string attributeName2 = null)
        {
            List <string> optionDiff = new List <string>();

            int?displayOrder1 = null;
            int?displayOrder2 = null;

            if (entityName2 == null)
            {
                entityName2 = entityName1;
            }

            if (attributeName2 == null)
            {
                attributeName2 = attributeName1;
            }

            if (!string.IsNullOrEmpty(entityName1) && !string.IsNullOrEmpty(attributeName1))
            {
                {
                    if (!_cache1.ContainsKey(entityName1))
                    {
                        _cache1[entityName1] = await _rep1.GetListAsync(entityName1);
                    }

                    var stringMap1 = _cache1[entityName1].FirstOrDefault(e =>
                                                                         string.Equals(e.AttributeName, attributeName1, StringComparison.InvariantCultureIgnoreCase) &&
                                                                         string.Equals(e.ObjectTypeCode, entityName1, StringComparison.InvariantCultureIgnoreCase) &&
                                                                         e.AttributeValue == optionMetadata1.Value.Value
                                                                         );

                    if (stringMap1 != null)
                    {
                        displayOrder1 = stringMap1.DisplayOrder;
                    }
                }
            }

            if (!string.IsNullOrEmpty(entityName2) && !string.IsNullOrEmpty(attributeName2))
            {
                {
                    if (!_cache2.ContainsKey(entityName2))
                    {
                        _cache2[entityName2] = await _rep2.GetListAsync(entityName2);
                    }

                    var stringMap2 = _cache2[entityName2].FirstOrDefault(e =>
                                                                         string.Equals(e.AttributeName, attributeName2, StringComparison.InvariantCultureIgnoreCase) &&
                                                                         string.Equals(e.ObjectTypeCode, entityName2, StringComparison.InvariantCultureIgnoreCase) &&
                                                                         e.AttributeValue == optionMetadata1.Value.Value
                                                                         );

                    if (stringMap2 != null)
                    {
                        displayOrder2 = stringMap2.DisplayOrder;
                    }
                }
            }

            {
                FormatTextTableHandler tableFormatter = new FormatTextTableHandler(true);

                tableFormatter.CalculateLineLengths("LanguageCode", "Value");
                tableFormatter.CalculateLineLengths("LanguageCode", "Organization", "Value");

                var isDifferentLabel       = LabelComparer.GetDifference(optionMetadata1.Label, optionMetadata2.Label);
                var isDifferentDescription = LabelComparer.GetDifference(optionMetadata1.Description, optionMetadata2.Description);

                isDifferentLabel.LabelsOnlyIn1.ForEach(i => tableFormatter.CalculateLineLengths(i.Locale, i.Value));
                isDifferentLabel.LabelsOnlyIn2.ForEach(i => tableFormatter.CalculateLineLengths(i.Locale, i.Value));
                isDifferentLabel.LabelDifference.ForEach(i =>
                {
                    tableFormatter.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    tableFormatter.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                isDifferentDescription.LabelsOnlyIn1.ForEach(i => tableFormatter.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelsOnlyIn2.ForEach(i => tableFormatter.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelDifference.ForEach(i =>
                {
                    tableFormatter.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    tableFormatter.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                if (!isDifferentLabel.IsEmpty)
                {
                    if (isDifferentLabel.LabelsOnlyIn1.Count > 0)
                    {
                        optionDiff.Add(string.Format("Labels ONLY in {0}: {1}", _connectionName1, isDifferentLabel.LabelsOnlyIn1.Count));
                        optionDiff.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Value"));
                        isDifferentLabel.LabelsOnlyIn1.ForEach(e => optionDiff.Add(_tabSpacer + tableFormatter.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentLabel.LabelsOnlyIn2.Count > 0)
                    {
                        optionDiff.Add(string.Format("Labels ONLY in {0}: {1}", _connectionName2, isDifferentLabel.LabelsOnlyIn2.Count));
                        optionDiff.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Value"));
                        isDifferentLabel.LabelsOnlyIn2.ForEach(e => optionDiff.Add(_tabSpacer + tableFormatter.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentLabel.LabelDifference.Count > 0)
                    {
                        optionDiff.Add(string.Format("Labels DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentLabel.LabelDifference.Count));
                        optionDiff.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentLabel.LabelDifference.ForEach(i =>
                        {
                            optionDiff.Add(_tabSpacer + tableFormatter.FormatLine(i.Locale, _connectionName1, i.Value1));
                            optionDiff.Add(_tabSpacer + tableFormatter.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }

                if (!isDifferentDescription.IsEmpty)
                {
                    if (isDifferentDescription.LabelsOnlyIn1.Count > 0)
                    {
                        optionDiff.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName1, isDifferentDescription.LabelsOnlyIn1.Count));
                        optionDiff.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn1.ForEach(e => optionDiff.Add(_tabSpacer + tableFormatter.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelsOnlyIn2.Count > 0)
                    {
                        optionDiff.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName2, isDifferentDescription.LabelsOnlyIn2.Count));
                        optionDiff.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn2.ForEach(e => optionDiff.Add(_tabSpacer + tableFormatter.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelDifference.Count > 0)
                    {
                        optionDiff.Add(string.Format("Descriptions DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDescription.LabelDifference.Count));
                        optionDiff.Add(_tabSpacer + tableFormatter.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDescription.LabelDifference.ForEach(i =>
                        {
                            optionDiff.Add(_tabSpacer + tableFormatter.FormatLine(i.Locale, _connectionName1, i.Value1));
                            optionDiff.Add(_tabSpacer + tableFormatter.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }
            }

            {
                var table = new FormatTextTableHandler(true);
                table.SetHeader("Property", _connectionName1, _connectionName2);

                table.AddLineIfNotEqual("DisplayOrder", displayOrder1, displayOrder2);
                table.AddLineIfNotEqual("Value", optionMetadata1.Value, optionMetadata2.Value);
                table.AddLineIfNotEqual("Color", optionMetadata1.Color, optionMetadata2.Color);
                //table.AddLineIfNotEqual("IsManaged", optionMetadata1.IsManaged, optionMetadata2.IsManaged);

                if (optionMetadata1.GetType().FullName != optionMetadata2.GetType().FullName)
                {
                    table.AddLine("Type", optionMetadata1.GetType().Name, optionMetadata2.GetType().Name);
                }
                else
                {
                    if (optionMetadata1 is StateOptionMetadata)
                    {
                        var optionState1 = optionMetadata1 as StateOptionMetadata;
                        var optionState2 = optionMetadata2 as StateOptionMetadata;

                        table.AddLineIfNotEqual("DefaultStatus", optionState1.DefaultStatus, optionState2.DefaultStatus);
                        table.AddLineIfNotEqual("InvariantName", optionState1.InvariantName, optionState2.InvariantName);
                    }

                    if (optionMetadata1 is StatusOptionMetadata)
                    {
                        var optionState1 = optionMetadata1 as StatusOptionMetadata;
                        var optionState2 = optionMetadata2 as StatusOptionMetadata;

                        table.AddLineIfNotEqual("State", optionState1.State, optionState2.State);
                        table.AddLineIfNotEqual("TransitionData", optionState1.TransitionData, optionState2.TransitionData);
                    }
                }

                if (table.Count > 0)
                {
                    optionDiff.AddRange(table.GetFormatedLines(true));
                }
            }

            return(optionDiff);
        }
Esempio n. 7
0
        public async Task <List <string> > GetDifference(OptionSetMetadata optionSet1, OptionSetMetadata optionSet2, string entityName1, string attributeName1, string entityName2 = null, string attributeName2 = null)
        {
            List <string> strDifference = new List <string>();

            {
                FormatTextTableHandler table = new FormatTextTableHandler(true);

                table.CalculateLineLengths("LanguageCode", "Value");
                table.CalculateLineLengths("LanguageCode", "Organization", "Value");

                var isDifferentDisplayName = LabelComparer.GetDifference(optionSet1.DisplayName, optionSet2.DisplayName);
                var isDifferentDescription = LabelComparer.GetDifference(optionSet1.Description, optionSet2.Description);

                isDifferentDisplayName.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                isDifferentDescription.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                if (!isDifferentDisplayName.IsEmpty)
                {
                    if (isDifferentDisplayName.LabelsOnlyIn1.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName1, isDifferentDisplayName.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelsOnlyIn2.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName2, isDifferentDisplayName.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelDifference.Count > 0)
                    {
                        strDifference.Add(string.Format("DisplayNames DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDisplayName.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDisplayName.LabelDifference.ForEach(i =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName1, i.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }

                if (!isDifferentDescription.IsEmpty)
                {
                    if (isDifferentDescription.LabelsOnlyIn1.Count > 0)
                    {
                        strDifference.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName1, isDifferentDescription.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelsOnlyIn2.Count > 0)
                    {
                        strDifference.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName2, isDifferentDescription.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelDifference.Count > 0)
                    {
                        strDifference.Add(string.Format("Descriptions DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDescription.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDescription.LabelDifference.ForEach(i =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName1, i.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }
            }

            {
                var table = new FormatTextTableHandler(true);
                table.SetHeader("Property", _connectionName1, _connectionName2);

                table.AddLineIfNotEqual("IsCustomizable", optionSet1.IsCustomizable, optionSet2.IsCustomizable);
                table.AddLineIfNotEqual("IsCustomOptionSet", optionSet1.IsCustomOptionSet, optionSet2.IsCustomOptionSet);
                table.AddLineIfNotEqual("IsGlobal", optionSet1.IsGlobal, optionSet2.IsGlobal);
                //table.AddLineIfNotEqual("IsManaged", optionSet1.IsManaged, optionSet2.IsManaged);
                table.AddLineIfNotEqual("Name", optionSet1.Name, optionSet2.Name);

                if (table.Count > 0)
                {
                    strDifference.AddRange(table.GetFormatedLines(true));
                }
            }

            {
                var optionValueOnly1 = new Dictionary <Tuple <int, bool?>, List <string> >();
                var optionValueOnly2 = new Dictionary <Tuple <int, bool?>, List <string> >();

                var optionValueDifferent = new Dictionary <int, List <string> >();

                foreach (var optionMetadata1 in optionSet1.Options.Where(e => e.Value.HasValue).OrderBy(e => e.Value))
                {
                    {
                        var optionMetadata2 = optionSet2.Options.FirstOrDefault(e => e.Value.HasValue && e.Value == optionMetadata1.Value);

                        if (optionMetadata2 != null)
                        {
                            continue;
                        }
                    }

                    List <string> listStrings = new List <string>();

                    CreateFileHandler.FillLabelDisplayNameAndDescription(listStrings, true, optionMetadata1.Label, optionMetadata1.Description, _tabSpacer);

                    optionValueOnly1.Add(Tuple.Create(optionMetadata1.Value.Value, optionMetadata1.IsManaged), listStrings);
                }

                foreach (var optionMetadata2 in optionSet2.Options.Where(e => e.Value.HasValue).OrderBy(e => e.Value))
                {
                    {
                        var optionMetadata1 = optionSet1.Options.FirstOrDefault(e => e.Value.HasValue && e.Value == optionMetadata2.Value);

                        if (optionMetadata1 != null)
                        {
                            continue;
                        }
                    }

                    List <string> listStrings = new List <string>();

                    CreateFileHandler.FillLabelDisplayNameAndDescription(listStrings, true, optionMetadata2.Label, optionMetadata2.Description, _tabSpacer);

                    optionValueOnly2.Add(Tuple.Create(optionMetadata2.Value.Value, optionMetadata2.IsManaged), listStrings);
                }

                foreach (var optionMetadata1 in optionSet1.Options.Where(e => e.Value.HasValue).OrderBy(e => e.Value))
                {
                    var optionMetadata2 = optionSet2.Options.FirstOrDefault(e => e.Value.HasValue && e.Value == optionMetadata1.Value);

                    if (optionMetadata2 == null)
                    {
                        continue;
                    }

                    List <string> optionDiff = await GetDifferenceOptionSetValue(optionMetadata1, optionMetadata2, entityName1, attributeName1, entityName2, attributeName2);

                    if (optionDiff.Count > 0)
                    {
                        optionValueDifferent.Add(optionMetadata1.Value.Value, optionDiff);
                    }
                }

                if (optionValueOnly1.Count > 0)
                {
                    if (strDifference.Count > 0)
                    {
                        strDifference.Add(string.Empty);
                    }

                    strDifference.Add(string.Format("Values ONLY EXISTS in {0}: {1}", _connectionName1, optionValueOnly1.Count));

                    foreach (var value in optionValueOnly1.OrderBy(s => s.Key.Item1))
                    {
                        strDifference.Add(_tabSpacer + string.Format("{0}   IsManaged: {1}", value.Key.Item1, value.Key.Item2));

                        foreach (var str in value.Value)
                        {
                            strDifference.Add(_tabSpacer + _tabSpacer + str);
                        }
                    }
                }

                if (optionValueOnly2.Count > 0)
                {
                    if (strDifference.Count > 0)
                    {
                        strDifference.Add(string.Empty);
                    }

                    strDifference.Add(string.Format("Values ONLY EXISTS in {0}: {1}", _connectionName2, optionValueOnly2.Count));

                    foreach (var value in optionValueOnly2)
                    {
                        strDifference.Add(_tabSpacer + string.Format("{0}   IsManaged: {1}", value.Key.Item1, value.Key.Item2));

                        foreach (var str in value.Value)
                        {
                            strDifference.Add(_tabSpacer + _tabSpacer + str);
                        }
                    }
                }

                if (optionValueDifferent.Count > 0)
                {
                    if (strDifference.Count > 0)
                    {
                        strDifference.Add(string.Empty);
                    }

                    strDifference.Add(string.Format("Values DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, optionValueDifferent.Count));

                    foreach (var value in optionValueDifferent.OrderBy(e => e.Key))
                    {
                        strDifference.Add(_tabSpacer + value.Key);

                        foreach (var str in value.Value)
                        {
                            strDifference.Add(_tabSpacer + _tabSpacer + str);
                        }
                    }
                }
            }

            return(strDifference);
        }
Esempio n. 8
0
        internal async Task <List <string> > GetDifference(BooleanOptionSetMetadata optionSet1, BooleanOptionSetMetadata optionSet2, string entityName, string attributeName)
        {
            List <string> strDifference = new List <string>();

            {
                FormatTextTableHandler table = new FormatTextTableHandler(true);

                table.CalculateLineLengths("LanguageCode", "Value");
                table.CalculateLineLengths("LanguageCode", "Organization", "Value");

                var isDifferentDisplayName = LabelComparer.GetDifference(optionSet1.DisplayName, optionSet2.DisplayName);
                var isDifferentDescription = LabelComparer.GetDifference(optionSet1.Description, optionSet2.Description);

                isDifferentDisplayName.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDisplayName.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                isDifferentDescription.LabelsOnlyIn1.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelsOnlyIn2.ForEach(i => table.CalculateLineLengths(i.Locale, i.Value));
                isDifferentDescription.LabelDifference.ForEach(i =>
                {
                    table.CalculateLineLengths(i.Locale, _connectionName1, i.Value1);
                    table.CalculateLineLengths(i.Locale, _connectionName2, i.Value2);
                });

                if (!isDifferentDisplayName.IsEmpty)
                {
                    if (isDifferentDisplayName.LabelsOnlyIn1.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName1, isDifferentDisplayName.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelsOnlyIn2.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("DisplayNames ONLY in {0}: {1}", _connectionName2, isDifferentDisplayName.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDisplayName.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDisplayName.LabelDifference.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("DisplayNames DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDisplayName.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDisplayName.LabelDifference.ForEach(i =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName1, i.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }

                if (!isDifferentDescription.IsEmpty)
                {
                    if (isDifferentDescription.LabelsOnlyIn1.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName1, isDifferentDescription.LabelsOnlyIn1.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn1.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelsOnlyIn2.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("Descriptions ONLY in {0}: {1}", _connectionName2, isDifferentDescription.LabelsOnlyIn2.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Value"));
                        isDifferentDescription.LabelsOnlyIn2.ForEach(e => strDifference.Add(_tabSpacer + table.FormatLine(e.Locale, e.Value)));
                    }

                    if (isDifferentDescription.LabelDifference.Count > 0)
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("Descriptions DIFFERENT in {0} and {1}: {2}", _connectionName1, _connectionName2, isDifferentDescription.LabelDifference.Count));
                        strDifference.Add(_tabSpacer + table.FormatLine("LanguageCode", "Organization", "Value"));
                        isDifferentDescription.LabelDifference.ForEach(i =>
                        {
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName1, i.Value1));
                            strDifference.Add(_tabSpacer + table.FormatLine(i.Locale, _connectionName2, i.Value2));
                        });
                    }
                }
            }

            {
                var table = new FormatTextTableHandler(true);
                table.SetHeader("Property", _connectionName1, _connectionName2);

                table.AddLineIfNotEqual("IsCustomizable", optionSet1.IsCustomizable, optionSet2.IsCustomizable);
                table.AddLineIfNotEqual("IsCustomOptionSet", optionSet1.IsCustomOptionSet, optionSet2.IsCustomOptionSet);
                table.AddLineIfNotEqual("IsGlobal", optionSet1.IsGlobal, optionSet2.IsGlobal);
                //table.AddLineIfNotEqual("IsManaged", optionSet1.IsManaged, optionSet2.IsManaged);
                table.AddLineIfNotEqual("Name", optionSet1.Name, optionSet2.Name);

                if (table.Count > 0)
                {
                    strDifference.AddRange(table.GetFormatedLines(true));
                }
            }

            {
                Dictionary <string, List <string> > optionValueDifferent = new Dictionary <string, List <string> >(StringComparer.InvariantCultureIgnoreCase);

                {
                    List <string> optionDiff = await GetDifferenceOptionSetValue(optionSet1.FalseOption, optionSet2.FalseOption, entityName, attributeName);

                    if (optionDiff.Count > 0)
                    {
                        optionValueDifferent.Add("FalseOption", optionDiff);
                    }
                }

                {
                    List <string> optionDiff = await GetDifferenceOptionSetValue(optionSet1.TrueOption, optionSet2.TrueOption, entityName, attributeName);

                    if (optionDiff.Count > 0)
                    {
                        optionValueDifferent.Add("TrueOption", optionDiff);
                    }
                }

                if (optionValueDifferent.Count > 0)
                {
                    foreach (var item in optionValueDifferent.OrderBy(e => e.Key))
                    {
                        if (strDifference.Count > 0)
                        {
                            strDifference.Add(string.Empty);
                        }

                        strDifference.Add(string.Format("Different Value {0}", item.Key));

                        foreach (var value in item.Value)
                        {
                            strDifference.Add(_tabSpacer + value);
                        }
                    }
                }
            }

            return(strDifference);
        }