public override string GetDisplayName(SolutionComponent component) { var entity = GetEntity <SavedQuery>(component.ObjectId.Value); if (entity != null) { return(SavedQueryRepository.GetQueryTypeName(entity.QueryType.Value)); } return(base.GetDisplayName(component)); }
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); }