Exemplo n.º 1
0
        public CreateGlobalOptionSetsFileCSharpHandler(
            TextWriter writer
            , IOrganizationServiceExtented service
            , IWriteToOutput iWriteToOutput
            , CreateFileCSharpConfiguration config
            ) : base(writer, config.TabSpacer, config.AllDescriptions)
        {
            this._service        = service ?? throw new ArgumentNullException(nameof(service));
            this._iWriteToOutput = iWriteToOutput ?? throw new ArgumentNullException(nameof(iWriteToOutput));

            this._config = config;

            this._descriptor = new SolutionComponentDescriptor(_service)
            {
                WithManagedInfo = config.WithManagedInfo,
            };

            this._dependencyRepository = new DependencyRepository(this._service);
            this._descriptorHandler    = new DependencyDescriptionHandler(this._descriptor);
            this._repositoryStringMap  = new StringMapRepository(_service);

            if (config.ConstantType == ConstantType.ReadOnlyField)
            {
                _fieldHeader = "static readonly";
            }
            else
            {
                _fieldHeader = "const";
            }
        }
Exemplo n.º 2
0
 public static void SetUp(TestContext _context)
 {
     dependency_repo = new DependencyRepository();
     project_repo    = new ProjectsRepository();
     project_repo.Add(new Project("Angular", 1, "03/02/2013", "03/04/2014", "www.github.com/angular"));
     project_repo.Add(new Project("js", 1, "03/02/2013", "03/04/2014", "www.github.com/js"));
     dependency_repo.Clear();
 }
Exemplo n.º 3
0
 public DiscoveryUnitOfWork(GravityManagerDbContext dbContext) : base(dbContext)
 {
     AwsAccounts        = new AwsAccountRepository(Context);
     AwsInstances       = new AwsInstanceRepository(Context);
     DiscoverySessions  = new DiscoverySessionRepository(Context);
     Dependencies       = new DependencyRepository(Context);
     DependencyFindings = new DependencyFindingRepository(Context);
     ReportLines        = new ReportLineRepository(Context);
 }
Exemplo n.º 4
0
        static InternalFactory()
        {
            IDependencyRepository dependencies = new DependencyRepository();
            IDependencyInjector   injector     = new DependencyInjector(dependencies);
            IDependencyBinder     binder       = new DependencyBinder(dependencies, injector);
            IMultiBindCollection  multiBindMap = new MultiBindCollection();

            singletons = new Dictionary <Type, object>
            {
                { typeof(IDependencyRepository), dependencies },
                { typeof(IDependencyInjector), injector },
                { typeof(IDependencyBinder), binder },
                { typeof(IMultiBindCollection), multiBindMap },
            };
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        public CreateGlobalOptionSetsFileJavaScriptHandler(
            TextWriter writer
            , IOrganizationServiceExtented service
            , IWriteToOutput iWriteToOutput
            , string tabSpacer
            , bool withDependentComponents
            ) : base(writer, tabSpacer, true)
        {
            this._service                 = service;
            this._iWriteToOutput          = iWriteToOutput;
            this._withDependentComponents = withDependentComponents;

            this._descriptor           = new SolutionComponentDescriptor(_service);
            this._dependencyRepository = new DependencyRepository(this._service);
            this._descriptorHandler    = new DependencyDescriptionHandler(this._descriptor);

            this._repositoryStringMap = new StringMapRepository(_service);
        }
        public CreateFileWithEntityMetadataJavaScriptHandler(
            TextWriter writer
            , CreateFileJavaScriptConfiguration config
            , IOrganizationServiceExtented service
            ) : base(writer, config.TabSpacer, true)
        {
            this._config  = config;
            this._service = service;

            this._solutionComponentDescriptor = new SolutionComponentDescriptor(_service)
            {
                WithManagedInfo = false,
            };

            if (_config.WithDependentComponents)
            {
                this._dependencyRepository = new DependencyRepository(_service);
                this._descriptorHandler    = new DependencyDescriptionHandler(_solutionComponentDescriptor);
            }
        }
        public async Task <bool> CreateFileWithDependentComponentsAsync(DependencyRepository dependencyRepository, string connectionInfo, string filePath, ComponentType componentType, Guid idComponent, string componentName)
        {
            var coll = await dependencyRepository.GetDependentComponentsAsync((int)componentType, idComponent);

            string description = await this.GetDescriptionDependentAsync(coll);

            if (string.IsNullOrEmpty(description))
            {
                return(false);
            }

            StringBuilder content = new StringBuilder();

            content.AppendLine(connectionInfo).AppendLine();
            content.AppendFormat("Dependent Components for {0} '{1}' at {2}", componentType.ToString(), componentName, DateTime.Now.ToString("G", System.Globalization.CultureInfo.CurrentCulture)).AppendLine();

            content.Append(description);

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

            return(true);
        }
        private async Task CheckingPluginImagesRequiredComponents(ConnectionData connectionData, CommonConfiguration commonConfig)
        {
            if (connectionData == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection);
                return;
            }

            StringBuilder content = new StringBuilder();

            content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM));

            content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription()));

            // Подключаемся к CRM.
            var service = await QuickConnection.ConnectAsync(connectionData);

            if (service == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name);
                return;
            }

            content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint));

            var repository = new PluginSearchRepository(service);
            var repositoryImage = new SdkMessageProcessingStepImageRepository(service);

            var listImages = await repositoryImage.GetAllImagesAsync();

            var queryImages = listImages
                            .OrderBy(image => image.Contains("sdkmessageprocessingstep.eventhandler") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.eventhandler").Value as EntityReference).Name : "Null")
                            .ThenBy(image => image.PrimaryObjectTypeCodeName)
                            .ThenBy(image => image.SecondaryObjectTypeCodeName)
                            .ThenBy(image => image.Contains("sdkmessageprocessingstep.sdkmessageid") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.sdkmessageid").Value as EntityReference).Name : "Null", new MessageComparer())
                            .ThenBy(image => image.Contains("sdkmessageprocessingstep.stage") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.stage").Value as OptionSetValue).Value : 0)
                            .ThenBy(image => image.Contains("sdkmessageprocessingstep.mode") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.mode").Value as OptionSetValue).Value : 0)
                            .ThenBy(image => image.Contains("sdkmessageprocessingstep.rank") ? (int)image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.rank").Value : 0)
                            .ThenBy(image => image.FormattedValues.ContainsKey("sdkmessageprocessingstep.statuscode") ? image.FormattedValues["sdkmessageprocessingstep.statuscode"] : "")
                            .ThenBy(image => image.FormattedValues.ContainsKey(SdkMessageProcessingStepImage.Schema.Attributes.imagetype) ? image.FormattedValues[SdkMessageProcessingStepImage.Schema.Attributes.imagetype] : "")
                            .ThenBy(image => image.Name)
                            .ThenBy(image => image.EntityAlias)
                            .ThenBy(image => image.Attributes1StringsSorted)
                            ;

            EntityMetadataRepository repositoryMetadata = new EntityMetadataRepository(service);
            var dependencyRepository = new DependencyRepository(service);

            var listMetaData = await repositoryMetadata.GetEntitiesWithAttributesAsync();

            var dictEntity = new Dictionary<Guid, EntityMetadata>();
            var dictAttribute = new Dictionary<Guid, AttributeMetadata>();

            foreach (var metaEntity in listMetaData)
            {
                dictEntity.Add(metaEntity.MetadataId.Value, metaEntity);

                foreach (var metaAttribute in metaEntity.Attributes)
                {
                    dictAttribute.Add(metaAttribute.MetadataId.Value, metaAttribute);
                }
            }

            bool hasInfo = false;

            foreach (var image in queryImages)
            {
                var listRequired = await dependencyRepository.GetRequiredComponentsAsync((int)ComponentType.SdkMessageProcessingStepImage, image.Id);

                var stepEntities = GetSetEntites(image);
                var stepAttributes = GetSetImageAttributes(image);

                var componentsEntities = GetSetComponentsEntites(listRequired, dictEntity);
                var componentsAttributes = GetSetComponentsAttributes(listRequired, dictAttribute);

                bool entitiesIsSame = stepEntities.SequenceEqual(componentsEntities);
                bool attributesIsSame = stepAttributes.SequenceEqual(componentsAttributes);

                string pluginType = image.Contains("sdkmessageprocessingstep.eventhandler") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.eventhandler").Value as EntityReference).Name : "Null";

                string sdkMessage = image.Contains("sdkmessageprocessingstep.sdkmessageid") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.sdkmessageid").Value as EntityReference).Name : "Null";
                int stage = image.Contains("sdkmessageprocessingstep.stage") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.stage").Value as OptionSetValue).Value : 0;
                int mode = image.Contains("sdkmessageprocessingstep.mode") ? (image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.mode").Value as OptionSetValue).Value : 0;
                int rank = image.Contains("sdkmessageprocessingstep.rank") ? (int)image.GetAttributeValue<AliasedValue>("sdkmessageprocessingstep.rank").Value : 0;
                string status = image.FormattedValues.ContainsKey("sdkmessageprocessingstep.statuscode") ? image.FormattedValues["sdkmessageprocessingstep.statuscode"] : "";

                if (!entitiesIsSame || !attributesIsSame)
                {
                    hasInfo = true;

                    if (content.Length > 0)
                    {
                        content.AppendLine().AppendLine().AppendLine();
                    }

                    //handler.SetHeader("PluginType", "Primary Entity", "Secondary Entity", "Message", "Stage", "Rank", "Status", "ImageType", "Name", "EntityAlias", "Attributes");

                    content.AppendFormat("{0}   Primary {1}   Secondary {2}   Message {3}   Stage {4}   Rank {5}   Status {6}   ImageType {7}   Name {8}   EntityAlias {9}   Attributes {10}"
                        , pluginType
                        , image.PrimaryObjectTypeCodeName
                        , image.SecondaryObjectTypeCodeName
                        , sdkMessage
                        , SdkMessageProcessingStepRepository.GetStageName(stage, mode)
                        , rank.ToString()
                        , status
                        , image.FormattedValues[SdkMessageProcessingStepImage.Schema.Attributes.imagetype]
                        , image.Name
                        , image.EntityAlias
                        , image.Attributes1StringsSorted
                    ).AppendLine();

                    if (!entitiesIsSame)
                    {
                        content.AppendLine("Conflict in entites.");

                        content.Append("Entities in plugin step description");

                        if (stepEntities.Count > 0)
                        {
                            content.AppendLine(":");

                            foreach (var item in stepEntities)
                            {
                                content.AppendFormat("    {0}", item).AppendLine();
                            }
                        }
                        else
                        {
                            content.AppendLine(" are empty.");
                        }


                        content.Append("Entities in required components");

                        if (componentsEntities.Count > 0)
                        {
                            content.AppendLine(":");

                            foreach (var item in componentsEntities)
                            {
                                content.AppendFormat("    {0}", item).AppendLine();
                            }
                        }
                        else
                        {
                            content.AppendLine(" are empty.");
                        }
                    }

                    if (!attributesIsSame)
                    {
                        content.AppendLine("Conflict in attributes.");

                        content.Append("Attributes in plugin step description");

                        if (componentsEntities.Count > 0)
                        {
                            content.AppendLine(":");

                            foreach (var item in stepAttributes)
                            {
                                content.AppendFormat("    {0}", item).AppendLine();
                            }
                        }
                        else
                        {
                            content.AppendLine(" are empty.");
                        }

                        content.Append("Attributes in required components");

                        if (componentsAttributes.Count > 0)
                        {
                            content.AppendLine(":");

                            foreach (var item in componentsAttributes)
                            {
                                content.AppendFormat("    {0}", item).AppendLine();
                            }
                        }
                        else
                        {
                            content.AppendLine(" are empty.");
                        }
                    }
                }
            }

            if (!hasInfo)
            {
                content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, "No conflicts were found."));
            }

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

            if (string.IsNullOrEmpty(commonConfig.FolderForExport))
            {
                _iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FolderForExportIsEmpty);
                commonConfig.FolderForExport = FileOperations.GetDefaultFolderForExportFilePath();
            }
            else if (!Directory.Exists(commonConfig.FolderForExport))
            {
                _iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FolderForExportDoesNotExistsFormat1, commonConfig.FolderForExport);
                commonConfig.FolderForExport = FileOperations.GetDefaultFolderForExportFilePath();
            }

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

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

            this._iWriteToOutput.WriteToOutput(connectionData, "Created file with Checking Plugin Images Required Components: {0}", filePath);

            this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
        }
        private async Task CheckingPluginStepsRequiredComponents(ConnectionData connectionData, CommonConfiguration commonConfig)
        {
            if (connectionData == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.NoCurrentCRMConnection);
                return;
            }

            StringBuilder content = new StringBuilder();

            content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectingToCRM));

            content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, connectionData.GetConnectionDescription()));

            // Подключаемся к CRM.
            var service = await QuickConnection.ConnectAsync(connectionData);

            if (service == null)
            {
                this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.ConnectionFailedFormat1, connectionData.Name);
                return;
            }

            content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CurrentServiceEndpointFormat1, service.CurrentServiceEndpoint));

            var repository = new PluginSearchRepository(service);

            var search = await repository.FindAllAsync(new List<PluginStage>(), string.Empty, string.Empty, string.Empty);

            var querySteps = search.SdkMessageProcessingStep
                            .OrderBy(ent => ent.EventHandler.Name)
                            .ThenBy(ent => ent.PrimaryObjectTypeCodeName)
                            .ThenBy(ent => ent.SdkMessageId.Name, new MessageComparer())
                            .ThenBy(ent => ent.Stage.Value)
                            .ThenBy(ent => ent.Mode.Value)
                            .ThenBy(ent => ent.Rank)
                            .ThenBy(ent => ent.Name)
                            ;

            EntityMetadataRepository repositoryMetadata = new EntityMetadataRepository(service);

            DependencyRepository dependencyRepository = new DependencyRepository(service);

            var listMetaData = await repositoryMetadata.GetEntitiesWithAttributesAsync();

            var dictEntity = new Dictionary<Guid, EntityMetadata>();
            var dictAttribute = new Dictionary<Guid, AttributeMetadata>();

            bool hasInfo = false;

            foreach (var metaEntity in listMetaData)
            {
                dictEntity.Add(metaEntity.MetadataId.Value, metaEntity);

                foreach (var metaAttribute in metaEntity.Attributes)
                {
                    dictAttribute.Add(metaAttribute.MetadataId.Value, metaAttribute);
                }
            }

            foreach (var step in querySteps)
            {
                var listRequired = await dependencyRepository.GetRequiredComponentsAsync((int)ComponentType.SdkMessageProcessingStep, step.Id);

                var stepEntities = GetSetEntites(step);
                var stepAttributes = GetSetStepAttributes(step);

                var componentsEntities = GetSetComponentsEntites(listRequired, dictEntity);
                var componentsAttributes = GetSetComponentsAttributes(listRequired, dictAttribute);

                bool entitiesIsSame = stepEntities.SequenceEqual(componentsEntities);
                bool attributesIsSame = stepAttributes.SequenceEqual(componentsAttributes);

                if (!entitiesIsSame || !attributesIsSame)
                {
                    if (content.Length > 0)
                    {
                        content.AppendLine().AppendLine().AppendLine();
                    }

                    content.AppendFormat("{0}   Primary {1}   Secondary {2}   Message {3}   Stage {4}   Rank {5}   Status {6}   FilteringAttributes {7}",
                        step.EventHandler?.Name ?? "Unknown"
                        , step.PrimaryObjectTypeCodeName
                        , step.SecondaryObjectTypeCodeName
                        , step.SdkMessageId?.Name ?? "Unknown"
                        , SdkMessageProcessingStepRepository.GetStageName(step.Stage.Value, step.Mode.Value)
                        , step.Rank.ToString()
                        , step.FormattedValues[SdkMessageProcessingStep.Schema.Attributes.statuscode]
                        , step.FilteringAttributesStringsSorted
                    ).AppendLine();

                    if (!entitiesIsSame)
                    {
                        hasInfo = true;

                        content.AppendLine("Conflict in entites.");

                        content.Append("Entities in plugin step description");

                        if (stepEntities.Count > 0)
                        {
                            content.AppendLine(":");

                            foreach (var item in stepEntities)
                            {
                                content.AppendFormat("    {0}", item).AppendLine();
                            }
                        }
                        else
                        {
                            content.AppendLine(" are empty.");
                        }


                        content.Append("Entities in required components");

                        if (componentsEntities.Count > 0)
                        {
                            content.AppendLine(":");

                            foreach (var item in componentsEntities)
                            {
                                content.AppendFormat("    {0}", item).AppendLine();
                            }
                        }
                        else
                        {
                            content.AppendLine(" are empty.");
                        }
                    }

                    if (!attributesIsSame)
                    {
                        hasInfo = true;

                        content.AppendLine("Conflict in attributes.");

                        content.Append("Attributes in plugin step description");

                        if (componentsEntities.Count > 0)
                        {
                            content.AppendLine(":");

                            foreach (var item in stepAttributes)
                            {
                                content.AppendFormat("    {0}", item).AppendLine();
                            }
                        }
                        else
                        {
                            content.AppendLine(" are empty.");
                        }

                        content.Append("Attributes in required components");

                        if (componentsAttributes.Count > 0)
                        {
                            content.AppendLine(":");

                            foreach (var item in componentsAttributes)
                            {
                                content.AppendFormat("    {0}", item).AppendLine();
                            }
                        }
                        else
                        {
                            content.AppendLine(" are empty.");
                        }
                    }
                }
            }

            if (!hasInfo)
            {
                content.AppendLine(this._iWriteToOutput.WriteToOutput(connectionData, "No conflicts were found."));
            }

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

            if (string.IsNullOrEmpty(commonConfig.FolderForExport))
            {
                _iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FolderForExportIsEmpty);
                commonConfig.FolderForExport = FileOperations.GetDefaultFolderForExportFilePath();
            }
            else if (!Directory.Exists(commonConfig.FolderForExport))
            {
                _iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FolderForExportDoesNotExistsFormat1, commonConfig.FolderForExport);
                commonConfig.FolderForExport = FileOperations.GetDefaultFolderForExportFilePath();
            }

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

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

            this._iWriteToOutput.WriteToOutput(connectionData, "Created file with Checking Plugin Steps Required Components: {0}", filePath);

            this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
        }
Exemplo n.º 11
0
        private async Task CheckingGlobalOptionSetDuplicates(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 entityMetadataSource = new SolutionComponentMetadataSource(service);

            var descriptor = new SolutionComponentDescriptor(service);

            descriptor.WithUrls          = true;
            descriptor.WithManagedInfo   = true;
            descriptor.WithSolutionsInfo = true;

            var dependencyRepository = new DependencyRepository(service);
            var descriptorHandler    = new DependencyDescriptionHandler(descriptor);

            RetrieveAllOptionSetsRequest request = new RetrieveAllOptionSetsRequest();

            RetrieveAllOptionSetsResponse response = (RetrieveAllOptionSetsResponse)service.Execute(request);

            bool hasInfo = false;

            foreach (var optionSet in response.OptionSetMetadata.OfType <OptionSetMetadata>().OrderBy(e => e.Name))
            {
                var coll = await dependencyRepository.GetDependentComponentsAsync((int)ComponentType.OptionSet, optionSet.MetadataId.Value);

                if (coll.Any())
                {
                    var filter = coll
                                 .Where(c => c.DependentComponentType.Value == (int)ComponentType.Attribute)
                                 .Select(c => new { Dependency = c, Attribute = entityMetadataSource.GetAttributeMetadata(c.DependentComponentObjectId.Value) })
                                 .Where(c => c.Attribute != null)
                                 .GroupBy(c => c.Attribute.EntityLogicalName)
                                 .Where(gr => gr.Count() > 1)
                                 .SelectMany(gr => gr.Select(c => c.Dependency))
                                 .ToList()
                    ;

                    if (filter.Any())
                    {
                        var desc = await descriptorHandler.GetDescriptionDependentAsync(filter);

                        if (!string.IsNullOrEmpty(desc))
                        {
                            if (content.Length > 0)
                            {
                                content
                                .AppendLine(new string('-', 150))
                                .AppendLine();
                            }

                            hasInfo = true;

                            content.AppendFormat("Global OptionSet Name {0}       IsCustomOptionSet {1}      IsManaged {2}", optionSet.Name, optionSet.IsCustomOptionSet, optionSet.IsManaged).AppendLine();

                            content.AppendLine(desc);
                        }
                    }
                }
            }

            if (!hasInfo)
            {
                content.AppendLine("No duplicates were found.");
            }

            commonConfig.CheckFolderForExportExists(this._iWriteToOutput);

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

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

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

            this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CreatedFileWithCheckingGlobalOptionSetDuplicatesOnEntityFormat1, filePath);

            this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
        }
Exemplo n.º 12
0
        private async Task ShowingWebResourcesDependentComponents(ConnectionData connectionData, CommonConfiguration commonConfig, List <SelectedFile> selectedFiles)
        {
            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 descriptor = new SolutionComponentDescriptor(service);

            descriptor.WithUrls          = true;
            descriptor.WithManagedInfo   = true;
            descriptor.WithSolutionsInfo = true;

            var descriptorHandler = new DependencyDescriptionHandler(descriptor);

            var dependencyRepository = new DependencyRepository(service);

            bool isconnectionDataDirty = false;

            List <string> listNotExistsOnDisk        = new List <string>();
            List <string> listNotFoundedInCRMNoLink  = new List <string>();
            List <string> listLastLinkEqualByContent = new List <string>();

            List <SolutionComponent> webResourceNames = new List <SolutionComponent>();

            Dictionary <SolutionComponent, string> webResourceDescriptions = new Dictionary <SolutionComponent, string>();

            WebResourceRepository repositoryWebResource = new WebResourceRepository(service);

            FormatTextTableHandler tableWithoutDependenComponents = new FormatTextTableHandler();

            tableWithoutDependenComponents.SetHeader("FilePath", "Web Resource Name", "Web Resource Type");

            var groups = selectedFiles.GroupBy(sel => sel.Extension);

            foreach (var gr in groups)
            {
                var names = gr.Select(sel => sel.FriendlyFilePath).ToArray();

                var dict = repositoryWebResource.FindMultiple(gr.Key, names);

                foreach (var selectedFile in gr)
                {
                    if (File.Exists(selectedFile.FilePath))
                    {
                        string name = selectedFile.FriendlyFilePath.ToLower();

                        var webresource = WebResourceRepository.FindWebResourceInDictionary(dict, name, gr.Key);

                        if (webresource == null)
                        {
                            Guid?webId = connectionData.GetLastLinkForFile(selectedFile.FriendlyFilePath);

                            if (webId.HasValue)
                            {
                                webresource = await repositoryWebResource.GetByIdAsync(webId.Value);

                                if (webresource != null)
                                {
                                    listLastLinkEqualByContent.Add(selectedFile.FriendlyFilePath);
                                }
                            }
                        }

                        if (webresource != null)
                        {
                            // Запоминается файл
                            isconnectionDataDirty = true;
                            connectionData.AddMapping(webresource.Id, selectedFile.FriendlyFilePath);

                            var coll = await dependencyRepository.GetDependentComponentsAsync((int)ComponentType.WebResource, webresource.Id);

                            var desc = await descriptorHandler.GetDescriptionDependentAsync(coll);

                            if (!string.IsNullOrEmpty(desc))
                            {
                                var component = new SolutionComponent()
                                {
                                    ComponentType = new OptionSetValue((int)ComponentType.WebResource),
                                    ObjectId      = webresource.Id,
                                };

                                webResourceNames.Add(component);

                                webResourceDescriptions.Add(component, desc);
                            }
                            else
                            {
                                tableWithoutDependenComponents.AddLine(selectedFile.FriendlyFilePath, webresource.Name, "'" + webresource.FormattedValues[WebResource.Schema.Attributes.webresourcetype] + "'");
                            }
                        }
                        else
                        {
                            connectionData.RemoveMapping(selectedFile.FriendlyFilePath);

                            listNotFoundedInCRMNoLink.Add(selectedFile.FriendlyFilePath);
                        }
                    }
                    else
                    {
                        listNotExistsOnDisk.Add(selectedFile.FilePath);
                    }
                }
            }

            if (isconnectionDataDirty)
            {
                //Сохранение настроек после публикации
                connectionData.Save();
            }

            FindsController.WriteToContentList(listNotFoundedInCRMNoLink, content, "File NOT FOUNDED in CRM: {0}");

            FindsController.WriteToContentList(listLastLinkEqualByContent, content, "Files NOT FOUNDED in CRM, but has Last Link: {0}");

            FindsController.WriteToContentList(listNotExistsOnDisk, content, Properties.OutputStrings.FileNotExistsFormat1);

            FindsController.WriteToContentList(tableWithoutDependenComponents.GetFormatedLines(true), content, "Files without dependent components: {0}");

            FindsController.WriteToContentDictionary(descriptor, content, webResourceNames, webResourceDescriptions, "WebResource dependent components: {0}");

            commonConfig.CheckFolderForExportExists(this._iWriteToOutput);

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

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

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

            this._iWriteToOutput.WriteToOutput(connectionData, Properties.OutputStrings.CreatedFileWithWebResourcesDependentComponentsFormat1, filePath);

            this._iWriteToOutput.PerformAction(service.ConnectionData, filePath);
        }
Exemplo n.º 13
0
 public EntityAttributesDependentComponentsHandler(DependencyRepository dependencyRepository, SolutionComponentDescriptor descriptor, DependencyDescriptionHandler descriptorHandler)
 {
     this._dependencyRepository = dependencyRepository;
     this._descriptor           = descriptor;
     this._descriptorHandler    = descriptorHandler;
 }
Exemplo n.º 14
0
 public GraphRepository(IDbConnection dbConnection, PointRepository pointRepository, DependencyRepository dependencyRepository) : base(dbConnection)
 {
 }