Esempio n. 1
0
        private async Task FindUniqueComponentsInSolutions(Guid idSolution1, Guid idSolution2)
        {
            SolutionRepository repositorySolution = new SolutionRepository(_service);

            var solution1 = await repositorySolution.GetSolutionByIdAsync(idSolution1);

            var solution2 = await repositorySolution.GetSolutionByIdAsync(idSolution2);

            SolutionComponentRepository repository = new SolutionComponentRepository(_service);

            var components1 = await repository.GetSolutionComponentsAsync(idSolution1, new ColumnSet(SolutionComponent.Schema.Attributes.componenttype, SolutionComponent.Schema.Attributes.objectid, SolutionComponent.Schema.Attributes.rootcomponentbehavior));

            var components2 = await repository.GetSolutionComponentsAsync(idSolution2, new ColumnSet(SolutionComponent.Schema.Attributes.componenttype, SolutionComponent.Schema.Attributes.objectid, SolutionComponent.Schema.Attributes.rootcomponentbehavior));

            var componentsOnlyIn1 = GetComponentsInFirstNotSecond(components1, components2);
            var componentsOnlyIn2 = GetComponentsInFirstNotSecond(components2, components1);

            this._iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.SolutionComponentsCountAndUniqueFormat4, solution1.UniqueName, components1.Count.ToString(), componentsOnlyIn1.Count.ToString(), solution2.UniqueName);
            this._iWriteToOutput.WriteToOutput(_service.ConnectionData, Properties.OutputStrings.SolutionComponentsCountAndUniqueFormat4, solution2.UniqueName, components2.Count.ToString(), componentsOnlyIn2.Count.ToString(), solution1.UniqueName);
        }
Esempio n. 2
0
        private async Task CreateFileWithSolutionMissingDependencies(string filePath, Guid solutionId, ComponentsGroupBy showComponents, string showString)
        {
            try
            {
                var repository = new SolutionRepository(_service);

                var solution = await repository.GetSolutionByIdAsync(solutionId);

                string message = null;

                message = string.Format("Analyzing Solution '{0}' {1} at {2}.", solution.UniqueName, showString, DateTime.Now.ToString("G", System.Globalization.CultureInfo.CurrentCulture));

                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty);
                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty);
                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, message);

                StringBuilder strFile = new StringBuilder();

                strFile.AppendLine(message);

                var dependencyRepository = new DependencyRepository(_service);

                var listComponents = await dependencyRepository.GetSolutionMissingDependenciesAsync(solution.UniqueName);

                message = string.Format("Solution '{0}' {1} {2}:", solution.UniqueName, showString, listComponents.Count.ToString());

                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty);
                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, message);

                strFile
                .AppendLine()
                .AppendLine(message)
                .AppendLine();

                message = await new DependencyDescriptionHandler(_descriptor).GetDescriptionFullAsynс(listComponents, showComponents);

                strFile.AppendLine(message);

                File.WriteAllText(filePath, strFile.ToString(), new UTF8Encoding(false));
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
            }
        }
Esempio n. 3
0
        private async Task CreateFileWithSolutionComponents(string filePath, Guid solutionId)
        {
            try
            {
                var repositorySolution = new SolutionRepository(_service);

                var solution = await repositorySolution.GetSolutionByIdAsync(solutionId);

                var repository = new SolutionComponentRepository(_service);

                var components = await repository.GetSolutionComponentsAsync(solutionId, new ColumnSet(SolutionComponent.Schema.Attributes.componenttype, SolutionComponent.Schema.Attributes.objectid, SolutionComponent.Schema.Attributes.rootcomponentbehavior));

                StringBuilder strFile = new StringBuilder();
                string        message = null;

                message = string.Format("Analyzing Solution Components '{0}' at {1}.", solution.UniqueName, DateTime.Now.ToString("G", System.Globalization.CultureInfo.CurrentCulture));

                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty);
                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty);
                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, message);

                strFile.AppendLine(message);

                message = string.Format("Solution '{0}' has {1} components:", solution.UniqueName, components.Count().ToString());

                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty);
                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, message);

                strFile.AppendLine().AppendLine(message);

                message = await _descriptor.GetSolutionComponentsDescriptionAsync(components);

                strFile.AppendLine(message);

                File.WriteAllText(filePath, strFile.ToString(), new UTF8Encoding(false));
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
            }
        }
Esempio n. 4
0
        private async Task CreateFileWithUniqueComponentsInSolution1(
            string filePath
            , Guid idSolution1
            , Guid idSolution2
            )
        {
            try
            {
                SolutionRepository repositorySolution = new SolutionRepository(_service);

                var solution1 = await repositorySolution.GetSolutionByIdAsync(idSolution1);

                var solution2 = await repositorySolution.GetSolutionByIdAsync(idSolution2);

                SolutionComponentRepository repository = new SolutionComponentRepository(_service);

                var components1 = await repository.GetSolutionComponentsAsync(solution1.Id, new ColumnSet(SolutionComponent.Schema.Attributes.componenttype, SolutionComponent.Schema.Attributes.objectid, SolutionComponent.Schema.Attributes.rootcomponentbehavior));

                var components2 = await repository.GetSolutionComponentsAsync(solution2.Id, new ColumnSet(SolutionComponent.Schema.Attributes.componenttype, SolutionComponent.Schema.Attributes.objectid, SolutionComponent.Schema.Attributes.rootcomponentbehavior));

                var componentsOnlyIn1 = GetComponentsInFirstNotSecond(components1, components2);
                var componentsOnlyIn2 = GetComponentsInFirstNotSecond(components2, components1);

                await CreateFileWithComponentsInSolution1(filePath, solution1.UniqueName, solution2.UniqueName, components1.Count, components2.Count, componentsOnlyIn1, componentsOnlyIn2.Count);

                var commonComponents = GetCommonComponents(components1, components2);

                List <SolutionImageComponent> imageCommonComponents = await _descriptor.GetSolutionImageComponentsListAsync(commonComponents);

                List <SolutionImageComponent> imageComponentsOnlyIn1 = await _descriptor.GetSolutionImageComponentsListAsync(componentsOnlyIn1);

                List <SolutionImageComponent> imageComponentsOnlyIn2 = await _descriptor.GetSolutionImageComponentsListAsync(componentsOnlyIn2);

                SolutionDifferenceImage image = new SolutionDifferenceImage()
                {
                    Solution1Name = solution1.UniqueName,
                    Solution2Name = solution2.UniqueName,

                    ConnectionName = _service.ConnectionData.Name,

                    ConnectionOrganizationName    = _service.ConnectionData.UniqueOrgName,
                    ConnectionDiscoveryService    = _service.ConnectionData.DiscoveryUrl,
                    ConnectionOrganizationService = _service.ConnectionData.OrganizationUrl,
                    ConnectionPublicUrl           = _service.ConnectionData.PublicUrl,

                    MachineName           = Environment.MachineName,
                    ExecuteUserDomainName = Environment.UserDomainName,
                    ExecuteUserName       = Environment.UserName,

                    ConnectionSystemUserName = _service.ConnectionData.GetUsername,

                    CreatedOn = DateTime.Now,
                };

                foreach (var item in imageCommonComponents)
                {
                    if (!image.CommonComponents.Contains(item))
                    {
                        image.CommonComponents.Add(item);
                    }
                }

                foreach (var item in imageComponentsOnlyIn1)
                {
                    if (!image.OnlySolution1Components.Contains(item))
                    {
                        image.OnlySolution1Components.Add(item);
                    }
                }

                foreach (var item in imageComponentsOnlyIn2)
                {
                    if (!image.OnlySolution2Components.Contains(item))
                    {
                        image.OnlySolution2Components.Add(item);
                    }
                }

                await image.SaveAsync(filePath + ".xml");
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
            }
        }
Esempio n. 5
0
        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);
            }
        }