Exemple #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);
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        private async Task <SolutionImage> CreateSolutionImage(Guid solutionId, string solutionUniqueName)
        {
            SolutionImage solutionImage = null;

            try
            {
                var repositorySolution = new SolutionRepository(_service);

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

                solutionImage = await CreateSolutionImageWithComponents(solutionUniqueName, components);
            }
            catch (Exception ex)
            {
                solutionImage = null;

                this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);
            }

            return(solutionImage);
        }
        private async void ClearUnmanagedSolution_Click(object sender, RoutedEventArgs e)
        {
            var solution = GetSelectedEntity();

            if (solution == null)
            {
                return;
            }

            string question = string.Format(Properties.MessageBoxStrings.ClearSolutionFormat1, solution.UniqueName);

            if (MessageBox.Show(question, Properties.MessageBoxStrings.QuestionTitle, MessageBoxButton.OKCancel, MessageBoxImage.Question) != MessageBoxResult.OK)
            {
                return;
            }

            try
            {
                ToggleControls(false, Properties.WindowStatusStrings.ClearingSolutionFormat2, _service.ConnectionData.Name, solution.UniqueName);

                var commonConfig = CommonConfiguration.Get();

                var descriptor = new SolutionComponentDescriptor(_service);
                descriptor.SetSettings(commonConfig);

                SolutionDescriptor solutionDescriptor = new SolutionDescriptor(_iWriteToOutput, _service, descriptor);

                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, string.Empty);
                this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "Creating backup Solution Components in '{0}'.", solution.UniqueName);

                {
                    string fileName = EntityFileNameFormatter.GetSolutionFileName(
                        _service.ConnectionData.Name
                        , solution.UniqueName
                        , "Components Backup"
                        );

                    string filePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName));

                    await solutionDescriptor.CreateFileWithSolutionComponentsAsync(filePath, solution.Id);

                    this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "Created backup Solution Components in '{0}': {1}", solution.UniqueName, filePath);
                    this._iWriteToOutput.WriteToOutputFilePathUri(_service.ConnectionData, filePath);
                }

                {
                    string fileName = EntityFileNameFormatter.GetSolutionFileName(
                        _service.ConnectionData.Name
                        , solution.UniqueName
                        , "SolutionImage Backup before Clearing"
                        , "xml"
                        );

                    string filePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName));

                    SolutionImage solutionImage = await solutionDescriptor.CreateSolutionImageAsync(solution.Id, solution.UniqueName);

                    await solutionImage.SaveAsync(filePath);
                }

                SolutionComponentRepository repository = new SolutionComponentRepository(_service);
                await repository.ClearSolutionAsync(solution.UniqueName);

                ToggleControls(true, Properties.WindowStatusStrings.ClearingSolutionCompletedFormat2, _service.ConnectionData.Name, solution.UniqueName);
            }
            catch (Exception ex)
            {
                this._iWriteToOutput.WriteErrorToOutput(_service.ConnectionData, ex);

                ToggleControls(true, Properties.WindowStatusStrings.ClearingSolutionFailedFormat2, _service.ConnectionData.Name, solution.UniqueName);
            }
        }
Exemple #5
0
        private async Task CheckingComponentTypeEnum(ConnectionData connectionData, CommonConfiguration commonConfig)
        {
            var service = await ConnectAndWriteToOutputAsync(connectionData);

            if (service == null)
            {
                return;
            }

            StringBuilder content = new StringBuilder();

            content.AppendLine(Properties.OutputStrings.ConnectingToCRM);
            content.AppendLine(connectionData.GetConnectionDescription());
            content.AppendFormat(Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint).AppendLine();

            var hash = new HashSet <Tuple <int, Guid> >();

            {
                var repository = new SolutionComponentRepository(service);

                var components = await repository.GetDistinctSolutionComponentsAsync();

                foreach (var item in components.Where(en => en.ComponentType != null && en.ObjectId.HasValue))
                {
                    if (!item.IsDefinedComponentType())
                    {
                        hash.Add(Tuple.Create(item.ComponentType.Value, item.ObjectId.Value));
                    }
                }
            }

            {
                var repository = new DependencyNodeRepository(service);

                var components = await repository.GetDistinctListUnknownComponentTypeAsync();

                foreach (var item in components.Where(en => en.ComponentType != null && en.ObjectId.HasValue))
                {
                    if (!item.IsDefinedComponentType())
                    {
                        hash.Add(Tuple.Create(item.ComponentType.Value, item.ObjectId.Value));
                    }
                }
            }

            {
                var repository = new InvalidDependencyRepository(service);

                var components = await repository.GetDistinctListAsync();

                foreach (var item in components.Where(en => en.MissingComponentType != null && en.MissingComponentId.HasValue))
                {
                    if (!item.IsDefinedMissingComponentType())
                    {
                        hash.Add(Tuple.Create(item.MissingComponentType.Value, item.MissingComponentId.Value));
                    }
                }

                foreach (var item in components.Where(en => en.ExistingComponentType != null && en.ExistingComponentId.HasValue))
                {
                    if (!item.IsDefinedExistingComponentType())
                    {
                        hash.Add(Tuple.Create(item.ExistingComponentType.Value, item.ExistingComponentId.Value));
                    }
                }
            }

            if (hash.Any())
            {
                var groups = hash.GroupBy(e => e.Item1);

                content.AppendLine().AppendLine();

                content.AppendFormat("ComponentTypes not founded in Enum: {0}", groups.Count());

                foreach (var gr in groups.OrderBy(e => e.Key))
                {
                    content.AppendLine().AppendLine();

                    foreach (var item in gr.OrderBy(e => e.Item2))
                    {
                        content.AppendFormat(_tabSpacer + item.Item1.ToString() + _tabSpacer + item.Item2.ToString()).AppendLine();
                    }
                }

                string fileName = string.Format("{0}.Checking ComponentType Enum at {1}.txt"
                                                , connectionData.Name
                                                , DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss")
                                                );

                commonConfig.CheckFolderForExportExists(this._iWriteToOutput);

                string filePath = Path.Combine(commonConfig.FolderForExport, FileOperations.RemoveWrongSymbols(fileName));

                File.WriteAllText(filePath, content.ToString(), new UTF8Encoding(false));

                this._iWriteToOutput.WriteToOutput(connectionData, "New ComponentTypes were exported to {0}", filePath);

                this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
            }
            else
            {
                this._iWriteToOutput.WriteToOutput(connectionData, "No New ComponentTypes in CRM were founded.");
                this._iWriteToOutput.ActivateOutputWindow(connectionData);
            }
        }
Exemple #6
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);
            }
        }
Exemple #7
0
        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);
            }
        }
Exemple #8
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);
            }
        }