Beispiel #1
0
        private RtEntityAttributeDto CreateRtEntityAttributeDto(RtEntity rtEntity,
                                                                AttributeCacheItem attributeCacheItem)
        {
            var attributeDto = new RtEntityAttributeDto
            {
                AttributeName = attributeCacheItem.AttributeName.ToCamelCase(),
                Value         = rtEntity.GetAttributeValueOrDefault(attributeCacheItem.AttributeName),
                UserContext   = attributeCacheItem
            };

            return(attributeDto);
        }
        private CkEntityAttributeDto CreateCkEntityAttributeDto(AttributeCacheItem attributeCacheItem)
        {
            var ckEntityAttributeDto = new CkEntityAttributeDto
            {
                AttributeId            = attributeCacheItem.AttributeId,
                AttributeName          = StringExtensions.ToCamelCase(attributeCacheItem.AttributeName),
                AttributeValueType     = (AttributeValueTypesDto)attributeCacheItem.AttributeValueType,
                IsAutoCompleteEnabled  = attributeCacheItem.IsAutoCompleteEnabled,
                AutoCompleteTexts      = attributeCacheItem.AutoCompleteTexts,
                AutoCompleteFilter     = attributeCacheItem.AutoCompleteFilter,
                AutoCompleteLimit      = attributeCacheItem.AutoCompleteLimit,
                AutoIncrementReference = attributeCacheItem.AutoIncrementReference,
                Attribute = CkAttributeDtoType.CreateCkAttributeDto(attributeCacheItem)
            };

            return(ckEntityAttributeDto);
        }
        internal static CkAttributeDto CreateCkAttributeDto(AttributeCacheItem attributeCacheItem)
        {
            var attributeDto = new CkAttributeDto
            {
                AttributeId        = attributeCacheItem.AttributeId,
                ScopeId            = (ScopeIdsDto)attributeCacheItem.ScopeId,
                AttributeValueType = (AttributeValueTypesDto)attributeCacheItem.AttributeValueType,
                DefaultValue       = attributeCacheItem.DefaultValue,
                DefaultValues      = attributeCacheItem.DefaultValues,
                SelectionValues    = attributeCacheItem.SelectionValues
                                     ?.Select(sv => new CkSelectionValueDto {
                    Key = sv.Key, Name = sv.Name
                }).ToList(),
            };

            return(attributeDto);
        }
Beispiel #4
0
        private void AddAttribute(AttributeCacheItem attributeCacheItem)
        {
            Expression <Func <RtEntityDto, object> > scalarValueExpression = dto => ((RtEntity)dto.UserContext).GetAttributeValueOrDefault(attributeCacheItem.AttributeName, null);

            Expression <Func <RtEntityDto, ICollection <object> > > compoundValueExpression = dto =>
                                                                                              (ICollection <object>)((RtEntity)dto.UserContext).GetAttributeValueOrDefault(attributeCacheItem.AttributeName, null);

            var attributeName = attributeCacheItem.AttributeName;

            switch (attributeCacheItem.AttributeValueType)
            {
            case AttributeValueTypes.String:
                Field(attributeName, type: typeof(StringGraphType), expression: scalarValueExpression);
                break;

            case AttributeValueTypes.StringArray:
                Field(attributeName, type: typeof(ListGraphType <StringGraphType>),
                      expression: compoundValueExpression);
                break;

            case AttributeValueTypes.Int:
                Field(attributeName, type: typeof(IntGraphType), expression: scalarValueExpression);
                break;

            case AttributeValueTypes.IntArray:
                Field(attributeName, type: typeof(ListGraphType <IntGraphType>),
                      expression: compoundValueExpression);
                break;

            case AttributeValueTypes.Boolean:
                Field(attributeName, type: typeof(BooleanGraphType), expression: scalarValueExpression);
                break;

            case AttributeValueTypes.Double:
                Field(attributeName, type: typeof(DecimalGraphType), expression: scalarValueExpression);
                break;

            case AttributeValueTypes.DateTime:
                Field(attributeName, type: typeof(DateTimeGraphType), expression: scalarValueExpression);
                break;

            default:
                throw new NotImplementedException("Type is not supported for RT Entity GraphQL implementation");
            }
        }
        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?");
                }
            }
        }
Beispiel #6
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?");
                }
            }
        }