private List <string> GetDifferenceOneToMany(OneToManyRelationshipMetadata rel1, OneToManyRelationshipMetadata rel2) { var table = new FormatTextTableHandler(true); table.SetHeader("Property", _connectionName1, _connectionName2); AddAssociatedMenuConfigurationDifference(table, "AssociatedMenuConfiguration", rel1.AssociatedMenuConfiguration, rel2.AssociatedMenuConfiguration); List <string> result = new List <string>(); if (table.Count > 0) { result.AddRange(table.GetFormatedLines(false)); } return(result); }
private static string GetEntityDescription(Entity entity, ConnectionData connectionData) { StringBuilder result = new StringBuilder(); result.AppendFormat("Entity : {0}", entity.LogicalName).AppendLine(); result.AppendFormat("Id : {0}", entity.Id).AppendLine(); if (connectionData != null) { var url = connectionData.GetEntityInstanceUrl(entity.LogicalName, entity.Id); if (!string.IsNullOrEmpty(url)) { result.AppendFormat("Url : {0}", url).AppendLine(); } } result.AppendLine(); FormatTextTableHandler table = new FormatTextTableHandler(); table.SetHeader("Field Name", "Type", "Value"); IEnumerable <string> attributeToIgnore = GetAttributesToIgnore(entity.LogicalName); HashSet <string> hashAttributeToIgnore = new HashSet <string>(attributeToIgnore, StringComparer.InvariantCultureIgnoreCase); foreach (var attr in entity.Attributes.OrderBy(s => s.Key)) { if (hashAttributeToIgnore.Any()) { if (hashAttributeToIgnore.Contains(attr.Key)) { continue; } } table.AddLine(attr.Key, GetAttributeType(attr.Value), GetAttributeString(entity, attr.Key, connectionData)); } table.GetFormatedLines(false).ForEach(s => result.AppendLine(s)); return(result.ToString()); }
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); }
private async Task <string> CheckSystemSavedQueryVisualizations() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingSystemChartsFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); var task1 = _comparerSource.GetSavedQueryVisualization1Async(); var task2 = _comparerSource.GetSavedQueryVisualization2Async(); var list1 = await task1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.SavedQueryVisualizationsInConnectionFormat2, Connection1.Name, list1.Count)); var list2 = await task2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.SavedQueryVisualizationsInConnectionFormat2, Connection2.Name, list2.Count)); if (!list1.Any() && !list2.Any()) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } FormatTextTableHandler tableOnlyExistsIn1 = new FormatTextTableHandler(); tableOnlyExistsIn1.SetHeader("Entity", "Name", "IsManaged", "Id"); FormatTextTableHandler tableOnlyExistsIn2 = new FormatTextTableHandler(); tableOnlyExistsIn2.SetHeader("Entity", "Name", "IsManaged", "Id"); var dictDifference = new Dictionary <Tuple <string, string, string>, List <string> >(); var commonList = new List <LinkedEntities <SavedQueryVisualization> >(); foreach (var chart1 in list1) { { var chart2 = list2.FirstOrDefault(chart => chart.Id == chart1.Id); if (chart2 != null) { commonList.Add(new LinkedEntities <SavedQueryVisualization>(chart1, chart2)); continue; } } var entityName1 = chart1.PrimaryEntityTypeCode; var name1 = chart1.Name; tableOnlyExistsIn1.AddLine(entityName1, name1, chart1.IsManaged.ToString(), chart1.Id.ToString()); this.ImageBuilder.AddComponentSolution1((int)ComponentType.SavedQueryVisualization, chart1.Id); } foreach (var chart2 in list2) { var entityName2 = chart2.PrimaryEntityTypeCode; var name2 = chart2.Name; { var chart1 = list1.FirstOrDefault(chart => chart.Id == chart2.Id); if (chart1 != null) { continue; } } tableOnlyExistsIn2.AddLine(entityName2, name2, chart2.IsManaged.ToString(), chart2.Id.ToString()); this.ImageBuilder.AddComponentSolution2((int)ComponentType.SavedQueryVisualization, chart2.Id); } { var reporter = new ProgressReporter(_iWriteToOutput, commonList.Count, 5, "Processing Common Saved Query Visualizations (Charts)"); foreach (var chart in commonList) { var chart1 = chart.Entity1; var chart2 = chart.Entity2; FormatTextTableHandler tabDiff = new FormatTextTableHandler(); tabDiff.SetHeader("Attribute", "Organization", "Value"); { List <string> fieldsToCompare = new List <string>() { SavedQueryVisualization.Schema.Attributes.componentstate //, SavedQueryVisualization.Schema.Attributes.createdby //, SavedQueryVisualization.Schema.Attributes.createdon //, SavedQueryVisualization.Schema.Attributes.createdonbehalfby //, SavedQueryVisualization.Schema.Attributes.datadescription , SavedQueryVisualization.Schema.Attributes.description , SavedQueryVisualization.Schema.Attributes.introducedversion , SavedQueryVisualization.Schema.Attributes.iscustomizable , SavedQueryVisualization.Schema.Attributes.isdefault //, SavedQueryVisualization.Schema.Attributes.ismanaged //, SavedQueryVisualization.Schema.Attributes.modifiedby //, SavedQueryVisualization.Schema.Attributes.modifiedon //, SavedQueryVisualization.Schema.Attributes.modifiedonbehalfby , SavedQueryVisualization.Schema.Attributes.name //, SavedQueryVisualization.Schema.Attributes.organizationid //, SavedQueryVisualization.Schema.Attributes.overwritetime //, SavedQueryVisualization.Schema.Attributes.presentationdescription , SavedQueryVisualization.Schema.Attributes.primaryentitytypecode //, SavedQueryVisualization.Schema.Attributes.savedqueryvisualizationid //, SavedQueryVisualization.Schema.Attributes.savedqueryvisualizationidunique //, SavedQueryVisualization.Schema.Attributes.solutionid //, SavedQueryVisualization.Schema.Attributes.supportingsolutionid , SavedQueryVisualization.Schema.Attributes.versionnumber , SavedQueryVisualization.Schema.Attributes.webresourceid }; foreach (var fieldName in fieldsToCompare) { if (ContentComparerHelper.IsEntityDifferentInField(chart1, chart2, fieldName)) { var str1 = EntityDescriptionHandler.GetAttributeString(chart1, fieldName, Connection1); var str2 = EntityDescriptionHandler.GetAttributeString(chart2, fieldName, Connection2); tabDiff.AddLine(fieldName, Connection1.Name, str1); tabDiff.AddLine(fieldName, Connection2.Name, str2); } } } var entityName1 = chart1.PrimaryEntityTypeCode; var name1 = chart1.Name; { List <string> fieldsToCompare = new List <string>() { SavedQueryVisualization.Schema.Attributes.datadescription , SavedQueryVisualization.Schema.Attributes.presentationdescription }; foreach (var fieldName in fieldsToCompare) { string xml1 = chart1.GetAttributeValue <string>(fieldName) ?? string.Empty; string xml2 = chart2.GetAttributeValue <string>(fieldName) ?? string.Empty; if (!ContentComparerHelper.CompareXML(xml1, xml2).IsEqual) { string reason = string.Empty; var compare = ContentComparerHelper.CompareXML(xml1.ToLower(), xml2.ToLower(), true); if (compare.IsEqual) { reason = "InCase"; } else { reason = compare.GetCompareDescription(); } if (!string.IsNullOrEmpty(reason)) { tabDiff.AddLine(fieldName, string.Empty, string.Format(Properties.OrganizationComparerStrings.FieldDifferenceReasonFormat3, Connection1.Name, Connection2.Name, reason)); } } } } if (tabDiff.Count > 0) { var diff = tabDiff.GetFormatedLines(false); this.ImageBuilder.AddComponentDifferent((int)ComponentType.SavedQueryVisualization, chart1.Id, chart2.Id, string.Join(Environment.NewLine, diff)); dictDifference.Add(Tuple.Create(entityName1, name1, chart1.Id.ToString()), diff); } } } if (tableOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Saved Query Visualizations (Charts) ONLY EXISTS in {0}: {1}", Connection1.Name, tableOnlyExistsIn1.Count); tableOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (tableOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Saved Query Visualizations (Charts) ONLY EXISTS in {0}: {1}", Connection2.Name, tableOnlyExistsIn2.Count); tableOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (dictDifference.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Saved Query Visualizations (Charts) DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); FormatTextTableHandler tableDifference = new FormatTextTableHandler(); tableDifference.SetHeader("Entity", "Name", "Id"); foreach (var template in dictDifference) { tableDifference.CalculateLineLengths(template.Key.Item1, template.Key.Item2, template.Key.Item3); } foreach (var template in dictDifference .OrderBy(w => w.Key.Item1) .ThenBy(w => w.Key.Item2) .ThenBy(w => w.Key.Item3) ) { content.AppendLine().Append(tabSpacer + tableDifference.FormatLine(template.Key.Item1, template.Key.Item2, template.Key.Item3)); foreach (var str in template.Value) { content.AppendLine().Append(tabSpacer + tabSpacer + str); } } } if (tableOnlyExistsIn2.Count == 0 && tableOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine("No difference in System Saved Query Visualizations (Charts)."); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, "Saved Query Visualizations (Charts)"); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }
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); }
private async Task <string> CheckMailMergeTemplates() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingMailMergeTemplatesFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); Task <List <MailMergeTemplate> > task1 = _comparerSource.GetMailMergeTemplate1Async(); Task <List <MailMergeTemplate> > task2 = _comparerSource.GetMailMergeTemplate2Async(); List <MailMergeTemplate> list1 = await task1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Mail Merge Templates in {0}: {1}", Connection1.Name, list1.Count())); List <MailMergeTemplate> list2 = await task2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Mail Merge Templates in {0}: {1}", Connection2.Name, list2.Count())); if (list1.Count == 0 && list2.Count == 0) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } FormatTextTableHandler tableOnlyExistsIn1 = new FormatTextTableHandler(); tableOnlyExistsIn1.SetHeader("AssociatedEntity", "Name", "Language", "File Name", "Mail Merge Type", "Viewable By", "Owner", "Id"); FormatTextTableHandler tableOnlyExistsIn2 = new FormatTextTableHandler(); tableOnlyExistsIn2.SetHeader("AssociatedEntity", "Name", "Language", "File Name", "Mail Merge Type", "Viewable By", "Owner", "Id"); Dictionary <Tuple <string, string, string, string>, List <string> > dictDifference = new Dictionary <Tuple <string, string, string, string>, List <string> >(); foreach (MailMergeTemplate template1 in list1) { { MailMergeTemplate template2 = list2.FirstOrDefault(template => template.Id == template1.Id); if (template2 != null) { continue; } } string name1 = template1.Name; string entityName1 = template1.TemplateTypeCode; int language1 = template1.LanguageCode.Value; string filename = template1.FileName; string reportType = template1.FormattedValues.ContainsKey(MailMergeTemplate.Schema.Attributes.mailmergetype) ? template1.FormattedValues[MailMergeTemplate.Schema.Attributes.mailmergetype] : string.Empty; Microsoft.Xrm.Sdk.EntityReference ownerRef = template1.OwnerId; string owner = string.Empty; if (ownerRef != null) { owner = ownerRef.Name; } string ispersonal = template1.FormattedValues.ContainsKey(MailMergeTemplate.Schema.Attributes.ispersonal) ? template1.FormattedValues[MailMergeTemplate.Schema.Attributes.ispersonal] : string.Empty; tableOnlyExistsIn1.AddLine(entityName1, name1, LanguageLocale.GetLocaleName(language1), filename, reportType, ispersonal, owner, template1.Id.ToString()); this.ImageBuilder.AddComponentSolution1((int)ComponentType.MailMergeTemplate, template1.Id); } foreach (MailMergeTemplate template2 in list2) { { MailMergeTemplate template1 = list1.FirstOrDefault(template => template.Id == template2.Id); if (template1 != null) { continue; } } string name2 = template2.Name; string entityName2 = template2.TemplateTypeCode; int language2 = template2.LanguageCode.Value; string filename = template2.FileName; string templateType = template2.FormattedValues.ContainsKey(MailMergeTemplate.Schema.Attributes.mailmergetype) ? template2.FormattedValues[MailMergeTemplate.Schema.Attributes.mailmergetype] : string.Empty; Microsoft.Xrm.Sdk.EntityReference ownerRef = template2.OwnerId; string owner = string.Empty; if (ownerRef != null) { owner = ownerRef.Name; } string ispersonal = template2.FormattedValues.ContainsKey(MailMergeTemplate.Schema.Attributes.ispersonal) ? template2.FormattedValues[MailMergeTemplate.Schema.Attributes.ispersonal] : string.Empty; tableOnlyExistsIn2.AddLine(entityName2, name2, LanguageLocale.GetLocaleName(language2), filename, templateType, ispersonal, owner, template2.Id.ToString()); this.ImageBuilder.AddComponentSolution2((int)ComponentType.MailMergeTemplate, template2.Id); } foreach (MailMergeTemplate template1 in list1) { MailMergeTemplate template2 = list2.FirstOrDefault(template => template.Id == template1.Id); if (template2 == null) { continue; } FormatTextTableHandler tabDiff = new FormatTextTableHandler(); tabDiff.SetHeader("Attribute", "Organization", "Value"); foreach (string fieldName in _fieldsToCompareMailMergeTemplateOrdinal) { if (ContentCoparerHelper.IsEntityDifferentInField(template1, template2, fieldName)) { string str1 = EntityDescriptionHandler.GetAttributeString(template1, fieldName, Connection1); string str2 = EntityDescriptionHandler.GetAttributeString(template2, fieldName, Connection2); tabDiff.AddLine(fieldName, Connection1.Name, str1); tabDiff.AddLine(fieldName, Connection2.Name, str2); } } foreach (string fieldName in _fieldsToCompareMailMergeTemplateXml) { string xml1 = template1.GetAttributeValue <string>(fieldName) ?? string.Empty; string xml2 = template2.GetAttributeValue <string>(fieldName) ?? string.Empty; if (!ContentCoparerHelper.CompareXML(xml1, xml2).IsEqual) { string reason = string.Empty; ContentCopareResult compare = ContentCoparerHelper.CompareXML(xml1.ToLower(), xml2.ToLower(), true); if (!compare.IsEqual) { reason = "InCase"; } else { reason = compare.GetCompareDescription(); } tabDiff.AddLine(fieldName, string.Empty, string.Format(Properties.OrganizationComparerStrings.FieldDifferenceReasonFormat3, Connection1.Name, Connection2.Name, reason)); } } if (tabDiff.Count > 0) { string name1 = template1.Name; string entityName1 = template1.TemplateTypeCode; int language1 = template1.LanguageCode.Value; var diff = tabDiff.GetFormatedLines(false); this.ImageBuilder.AddComponentDifferent((int)ComponentType.MailMergeTemplate, template1.Id, template2.Id, string.Join(Environment.NewLine, diff)); dictDifference.Add(Tuple.Create(entityName1, name1, LanguageLocale.GetLocaleName(language1), template1.Id.ToString()), diff); } } if (tableOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Mail Merge Templates ONLY EXISTS in {0}: {1}", Connection1.Name, tableOnlyExistsIn1.Count); tableOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (tableOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Mail Merge Templates ONLY EXISTS in {0}: {1}", Connection2.Name, tableOnlyExistsIn2.Count); tableOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (dictDifference.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Mail Merge Templates DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); FormatTextTableHandler tableDifference = new FormatTextTableHandler(); tableDifference.SetHeader("AssociatedEntity", "Name", "Language", "Id"); foreach (KeyValuePair <Tuple <string, string, string, string>, List <string> > template in dictDifference) { tableDifference.CalculateLineLengths(template.Key.Item1, template.Key.Item2, template.Key.Item3, template.Key.Item4); } foreach (KeyValuePair <Tuple <string, string, string, string>, List <string> > template in dictDifference .OrderBy(w => w.Key.Item1) .ThenBy(w => w.Key.Item2) .ThenBy(w => w.Key.Item3) .ThenBy(w => w.Key.Item4) ) { content.AppendLine().Append(tabSpacer + tableDifference.FormatLine(template.Key.Item1, template.Key.Item2, template.Key.Item3, template.Key.Item4)); foreach (string str in template.Value) { content.AppendLine().Append(tabSpacer + tabSpacer + str); } } } if (tableOnlyExistsIn2.Count == 0 && tableOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine("No difference in Mail Merge Templates."); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, "Mail Merge Templates"); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }
private async Task <string> CheckFieldSecurityProfiles() { var content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingFieldSecurityProfilesFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); var task1 = _comparerSource.GetFieldSecurityProfile1Async(); var task2 = _comparerSource.GetFieldSecurityProfile2Async(); var list1 = await task1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.FieldSecurityProfilesInConnectionFormat2, Connection1.Name, list1.Count())); var list2 = await task2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.FieldSecurityProfilesInConnectionFormat2, Connection2.Name, list2.Count())); if (!list1.Any() && !list2.Any()) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } var taskPerm1 = _comparerSource.GetFieldPermission1Async(); var taskPerm2 = _comparerSource.GetFieldPermission2Async(); var listPermission1 = await taskPerm1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.FieldSecurityProfilesPermissionsInConnectionFormat2, Connection1.Name, listPermission1.Count())); var listPermission2 = await taskPerm2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.FieldSecurityProfilesPermissionsInConnectionFormat2, Connection2.Name, listPermission2.Count())); var group1 = listPermission1.GroupBy(e => e.FieldSecurityProfileId.Id); var group2 = listPermission2.GroupBy(e => e.FieldSecurityProfileId.Id); var tableOnlyExistsIn1 = new FormatTextTableHandler("Name", "Id"); var tableOnlyExistsIn2 = new FormatTextTableHandler("Name", "Id"); var dictDifference = new Dictionary <Tuple <string, Guid>, List <string> >(); foreach (var profile1 in list1) { { var profile2 = list2.FirstOrDefault(profile => profile.Id == profile1.Id); if (profile2 != null) { continue; } } var name1 = profile1.Name; tableOnlyExistsIn1.AddLine(name1, profile1.Id.ToString()); this.ImageBuilder.AddComponentSolution1((int)ComponentType.FieldSecurityProfile, profile1.Id); } foreach (var profile2 in list2) { var name2 = profile2.Name; { var profile1 = list1.FirstOrDefault(profile => profile.Id == profile2.Id); if (profile1 != null) { continue; } } tableOnlyExistsIn2.AddLine(name2, profile2.Id.ToString()); this.ImageBuilder.AddComponentSolution2((int)ComponentType.FieldSecurityProfile, profile2.Id); } foreach (var profile1 in list1) { var profile2 = list2.FirstOrDefault(profile => profile.Id == profile1.Id); if (profile2 == null) { continue; } var name1 = profile1.Name; var diff = new List <string>(); IEnumerable <FieldPermission> enumerable1 = group1.FirstOrDefault(g => g.Key == profile1.Id); IEnumerable <FieldPermission> enumerable2 = group2.FirstOrDefault(g => g.Key == profile2.Id); CompareFieldPermissions(diff, enumerable1, enumerable2, tabSpacer); if (diff.Count > 0) { dictDifference.Add(Tuple.Create(name1, profile1.Id), diff); this.ImageBuilder.AddComponentDifferent((int)ComponentType.FieldSecurityProfile, profile1.Id, profile2.Id, string.Join(Environment.NewLine, diff)); } } if (tableOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Field Security Profiles ONLY EXISTS in {0}: {1}", Connection1.Name, tableOnlyExistsIn1.Count); tableOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append(tabSpacer + e.TrimEnd())); } if (tableOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Field Security Profiles ONLY EXISTS in {0}: {1}", Connection2.Name, tableOnlyExistsIn2.Count); tableOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append(tabSpacer + e.TrimEnd())); } if (dictDifference.Count > 0) { var order = dictDifference.OrderBy(s => s.Key.Item1).ThenBy(s => s.Key.Item2); content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendFormat("Field Security Profiles DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); { var table = new FormatTextTableHandler(); table.SetHeader("Name", "Id"); foreach (var item in order) { table.AddLine(item.Key.Item1, item.Key.Item2.ToString()); } table.GetFormatedLines(true).ForEach(e => content.AppendLine().Append(tabSpacer + e.TrimEnd())); } content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendFormat("Field Security Profiles DIFFERENT Details in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); foreach (var item in dictDifference.OrderBy(s => s.Key.Item1).ThenBy(s => s.Key.Item2)) { content .AppendLine() .AppendLine() .Append((tabSpacer + item.Key.Item1 + tabSpacer + item.Key.Item2).TrimEnd()); foreach (var str in item.Value) { content.AppendLine().Append((tabSpacer + tabSpacer + str).TrimEnd()); } content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)); } } if (tableOnlyExistsIn2.Count == 0 && tableOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine("No difference in Field Security Profiles."); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, "Field Security Profiles"); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }
private async Task <string> CheckDisplayStrings() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingDisplayStringsFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); var task1 = _comparerSource.GetDisplayString1Async(); var task2 = _comparerSource.GetDisplayString2Async(); var list1 = await task1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Display Strings in {0}: {1}", Connection1.Name, list1.Count())); var list2 = await task2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Display Strings in {0}: {1}", Connection2.Name, list2.Count())); if (list1.Count == 0 && list2.Count == 0) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } var taskMap1 = _comparerSource.GetDisplayStringMap1Async(); var taskMap2 = _comparerSource.GetDisplayStringMap2Async(); var listMap1 = await taskMap1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Display Strings Maps in {0}: {1}", Connection1.Name, listMap1.Count())); var listMap2 = await taskMap2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Display Strings Maps in {0}: {1}", Connection1.Name, listMap2.Count())); FormatTextTableHandler tableOnlyExistsIn1 = new FormatTextTableHandler(); tableOnlyExistsIn1.SetHeader("Key", "LanguageCode", "Published", "Custom", "CustomComment", "FormatParameters"); FormatTextTableHandler tableOnlyExistsIn2 = new FormatTextTableHandler(); tableOnlyExistsIn2.SetHeader("Key", "LanguageCode", "Published", "Custom", "CustomComment", "FormatParameters"); var dictDifference = new Dictionary <Tuple <string, string>, List <string> >(); foreach (var displayString1 in list1) { var displaystringkey1 = displayString1.DisplayStringKey; var languagecode1 = displayString1.LanguageCode.Value; { var displayString2 = list2.FirstOrDefault(displayString => { var displaystringkey2 = displayString.DisplayStringKey; var languagecode2 = displayString.LanguageCode.Value; return(displaystringkey1 == displaystringkey2 && languagecode1 == languagecode2); }); if (displayString2 != null) { continue; } } var customComment = displayString1.CustomComment; var customDisplayString = displayString1.CustomComment; var formatParameters = displayString1.FormatParameters.Value; var publishedDisplayString = displayString1.PublishedDisplayString; tableOnlyExistsIn1.AddLine(displaystringkey1, LanguageLocale.GetLocaleName(languagecode1), publishedDisplayString, customDisplayString, customComment, formatParameters.ToString()); this.ImageBuilder.AddComponentSolution1((int)ComponentType.DisplayString, displayString1.Id); } foreach (var displayString2 in list2) { var displaystringkey2 = displayString2.DisplayStringKey; var languagecode2 = displayString2.LanguageCode.Value; { var displayString1 = list1.FirstOrDefault(displayString => { var displaystringkey1 = displayString.DisplayStringKey; var languagecode1 = displayString.LanguageCode.Value; return(displaystringkey1 == displaystringkey2 && languagecode1 == languagecode2); }); if (displayString1 != null) { continue; } } var customComment = displayString2.CustomComment; var customDisplayString = displayString2.CustomDisplayString; var formatParameters = displayString2.FormatParameters.Value; var publishedDisplayString = displayString2.PublishedDisplayString; tableOnlyExistsIn2.AddLine(displaystringkey2, LanguageLocale.GetLocaleName(languagecode2), publishedDisplayString, customDisplayString, customComment, formatParameters.ToString()); this.ImageBuilder.AddComponentSolution2((int)ComponentType.DisplayString, displayString2.Id); } foreach (var displayString1 in list1) { var displaystringkey1 = displayString1.DisplayStringKey; var languagecode1 = displayString1.LanguageCode.Value; var displayString2 = list2.FirstOrDefault(displayString => { var displaystringkey2 = displayString.DisplayStringKey; var languagecode2 = displayString.LanguageCode.Value; return(displaystringkey1 == displaystringkey2 && languagecode1 == languagecode2); }); if (displayString2 == null) { continue; } FormatTextTableHandler tabDiff = new FormatTextTableHandler(); tabDiff.SetHeader("Attribute", "Organization", "Value"); var temp1 = listMap1.Where(s => s.DisplayStringId == displayString1.Id); var temp2 = listMap2.Where(s => s.DisplayStringId == displayString2.Id); if (temp1.SequenceEqual(temp2)) { tabDiff.AddLine("DisplayStringMap", Connection1.Name, "Differs"); tabDiff.AddLine("DisplayStringMap", Connection2.Name, "Differs"); } List <string> fieldsToCompare = new List <string>() { DisplayString.Schema.Attributes.customcomment , DisplayString.Schema.Attributes.customdisplaystring , DisplayString.Schema.Attributes.formatparameters , DisplayString.Schema.Attributes.publisheddisplaystring }; foreach (var fieldName in fieldsToCompare) { if (ContentComparerHelper.IsEntityDifferentInField(displayString1, displayString2, fieldName)) { var str1 = EntityDescriptionHandler.GetAttributeString(displayString1, fieldName, Connection1); var str2 = EntityDescriptionHandler.GetAttributeString(displayString2, fieldName, Connection2); tabDiff.AddLine(fieldName, Connection1.Name, str1); tabDiff.AddLine(fieldName, Connection2.Name, str2); } } if (tabDiff.Count > 0) { var diff = tabDiff.GetFormatedLines(false); dictDifference.Add(Tuple.Create(displaystringkey1, LanguageLocale.GetLocaleName(languagecode1)), diff); this.ImageBuilder.AddComponentDifferent((int)ComponentType.DisplayString, displayString1.Id, displayString2.Id, string.Join(Environment.NewLine, diff)); } } if (tableOnlyExistsIn1.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, tableOnlyExistsIn1.Count); tableOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (tableOnlyExistsIn2.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, tableOnlyExistsIn2.Count); tableOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (dictDifference.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, dictDifference.Count); FormatTextTableHandler tableDifference = new FormatTextTableHandler(); tableDifference.SetHeader("Key", "LanguageCode"); foreach (var displayString in dictDifference) { tableDifference.CalculateLineLengths(displayString.Key.Item1, displayString.Key.Item2); } foreach (var displayString in dictDifference .OrderBy(w => w.Key.Item1) .ThenBy(w => w.Key.Item2) ) { content.AppendLine().Append(tabSpacer + tableDifference.FormatLine(displayString.Key.Item1, displayString.Key.Item2)); foreach (var str in displayString.Value) { content.AppendLine().Append(tabSpacer + tabSpacer + str); } } } if (tableOnlyExistsIn2.Count == 0 && tableOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine("No difference in Display Strings."); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, "Display Strings"); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }
private async Task <string> CheckSecurityRoles() { StringBuilder content = new StringBuilder(); var privilegeComparer = new PrivilegeNameComparer(); var privileteEquality = new PrivilegeEqualityComparer(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingSecurityRolesFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); var task1 = _comparerSource.GetRole1Async(); var task2 = _comparerSource.GetRole2Async(); var list1 = await task1; var taskPriv1 = new PrivilegeRepository(_comparerSource.Service1).GetListAsync(null); content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.SecurityRolesInConnectionFormat2, Connection1.Name, list1.Count())); var list2 = await task2; var taskPriv2 = new PrivilegeRepository(_comparerSource.Service2).GetListAsync(null); content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.SecurityRolesInConnectionFormat2, Connection2.Name, list2.Count())); var dictPrivilege1 = (await taskPriv1).ToDictionary(p => p.Name, StringComparer.InvariantCultureIgnoreCase); var taskPrivRole1 = new RolePrivilegesRepository(_comparerSource.Service1).GetListAsync(list1.Select(e => e.RoleId.Value)); content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.PrivilegesInConnectionFormat2, Connection1.Name, dictPrivilege1.Count())); var dictPrivilege2 = (await taskPriv2).ToDictionary(p => p.Name, StringComparer.InvariantCultureIgnoreCase); var taskPrivRole2 = new RolePrivilegesRepository(_comparerSource.Service2).GetListAsync(list2.Select(e => e.RoleId.Value)); content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.PrivilegesInConnectionFormat2, Connection2.Name, dictPrivilege2.Count())); var commonPrivileges = dictPrivilege1.Values.Intersect(dictPrivilege2.Values, privileteEquality).ToList(); content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Common Privileges in {0} and {1}: {2}", Connection1.Name, Connection2.Name, commonPrivileges.Count())); var listRolePrivilege1 = await taskPrivRole1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.RolePrivilegesInConnectionFormat2, Connection1.Name, listRolePrivilege1.Count())); var listRolePrivilege2 = await taskPrivRole2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.RolePrivilegesInConnectionFormat2, Connection2.Name, listRolePrivilege2.Count())); if (!list1.Any() && !list2.Any()) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } var groupByRole1 = listRolePrivilege1.GroupBy(e => e.RoleId.Value).ToDictionary(g => g.Key, g => g.AsEnumerable()); var groupByRole2 = listRolePrivilege2.GroupBy(e => e.RoleId.Value).ToDictionary(g => g.Key, g => g.AsEnumerable()); FormatTextTableHandler rolesOnlyExistsIn1 = new FormatTextTableHandler(); rolesOnlyExistsIn1.SetHeader("Name", "BusinessUnit", "IsManaged"); FormatTextTableHandler rolesOnlyExistsIn2 = new FormatTextTableHandler(); rolesOnlyExistsIn2.SetHeader("Name", "BusinessUnit", "IsManaged"); FormatTextTableHandler privilegesOnlyExistsIn1 = new FormatTextTableHandler(); privilegesOnlyExistsIn1.SetHeader("PrivilegeName", "PrivilegeType", "Linked Entities"); FormatTextTableHandler privilegesOnlyExistsIn2 = new FormatTextTableHandler(); privilegesOnlyExistsIn2.SetHeader("PrivilegeName", "PrivilegeType", "Linked Entities"); foreach (var item1 in dictPrivilege1.Values .Except(dictPrivilege2.Values, privileteEquality) .ToList() .OrderBy(p => p.LinkedEntitiesSorted) .ThenBy(p => p.Name, privilegeComparer) ) { privilegesOnlyExistsIn1.AddLine(item1.Name , item1.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)item1.AccessRight.Value).ToString() : string.Empty , item1.LinkedEntitiesSorted ); } foreach (var item2 in dictPrivilege2.Values .Except(dictPrivilege1.Values, privileteEquality) .ToList() .OrderBy(p => p.LinkedEntitiesSorted) .ThenBy(p => p.Name, privilegeComparer) ) { privilegesOnlyExistsIn2.AddLine(item2.Name , item2.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)item2.AccessRight.Value).ToString() : string.Empty , item2.LinkedEntitiesSorted ); } var commonList = new List <LinkedEntities <Role> >(); foreach (var role1 in list1) { var name1 = role1.Name; var businessUnit1 = role1.BusinessUnitId.Name; if (role1.BusinessUnitParentBusinessUnit == null) { businessUnit1 = "Root Organization"; } { Role role2 = null; if (role2 == null) { role2 = list2.FirstOrDefault(role => role.Id == role1.Id); } if (role2 == null && role1.RoleTemplateId != null) { role2 = list2.FirstOrDefault(role => role.RoleTemplateId != null && role.RoleTemplateId.Id == role1.RoleTemplateId.Id); } if (role2 != null) { commonList.Add(new LinkedEntities <Role>(role1, role2)); continue; } } string state = role1.FormattedValues[Role.Schema.Attributes.ismanaged]; rolesOnlyExistsIn1.AddLine(name1, businessUnit1, state); this.ImageBuilder.AddComponentSolution1((int)ComponentType.Role, role1.Id); } foreach (var role2 in list2) { var name2 = role2.Name; var businessUnit2 = role2.BusinessUnitId.Name; if (role2.BusinessUnitParentBusinessUnit == null) { businessUnit2 = "Root Organization"; } { Role role1 = null; if (role1 == null) { role1 = list1.FirstOrDefault(role => role.Id == role2.Id); } if (role1 == null && role2.RoleTemplateId != null) { role1 = list1.FirstOrDefault(role => role.RoleTemplateId != null && role.RoleTemplateId.Id == role2.RoleTemplateId.Id); } if (role1 != null) { continue; } } string state = role2.FormattedValues[Role.Schema.Attributes.ismanaged]; rolesOnlyExistsIn2.AddLine(name2, businessUnit2, state); this.ImageBuilder.AddComponentSolution2((int)ComponentType.Role, role2.Id); } var dictDifference = new Dictionary <LinkedEntities <Role>, List <string> >(); content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.RolesCommonFormat3, Connection1.Name, Connection2.Name, commonList.Count())); foreach (var commonRole in commonList) { groupByRole1.TryGetValue(commonRole.Entity1.Id, out IEnumerable <RolePrivileges> enumerable1); groupByRole2.TryGetValue(commonRole.Entity2.Id, out IEnumerable <RolePrivileges> enumerable2); List <string> diff = ComparePrivileges(enumerable1, enumerable2, commonPrivileges, dictPrivilege1, dictPrivilege2, privilegeComparer); if (diff.Count > 0) { dictDifference.Add(commonRole, diff); this.ImageBuilder.AddComponentDifferent((int)ComponentType.Role, commonRole.Entity1.Id, commonRole.Entity2.Id, string.Join(Environment.NewLine, diff)); } } if (privilegesOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Security Privileges ONLY EXISTS in {0}: {1}", Connection1.Name, privilegesOnlyExistsIn1.Count); privilegesOnlyExistsIn1.GetFormatedLines(false).ForEach(e => content.AppendLine().Append(tabSpacer + e.TrimEnd())); } if (privilegesOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Security Privileges ONLY EXISTS in {0}: {1}", Connection2.Name, privilegesOnlyExistsIn2.Count); privilegesOnlyExistsIn2.GetFormatedLines(false).ForEach(e => content.AppendLine().Append(tabSpacer + e.TrimEnd())); } if (rolesOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Security Roles ONLY EXISTS in {0}: {1}", Connection1.Name, rolesOnlyExistsIn1.Count); rolesOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append(tabSpacer + e.TrimEnd())); } if (rolesOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Security Roles ONLY EXISTS in {0}: {1}", Connection2.Name, rolesOnlyExistsIn2.Count); rolesOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append(tabSpacer + e.TrimEnd())); } if (dictDifference.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); var order = dictDifference.OrderBy(s => s.Key.Entity1.Name).ThenBy(s => s.Key.Entity1.BusinessUnitParentBusinessUnit == null ? "Root Organization" : s.Key.Entity1.BusinessUnitId.Name); content.AppendLine().AppendLine().AppendFormat("Security Roles DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); { var table = new FormatTextTableHandler(); table.SetHeader("Name", "BusinessUnit"); foreach (var item in order) { table.AddLine(item.Key.Entity1.Name, item.Key.Entity1.BusinessUnitParentBusinessUnit == null ? "Root Organization" : item.Key.Entity1.BusinessUnitId.Name); } table.GetFormatedLines(true).ForEach(e => content.AppendLine().Append(tabSpacer + e.TrimEnd())); } content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendFormat("Security Roles DIFFERENT Details in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); foreach (var item in order) { content .AppendLine() .AppendLine() .Append((tabSpacer + string.Format("Role: {0} Business Unit: {1}", item.Key.Entity1.Name, item.Key.Entity1.BusinessUnitParentBusinessUnit == null ? "Root Organization" : item.Key.Entity1.BusinessUnitId.Name)).TrimEnd()); foreach (var str in item.Value) { content.AppendLine().Append((tabSpacer + tabSpacer + str).TrimEnd()); } content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)); } } if (rolesOnlyExistsIn2.Count == 0 && rolesOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine("No difference in Security Roles."); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, "Security Roles"); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }
public async Task GetDescriptionEntitesAndAttributesInWorkflowAsync(StringBuilder strFile, Guid idWorkflow) { try { var repository = new WorkflowRepository(_service); var workflow = await repository.GetByIdAsync(idWorkflow, new ColumnSet(true)); string xmlContent = ContentCoparerHelper.RemoveDiacritics(workflow.Xaml); var doc = XElement.Parse(xmlContent); var handler = new WorkflowUsedEntitiesHandler(); strFile .AppendFormat("Entity: {0}", workflow.PrimaryEntity).AppendLine() .AppendFormat("Category: {0}", workflow.FormattedValues[Workflow.Schema.Attributes.category]).AppendLine() .AppendFormat("Name: {0}", workflow.Name).AppendLine() .AppendFormat("Url: {0}", _service.UrlGenerator.GetSolutionComponentUrl(ComponentType.Workflow, idWorkflow)).AppendLine() .AppendLine() ; WorkflowAnalysis analysis = handler.GetWorkflowAnalysis(doc); if (analysis.UsedEntityAttributes.Any()) { strFile .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine() .AppendLine() ; var tableUsedAttributes = new FormatTextTableHandler(); tableUsedAttributes.SetHeader("Entity", "Attribute", "StepName"); foreach (var step in analysis.UsedEntityAttributes .OrderBy(e => e.EntityName) .ThenBy(e => e.Attribute) .ThenBy(e => e.DisplayName) ) { tableUsedAttributes.AddLine(step.EntityName, step.Attribute, step.DisplayName); } strFile.AppendFormat("Used Attributes: {0}", analysis.UsedEntityAttributes.Count).AppendLine(); tableUsedAttributes.GetFormatedLines(false).ForEach(s => strFile.AppendLine(tabspacer + s)); } if (analysis.CreateUpdateEntitySteps.Any()) { strFile .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine() .AppendLine() ; strFile.AppendFormat("Created or Updated Entities {0}", analysis.CreateUpdateEntitySteps.Count).AppendLine(); foreach (var step in analysis.CreateUpdateEntitySteps) { strFile.AppendFormat("Entity {0} Operation {1} StepName {2} With Attributes {2}", step.EntityName, step.StepType, step.DisplayName, step.SetEntityPropertySteps.Count).AppendLine() ; var tableUsedAttributes = new FormatTextTableHandler(); tableUsedAttributes.SetHeader("Attribute"); foreach (var stepSet in step.SetEntityPropertySteps .OrderBy(e => e.EntityName) .ThenBy(e => e.Attribute) ) { tableUsedAttributes.AddLine(stepSet.Attribute); } tableUsedAttributes.GetFormatedLines(false).ForEach(s => strFile.AppendLine(tabspacer + s)); strFile.AppendLine().AppendLine(); } } } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); } }
/// <summary> /// Обновление контента веб-ресурсов /// </summary> /// <returns></returns> private void UpdateContent() { var list = _Elements.Values.OrderBy(element => element.SelectedFile.FriendlyFilePath).ToList(); FormatTextTableHandler tableUpdated = new FormatTextTableHandler(); tableUpdated.SetHeader("FileName", "WebResourceName", "WebResourceType"); FormatTextTableHandler tableNotCustomizable = new FormatTextTableHandler(); tableNotCustomizable.SetHeader("FileName", "WebResourceName", "WebResourceType"); FormatTextTableHandler tableEqual = new FormatTextTableHandler(); tableEqual.SetHeader("FileName", "WebResourceName", "WebResourceType"); foreach (var element in list) { var contentFile = Convert.ToBase64String(File.ReadAllBytes(element.SelectedFile.FilePath)); var contentWebResource = element.WebResource.Content ?? string.Empty; element.WebResource.FormattedValues.TryGetValue(WebResource.Schema.Attributes.webresourcetype, out var webresourcetype); if (contentFile == contentWebResource) { tableEqual.AddLine(element.SelectedFile.FileName, element.WebResource.Name, webresourcetype); } else { var isCustomizable = (element.WebResource.IsCustomizable?.Value).GetValueOrDefault(true); if (isCustomizable) { WebResource resource = new WebResource(); resource.WebResourceId = resource.Id = element.WebResource.Id; resource.Content = contentFile; this._service.Update(resource); tableUpdated.AddLine(element.SelectedFile.FileName, element.WebResource.Name, webresourcetype); } else { tableNotCustomizable.AddLine(element.SelectedFile.FileName, element.WebResource.Name, webresourcetype); } } } if (tableEqual.Count > 0) { this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "WebResources equal to file content:"); var lines = tableEqual.GetFormatedLines(false); lines.ForEach(item => _iWriteToOutput.WriteToOutput(_service.ConnectionData, " {0}", item)); } if (tableNotCustomizable.Count > 0) { this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "WebResources are NOT Customizable, can't change WebResource's content:"); var lines = tableNotCustomizable.GetFormatedLines(false); lines.ForEach(item => _iWriteToOutput.WriteToOutput(_service.ConnectionData, " {0}", item)); } if (tableUpdated.Count > 0) { this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "Updated WebResources:"); var lines = tableUpdated.GetFormatedLines(false); lines.ForEach(item => _iWriteToOutput.WriteToOutput(_service.ConnectionData, " {0}", item)); } }
private async Task FillDescriptionNotExistsEntities(StringBuilder strFile, HashSet <Guid> workflowsWithEntities, Dictionary <EntityReference, HashSet <Guid> > list) { { var listToDelete = new List <EntityReference>(); foreach (var itemRef in list.Keys) { try { var entityMetadata = _descriptor.MetadataSource.GetEntityMetadata(itemRef.LogicalName); if (entityMetadata != null) { var repositoryGeneric = new GenericRepository(_service, entityMetadata); var entity = await repositoryGeneric.GetEntityByIdAsync(itemRef.Id, new ColumnSet(true)); if (entity != null) { listToDelete.Add(itemRef); } } } catch (Exception) { } } foreach (var item in listToDelete) { list.Remove(item); } workflowsWithEntities.Clear(); foreach (var set in list.Values) { foreach (var item in set) { workflowsWithEntities.Add(item); } } } if (list.Count == 0) { strFile .AppendLine() .AppendLine() .AppendLine() .AppendLine(this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "No used not exists entities in workflows.")) ; return; } strFile .AppendLine() .AppendLine() .AppendFormat(this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "Used Not Exists Entities {0}", list.Count)).AppendLine() ; var orderedList = list.Keys.OrderBy(i => i.LogicalName).ThenBy(i => i.Name).ThenBy(i => i.Id); { FormatTextTableHandler table = new FormatTextTableHandler(); table.SetHeader("LogicalName", "Name", "Id", "Url"); foreach (var item in orderedList) { var values = new List <string>() { item.LogicalName, item.Name, item.Id.ToString() }; var url = _service.ConnectionData.GetEntityInstanceUrl(item.LogicalName, item.Id); if (!string.IsNullOrEmpty(url)) { values.Add(url); } table.AddLine(values); } table.GetFormatedLines(false).ForEach(s => strFile.AppendLine(tabspacer + s)); } strFile .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine() .AppendLine() ; strFile.AppendFormat("Used Not Exists Entities Full Information {0}", list.Count).AppendLine(); foreach (var item in orderedList) { strFile .AppendLine() .AppendLine() .AppendLine(); FormatTextTableHandler table = new FormatTextTableHandler(); table.SetHeader("LogicalName", "Name", "Id"); table.AddLine(item.LogicalName, item.Name, item.Id.ToString()); table.GetFormatedLines(false).ForEach(s => strFile.AppendLine(s)); var url = _service.ConnectionData.GetEntityInstanceUrl(item.LogicalName, item.Id); if (!string.IsNullOrEmpty(url)) { strFile.AppendLine("Url:"); strFile.AppendLine(url); } strFile.AppendLine(); var message = await _descriptor.GetSolutionComponentsDescriptionAsync(list[item].Select(id => new SolutionComponent() { ObjectId = id, ComponentType = new OptionSetValue((int)ComponentType.Workflow), })); strFile .AppendLine("This entity Used By Workflows:") .AppendLine(message) .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) ; } if (workflowsWithEntities.Any()) { strFile .AppendLine() .AppendLine() .AppendLine() .AppendLine() .AppendLine() .AppendLine() .AppendLine("These entities Used By Workflows:") ; var desc = await _descriptor.GetSolutionComponentsDescriptionAsync(workflowsWithEntities.Select(id => new SolutionComponent() { ObjectId = id, ComponentType = new OptionSetValue((int)ComponentType.Workflow), })); strFile.AppendLine(desc); } }
private async Task FillDescriptionUsedEntities(StringBuilder strFile, HashSet <Guid> workflowsWithEntities, Dictionary <EntityReference, HashSet <Guid> > dictUsedEntities) { string message = string.Empty; if (dictUsedEntities.Count == 0) { strFile .AppendLine() .AppendLine() .AppendLine() .AppendLine(this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "No used entities in workflows.")) ; return; } strFile .AppendLine() .AppendLine() .AppendFormat(this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "Used Entities {0}", dictUsedEntities.Count)).AppendLine() ; var orderedList = dictUsedEntities.Keys.OrderBy(i => i.LogicalName).ThenBy(i => i.Name).ThenBy(i => i.Id); { var table = new FormatTextTableHandler( nameof(EntityReference.LogicalName) , nameof(EntityReference.Name) , nameof(EntityReference.Id) , "Url" ); foreach (var item in orderedList) { var values = new List <string>() { item.LogicalName, item.Name, item.Id.ToString() }; var url = _service.ConnectionData.GetEntityInstanceUrl(item.LogicalName, item.Id); if (!string.IsNullOrEmpty(url)) { values.Add(url); } table.AddLine(values); } table.GetFormatedLines(false).ForEach(s => strFile.AppendLine(tabspacer + s)); } strFile .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine() .AppendLine() ; strFile.AppendFormat("Used Entities Full Information {0}", dictUsedEntities.Count).AppendLine(); foreach (var item in orderedList) { strFile .AppendLine() .AppendLine() .AppendLine() ; var table = new FormatTextTableHandler(); table.SetHeader(nameof(EntityReference.LogicalName), nameof(EntityReference.Name), nameof(EntityReference.Id)); table.AddLine(item.LogicalName, item.Name, item.Id.ToString()); table.GetFormatedLines(false).ForEach(s => strFile.AppendLine(s)); var url = _service.ConnectionData.GetEntityInstanceUrl(item.LogicalName, item.Id); if (!string.IsNullOrEmpty(url)) { strFile.AppendLine("Url:"); strFile.AppendLine(url); } strFile.AppendLine(); try { var entityMetadata = _descriptor.MetadataSource.GetEntityMetadata(item.LogicalName); if (entityMetadata != null) { var repositoryGeneric = new GenericRepository(_service, entityMetadata); var entity = await repositoryGeneric.GetEntityByIdAsync(item.Id, ColumnSetInstances.AllColumns); if (entity != null) { var desc = await EntityDescriptionHandler.GetEntityDescriptionAsync(entity, _service.ConnectionData); strFile .AppendLine(desc) .AppendLine() .AppendLine() ; } else { strFile .AppendFormat("{0} With Id = {1} Does Not Exists", item.LogicalName, item.Id).AppendLine() .AppendLine() .AppendLine() ; } } else { strFile .AppendFormat("Entity with name '{0}' Does Not Exists", item.LogicalName).AppendLine() .AppendFormat("{0} With Id = {1} Does Not Exists", item.LogicalName, item.Id).AppendLine() .AppendLine() .AppendLine() ; } } catch (Exception ex) { var description = DTEHelper.GetExceptionDescription(ex); strFile .AppendLine(description) .AppendLine() .AppendLine() ; } message = await _descriptor.GetSolutionComponentsDescriptionAsync(dictUsedEntities[item].Select(id => new SolutionComponent() { ObjectId = id, ComponentType = new OptionSetValue((int)ComponentType.Workflow), })); strFile .AppendLine("This entity Used By Workflows:") .AppendLine(message) .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) ; } if (workflowsWithEntities.Any()) { strFile .AppendLine() .AppendLine() .AppendLine() .AppendLine() .AppendLine() .AppendLine() .AppendLine("These entities Used By Workflows:") ; message = await _descriptor.GetSolutionComponentsDescriptionAsync(workflowsWithEntities.Select(id => new SolutionComponent() { ObjectId = id, ComponentType = new OptionSetValue((int)ComponentType.Workflow), })); strFile.AppendLine(message); } }
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); }
private async Task <string> TrasnferWorkflowsStates() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content, "Connection CRM Source.", "Connection CRM Target."); string operation = string.Format(Properties.OperationNames.TransferingWorkflowsStatesFormat2, ConnectionSource.Name, ConnectionTarget.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); var columnsSet = new ColumnSet ( Workflow.Schema.EntityPrimaryIdAttribute , Workflow.Schema.Attributes.primaryentity , Workflow.Schema.Attributes.category , Workflow.Schema.Attributes.name , Workflow.Schema.Attributes.statecode , Workflow.Schema.Attributes.statuscode , Workflow.Schema.Attributes.iscrmuiworkflow , Workflow.Schema.Attributes.ismanaged ); var taskSource = _comparerSource.GetWorkflow1Async(columnsSet); var taskTarget = _comparerSource.GetWorkflow2Async(columnsSet); List <Workflow> listSource = (await taskSource).ToList(); content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.WorkflowsInConnectionFormat2, ConnectionSource.Name, listSource.Count())); List <Workflow> listTarget = (await taskTarget).ToList(); content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.WorkflowsInConnectionFormat2, ConnectionTarget.Name, listTarget.Count())); List <LinkedEntities <Workflow> > commonList = new List <LinkedEntities <Workflow> >(); foreach (Workflow workflowSource in listSource) { Workflow workflowTarget = listTarget.FirstOrDefault(workflow => workflow.Id == workflowSource.Id); if (workflowTarget != null) { commonList.Add(new LinkedEntities <Workflow>(workflowSource, workflowTarget)); continue; } } content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.WorkflowsCommonFormat3, ConnectionSource.Name, ConnectionTarget.Name, commonList.Count())); List <Workflow> workflowsToActivate = new List <Workflow>(); List <Workflow> workflowsToDeactivate = new List <Workflow>(); { ProgressReporter reporter = new ProgressReporter(_iWriteToOutput, commonList.Count, 5, Properties.OrganizationComparerStrings.WorkflowsProcessingCommon); foreach (LinkedEntities <Workflow> workflow in commonList) { reporter.Increase(); if (workflow.Entity1.StatusCode?.Value != workflow.Entity2.StatusCode?.Value) { List <Workflow> list = null; if (workflow.Entity1.StatusCode.Value == (int)Workflow.Schema.OptionSets.statuscode.Activated_1_Activated_2) { list = workflowsToActivate; } else if (workflow.Entity1.StatusCode.Value == (int)Workflow.Schema.OptionSets.statuscode.Draft_0_Draft_1) { list = workflowsToDeactivate; } if (list != null) { list.Add(workflow.Entity2); } } } } var orderedDeactivate = workflowsToDeactivate .OrderBy(w => w.PrimaryEntity) .ThenBy(w => w.Category?.Value) .ThenBy(w => w.Name) .ThenBy(w => w.Id); var orderedActivate = workflowsToActivate .OrderBy(w => w.PrimaryEntity) .ThenBy(w => w.Category?.Value) .ThenBy(w => w.Name) .ThenBy(w => w.Id); FormatTextTableHandler tableDeactivateWorkflows = new FormatTextTableHandler(); tableDeactivateWorkflows.SetHeader("Entity", "Category", "Name", "StatusCode", "IsCrmUIWorkflow", "IsManaged", "Id", "Url"); FormatTextTableHandler tableActivateWorkflows = new FormatTextTableHandler(); tableActivateWorkflows.SetHeader("Entity", "Category", "Name", "StatusCode", "IsCrmUIWorkflow", "IsManaged", "Id", "Url"); foreach (var workflow in orderedDeactivate) { workflow.FormattedValues.TryGetValue(Workflow.Schema.Attributes.category, out string categoryName2); workflow.FormattedValues.TryGetValue(Workflow.Schema.Attributes.statuscode, out string statusCode2); tableDeactivateWorkflows.AddLine( workflow.PrimaryEntity , categoryName2 , workflow.Name , statusCode2 , workflow.IsCrmUIWorkflow.ToString() , workflow.IsManaged.ToString() , workflow.Id.ToString() , _comparerSource.Service2.UrlGenerator.GetSolutionComponentUrl(ComponentType.Workflow, workflow.Id) ); } foreach (var workflow in orderedActivate) { workflow.FormattedValues.TryGetValue(Workflow.Schema.Attributes.category, out string categoryName2); workflow.FormattedValues.TryGetValue(Workflow.Schema.Attributes.statuscode, out string statusCode2); tableActivateWorkflows.AddLine( workflow.PrimaryEntity , categoryName2 , workflow.Name , statusCode2 , workflow.IsCrmUIWorkflow.ToString() , workflow.IsManaged.ToString() , workflow.Id.ToString() , _comparerSource.Service2.UrlGenerator.GetSolutionComponentUrl(ComponentType.Workflow, workflow.Id) ); } if (tableDeactivateWorkflows.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat(Properties.OrganizationComparerStrings.WorkflowsToDeactivationInConnectionFormat2, ConnectionTarget.Name, tableDeactivateWorkflows.Count); tableDeactivateWorkflows.GetFormatedLines(false).ForEach(e => content.AppendLine().Append((_tabSpacer + e).TrimEnd())); } if (tableActivateWorkflows.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat(Properties.OrganizationComparerStrings.WorkflowsToActivationInConnectionFormat2, ConnectionTarget.Name, tableActivateWorkflows.Count); tableActivateWorkflows.GetFormatedLines(false).ForEach(e => content.AppendLine().Append((_tabSpacer + e).TrimEnd())); } foreach (var workflow in orderedDeactivate) { try { await _comparerSource.Service2.ExecuteAsync <SetStateResponse>(new SetStateRequest() { EntityMoniker = workflow.ToEntityReference(), State = new Microsoft.Xrm.Sdk.OptionSetValue((int)Workflow.Schema.OptionSets.statecode.Draft_0), Status = new Microsoft.Xrm.Sdk.OptionSetValue((int)Workflow.Schema.OptionSets.statuscode.Draft_0_Draft_1), }); } catch (Exception ex) { var desc = DTEHelper.GetExceptionDescription(ex); workflow.FormattedValues.TryGetValue(Workflow.Schema.Attributes.category, out string categoryName2); workflow.FormattedValues.TryGetValue(Workflow.Schema.Attributes.statuscode, out string statusCode2); var workflowDescription = tableDeactivateWorkflows.FormatLineWithHeadersInLine( workflow.PrimaryEntity , categoryName2 , workflow.Name , statusCode2 , workflow.IsCrmUIWorkflow.ToString() , workflow.IsManaged.ToString() , workflow.Id.ToString() , _comparerSource.Service2.UrlGenerator.GetSolutionComponentUrl(ComponentType.Workflow, workflow.Id) ); string operationLocal = string.Format(Properties.OperationNames.DeactivatingEntityFormat2, workflow.LogicalName, ConnectionTarget.Name, workflowDescription); content.AppendLine().AppendLine().AppendLine(); content.AppendLine(new string('-', 150)).AppendLine(); content.AppendFormat(Properties.OutputStrings.ExceptionWhileOperationFormat1, operationLocal).AppendLine(); content.AppendLine(desc); content.AppendLine(new string('-', 150)).AppendLine(); } } foreach (var workflow in orderedActivate) { try { await _comparerSource.Service2.ExecuteAsync <SetStateResponse>(new SetStateRequest() { EntityMoniker = workflow.ToEntityReference(), State = new Microsoft.Xrm.Sdk.OptionSetValue((int)Workflow.Schema.OptionSets.statecode.Activated_1), Status = new Microsoft.Xrm.Sdk.OptionSetValue((int)Workflow.Schema.OptionSets.statuscode.Activated_1_Activated_2), }); } catch (Exception ex) { var desc = DTEHelper.GetExceptionDescription(ex); workflow.FormattedValues.TryGetValue(Workflow.Schema.Attributes.category, out string categoryName2); workflow.FormattedValues.TryGetValue(Workflow.Schema.Attributes.statuscode, out string statusCode2); var workflowDescription = tableDeactivateWorkflows.FormatLineWithHeadersInLine( workflow.PrimaryEntity , categoryName2 , workflow.Name , statusCode2 , workflow.IsCrmUIWorkflow.ToString() , workflow.IsManaged.ToString() , workflow.Id.ToString() , _comparerSource.Service2.UrlGenerator.GetSolutionComponentUrl(ComponentType.Workflow, workflow.Id) ); string operationLocal = string.Format(Properties.OperationNames.ActivatingEntityFormat3, workflow.LogicalName, ConnectionTarget.Name, workflowDescription); content.AppendLine().AppendLine().AppendLine(); content.AppendLine(new string('-', 150)).AppendLine(); content.AppendFormat(Properties.OutputStrings.ExceptionWhileOperationFormat1, operationLocal).AppendLine(); content.AppendLine(desc); content.AppendLine(new string('-', 150)).AppendLine(); } } if (tableActivateWorkflows.Count == 0 && tableDeactivateWorkflows.Count == 0 ) { content.AppendLine(Properties.OrganizationComparerStrings.WorkflowsNoDifference); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = string.Format("OrgTransfer Workflows States from {0} to {1} at {2}.txt" , this.ConnectionSource.Name , this.ConnectionTarget.Name , DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss")); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); return(filePath); }
private void CompareFieldPermissions(List <string> diff, IEnumerable <FieldPermission> enumerable1, IEnumerable <FieldPermission> enumerable2, string tabSpacer) { FormatTextTableHandler tableOnlyIn1 = new FormatTextTableHandler(); FormatTextTableHandler tableOnlyIn2 = new FormatTextTableHandler(); tableOnlyIn1.SetHeader("Entity name", "Attribute Name", "Can Create", "Can Read", "Can Update"); tableOnlyIn2.SetHeader("Entity name", "Attribute Name", "Can Create", "Can Read", "Can Update"); FormatTextTableHandler tableDifferent = new FormatTextTableHandler(); tableDifferent.SetHeader("FieldPermission" , Connection1.Name + " Can Create" , Connection2.Name + " Can Create" , Connection1.Name + " Can Read" , Connection2.Name + " Can Read" , Connection1.Name + " Can Update" , Connection2.Name + " Can Update" ); if (enumerable1 != null) { foreach (var item1 in enumerable1) { var entityName1 = item1.EntityName; var attributeName1 = item1.AttributeLogicalName; if (enumerable2 != null) { var item2 = enumerable2.FirstOrDefault(i => string.Equals(i.EntityName, entityName1, StringComparison.InvariantCultureIgnoreCase) && string.Equals(i.AttributeLogicalName, attributeName1, StringComparison.InvariantCultureIgnoreCase) ); if (item2 != null) { continue; } } var cancreate1 = item1.FormattedValues.Contains(FieldPermission.Schema.Attributes.cancreate) ? item1.FormattedValues[FieldPermission.Schema.Attributes.cancreate] : string.Empty; var canread1 = item1.FormattedValues.Contains(FieldPermission.Schema.Attributes.canread) ? item1.FormattedValues[FieldPermission.Schema.Attributes.canread] : string.Empty; var canupdate1 = item1.FormattedValues.Contains(FieldPermission.Schema.Attributes.canupdate) ? item1.FormattedValues[FieldPermission.Schema.Attributes.canupdate] : string.Empty; tableOnlyIn1.AddLine(entityName1, attributeName1, cancreate1, canread1, canupdate1); tableOnlyIn2.CalculateLineLengths(entityName1, attributeName1, cancreate1, canread1, canupdate1); this.ImageBuilder.AddComponentSolution1((int)ComponentType.FieldPermission, item1.Id); } } if (enumerable2 != null) { foreach (var item2 in enumerable2) { var entityName2 = item2.EntityName; var attributeName2 = item2.AttributeLogicalName; if (enumerable1 != null) { var item1 = enumerable1.FirstOrDefault(i => string.Equals(i.EntityName, entityName2, StringComparison.InvariantCultureIgnoreCase) && string.Equals(i.AttributeLogicalName, attributeName2, StringComparison.InvariantCultureIgnoreCase) ); if (item1 != null) { continue; } } var cancreate2 = item2.FormattedValues.Contains(FieldPermission.Schema.Attributes.cancreate) ? item2.FormattedValues[FieldPermission.Schema.Attributes.cancreate] : string.Empty; var canread2 = item2.FormattedValues.Contains(FieldPermission.Schema.Attributes.canread) ? item2.FormattedValues[FieldPermission.Schema.Attributes.canread] : string.Empty; var canupdate2 = item2.FormattedValues.Contains(FieldPermission.Schema.Attributes.canupdate) ? item2.FormattedValues[FieldPermission.Schema.Attributes.canupdate] : string.Empty; tableOnlyIn2.AddLine(entityName2, attributeName2, cancreate2, canread2, canupdate2); tableOnlyIn1.CalculateLineLengths(entityName2, attributeName2, cancreate2, canread2, canupdate2); this.ImageBuilder.AddComponentSolution2((int)ComponentType.FieldPermission, item2.Id); } } if (enumerable1 != null && enumerable2 != null) { foreach (var item1 in enumerable1) { var entityName1 = item1.EntityName; var attributeName1 = item1.AttributeLogicalName; var item2 = enumerable2.FirstOrDefault(i => string.Equals(i.EntityName, entityName1, StringComparison.InvariantCultureIgnoreCase) && string.Equals(i.AttributeLogicalName, attributeName1, StringComparison.InvariantCultureIgnoreCase) ); if (item2 != null) { continue; } var cancreate1 = item1.FormattedValues.Contains(FieldPermission.Schema.Attributes.cancreate) ? item1.FormattedValues[FieldPermission.Schema.Attributes.cancreate] : string.Empty; var canread1 = item1.FormattedValues.Contains(FieldPermission.Schema.Attributes.canread) ? item1.FormattedValues[FieldPermission.Schema.Attributes.canread] : string.Empty; var canupdate1 = item1.FormattedValues.Contains(FieldPermission.Schema.Attributes.canupdate) ? item1.FormattedValues[FieldPermission.Schema.Attributes.canupdate] : string.Empty; var cancreate2 = item2.FormattedValues.Contains(FieldPermission.Schema.Attributes.cancreate) ? item2.FormattedValues[FieldPermission.Schema.Attributes.cancreate] : string.Empty; var canread2 = item2.FormattedValues.Contains(FieldPermission.Schema.Attributes.canread) ? item2.FormattedValues[FieldPermission.Schema.Attributes.canread] : string.Empty; var canupdate2 = item2.FormattedValues.Contains(FieldPermission.Schema.Attributes.canupdate) ? item2.FormattedValues[FieldPermission.Schema.Attributes.canupdate] : string.Empty; if (cancreate1 != cancreate2 || canread1 != canread2 || canupdate1 != canupdate2) { this.ImageBuilder.AddComponentDifferent((int)ComponentType.FieldPermission, item1.Id, item2.Id); tableDifferent.AddLine(entityName1, attributeName1 , cancreate1, cancreate2 , canread1, canread2 , canupdate1, canupdate2 ); } } } if (tableOnlyIn1.Count > 0) { diff.Add(string.Format("Privileges ONLY in {0}: {1}", Connection1.Name, tableOnlyIn1.Count)); tableOnlyIn1.GetFormatedLines(true).ForEach(s => diff.Add(tabSpacer + s)); } if (tableOnlyIn2.Count > 0) { diff.Add(string.Format("Privileges ONLY in {0}: {1}", Connection2.Name, tableOnlyIn2.Count)); tableOnlyIn2.GetFormatedLines(true).ForEach(s => diff.Add(tabSpacer + s)); } if (tableDifferent.Count > 0) { diff.Add(string.Format("Different Privileges {0} and {1}", Connection1.Name, Connection2.Name)); tableDifferent.GetFormatedLines(true).ForEach(s => diff.Add(tabSpacer + s)); } }
private async Task <string> TrasnferPluginStepsStates() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content, "Connection CRM Source.", "Connection CRM Target."); string operation = string.Format(Properties.OperationNames.TransferingPluginStepsStatesFormat2, ConnectionSource.Name, ConnectionTarget.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); var taskSource = _comparerSource.GetSdkMessageProcessingStep1Async(); var taskTarget = _comparerSource.GetSdkMessageProcessingStep2Async(); List <SdkMessageProcessingStep> listSource = await taskSource; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.PluginStepsInConnectionFormat2, ConnectionSource.Name, listSource.Count())); List <SdkMessageProcessingStep> listTarget = await taskTarget; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.PluginStepsInConnectionFormat2, ConnectionTarget.Name, listTarget.Count())); List <LinkedEntities <SdkMessageProcessingStep> > commonList = new List <LinkedEntities <SdkMessageProcessingStep> >(); foreach (SdkMessageProcessingStep stepSource in listSource) { SdkMessageProcessingStep stepTarget = listTarget.FirstOrDefault(st => st.Id == stepSource.Id); if (stepTarget != null) { commonList.Add(new LinkedEntities <SdkMessageProcessingStep>(stepSource, stepTarget)); continue; } } content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.PluginStepsCommonFormat3, ConnectionSource.Name, ConnectionTarget.Name, commonList.Count())); List <SdkMessageProcessingStep> pluginStepsToActivate = new List <SdkMessageProcessingStep>(); List <SdkMessageProcessingStep> pluginStepsToDeactivate = new List <SdkMessageProcessingStep>(); foreach (LinkedEntities <SdkMessageProcessingStep> step in commonList .OrderBy(s => s.Entity1.EventHandler?.Name ?? "Unknown") .ThenBy(s => s.Entity1.PrimaryObjectTypeCodeName) .ThenBy(s => s.Entity1.SecondaryObjectTypeCodeName) .ThenBy(s => s.Entity1.SdkMessageId?.Name ?? "Unknown", new MessageComparer()) .ThenBy(s => s.Entity1.Stage.Value) .ThenBy(s => s.Entity1.Mode.Value) ) { if (step.Entity1.StatusCode?.Value != step.Entity2.StatusCode?.Value) { List <SdkMessageProcessingStep> list = null; if (step.Entity1.StatusCode.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.statuscode.Enabled_0_Enabled_1) { list = pluginStepsToActivate; } else if (step.Entity1.StatusCode.Value == (int)SdkMessageProcessingStep.Schema.OptionSets.statuscode.Disabled_1_Disabled_2) { list = pluginStepsToDeactivate; } if (list != null) { list.Add(step.Entity2); } } } var orderedDeactivate = pluginStepsToDeactivate .OrderBy(s => s.EventHandler?.Name ?? "Unknown") .ThenBy(s => s.PrimaryObjectTypeCodeName) .ThenBy(s => s.SecondaryObjectTypeCodeName) .ThenBy(s => s.SdkMessageId?.Name ?? "Unknown", new MessageComparer()) .ThenBy(s => s.Stage.Value) .ThenBy(s => s.Mode.Value) ; var orderedActivate = pluginStepsToActivate .OrderBy(s => s.EventHandler?.Name ?? "Unknown") .ThenBy(s => s.PrimaryObjectTypeCodeName) .ThenBy(s => s.SecondaryObjectTypeCodeName) .ThenBy(s => s.SdkMessageId?.Name ?? "Unknown", new MessageComparer()) .ThenBy(s => s.Stage.Value) .ThenBy(s => s.Mode.Value) ; FormatTextTableHandler tableDeactivatePluginSteps = new FormatTextTableHandler(); tableDeactivatePluginSteps.SetHeader("PluginType", "Primary Entity", "Secondary Entity", "Message", "Stage", "Rank", "Status", "IsHidden", "IsManaged", "FilteringAttributes"); FormatTextTableHandler tableActivatePluginSteps = new FormatTextTableHandler(); tableActivatePluginSteps.SetHeader("PluginType", "Primary Entity", "Secondary Entity", "Message", "Stage", "Rank", "Status", "IsHidden", "IsManaged", "FilteringAttributes"); foreach (var step in orderedDeactivate) { tableDeactivatePluginSteps.AddLine( step.EventHandler?.Name ?? "Unknown" , step.PrimaryObjectTypeCodeName , step.SecondaryObjectTypeCodeName , step.SdkMessageId?.Name ?? "Unknown" , SdkMessageProcessingStepRepository.GetStageName(step.Stage.Value, step.Mode.Value) , step.Rank.ToString() , step.FormattedValues[SdkMessageProcessingStep.Schema.Attributes.statuscode] , step.IsHidden?.Value.ToString() , step.IsManaged.ToString() , step.FilteringAttributesStringsSorted ); } foreach (var step in orderedActivate) { tableActivatePluginSteps.AddLine( step.EventHandler?.Name ?? "Unknown" , step.PrimaryObjectTypeCodeName , step.SecondaryObjectTypeCodeName , step.SdkMessageId?.Name ?? "Unknown" , SdkMessageProcessingStepRepository.GetStageName(step.Stage.Value, step.Mode.Value) , step.Rank.ToString() , step.FormattedValues[SdkMessageProcessingStep.Schema.Attributes.statuscode] , step.IsHidden?.Value.ToString() , step.IsManaged.ToString() , step.FilteringAttributesStringsSorted ); } if (tableDeactivatePluginSteps.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat(Properties.OrganizationComparerStrings.PluginStepsToDeactivationInConnectionFormat2, ConnectionTarget.Name, tableDeactivatePluginSteps.Count); tableDeactivatePluginSteps.GetFormatedLines(false).ForEach(e => content.AppendLine().Append((_tabSpacer + e).TrimEnd())); } if (tableActivatePluginSteps.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat(Properties.OrganizationComparerStrings.PluginStepsToActivationInConnectionFormat2, ConnectionTarget.Name, tableActivatePluginSteps.Count); tableActivatePluginSteps.GetFormatedLines(false).ForEach(e => content.AppendLine().Append((_tabSpacer + e).TrimEnd())); } foreach (var step in orderedDeactivate) { try { await _comparerSource.Service2.ExecuteAsync <SetStateResponse>(new SetStateRequest() { EntityMoniker = step.ToEntityReference(), State = new Microsoft.Xrm.Sdk.OptionSetValue((int)SdkMessageProcessingStep.Schema.OptionSets.statecode.Disabled_1), Status = new Microsoft.Xrm.Sdk.OptionSetValue((int)SdkMessageProcessingStep.Schema.OptionSets.statuscode.Disabled_1_Disabled_2), }); } catch (Exception ex) { var desc = DTEHelper.GetExceptionDescription(ex); var stepDescription = tableDeactivatePluginSteps.FormatLineWithHeadersInLine( step.EventHandler?.Name ?? "Unknown" , step.PrimaryObjectTypeCodeName , step.SecondaryObjectTypeCodeName , step.SdkMessageId?.Name ?? "Unknown" , SdkMessageProcessingStepRepository.GetStageName(step.Stage.Value, step.Mode.Value) , step.Rank.ToString() , step.FormattedValues[SdkMessageProcessingStep.Schema.Attributes.statuscode] , step.IsHidden?.Value.ToString() , step.IsManaged.ToString() , step.FilteringAttributesStringsSorted ); string operationLocal = string.Format(Properties.OperationNames.DeactivatingEntityFormat2, step.LogicalName, ConnectionTarget.Name, stepDescription); content.AppendLine().AppendLine().AppendLine(); content.AppendLine(new string('-', 150)).AppendLine(); content.AppendFormat(Properties.OutputStrings.ExceptionWhileOperationFormat1, operationLocal).AppendLine(); content.AppendLine(desc); content.AppendLine(new string('-', 150)).AppendLine(); } } foreach (var step in orderedActivate) { try { await _comparerSource.Service2.ExecuteAsync <SetStateResponse>(new SetStateRequest() { EntityMoniker = step.ToEntityReference(), State = new Microsoft.Xrm.Sdk.OptionSetValue((int)SdkMessageProcessingStep.Schema.OptionSets.statecode.Enabled_0), Status = new Microsoft.Xrm.Sdk.OptionSetValue((int)SdkMessageProcessingStep.Schema.OptionSets.statuscode.Enabled_0_Enabled_1), }); } catch (Exception ex) { var desc = DTEHelper.GetExceptionDescription(ex); var stepDescription = tableActivatePluginSteps.FormatLineWithHeadersInLine( step.EventHandler?.Name ?? "Unknown" , step.PrimaryObjectTypeCodeName , step.SecondaryObjectTypeCodeName , step.SdkMessageId?.Name ?? "Unknown" , SdkMessageProcessingStepRepository.GetStageName(step.Stage.Value, step.Mode.Value) , step.Rank.ToString() , step.FormattedValues[SdkMessageProcessingStep.Schema.Attributes.statuscode] , step.IsHidden?.Value.ToString() , step.IsManaged.ToString() , step.FilteringAttributesStringsSorted ); string operationLocal = string.Format(Properties.OperationNames.ActivatingEntityFormat3, step.LogicalName, ConnectionTarget.Name, stepDescription); content.AppendLine().AppendLine().AppendLine(); content.AppendLine(new string('-', 150)).AppendLine(); content.AppendFormat(Properties.OutputStrings.ExceptionWhileOperationFormat1, operationLocal).AppendLine(); content.AppendLine(desc); content.AppendLine(new string('-', 150)).AppendLine(); } } if (tableActivatePluginSteps.Count == 0 && tableDeactivatePluginSteps.Count == 0 ) { content.AppendLine(Properties.OrganizationComparerStrings.PluginStepsStatesNoDifference); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = string.Format("OrgTransfer Plugin Steps States from {0} to {1} at {2}.txt" , this.ConnectionSource.Name , this.ConnectionTarget.Name , DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss")); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); return(filePath); }
public List <string> CompareRolePrivileges( IEnumerable <RolePrivilege> enumerableRolePriv1 , IEnumerable <RolePrivilege> enumerableRolePriv2 , IEnumerable <Privilege> commonPrivileges , PrivilegeNameComparer privilegeNameComparer ) { List <string> result = new List <string>(); FormatTextTableHandler tableOnlyIn1 = new FormatTextTableHandler(); tableOnlyIn1.SetHeader("PrivilegeName", "PrivilegeType", "Depth", "Linked Entities"); FormatTextTableHandler tableOnlyIn2 = new FormatTextTableHandler(); tableOnlyIn2.SetHeader("PrivilegeName", "PrivilegeType", "Depth", "Linked Entities"); FormatTextTableHandler tableDifferent = new FormatTextTableHandler(); tableDifferent.SetHeader("PrivilegeName", "PrivilegeType", Entity1Name, Entity2Name, "Linked Entities"); foreach (var priv in commonPrivileges.OrderBy(s => s.LinkedEntitiesSorted).OrderBy(s => s.Name, privilegeNameComparer)) { RolePrivilege rolePriv1 = null; RolePrivilege rolePriv2 = null; if (enumerableRolePriv1 != null) { rolePriv1 = enumerableRolePriv1.FirstOrDefault(i => i.PrivilegeId == priv.PrivilegeId); } if (enumerableRolePriv2 != null) { rolePriv2 = enumerableRolePriv2.FirstOrDefault(i => i.PrivilegeId == priv.PrivilegeId); } if (rolePriv1 != null && rolePriv2 == null) { var privilegedepthmask = rolePriv1.Depth; tableOnlyIn1.AddLine(priv.Name , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask) , priv.LinkedEntitiesSorted ); tableOnlyIn2.CalculateLineLengths(priv.Name , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask) , priv.LinkedEntitiesSorted ); } else if (rolePriv1 == null && rolePriv2 != null) { var privilegedepthmask = rolePriv2.Depth; tableOnlyIn2.AddLine(priv.Name , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask) , priv.LinkedEntitiesSorted ); tableOnlyIn1.CalculateLineLengths(priv.Name , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask) , priv.LinkedEntitiesSorted ); } else if (rolePriv1 != null && rolePriv2 != null) { var privilegedepthmask1 = rolePriv1.Depth; var privilegedepthmask2 = rolePriv2.Depth; if (privilegedepthmask1 != privilegedepthmask2) { tableDifferent.AddLine(priv.Name , priv.AccessRight.HasValue ? ((Microsoft.Crm.Sdk.Messages.AccessRights)priv.AccessRight.Value).ToString() : string.Empty , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask1) , RolePrivilegesRepository.GetPrivilegeDepthMaskName(privilegedepthmask2) , priv.LinkedEntitiesSorted ); } } } if (tableOnlyIn1.Count > 0) { if (result.Count > 0) { result.Add(string.Empty); } result.Add(string.Format("RolePrivileges ONLY in {0}: {1}", Entity1Name, tableOnlyIn1.Count)); tableOnlyIn1.GetFormatedLines(false).ForEach(s => result.Add(_tabSpacer + s)); } if (tableOnlyIn2.Count > 0) { if (result.Count > 0) { result.Add(string.Empty); } result.Add(string.Format("RolePrivileges ONLY in {0}: {1}", Entity2Name, tableOnlyIn2.Count)); tableOnlyIn2.GetFormatedLines(false).ForEach(s => result.Add(_tabSpacer + s)); } if (tableDifferent.Count > 0) { if (result.Count > 0) { result.Add(string.Empty); } result.Add(string.Format("Different RolePrivileges in {0} and {1}: {2}", Entity1Name, Entity2Name, tableDifferent.Count)); tableDifferent.GetFormatedLines(false).ForEach(s => result.Add(_tabSpacer + s)); } if (tableOnlyIn1.Count == 0 && tableOnlyIn2.Count == 0 && tableDifferent.Count == 0 ) { result.Add(string.Format("No difference RolePrivileges in {0} and {1}", Entity1Name, Entity2Name)); } return(result); }
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 <string> CheckSystemForms() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingSystemFormsFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); FormDescriptionHandler handler1 = new FormDescriptionHandler(ImageBuilder.Descriptor1, new DependencyRepository(_comparerSource.Service1)) { WithManagedInfo = false, WithDependentComponents = false, }; FormDescriptionHandler handler2 = new FormDescriptionHandler(ImageBuilder.Descriptor2, new DependencyRepository(_comparerSource.Service2)) { WithManagedInfo = false, WithDependentComponents = false, }; var task1 = _comparerSource.GetSystemForm1Async(); var task2 = _comparerSource.GetSystemForm2Async(); var list1 = await task1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.SystemFormsInConnectionFormat2, Connection1.Name, list1.Count)); var list2 = await task2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.SystemFormsInConnectionFormat2, Connection2.Name, list2.Count)); if (!list1.Any() && !list2.Any()) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } FormatTextTableHandler tableOnlyExistsIn1 = new FormatTextTableHandler(); tableOnlyExistsIn1.SetHeader("Entity", "Type", "Name", "IsManaged", "Id"); FormatTextTableHandler tableOnlyExistsIn2 = new FormatTextTableHandler(); tableOnlyExistsIn2.SetHeader("Entity", "Type", "Name", "IsManaged", "Id"); var dictDifference = new Dictionary <Tuple <string, string, string, string>, List <string> >(); var commonList = new List <LinkedEntities <SystemForm> >(); foreach (var form1 in list1) { { var form2 = list2.FirstOrDefault(form => form.Id == form1.Id); if (form2 != null) { commonList.Add(new LinkedEntities <SystemForm>(form1, form2)); continue; } } var entityName1 = form1.ObjectTypeCode; var name1 = form1.Name; string typeName1 = form1.FormattedValues[SystemForm.Schema.Attributes.type]; tableOnlyExistsIn1.AddLine(entityName1, typeName1, name1, form1.IsManaged.ToString(), form1.Id.ToString()); this.ImageBuilder.AddComponentSolution1((int)ComponentType.SystemForm, form1.Id); } foreach (var form2 in list2) { { var form1 = list1.FirstOrDefault(form => form.Id == form2.Id); if (form1 != null) { continue; } } var entityName2 = form2.ObjectTypeCode; var name2 = form2.Name; string typeName2 = form2.FormattedValues[SystemForm.Schema.Attributes.type]; tableOnlyExistsIn2.AddLine(entityName2, typeName2, name2, form2.IsManaged.ToString(), form2.Id.ToString()); this.ImageBuilder.AddComponentSolution2((int)ComponentType.SystemForm, form2.Id); } { var reporter = new ProgressReporter(_iWriteToOutput, commonList.Count, 5, "Processing Common Forms"); foreach (var form in commonList) { reporter.Increase(); FormatTextTableHandler tabDiff = new FormatTextTableHandler(); tabDiff.SetHeader("Attribute", "Organization", "Value"); { List <string> fieldsToCompare = new List <string>() { //SystemForm.Schema.Attributes.ancestorformid SystemForm.Schema.Attributes.canbedeleted , SystemForm.Schema.Attributes.componentstate , SystemForm.Schema.Attributes.description , SystemForm.Schema.Attributes.formactivationstate , SystemForm.Schema.Attributes.formpresentation //, SystemForm.Schema.Attributes.formxml //, SystemForm.Schema.Attributes.formxmlmanaged , SystemForm.Schema.Attributes.introducedversion , SystemForm.Schema.Attributes.isairmerged , SystemForm.Schema.Attributes.iscustomizable , SystemForm.Schema.Attributes.isdefault //, SystemForm.Schema.Attributes.ismanaged , SystemForm.Schema.Attributes.istabletenabled , SystemForm.Schema.Attributes.name , SystemForm.Schema.Attributes.objecttypecode //, SystemForm.Schema.Attributes.organizationid //, SystemForm.Schema.Attributes.overwritetime //, SystemForm.Schema.Attributes.publishedon //, SystemForm.Schema.Attributes.solutionid //, SystemForm.Schema.Attributes.supportingsolutionid , SystemForm.Schema.Attributes.type , SystemForm.Schema.Attributes.version , SystemForm.Schema.Attributes.versionnumber }; foreach (var fieldName in fieldsToCompare) { if (ContentComparerHelper.IsEntityDifferentInField(form.Entity1, form.Entity2, fieldName)) { var str1 = EntityDescriptionHandler.GetAttributeString(form.Entity1, fieldName, Connection1); var str2 = EntityDescriptionHandler.GetAttributeString(form.Entity2, fieldName, Connection2); tabDiff.AddLine(fieldName, Connection1.Name, str1); tabDiff.AddLine(fieldName, Connection2.Name, str2); } } } string typeName1 = form.Entity1.FormattedValues[SystemForm.Schema.Attributes.type]; string typeName2 = form.Entity2.FormattedValues[SystemForm.Schema.Attributes.type]; { List <string> fieldsToCompare = new List <string>() { SystemForm.Schema.Attributes.formxml }; foreach (var fieldName in fieldsToCompare) { string formXml1 = form.Entity1.GetAttributeValue <string>(fieldName) ?? string.Empty; string formXml2 = form.Entity2.GetAttributeValue <string>(fieldName) ?? string.Empty; if (!ContentComparerHelper.CompareXML(formXml1, formXml2).IsEqual) { string descReason = string.Empty; if (ContentComparerHelper.TryParseXml(formXml1, out var doc1) && ContentComparerHelper.TryParseXml(formXml2, out var doc2)) { string desc1 = await handler1.GetFormDescriptionAsync(doc1, form.Entity1.ObjectTypeCode, form.Entity1.Id, form.Entity1.Name, typeName1); string desc2 = await handler2.GetFormDescriptionAsync(doc2, form.Entity2.ObjectTypeCode, form.Entity2.Id, form.Entity2.Name, typeName2); if (!string.Equals(desc1, desc2)) { var compare = ContentComparerHelper.CompareText(desc1.ToLower(), desc2.ToLower()); if (compare.IsEqual) { descReason = "InCase"; } else { descReason = compare.GetCompareDescription(); } } } string formReason = string.Empty; { if (ContentComparerHelper.TryParseXml(formXml1, out var docCorrected1) && ContentComparerHelper.TryParseXml(formXml2, out var docCorrected2) ) { handler1.ReplaceRoleToRoleTemplates(docCorrected1); handler2.ReplaceRoleToRoleTemplates(docCorrected2); if (ContentComparerHelper.CompareXML(docCorrected1.ToString(), docCorrected2.ToString()).IsEqual) { formReason = string.Empty; } else { var compare = ContentComparerHelper.CompareXML(docCorrected1.ToString().ToLower(), docCorrected2.ToString().ToLower(), true); if (compare.IsEqual) { formReason = "InCase"; } else { formReason = compare.GetCompareDescription(); } } } else { var compare = ContentComparerHelper.CompareXML(formXml1.ToLower(), formXml2.ToLower(), true); if (compare.IsEqual) { formReason = "InCase"; } else { formReason = compare.GetCompareDescription(); } } } if (!string.IsNullOrEmpty(formReason)) { tabDiff.AddLine(fieldName, string.Empty, string.Format(Properties.OrganizationComparerStrings.FieldDifferenceReasonFormat3, Connection1.Name, Connection2.Name, formReason)); } if (!string.IsNullOrEmpty(descReason)) { tabDiff.AddLine(fieldName + "Description", string.Empty, string.Format(Properties.OrganizationComparerStrings.FieldDifferenceReasonFormat3, Connection1.Name, Connection2.Name, descReason)); } } } } if (tabDiff.Count > 0) { var diff = tabDiff.GetFormatedLines(false); this.ImageBuilder.AddComponentDifferent((int)ComponentType.SystemForm, form.Entity1.Id, form.Entity2.Id, string.Join(Environment.NewLine, diff)); var entityName1 = form.Entity1.ObjectTypeCode; var name1 = form.Entity1.Name; dictDifference.Add(Tuple.Create(entityName1, typeName1, name1, form.Entity1.Id.ToString()), diff); } } } if (tableOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Forms ONLY EXISTS in {0}: {1}", Connection1.Name, tableOnlyExistsIn1.Count); tableOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (tableOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Forms ONLY EXISTS in {0}: {1}", Connection2.Name, tableOnlyExistsIn2.Count); tableOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (dictDifference.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Forms DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); FormatTextTableHandler tableDifference = new FormatTextTableHandler(); tableDifference.SetHeader("Entity", "Type", "Name", "Id"); foreach (var template in dictDifference) { tableDifference.CalculateLineLengths(template.Key.Item1, template.Key.Item2, template.Key.Item3, template.Key.Item4); } foreach (var template in dictDifference .OrderBy(w => w.Key.Item1) .ThenBy(w => w.Key.Item2) .ThenBy(w => w.Key.Item3) .ThenBy(w => w.Key.Item4) ) { content.AppendLine().Append(tabSpacer + tableDifference.FormatLine(template.Key.Item1, template.Key.Item2, template.Key.Item3, template.Key.Item4)); foreach (var str in template.Value) { content.AppendLine().Append(tabSpacer + tabSpacer + str); } } } if (tableOnlyExistsIn2.Count == 0 && tableOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine("No difference in System Forms."); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, "System Forms"); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }
private async Task <string> CheckConnectionRoles() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingConnectionRolesFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); var taskRole1 = _comparerSource.GetConnectionRole1Async(); var taskRole2 = _comparerSource.GetConnectionRole2Async(); var listRole1 = await taskRole1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ConnectionRolesInConnectionFormat2, Connection1.Name, listRole1.Count)); var listRole2 = await taskRole2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ConnectionRolesInConnectionFormat2, Connection2.Name, listRole2.Count)); if (!listRole1.Any() && !listRole2.Any()) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } var taskRoleAssociation1 = _comparerSource.GetConnectionRoleAssociation1Async(); var taskRoleAssociation2 = _comparerSource.GetConnectionRoleAssociation2Async(); var taskRoleObjectTypeCode1 = _comparerSource.GetConnectionRoleObjectTypeCode1Async(); var taskRoleObjectTypeCode2 = _comparerSource.GetConnectionRoleObjectTypeCode2Async(); var listRoleAssociation1 = await taskRoleAssociation1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ConnectionRoleAssociationsInConnectionFormat2, Connection1.Name, listRoleAssociation1.Count)); var listRoleAssociation2 = await taskRoleAssociation2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ConnectionRoleAssociationsInConnectionFormat2, Connection2.Name, listRoleAssociation2.Count)); var listRoleObjectTypeCode1 = await taskRoleObjectTypeCode1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ConnectionRoleObjectTypeCodesInConnectionFormat2, Connection1.Name, listRoleObjectTypeCode1.Count)); var listRoleObjectTypeCode2 = await taskRoleObjectTypeCode2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ConnectionRoleObjectTypeCodesInConnectionFormat2, Connection2.Name, listRoleObjectTypeCode2.Count)); var commonRolesList = new List <LinkedEntities <ConnectionRole> >(); var dictDifference = new Dictionary <LinkedEntities <ConnectionRole>, List <string> >(); FormatTextTableHandler tableOnlyExistsIn1 = new FormatTextTableHandler(); tableOnlyExistsIn1.SetHeader("Category", "Name", "Id", "IsManaged"); FormatTextTableHandler tableOnlyExistsIn2 = new FormatTextTableHandler(); tableOnlyExistsIn2.SetHeader("Category", "Name", "Id", "IsManaged"); foreach (var role1 in listRole1) { { var role2 = listRole2.FirstOrDefault(role => role.Id == role1.Id); if (role2 != null) { commonRolesList.Add(new LinkedEntities <ConnectionRole>(role1, role2)); continue; } } var category1 = role1.FormattedValues[ConnectionRole.Schema.Attributes.category]; var name1 = role1.Name; tableOnlyExistsIn1.AddLine(category1, name1, role1.Id.ToString(), role1.IsManaged.ToString()); this.ImageBuilder.AddComponentSolution1((int)ComponentType.ConnectionRole, role1.Id); } foreach (var role2 in listRole2) { { var role1 = listRole1.FirstOrDefault(role => role.Id == role2.Id); if (role1 != null) { continue; } } var name2 = role2.Name; var category2 = role2.FormattedValues[ConnectionRole.Schema.Attributes.category]; tableOnlyExistsIn2.AddLine(category2, name2, role2.Id.ToString(), role2.IsManaged.ToString()); this.ImageBuilder.AddComponentSolution2((int)ComponentType.ConnectionRole, role2.Id); } content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ConnectionRolesCommonFormat3, Connection1.Name, Connection2.Name, commonRolesList.Count())); foreach (var commonItem in commonRolesList) { var diff = new List <string>(); { FormatTextTableHandler tabDiff = new FormatTextTableHandler(); tabDiff.SetHeader("Attribute", "Organization", "Value"); List <string> fieldsToCompare = new List <string>() { ConnectionRole.Schema.Attributes.category , ConnectionRole.Schema.Attributes.componentstate //, ConnectionRole.Schema.Attributes.connectionroleid //, ConnectionRole.Schema.Attributes.connectionroleidunique //, ConnectionRole.Schema.Attributes.createdby //, ConnectionRole.Schema.Attributes.createdon //, ConnectionRole.Schema.Attributes.createdonbehalfby , ConnectionRole.Schema.Attributes.description //, ConnectionRole.Schema.Attributes.importsequencenumber //, ConnectionRole.Schema.Attributes.introducedversion , ConnectionRole.Schema.Attributes.iscustomizable //, ConnectionRole.Schema.Attributes.ismanaged //, ConnectionRole.Schema.Attributes.modifiedby //, ConnectionRole.Schema.Attributes.modifiedon //, ConnectionRole.Schema.Attributes.modifiedonbehalfby , ConnectionRole.Schema.Attributes.name //, ConnectionRole.Schema.Attributes.organizationid //, ConnectionRole.Schema.Attributes.overwritetime //, ConnectionRole.Schema.Attributes.solutionid , ConnectionRole.Schema.Attributes.statecode , ConnectionRole.Schema.Attributes.statuscode //, ConnectionRole.Schema.Attributes.supportingsolutionid //, ConnectionRole.Schema.Attributes.versionnumber }; foreach (var fieldName in fieldsToCompare) { if (ContentCoparerHelper.IsEntityDifferentInField(commonItem.Entity1, commonItem.Entity2, fieldName)) { var str1 = EntityDescriptionHandler.GetAttributeString(commonItem.Entity1, fieldName, Connection1); var str2 = EntityDescriptionHandler.GetAttributeString(commonItem.Entity2, fieldName, Connection2); tabDiff.AddLine(fieldName, Connection1.Name, str1); tabDiff.AddLine(fieldName, Connection2.Name, str2); } } if (tabDiff.Count > 0) { diff.AddRange(tabDiff.GetFormatedLines(false)); } } { var enumerable1 = listRoleObjectTypeCode1 .Where(e => e.ConnectionRoleId != null && e.ConnectionRoleId.Id == commonItem.Entity1.ConnectionRoleId) .Select(e => e.AssociatedObjectTypeCode) .Distinct() ; var enumerable2 = listRoleObjectTypeCode2 .Where(e => e.ConnectionRoleId != null && e.ConnectionRoleId.Id == commonItem.Entity2.ConnectionRoleId) .Select(e => e.AssociatedObjectTypeCode) .Distinct() ; CompareConnectionRoleAssociatedObjects(Properties.OrganizationComparerStrings.PrefixAssociatedObjectTypeCodes, diff, enumerable1, enumerable2); } { var enumerable1 = listRoleAssociation1 .Where(e => e.ConnectionRoleId != null && e.ConnectionRoleId == commonItem.Entity1.ConnectionRoleId) .Select(e => e.AssociatedConnectionRoleName) .Distinct() ; var enumerable2 = listRoleAssociation2 .Where(e => e.ConnectionRoleId != null && e.ConnectionRoleId == commonItem.Entity2.ConnectionRoleId) .Select(e => e.AssociatedConnectionRoleName) .Distinct() ; CompareConnectionRoleAssociatedObjects(Properties.OrganizationComparerStrings.PrefixAssociatedConnectionRoles, diff, enumerable1, enumerable2); } if (diff.Count > 0) { dictDifference.Add(commonItem, diff); this.ImageBuilder.AddComponentDifferent((int)ComponentType.ConnectionRole, commonItem.Entity1.Id, commonItem.Entity2.Id, string.Join(Environment.NewLine, diff)); } } if (tableOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat(Properties.OrganizationComparerStrings.ConnectionRolesOnlyExistsInConnectionFormat2, Connection1.Name, tableOnlyExistsIn1.Count); tableOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (tableOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat(Properties.OrganizationComparerStrings.ConnectionRolesOnlyExistsInConnectionFormat2, Connection2.Name, tableOnlyExistsIn2.Count); tableOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (dictDifference.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat(Properties.OrganizationComparerStrings.ConnectionRolesDifferentFormat3, Connection1.Name, Connection2.Name, dictDifference.Count); FormatTextTableHandler tableDifference = new FormatTextTableHandler(); tableDifference.SetHeader(Connection1.Name, Connection2.Name, "Id"); foreach (var item in dictDifference) { tableDifference.CalculateLineLengths(item.Key.Entity1.Name, item.Key.Entity2.Name, item.Key.Entity1.Id.ToString()); } foreach (var item in dictDifference .OrderBy(w => w.Key.Entity1.Name) .ThenBy(w => w.Key.Entity2.Name) .ThenBy(w => w.Key.Entity1.Id.ToString()) ) { content.AppendLine().Append(tabSpacer + tableDifference.FormatLine(item.Key.Entity1.Name, item.Key.Entity2.Name, item.Key.Entity1.Id.ToString())); foreach (var str in item.Value) { content.AppendLine().Append(tabSpacer + tabSpacer + str); } } } if (tableOnlyExistsIn2.Count == 0 && tableOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine(Properties.OrganizationComparerStrings.ConnectionRolesNoDifference); } content.AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, Properties.OrganizationComparerStrings.ConnectionRolesFileName); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }
private async Task <string> CheckSystemSavedQueries() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingSystemSavedQueriesFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); var task1 = _comparerSource.GetSavedQuery1Async(); var task2 = _comparerSource.GetSavedQuery2Async(); var list1 = await task1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.SavedQueriesInConnectionFormat2, Connection1.Name, list1.Count)); var list2 = await task2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.SavedQueriesInConnectionFormat2, Connection2.Name, list2.Count)); if (!list1.Any() && !list2.Any()) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } FormatTextTableHandler tableOnlyExistsIn1 = new FormatTextTableHandler(); tableOnlyExistsIn1.SetHeader("Entity", "Name", "QueryType", "IsUserDefined", "IsManaged", "Id"); FormatTextTableHandler tableOnlyExistsIn2 = new FormatTextTableHandler(); tableOnlyExistsIn2.SetHeader("Entity", "Name", "QueryType", "IsUserDefined", "IsManaged", "Id"); var dictDifference = new Dictionary <Tuple <string, string, string, string>, List <string> >(); var commonList = new List <LinkedEntities <SavedQuery> >(); foreach (var query1 in list1) { { var query2 = list2.FirstOrDefault(query => query.Id == query1.Id); if (query2 != null) { commonList.Add(new LinkedEntities <SavedQuery>(query1, query2)); continue; } } var entityName1 = query1.ReturnedTypeCode; var name1 = query1.Name; var querytype1 = query1.QueryType.Value; var querytypeName1 = SavedQueryRepository.GetQueryTypeName(querytype1); tableOnlyExistsIn1.AddLine( entityName1 , name1 , querytypeName1 , query1.IsUserDefined.ToString() , query1.IsManaged.ToString() , query1.Id.ToString()); this.ImageBuilder.AddComponentSolution1((int)ComponentType.SavedQuery, query1.Id); } foreach (var query2 in list2) { { var query1 = list1.FirstOrDefault(query => query.Id == query2.Id); if (query1 != null) { continue; } } var entityName2 = query2.ReturnedTypeCode; var name2 = query2.Name; var querytype2 = query2.QueryType.Value; var querytypeName2 = SavedQueryRepository.GetQueryTypeName(querytype2); tableOnlyExistsIn2.AddLine( entityName2 , name2 , querytypeName2 , query2.IsUserDefined.ToString() , query2.IsManaged.ToString() , query2.Id.ToString() ); this.ImageBuilder.AddComponentSolution2((int)ComponentType.SavedQuery, query2.Id); } { var reporter = new ProgressReporter(_iWriteToOutput, commonList.Count, 5, "Processing Common Saved Queries"); foreach (var query in commonList) { reporter.Increase(); FormatTextTableHandler tabDiff = new FormatTextTableHandler(); tabDiff.SetHeader("Attribute", "Organization", "Value"); { List <string> fieldsToCompare = new List <string>() { SavedQuery.Schema.Attributes.advancedgroupby , SavedQuery.Schema.Attributes.canbedeleted //, columnsetxml , SavedQuery.Schema.Attributes.componentstate , SavedQuery.Schema.Attributes.conditionalformatting //, SavedQuery.Schema.Attributes.createdby //, SavedQuery.Schema.Attributes.createdon //, SavedQuery.Schema.Attributes.createdonbehalfby , SavedQuery.Schema.Attributes.description //, SavedQuery.Schema.Attributes.fetchxml , SavedQuery.Schema.Attributes.introducedversion , SavedQuery.Schema.Attributes.iscustomizable , SavedQuery.Schema.Attributes.isdefault //, SavedQuery.Schema.Attributes.ismanaged , SavedQuery.Schema.Attributes.isprivate , SavedQuery.Schema.Attributes.isquickfindquery , SavedQuery.Schema.Attributes.isuserdefined //, SavedQuery.Schema.Attributes.layoutxml //, SavedQuery.Schema.Attributes.modifiedby //, SavedQuery.Schema.Attributes.modifiedon //, SavedQuery.Schema.Attributes.modifiedonbehalfby , SavedQuery.Schema.Attributes.name //, SavedQuery.Schema.Attributes.organizationid , SavedQuery.Schema.Attributes.organizationtaborder //, SavedQuery.Schema.Attributes.overwritetime , SavedQuery.Schema.Attributes.queryapi , SavedQuery.Schema.Attributes.queryappusage , SavedQuery.Schema.Attributes.querytype , SavedQuery.Schema.Attributes.returnedtypecode //, SavedQuery.Schema.Attributes.savedqueryid //, SavedQuery.Schema.Attributes.savedqueryidunique //, SavedQuery.Schema.Attributes.solutionid , SavedQuery.Schema.Attributes.statecode , SavedQuery.Schema.Attributes.statuscode //, SavedQuery.Schema.Attributes.supportingsolutionid , SavedQuery.Schema.Attributes.versionnumber }; foreach (var fieldName in fieldsToCompare) { if (ContentComparerHelper.IsEntityDifferentInField(query.Entity1, query.Entity2, fieldName)) { var str1 = EntityDescriptionHandler.GetAttributeString(query.Entity1, fieldName, Connection1); var str2 = EntityDescriptionHandler.GetAttributeString(query.Entity2, fieldName, Connection2); tabDiff.AddLine(fieldName, Connection1.Name, str1); tabDiff.AddLine(fieldName, Connection2.Name, str2); } } } { List <string> fieldsToCompare = new List <string>() { SavedQuery.Schema.Attributes.fetchxml , SavedQuery.Schema.Attributes.layoutxml , SavedQuery.Schema.Attributes.columnsetxml }; foreach (var fieldName in fieldsToCompare) { Action <XElement> action = null; if (string.Equals(fieldName, SavedQuery.Schema.Attributes.layoutxml)) { action = ContentComparerHelper.RemoveLayoutObjectCode; } string xml1 = query.Entity1.GetAttributeValue <string>(fieldName) ?? string.Empty; string xml2 = query.Entity2.GetAttributeValue <string>(fieldName) ?? string.Empty; if (!ContentComparerHelper.CompareXML(xml1, xml2, false, action).IsEqual) { string reason = string.Empty; var compare = ContentComparerHelper.CompareXML(xml1.ToLower(), xml2.ToLower(), true, action); if (compare.IsEqual) { reason = "InCase"; } else { reason = compare.GetCompareDescription(); } if (!string.IsNullOrEmpty(reason)) { tabDiff.AddLine(fieldName, string.Empty, string.Format(Properties.OrganizationComparerStrings.FieldDifferenceReasonFormat3, Connection1.Name, Connection2.Name, reason)); } } } } if (tabDiff.Count > 0) { var entityName1 = query.Entity1.ReturnedTypeCode; var name1 = query.Entity1.Name; var querytype1 = query.Entity1.QueryType.Value; var querytypeName1 = SavedQueryRepository.GetQueryTypeName(querytype1); var diff = tabDiff.GetFormatedLines(false); this.ImageBuilder.AddComponentDifferent((int)ComponentType.SavedQuery, query.Entity1.Id, query.Entity2.Id, string.Join(Environment.NewLine, diff)); dictDifference.Add(Tuple.Create(entityName1, name1, querytypeName1, query.Entity1.Id.ToString()), diff); } } } if (tableOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Saved Queries ONLY EXISTS in {0}: {1}", Connection1.Name, tableOnlyExistsIn1.Count); tableOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (tableOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Saved Queries ONLY EXISTS in {0}: {1}", Connection2.Name, tableOnlyExistsIn2.Count); tableOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (dictDifference.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("System Saved Queries DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); FormatTextTableHandler tableDifference = new FormatTextTableHandler(); tableDifference.SetHeader("Entity", "Name", "QueryType", "Id"); foreach (var template in dictDifference) { tableDifference.CalculateLineLengths(template.Key.Item1, template.Key.Item2, template.Key.Item3, template.Key.Item4); } foreach (var template in dictDifference .OrderBy(w => w.Key.Item1) .ThenBy(w => w.Key.Item2) .ThenBy(w => w.Key.Item3) .ThenBy(w => w.Key.Item4) ) { content.AppendLine().Append(tabSpacer + tableDifference.FormatLine(template.Key.Item1, template.Key.Item2, template.Key.Item3, template.Key.Item4)); foreach (var str in template.Value) { content.AppendLine().Append(tabSpacer + tabSpacer + str); } } } if (tableOnlyExistsIn2.Count == 0 && tableOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine("No difference in System Saved Queries."); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, "System Saved Queries"); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }
private async Task <string> CheckContractTemplates() { StringBuilder content = new StringBuilder(); await _comparerSource.InitializeConnection(_iWriteToOutput, content); string operation = string.Format(Properties.OperationNames.CheckingContractTemplatesFormat2, Connection1.Name, Connection2.Name); content.AppendLine(_iWriteToOutput.WriteToOutputStartOperation(null, operation)); Task <List <ContractTemplate> > task1 = _comparerSource.GetContractTemplate1Async(); Task <List <ContractTemplate> > task2 = _comparerSource.GetContractTemplate2Async(); List <ContractTemplate> list1 = await task1; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Contract Templates in {0}: {1}", Connection1.Name, list1.Count())); List <ContractTemplate> list2 = await task2; content.AppendLine(_iWriteToOutput.WriteToOutput(null, "Contract Templates in {0}: {1}", Connection2.Name, list2.Count())); if (list1.Count == 0 && list2.Count == 0) { _iWriteToOutput.WriteToOutput(null, Properties.OrganizationComparerStrings.ThereIsNothingToCompare); _iWriteToOutput.WriteToOutputEndOperation(null, operation); return(null); } List <string> fieldsToCompare = new List <string>() { ContractTemplate.Schema.Attributes.abbreviation , ContractTemplate.Schema.Attributes.allotmenttypecode , ContractTemplate.Schema.Attributes.billingfrequencycode //, ContractTemplate.Schema.Attributes.componentstate , ContractTemplate.Schema.Attributes.contractservicelevelcode //, ContractTemplate.Schema.Attributes.contracttemplateid //, ContractTemplate.Schema.Attributes.contracttemplateidunique //, ContractTemplate.Schema.Attributes.createdby //, ContractTemplate.Schema.Attributes.createdon //, ContractTemplate.Schema.Attributes.createdonbehalfby , ContractTemplate.Schema.Attributes.description , ContractTemplate.Schema.Attributes.effectivitycalendar //, ContractTemplate.Schema.Attributes.importsequencenumber //, ContractTemplate.Schema.Attributes.introducedversion , ContractTemplate.Schema.Attributes.iscustomizable //, ContractTemplate.Schema.Attributes.ismanaged //, ContractTemplate.Schema.Attributes.modifiedby //, ContractTemplate.Schema.Attributes.modifiedon //, ContractTemplate.Schema.Attributes.modifiedonbehalfby , ContractTemplate.Schema.Attributes.name //, ContractTemplate.Schema.Attributes.organizationid //, ContractTemplate.Schema.Attributes.overriddencreatedon //, ContractTemplate.Schema.Attributes.overwritetime //, ContractTemplate.Schema.Attributes.solutionid //, ContractTemplate.Schema.Attributes.supportingsolutionid , ContractTemplate.Schema.Attributes.usediscountaspercentage //, ContractTemplate.Schema.Attributes.versionnumber }; List <string> xmlFieldsToCompare = new List <string>() { //ContractTemplate.Schema.Attributes.body //, ContractTemplate.Schema.Attributes.presentationxml //, ContractTemplate.Schema.Attributes.subjectpresentationxml }; FormatTextTableHandler tableOnlyExistsIn1 = new FormatTextTableHandler(); tableOnlyExistsIn1.SetHeader("Name", "Id"); FormatTextTableHandler tableOnlyExistsIn2 = new FormatTextTableHandler(); tableOnlyExistsIn2.SetHeader("Name", "Id"); Dictionary <Tuple <string, string>, List <string> > dictDifference = new Dictionary <Tuple <string, string>, List <string> >(); foreach (ContractTemplate template1 in list1) { { ContractTemplate template2 = list2.FirstOrDefault(template => template.Id == template1.Id); if (template2 != null) { continue; } } string name1 = template1.Name; tableOnlyExistsIn1.AddLine(name1, template1.Id.ToString()); this.ImageBuilder.AddComponentSolution1((int)ComponentType.ContractTemplate, template1.Id); } foreach (ContractTemplate template2 in list2) { { ContractTemplate template1 = list1.FirstOrDefault(template => template.Id == template2.Id); if (template1 != null) { continue; } } string name2 = template2.Name; tableOnlyExistsIn2.AddLine(name2, template2.Id.ToString()); this.ImageBuilder.AddComponentSolution2((int)ComponentType.ContractTemplate, template2.Id); } foreach (ContractTemplate template1 in list1) { ContractTemplate template2 = list2.FirstOrDefault(template => template.Id == template1.Id); if (template2 == null) { continue; } FormatTextTableHandler tabDiff = new FormatTextTableHandler(); tabDiff.SetHeader("Attribute", "Organization", "Value"); foreach (string fieldName in fieldsToCompare) { if (ContentCoparerHelper.IsEntityDifferentInField(template1, template2, fieldName)) { string str1 = EntityDescriptionHandler.GetAttributeString(template1, fieldName, Connection1); string str2 = EntityDescriptionHandler.GetAttributeString(template2, fieldName, Connection2); tabDiff.AddLine(fieldName, Connection1.Name, str1); tabDiff.AddLine(fieldName, Connection2.Name, str2); } } foreach (string fieldName in xmlFieldsToCompare) { string xml1 = template1.GetAttributeValue <string>(fieldName) ?? string.Empty; string xml2 = template2.GetAttributeValue <string>(fieldName) ?? string.Empty; if (!ContentCoparerHelper.CompareXML(xml1, xml2).IsEqual) { string reason = string.Empty; ContentCopareResult compare = ContentCoparerHelper.CompareXML(xml1.ToLower(), xml2.ToLower(), true); if (!compare.IsEqual) { reason = "InCase"; } else { reason = compare.GetCompareDescription(); } tabDiff.AddLine(fieldName, string.Empty, string.Format(Properties.OrganizationComparerStrings.FieldDifferenceReasonFormat3, Connection1.Name, Connection2.Name, reason)); } } if (tabDiff.Count > 0) { string name1 = template1.Name; var diff = tabDiff.GetFormatedLines(false); this.ImageBuilder.AddComponentDifferent((int)ComponentType.ContractTemplate, template1.Id, template2.Id, string.Join(Environment.NewLine, diff)); dictDifference.Add(Tuple.Create(name1, template1.Id.ToString()), diff); } } if (tableOnlyExistsIn1.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Contract Templates ONLY EXISTS in {0}: {1}", Connection1.Name, tableOnlyExistsIn1.Count); tableOnlyExistsIn1.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (tableOnlyExistsIn2.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Contract Templates ONLY EXISTS in {0}: {1}", Connection2.Name, tableOnlyExistsIn2.Count); tableOnlyExistsIn2.GetFormatedLines(true).ForEach(e => content.AppendLine().Append((tabSpacer + e).TrimEnd())); } if (dictDifference.Count > 0) { content .AppendLine() .AppendLine() .AppendLine() .AppendLine(new string('-', 150)) .AppendLine() .AppendLine(); content.AppendLine().AppendLine().AppendFormat("Contract Templates DIFFERENT in {0} and {1}: {2}", Connection1.Name, Connection2.Name, dictDifference.Count); FormatTextTableHandler tableDifference = new FormatTextTableHandler(); tableDifference.SetHeader("Title", "Id"); foreach (KeyValuePair <Tuple <string, string>, List <string> > template in dictDifference) { tableDifference.CalculateLineLengths(template.Key.Item1, template.Key.Item2); } foreach (KeyValuePair <Tuple <string, string>, List <string> > template in dictDifference .OrderBy(w => w.Key.Item1) .ThenBy(w => w.Key.Item2) ) { content.AppendLine().Append(tabSpacer + tableDifference.FormatLine(template.Key.Item1, template.Key.Item2)); foreach (string str in template.Value) { content.AppendLine().Append(tabSpacer + tabSpacer + str); } } } if (tableOnlyExistsIn2.Count == 0 && tableOnlyExistsIn1.Count == 0 && dictDifference.Count == 0 ) { content.AppendLine("No difference in Contract Templates."); } content.AppendLine().AppendLine().AppendLine(_iWriteToOutput.WriteToOutputEndOperation(null, operation)); string fileName = EntityFileNameFormatter.GetDifferenceConnectionsForFieldFileName(_OrgOrgName, "Contract Templates"); string filePath = Path.Combine(_folder, FileOperations.RemoveWrongSymbols(fileName)); File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false)); await SaveOrganizationDifferenceImage(); return(filePath); }
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); }