Example #1
0
        /// <summary>
        /// Populates the type with ck related attributes and associations
        /// </summary>
        /// <param name="entityDtoCache">The entity type cache</param>
        /// <param name="entityCacheItem">The cache item</param>
        public void Populate(IGraphTypesCache entityDtoCache, EntityCacheItem entityCacheItem)
        {
            AddConstructionKit(entityCacheItem);

            foreach (var attribute in entityCacheItem.Attributes.Values)
            {
                AddAttribute(attribute);
            }

            foreach (var cacheItems in entityCacheItem.OutboundAssociations)
            {
                var    allowedTypes = cacheItems.Value.SelectMany(x => x.AllowedTypes).ToList();
                string name         = cacheItems.Key;
                if (!allowedTypes.Any())
                {
                    continue; // All Ck entities are abstract for that associations
                }

                this.AssociationField(entityDtoCache, name, allowedTypes.Select(x => x.CkId).Distinct().ToList(), cacheItems.Value.First().RoleId, GraphDirections.Outbound);
            }

            foreach (var cacheItems in entityCacheItem.InboundAssociations)
            {
                var    allowedTypes = cacheItems.Value.SelectMany(x => x.AllowedTypes).ToList();
                string name         = cacheItems.Key;
                if (!allowedTypes.Any())
                {
                    continue; // All Ck entities are abstract for that associations
                }

                this.AssociationField(entityDtoCache, name, allowedTypes.Select(x => x.CkId).Distinct().ToList(), cacheItems.Value.First().RoleId, GraphDirections.Inbound);
            }
        }
        /// <summary>
        /// Populates the type with ck related attributes and associations
        /// </summary>
        /// <param name="entityCacheItem">The cache item</param>
        public void Populate(EntityCacheItem entityCacheItem)
        {
            foreach (var attribute in entityCacheItem.Attributes.Values)
            {
                AddAttribute(attribute);
            }

            foreach (var cacheItems in entityCacheItem.OutboundAssociations)
            {
                var    allowedTypes = cacheItems.Value.SelectMany(x => x.AllowedTypes).ToList();
                string name         = cacheItems.Key;
                if (!allowedTypes.Any())
                {
                    continue; // All Ck entities are abstract for that assocs
                }

                AddAssociation(name);
            }

            foreach (var cacheItems in entityCacheItem.InboundAssociations)
            {
                var    allowedTypes = cacheItems.Value.SelectMany(x => x.AllowedTypes).ToList();
                string name         = cacheItems.Key;
                if (!allowedTypes.Any())
                {
                    continue; // All Ck entities are abstract for that assocs
                }

                AddAssociation(name);
            }
        }
        // ReSharper disable once UnusedMethodReturnValue.Local
        private bool TryHandleOutboundAssoc(RtEntity rtEntity, EntityCacheItem entityCacheItem, KeyValuePair <string, object> item, List <AssociationUpdateInfo> associations)
        {
            var assocName = item.Key;

            var associationCacheItem = entityCacheItem.OutboundAssociations.Values.SelectMany(x => x).FirstOrDefault(a => a.Name == assocName);

            if (associationCacheItem == null)
            {
                return(false);
            }

            var rtAssociationInputDtos = (IEnumerable <object>)item.Value;

            foreach (RtAssociationInputDto rtAssociationDto in rtAssociationInputDtos)
            {
                var assocInfo = new AssociationUpdateInfo(
                    rtEntity.ToRtEntityId(),
                    rtAssociationDto.Target,
                    associationCacheItem.RoleId,
                    rtAssociationDto.ModOption ?? AssociationModOptionsDto.Create);
                associations.Add(assocInfo);
            }

            return(true);
        }
 internal HierarchicalRtStatementCreator(EntityCacheItem entityCacheItem, IDatabaseContext databaseContext,
                                         string language, ObjectId rtId, GraphDirections graphDirections, string targetCkId) : base(entityCacheItem, databaseContext, language)
 {
     _databaseContext = databaseContext;
     _rtId            = rtId;
     _graphDirections = graphDirections;
     _targetCkId      = targetCkId;
 }
        internal static CkEntityDto CreateCkEntityDto(EntityCacheItem entityCacheItem)
        {
            var ckEntityDto = new CkEntityDto
            {
                CkId       = entityCacheItem.CkId,
                TypeName   = entityCacheItem.CkId.GetGraphQLName(),
                IsFinal    = entityCacheItem.IsFinal,
                IsAbstract = entityCacheItem.IsAbstract,
                ScopeId    = (ScopeIdsDto)entityCacheItem.ScopeId
            };

            return(ckEntityDto);
        }
        private bool TryHandleAttribute(RtEntity rtEntity, EntityCacheItem entityCacheItem, KeyValuePair <string, object> item)
        {
            var attributeName = item.Key;

            var attributeCacheItem = entityCacheItem.Attributes.Values.FirstOrDefault(a => a.AttributeName == attributeName);

            if (attributeCacheItem == null)
            {
                return(false);
            }

            rtEntity.SetAttributeValue(attributeCacheItem.AttributeName, attributeCacheItem.AttributeValueType, item.Value);
            return(true);
        }
Example #7
0
        private TEntity CreateTransientRtEntity <TEntity>(EntityCacheItem entityCacheItem)
            where TEntity : RtEntity, new()
        {
            ArgumentValidation.Validate(nameof(entityCacheItem), entityCacheItem);

            var rtEntity = new TEntity
            {
                RtId = ObjectId.GenerateNewId(),
                CkId = entityCacheItem.CkId
            };

            foreach (var attributeCacheItem in entityCacheItem.Attributes.Values)
            {
                object value = attributeCacheItem.DefaultValue ?? attributeCacheItem.DefaultValues?.ToList();
                rtEntity.SetAttributeValue(attributeCacheItem.AttributeName, attributeCacheItem.AttributeValueType,
                                           value);
            }

            return(rtEntity);
        }
        private void TransformOptionSets(CodeMemberProperty member, EntityCacheItem entity, AttributeCacheItem attribute)
        {
            AttributeMetadata attributeMetadata = attribute.Metadata;

            if (entity != null && attributeMetadata != null)
            {
                if (attributeMetadata is EnumAttributeMetadata)
                {
                    string typeName;
                    EnumAttributeMetadata enumMetadata = attributeMetadata as EnumAttributeMetadata;
                    OptionSetCacheItem    optionSet    = DynamicsMetadataCache.OptionSets.GetBy(entity.LogicalName, enumMetadata.OptionSet.Name);

                    if (optionSet == null)
                    {
                        optionSet = DynamicsMetadataCache.OptionSets.GetBy("*", enumMetadata.OptionSet.Name);
                    }

                    if (optionSet != null)
                    {
                        typeName = optionSet.GeneratedTypeName;
                    }
                    else
                    {
                        var namingService = (INamingService)serviceProvider.GetService(typeof(INamingService));

                        typeName = namingService.GetNameForOptionSet(entity.Metadata, enumMetadata.OptionSet, serviceProvider);
                    }

                    if (!this.addedEnums.ContainsKey(typeName))
                    {
                        this.addedEnums.Add(typeName, enumMetadata);
                    }

                    FixEnums(member, enumMetadata, typeName);
                }
                else
                {
                    member.Type = new CodeTypeReference("int?");
                }
            }
        }
Example #9
0
        private static void TransformOptionSets(CodeTypeMember member, EntityCacheItem entity, AttributeCacheItem attribute)
        {
            var codeProperty = (CodeMemberProperty)member;

            if (member.Name.ToLower() == "statecode" || codeProperty.Type.BaseType != "Microsoft.Xrm.Sdk.OptionSetValue")
            {
                return;
            }

            OptionSetCacheItem optionSet         = null;
            AttributeMetadata  attributeMetadata = attribute.Metadata;

            if (entity != null && attributeMetadata != null)
            {
                if (attributeMetadata is EnumAttributeMetadata)
                {
                    FixEnums(codeProperty, (EnumAttributeMetadata)attributeMetadata, optionSet);
                }
                else
                {
                    codeProperty.Type = new CodeTypeReference("int?");
                }
            }
        }
Example #10
0
 public RtEntity CreateTransientRtEntity(EntityCacheItem entityCacheItem)
 {
     return(CreateTransientRtEntity <RtEntity>(entityCacheItem));
 }
Example #11
0
 private void AddConstructionKit(EntityCacheItem entityCacheItem)
 {
     Field(typeof(CkEntityDtoType), "ConstructionKitType", resolve: ResolveCkEntity)
     .AddMetadata(Statics.EntityCacheItem, entityCacheItem);
 }
Example #12
0
 internal RtStatementCreator(EntityCacheItem entityCacheItem, IDatabaseContext databaseContext, string language)
     : base(entityCacheItem, databaseContext, language)
 {
 }