public override void FillSolutionComponent(ICollection <SolutionComponent> result, SolutionImageComponent solutionImageComponent)
        {
            if (solutionImageComponent == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(solutionImageComponent.SchemaName) &&
                !string.IsNullOrEmpty(solutionImageComponent.ParentSchemaName) &&
                int.TryParse(solutionImageComponent.ParentSchemaName, out var langCode)
                )
            {
                string key      = solutionImageComponent.SchemaName;
                int?   behavior = solutionImageComponent.RootComponentBehavior;

                var repository = new DisplayStringRepository(_service);

                var entity = repository.GetByKeyAndLanguage(key, langCode, new ColumnSet(false));

                if (entity != null)
                {
                    FillSolutionComponentInternal(result, entity.Id, behavior);
                }
            }
        }
Пример #2
0
        protected override async Task <List <DisplayString> > GetDisplayStringAsync(IOrganizationServiceExtented service)
        {
            List <DisplayString> result = new List <DisplayString>();

            var descriptor = new SolutionComponentDescriptor(service);
            var repository = new DisplayStringRepository(service);

            var imageComponents = _solutionImage.Components.Where(c => c.ComponentType == (int)ComponentType.DisplayString);

            if (imageComponents.Any())
            {
                var solutionComponents = await descriptor.GetSolutionComponentsListAsync(imageComponents);

                if (solutionComponents.Any())
                {
                    var tempList = await repository.GetListByIdListAsync(solutionComponents.Select(s => s.ObjectId.Value), new ColumnSet(true));

                    result.AddRange(tempList);
                }
            }

            var hashSet = new HashSet <Guid>(result.Select(c => c.Id));

            imageComponents = _solutionImage.Components.Where(c => c.ComponentType == (int)ComponentType.Entity);

            if (imageComponents.Any())
            {
                var solutionComponents = await descriptor.GetSolutionComponentsListAsync(imageComponents);

                if (solutionComponents.Any())
                {
                    var entities = solutionComponents
                                   .Where(c => c.RootComponentBehaviorEnum.GetValueOrDefault(SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0) == SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0 &&
                                          c.ObjectId.HasValue)
                                   .Select(e => descriptor.MetadataSource.GetEntityMetadata(e.ObjectId.Value))
                                   .Where(e => e != null)
                                   .Select(e => e.LogicalName)
                                   .ToArray();

                    if (entities.Any())
                    {
                        var tempList = await repository.GetListForEntitiesAsync(entities, new ColumnSet(true));

                        foreach (var item in tempList)
                        {
                            if (hashSet.Add(item.Id))
                            {
                                result.Add(item);
                            }
                        }
                    }
                }
            }

            return(result);
        }
        private void FillDisplayStringsFromCustomization(ICollection <SolutionComponent> result, EntityMetadata metaData, XElement elementEntity)
        {
            var repository = new DisplayStringRepository(_source.Service);

            var elements = elementEntity.XPathSelectElements("./Strings/Strings");

            foreach (var stringKey in elements)
            {
                if (stringKey.Attribute("ResourceKey") == null || string.IsNullOrEmpty((string)stringKey.Attribute("ResourceKey")))
                {
                    continue;
                }

                string key = (string)stringKey.Attribute("ResourceKey");

                foreach (var item in stringKey.Elements("String"))
                {
                    if (item.Attribute("languagecode") == null ||
                        string.IsNullOrEmpty((string)item.Attribute("languagecode")) ||
                        !int.TryParse((string)item.Attribute("languagecode"), out var langCode)
                        )
                    {
                        continue;
                    }

                    var entity = repository.GetByKeyAndLanguage(key, langCode, ColumnSetInstances.None);

                    if (entity != null)
                    {
                        var component = new SolutionComponent()
                        {
                            ComponentType = new OptionSetValue((int)ComponentType.DisplayString),

                            ObjectId = entity.Id,

                            RootComponentBehaviorEnum = SolutionComponent.Schema.OptionSets.rootcomponentbehavior.Include_Subcomponents_0,
                        };

                        result.Add(component);
                    }
                }
            }
        }