private async Task <bool> ValidateDocumentSavedQueryXml(ConnectionData connectionData, XDocument doc) { string fieldName = SavedQueryRepository.GetFieldNameByXmlRoot(doc.Root.Name.ToString()); string fieldTitle = SavedQueryRepository.GetFieldTitleByXmlRoot(doc.Root.Name.ToString()); this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ValidatingXmlForFieldFormat1, fieldTitle); ContentComparerHelper.ClearRoot(doc); bool validateResult = await SavedQueryRepository.ValidateXmlDocumentAsync(connectionData, _iWriteToOutput, doc, fieldTitle); if (!validateResult) { this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ValidatingXmlForFieldFailedFormat1, fieldTitle); _iWriteToOutput.ActivateOutputWindow(connectionData); var dialogResult = MessageBoxResult.Cancel; var thread = new Thread(() => { dialogResult = MessageBox.Show(Properties.MessageBoxStrings.ContinueOperation, Properties.MessageBoxStrings.QuestionTitle, MessageBoxButton.OKCancel, MessageBoxImage.Question); }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); if (dialogResult != MessageBoxResult.OK) { return(false); } } return(true); }
private void GetCurrentSavedQueryXml(IOrganizationServiceExtented service, CommonConfiguration commonConfig, XDocument doc, string filePath, SavedQuery savedQuery) { string fieldName = SavedQueryRepository.GetFieldNameByXmlRoot(doc.Root.Name.ToString()); string fieldTitle = SavedQueryRepository.GetFieldTitleByXmlRoot(doc.Root.Name.ToString()); string xmlContent = savedQuery.GetAttributeValue <string>(fieldName); if (string.IsNullOrEmpty(xmlContent)) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string currentFileName = EntityFileNameFormatter.GetSavedQueryFileName(service.ConnectionData.Name, savedQuery.ReturnedTypeCode, savedQuery.Name, fieldTitle, FileExtension.xml); string currentFilePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(currentFileName)); try { File.WriteAllText(currentFilePath, xmlContent, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldExportedToFormat5, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle, currentFilePath); this._iWriteToOutput.PerformAction(service.ConnectionData, currentFilePath); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); service.TryDispose(); } }
private void FillSavedQueriesFromCustomization(ICollection <SolutionComponent> result, EntityMetadata metaData, XElement elementEntity) { var repository = new SavedQueryRepository(_source.Service); var elements = elementEntity.XPathSelectElements("./SavedQueries/savedqueries/savedquery/savedqueryid"); foreach (var item in elements) { if (string.IsNullOrEmpty(item.Value) || !Guid.TryParse(item.Value, out var idSavedQuery)) { continue; } var entity = repository.GetById(idSavedQuery, ColumnSetInstances.None); if (entity != null) { var component = new SolutionComponent() { ComponentType = new OptionSetValue((int)ComponentType.SavedQuery), ObjectId = entity.Id, RootComponentBehaviorEnum = SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0, }; result.Add(component); } } }
private async void cmBEntityName_SelectionChanged(object sender, SelectionChangedEventArgs e) { cmBSearchView.Items.Clear(); if (cmBEntityName.SelectedItem == null) { return; } string entityName = cmBEntityName.SelectedItem.ToString(); var repository = new SavedQueryRepository(_service); var viewsList = await repository.GetListSearchQueriesAsync(entityName, ColumnSetInstances.AllColumns); foreach (var savedQuery in viewsList) { cmBSearchView.Items.Add(new EntityViewItem(savedQuery)); } if (cmBSearchView.Items.Count > 0) { cmBSearchView.SelectedIndex = 0; } }
protected override async Task <List <SavedQuery> > GetSavedQueryAsync(IOrganizationServiceExtented service) { List <SavedQuery> result = new List <SavedQuery>(); var descriptor = new SolutionComponentDescriptor(service); var repository = new SavedQueryRepository(service); var imageComponents = _solutionImage.Components.Where(c => c.ComponentType == (int)ComponentType.SavedQuery); if (imageComponents.Any()) { var solutionComponents = await descriptor.GetSolutionComponentsListAsync(imageComponents); if (solutionComponents.Any()) { var tempList = await repository.GetListByIdListAsync(solutionComponents.Select(s => s.ObjectId.Value), new ColumnSet(true)); result.AddRange(tempList); } } var hashSet = new HashSet <Guid>(result.Select(c => c.Id)); imageComponents = _solutionImage.Components.Where(c => c.ComponentType == (int)ComponentType.Entity); if (imageComponents.Any()) { var solutionComponents = await descriptor.GetSolutionComponentsListAsync(imageComponents); if (solutionComponents.Any()) { var entities = solutionComponents .Where(c => c.RootComponentBehaviorEnum.GetValueOrDefault(SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0) == (int)SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0 && c.ObjectId.HasValue) .Select(e => descriptor.MetadataSource.GetEntityMetadata(e.ObjectId.Value)) .Where(e => e != null) .Select(e => e.LogicalName) .ToArray(); if (entities.Any()) { var tempList = await repository.GetListForEntitiesAsync(entities, new ColumnSet(true)); foreach (var item in tempList) { if (hashSet.Add(item.Id)) { result.Add(item); } } } } } return(result); }
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 <Tuple <bool, SavedQuery> > GetSavedQueryByAttribute(IOrganizationServiceExtented service, CommonConfiguration commonConfig, string savedQueryId) { var repositorySavedQuery = new SavedQueryRepository(service); var savedQuery = await repositorySavedQuery.GetByIdAsync(Guid.Parse(savedQueryId), ColumnSetInstances.AllColumns); if (savedQuery == null) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionSavedQueryWasNotFoundFormat2, service.ConnectionData.Name, savedQueryId); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); WindowHelper.OpenSavedQueryExplorer(_iWriteToOutput, service, commonConfig, savedQueryId); } return(Tuple.Create(savedQuery != null, savedQuery)); }
private async Task DifferenceSavedQueryXml(IOrganizationServiceExtented service, CommonConfiguration commonConfig, XDocument doc, string filePath, SavedQuery savedQuery) { string fieldName = SavedQueryRepository.GetFieldNameByXmlRoot(doc.Root.Name.ToString()); string fieldTitle = SavedQueryRepository.GetFieldTitleByXmlRoot(doc.Root.Name.ToString()); string xmlContent = savedQuery.GetAttributeValue <string>(fieldName); string fileTitle2 = EntityFileNameFormatter.GetSavedQueryFileName(service.ConnectionData.Name, savedQuery.ReturnedTypeCode, savedQuery.Name, fieldTitle, FileExtension.xml); string filePath2 = FileOperations.GetNewTempFilePath(Path.GetFileNameWithoutExtension(fileTitle2), Path.GetExtension(fileTitle2)); if (string.IsNullOrEmpty(xmlContent)) { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); return; } try { xmlContent = ContentComparerHelper.FormatXmlByConfiguration( xmlContent , commonConfig , XmlOptionsControls.SavedQueryXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.FetchSchema , savedQueryId: savedQuery.Id , entityName: savedQuery.ReturnedTypeCode ); File.WriteAllText(filePath2, xmlContent, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldExportedToFormat5, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle, filePath2); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); } string fileLocalPath = filePath; string fileLocalTitle = Path.GetFileName(filePath); await this._iWriteToOutput.ProcessStartProgramComparerAsync(service.ConnectionData, fileLocalPath, filePath2, fileLocalTitle, fileTitle2); service.TryDispose(); }
private async Task UpdateSavedQueryXml(IOrganizationServiceExtented service, CommonConfiguration commonConfig, XDocument doc, string filePath, SavedQuery savedQuery) { string fieldName = SavedQueryRepository.GetFieldNameByXmlRoot(doc.Root.Name.ToString()); string fieldTitle = SavedQueryRepository.GetFieldTitleByXmlRoot(doc.Root.Name.ToString()); if (string.Equals(fieldName, SavedQuery.Schema.Attributes.layoutxml, StringComparison.InvariantCulture) && !string.IsNullOrEmpty(savedQuery.ReturnedTypeCode) ) { var entityData = service.ConnectionData.GetEntityIntellisenseData(savedQuery.ReturnedTypeCode); if (entityData != null && entityData.ObjectTypeCode.HasValue) { XAttribute attr = doc.Root.Attribute("object"); if (attr != null) { attr.Value = entityData.ObjectTypeCode.ToString(); } } } { string xmlContent = savedQuery.GetAttributeValue <string>(fieldName); if (!string.IsNullOrEmpty(xmlContent)) { commonConfig.CheckFolderForExportExists(this._iWriteToOutput); string fileNameBackUp = EntityFileNameFormatter.GetSavedQueryFileName(service.ConnectionData.Name, savedQuery.ReturnedTypeCode, savedQuery.Name, fieldTitle + " BackUp", FileExtension.xml); string filePathBackUp = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileNameBackUp)); try { xmlContent = ContentComparerHelper.FormatXmlByConfiguration( xmlContent , commonConfig , XmlOptionsControls.SavedQueryXmlOptions , schemaName: AbstractDynamicCommandXsdSchemas.FetchSchema , savedQueryId: savedQuery.Id , entityName: savedQuery.ReturnedTypeCode ); File.WriteAllText(filePathBackUp, xmlContent, new UTF8Encoding(false)); this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldExportedToFormat5, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle, filePathBackUp); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); } } else { this._iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionEntityFieldIsEmptyFormat4, service.ConnectionData.Name, SavedQuery.Schema.EntityLogicalName, savedQuery.Name, fieldTitle); this._iWriteToOutput.ActivateOutputWindow(service.ConnectionData); } } var newText = doc.ToString(SaveOptions.DisableFormatting); if (string.Equals(fieldName, SavedQuery.Schema.Attributes.fetchxml, StringComparison.InvariantCulture)) { try { _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.ExecutingValidateSavedQueryRequest); var request = new ValidateSavedQueryRequest() { FetchXml = newText, QueryType = savedQuery.QueryType.GetValueOrDefault() }; service.Execute(request); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(service.ConnectionData, ex); } } _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.SavingEntityFormat1, savedQuery.LogicalName); _iWriteToOutput.WriteToOutputEntityInstance(service.ConnectionData, savedQuery.LogicalName, savedQuery.Id); var updateEntity = new SavedQuery { Id = savedQuery.Id, }; updateEntity.Attributes[fieldName] = newText; await service.UpdateAsync(updateEntity); _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.SavingEntityCompletedFormat1, savedQuery.LogicalName); _iWriteToOutput.WriteToOutput(service.ConnectionData, Properties.OutputStrings.InConnectionPublishingEntitiesFormat2, service.ConnectionData.Name, savedQuery.ReturnedTypeCode); { var repositoryPublish = new PublishActionsRepository(service); await repositoryPublish.PublishEntitiesAsync(new[] { savedQuery.ReturnedTypeCode }); } service.TryDispose(); }
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); }