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); } }
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); } }