Exemple #1
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);
            }
        }
        private async Task <string> GetDescriptionDependent(List <Dependency> coll)
        {
            var list = coll.Select(d => d.DependentToSolutionComponent()).ToList();

            return(await _descriptor.GetSolutionComponentsDescriptionAsync(list));
        }
Exemple #3
0
        private async Task FillDescriptionUsedEntities(StringBuilder strFile, HashSet <Guid> workflowsWithEntities, Dictionary <EntityReference, HashSet <Guid> > list)
        {
            string message = string.Empty;

            if (list.Count == 0)
            {
                strFile
                .AppendLine()
                .AppendLine()
                .AppendLine()
                .AppendLine(this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "No used entities in workflows."))
                ;
                return;
            }

            strFile
            .AppendLine()
            .AppendLine()
            .AppendFormat(this._iWriteToOutput.WriteToOutput(_service.ConnectionData, "Used Entities {0}", list.Count)).AppendLine()
            ;

            var orderedList = list.Keys.OrderBy(i => i.LogicalName).ThenBy(i => i.Name).ThenBy(i => i.Id);

            {
                FormatTextTableHandler table = new FormatTextTableHandler();
                table.SetHeader("LogicalName", "Name", "Id", "Url");

                foreach (var item in orderedList)
                {
                    var values = new List <string>()
                    {
                        item.LogicalName, item.Name, item.Id.ToString()
                    };

                    var url = _service.ConnectionData.GetEntityInstanceUrl(item.LogicalName, item.Id);

                    if (!string.IsNullOrEmpty(url))
                    {
                        values.Add(url);
                    }

                    table.AddLine(values);
                }

                table.GetFormatedLines(false).ForEach(s => strFile.AppendLine(tabspacer + s));
            }

            strFile
            .AppendLine()
            .AppendLine()
            .AppendLine()
            .AppendLine(new string('-', 150))
            .AppendLine()
            .AppendLine()
            .AppendLine()
            ;

            strFile.AppendFormat("Used Entities Full Information {0}", list.Count).AppendLine();

            foreach (var item in orderedList)
            {
                strFile
                .AppendLine()
                .AppendLine()
                .AppendLine();

                FormatTextTableHandler table = new FormatTextTableHandler();
                table.SetHeader("LogicalName", "Name", "Id");
                table.AddLine(item.LogicalName, item.Name, item.Id.ToString());
                table.GetFormatedLines(false).ForEach(s => strFile.AppendLine(s));

                var url = _service.ConnectionData.GetEntityInstanceUrl(item.LogicalName, item.Id);

                if (!string.IsNullOrEmpty(url))
                {
                    strFile.AppendLine("Url:");
                    strFile.AppendLine(url);
                }

                strFile.AppendLine();

                try
                {
                    var entityMetadata = _descriptor.MetadataSource.GetEntityMetadata(item.LogicalName);

                    if (entityMetadata != null)
                    {
                        var repositoryGeneric = new GenericRepository(_service, entityMetadata);

                        var entity = await repositoryGeneric.GetEntityByIdAsync(item.Id, new ColumnSet(true));

                        if (entity != null)
                        {
                            var desc = await EntityDescriptionHandler.GetEntityDescriptionAsync(entity, null, _service.ConnectionData);

                            strFile
                            .AppendLine(desc)
                            .AppendLine()
                            .AppendLine()
                            ;
                        }
                        else
                        {
                            strFile
                            .AppendFormat("{0} With Id = {1} Does Not Exists", item.LogicalName, item.Id).AppendLine()
                            .AppendLine()
                            .AppendLine()
                            ;
                        }
                    }
                    else
                    {
                        strFile
                        .AppendFormat("Entity with name '{0}' Does Not Exists", item.LogicalName).AppendLine()
                        .AppendFormat("{0} With Id = {1} Does Not Exists", item.LogicalName, item.Id).AppendLine()
                        .AppendLine()
                        .AppendLine()
                        ;
                    }
                }
                catch (Exception ex)
                {
                    var description = DTEHelper.GetExceptionDescription(ex);

                    strFile
                    .AppendLine(description)
                    .AppendLine()
                    .AppendLine()
                    ;
                }

                message = await _descriptor.GetSolutionComponentsDescriptionAsync(list[item].Select(id => new SolutionComponent()
                {
                    ObjectId      = id,
                    ComponentType = new OptionSetValue((int)ComponentType.Workflow),
                }));

                strFile
                .AppendLine("This entity Used By Workflows:")
                .AppendLine(message)
                .AppendLine()
                .AppendLine()
                .AppendLine()
                .AppendLine(new string('-', 150))
                ;
            }

            if (workflowsWithEntities.Any())
            {
                strFile
                .AppendLine()
                .AppendLine()
                .AppendLine()
                .AppendLine()
                .AppendLine()
                .AppendLine()
                .AppendLine("These entities Used By Workflows:")
                ;

                message = await _descriptor.GetSolutionComponentsDescriptionAsync(workflowsWithEntities.Select(id => new SolutionComponent()
                {
                    ObjectId      = id,
                    ComponentType = new OptionSetValue((int)ComponentType.Workflow),
                }));

                strFile.AppendLine(message);
            }
        }