private async Task <IEnumerable <Guid> > GetDescriptionWithEntityFieldStringsInAllWorkflows(StringBuilder strFile) { var workflowsWithStrings = new Dictionary <Guid, List <WorkflowEntityFieldString> >(); try { this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty); this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty); strFile.AppendLine(this._iWriteToOutput.WriteToOutputStartOperation(_service.ConnectionData, Properties.OperationNames.AnalyzingWorkflowsFormat1, _service.ConnectionData.Name)); var repositoryWorkflow = new WorkflowRepository(_service); var handler = new WorkflowUsedEntitiesHandler(); { var workflowsList = await repositoryWorkflow.GetListAsync(null, null, null, null, new ColumnSet(Workflow.Schema.Attributes.xaml)); _descriptor.GetEntities <Workflow>((int)ComponentType.Workflow, workflowsList.Select(c => c.Id)); foreach (var workflow in workflowsList) { if (string.IsNullOrEmpty(workflow.Xaml)) { continue; } var xmlContent = ContentComparerHelper.RemoveDiacritics(workflow.Xaml); var doc = XElement.Parse(xmlContent); List <WorkflowEntityFieldString> coll = await handler.GetWorkflowStringsEntityFieldsAsync(doc); if (coll.Count > 0) { workflowsWithStrings.Add(workflow.Id, coll); } } } await FillDescriptionEntityFieldStrings(strFile, workflowsWithStrings); strFile.AppendLine(this._iWriteToOutput.WriteToOutputEndOperation(_service.ConnectionData, Properties.OperationNames.AnalyzingWorkflowsFormat1, _service.ConnectionData.Name)); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); } return(workflowsWithStrings.Keys.ToArray()); }
public async Task GetDescriptionUsedNotExistsEntitiesInWorkflowAsync(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); HashSet <Guid> workflowsWithEntities = new HashSet <Guid>() { idWorkflow }; var handler = new WorkflowUsedEntitiesHandler(); Dictionary <EntityReference, HashSet <Guid> > list = (await handler.GetWorkflowUsedEntitiesAsync(doc)).ToDictionary(e => e, k => new HashSet <Guid>() { idWorkflow }); 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() .AppendLine() .AppendLine() ; await FillDescriptionNotExistsEntities(strFile, workflowsWithEntities, list); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); } }
public async Task GetDescriptionEntityFieldStringsInWorkflowAsync(StringBuilder strFile, Guid idWorkflow) { try { var repository = new WorkflowRepository(_service); var workflow = await repository.GetByIdAsync(idWorkflow, ColumnSetInstances.AllColumns); string xmlContent = ContentComparerHelper.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() .AppendLine() .AppendLine() ; var strings = await handler.GetWorkflowStringsEntityFieldsAsync(doc); Dictionary <Guid, List <WorkflowEntityFieldString> > workflowsWithStrings = new Dictionary <Guid, List <WorkflowEntityFieldString> >(); if (strings.Any()) { workflowsWithStrings.Add(idWorkflow, strings); } await FillDescriptionEntityFieldStrings(strFile, workflowsWithStrings); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); } }
public static string GetCorrectedXaml(string xml, LabelReplacer replacer) { try { xml = xml ?? string.Empty; xml = ContentComparerHelper.RemoveDiacritics(xml); if (!TryParseXml(xml, out XElement doc)) { return(xml); } replacer.FullfillLabelsForWorkflow(doc); RemoveEmptyXMLText(doc); RenameClasses(doc); WorkflowUsedEntitiesHandler.ReplaceGuids(doc); return(doc.ToString()); } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(null, ex); #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } #endif throw; } }
public static ContentCompareResult CompareWorkflowXAML(string xml1, string xml2, LabelReplacer rep1, LabelReplacer rep2, bool withDetails = false) { try { xml1 = xml1 ?? string.Empty; xml2 = xml2 ?? string.Empty; xml1 = ContentComparerHelper.RemoveDiacritics(xml1); xml2 = ContentComparerHelper.RemoveDiacritics(xml2); diff_match_patch match = new diff_match_patch { Diff_Timeout = ContentComparerHelper.Diff_Timeout }; if (string.IsNullOrEmpty(xml1) && string.IsNullOrEmpty(xml2)) { return(new ContentCompareResult(true, null)); } if (string.IsNullOrEmpty(xml1) && !string.IsNullOrEmpty(xml2)) { return(new ContentCompareResult(false, match.diff_main(xml1, xml2, false))); } if (!string.IsNullOrEmpty(xml1) && string.IsNullOrEmpty(xml2)) { return(new ContentCompareResult(false, match.diff_main(xml1, xml2, false))); } if (!TryParseXml(xml1, out XElement doc1) || !TryParseXml(xml2, out XElement doc2)) { bool isEqual = string.Equals(xml1, xml2); if (isEqual) { return(new ContentCompareResult(true, null)); } else { if (withDetails) { return(new ContentCompareResult(false, match.diff_main(xml1, xml2, false))); } else { return(new ContentCompareResult(false, null)); } } } RemoveEmptyElements(doc1); RemoveEmptyElements(doc2); RenameClasses(doc1); RenameClasses(doc2); WorkflowUsedEntitiesHandler.ReplaceGuids(doc1); WorkflowUsedEntitiesHandler.ReplaceGuids(doc2); if (rep1 != null) { rep1.FullfillLabelsForWorkflow(doc1); } if (rep2 != null) { rep2.FullfillLabelsForWorkflow(doc2); } { bool isEqual = XNode.DeepEquals(doc1, doc2); if (isEqual) { return(new ContentCompareResult(true, null)); } else { if (withDetails) { return(new ContentCompareResult(false, match.diff_main(doc1.ToString(), doc2.ToString(), false))); } else { return(new ContentCompareResult(false, null)); } } } } catch (Exception ex) { DTEHelper.WriteExceptionToOutput(null, ex); #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } #endif throw; } }
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); } }
private async Task GetDescriptionWithUsedNotExistsEntitiesInAllWorkflows(StringBuilder strFile) { try { this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty); this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty); strFile.AppendLine(this._iWriteToOutput.WriteToOutputStartOperation(_service.ConnectionData, Properties.OperationNames.AnalyzingWorkflowsFormat1, _service.ConnectionData.Name)); SolutionComponentRepository repository = new SolutionComponentRepository(_service); HashSet <Guid> workflowsWithEntities = new HashSet <Guid>(); Dictionary <EntityReference, HashSet <Guid> > list = new Dictionary <EntityReference, HashSet <Guid> >(); var handler = new WorkflowUsedEntitiesHandler(); var repositoryWorkflow = new WorkflowRepository(_service); { var workflows = await repositoryWorkflow.GetListAsync(null, null, null, new ColumnSet(Workflow.Schema.Attributes.xaml)); _descriptor.GetEntities <Workflow>((int)ComponentType.Workflow, workflows.Select(c => c.Id)); foreach (var item in workflows) { var xmlContent = ContentCoparerHelper.RemoveDiacritics(item.Xaml); var doc = XElement.Parse(xmlContent); var coll = await handler.GetWorkflowUsedEntitiesAsync(doc); if (coll.Count > 0) { workflowsWithEntities.Add(item.Id); foreach (var entityRef in coll) { HashSet <Guid> linkedWorkflows = null; if (list.ContainsKey(entityRef)) { linkedWorkflows = list[entityRef]; } else { list[entityRef] = linkedWorkflows = new HashSet <Guid>(); } linkedWorkflows.Add(item.Id); } } } } await FillDescriptionNotExistsEntities(strFile, workflowsWithEntities, list); strFile.AppendLine(this._iWriteToOutput.WriteToOutputEndOperation(_service.ConnectionData, Properties.OperationNames.AnalyzingWorkflowsFormat1, _service.ConnectionData.Name)); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); } }
private async Task GetDescriptionWithUsedEntitiesInSolutionWorkflows(StringBuilder strFile, Guid idSolution) { try { var repositorySolution = new SolutionRepository(_service); var solution = await repositorySolution.GetSolutionByIdAsync(idSolution); this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty); this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty); strFile.AppendLine(this._iWriteToOutput.WriteToOutputStartOperation(_service.ConnectionData, Properties.OperationNames.AnalyzingSolutionWorkflowsFormat2, _service.ConnectionData.Name, solution.UniqueName)); SolutionComponentRepository repository = new SolutionComponentRepository(_service); var repositoryWorkflow = new WorkflowRepository(_service); HashSet <Guid> workflowsWithEntities = new HashSet <Guid>(); Dictionary <EntityReference, HashSet <Guid> > list = new Dictionary <EntityReference, HashSet <Guid> >(); var handler = new WorkflowUsedEntitiesHandler(); { var components = await repository.GetSolutionComponentsByTypeAsync(solution.Id, ComponentType.Workflow, new ColumnSet(SolutionComponent.Schema.Attributes.objectid)); _descriptor.GetEntities <Workflow>((int)ComponentType.Workflow, components.Select(c => c.ObjectId)); var workflows = await repositoryWorkflow.GetListByIdListAsync(components.Select(en => en.ObjectId.Value), new ColumnSet(Workflow.Schema.Attributes.xaml)); foreach (var item in workflows) { if (string.IsNullOrEmpty(item.Xaml)) { continue; } var xmlContent = ContentCoparerHelper.RemoveDiacritics(item.Xaml); var doc = XElement.Parse(xmlContent); var coll = await handler.GetWorkflowUsedEntitiesAsync(doc); if (coll.Count > 0) { workflowsWithEntities.Add(item.Id); foreach (var entityRef in coll) { HashSet <Guid> linkedWorkflows = null; if (list.ContainsKey(entityRef)) { linkedWorkflows = list[entityRef]; } else { list[entityRef] = linkedWorkflows = new HashSet <Guid>(); } linkedWorkflows.Add(item.Id); } } } } { var components = await repository.GetSolutionComponentsByTypeAsync(solution.Id, ComponentType.Entity, new ColumnSet(SolutionComponent.Schema.Attributes.objectid)); var listMetadata = _descriptor.MetadataSource.GetEntityMetadataList(components.Where(e => e.ObjectId.HasValue).Select(e => e.ObjectId.Value)); foreach (var entityMetadata in listMetadata) { var workflows = await repositoryWorkflow.GetListAsync(entityMetadata.LogicalName, (int)Workflow.Schema.OptionSets.category.Business_Rule_2, null, new ColumnSet(Workflow.Schema.Attributes.xaml)); foreach (var item in workflows) { if (!string.IsNullOrEmpty(item.Xaml) && !workflowsWithEntities.Contains(item.Id)) { var xmlContent = ContentCoparerHelper.RemoveDiacritics(item.Xaml); var doc = XElement.Parse(xmlContent); var coll = await handler.GetWorkflowUsedEntitiesAsync(doc); if (coll.Count > 0) { workflowsWithEntities.Add(item.Id); foreach (var entityRef in coll) { HashSet <Guid> linkedWorkflows = null; if (list.ContainsKey(entityRef)) { linkedWorkflows = list[entityRef]; } else { list[entityRef] = linkedWorkflows = new HashSet <Guid>(); } linkedWorkflows.Add(item.Id); } } } } } } await FillDescriptionUsedEntities(strFile, workflowsWithEntities, list); strFile.AppendLine(this._iWriteToOutput.WriteToOutputEndOperation(_service.ConnectionData, Properties.OperationNames.AnalyzingSolutionWorkflowsFormat2, _service.ConnectionData.Name, solution.UniqueName)); } catch (Exception ex) { this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex); } }