Exemple #1
0
        async Task <string> INamingService.GetNameForAttributeAsync(EntityMetadata entityMetadata,
                                                                    AttributeMetadata attributeMetadata, IServiceProvider services)
        {
            await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStartAsync("Entering {0}", MethodBase.GetCurrentMethod().Name);

            if (attributeMetadata.MetadataId != null && (entityMetadata.MetadataId != null && this._knowNames.ContainsKey(entityMetadata.MetadataId.Value.ToString() + attributeMetadata.MetadataId.Value)))
            {
                await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStopAsync("Exiting {0}", MethodBase.GetCurrentMethod().Name);

                return(this._knowNames[entityMetadata.MetadataId.Value.ToString() + attributeMetadata.MetadataId.Value]);
            }
            var text = StaticNamingService.GetNameForAttribute(attributeMetadata) ?? attributeMetadata.SchemaName;

            text = NamingService.CreateValidName(text);
            var namingService = (INamingService)services?.GetService(typeof(INamingService));

            if (this._reservedAttributeNames.Contains(text) || text == await namingService.GetNameForEntityAsync(entityMetadata, services))
            {
                text += "1";
            }

            if (entityMetadata.MetadataId != null)
            {
                if (attributeMetadata.MetadataId != null)
                {
                    this._knowNames.Add(entityMetadata.MetadataId.Value.ToString() + attributeMetadata.MetadataId.Value,
                                        text);
                }
            }
            await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStopAsync("Exiting {0}", MethodBase.GetCurrentMethod().Name);

            return(text);
        }