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); }
private string CreateValidTypeName(string name) { var text = NamingService.CreateValidName(name); if (this._nameMap.ContainsKey(text)) { var num = this._nameMap[text]; num++; this._nameMap[text] = num; return(string.Format(CultureInfo.InvariantCulture, "{0}{1}", text, num)); } this._nameMap.Add(name, 0); return(text); }
async Task <string> INamingService.GetNameForOptionAsync(OptionSetMetadataBase optionSetMetadata, OptionMetadata optionMetadata, IServiceProvider services) { await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStartAsync("Entering {0}", MethodBase.GetCurrentMethod().Name); if (optionMetadata.Value != null && (optionSetMetadata.MetadataId != null && this._knowNames.ContainsKey(optionSetMetadata.MetadataId.Value.ToString() + optionMetadata.Value.Value.ToString(CultureInfo.InvariantCulture)))) { await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStopAsync("Exiting {0}", MethodBase.GetCurrentMethod().Name); return(this._knowNames[optionSetMetadata.MetadataId.Value.ToString() + optionMetadata.Value.Value.ToString(CultureInfo.InvariantCulture)]); } var text = string.Empty; if (optionMetadata is StateOptionMetadata stateOptionMetadata) { text = stateOptionMetadata.InvariantName; } else { foreach (var localizedLabel in optionMetadata.Label.LocalizedLabels) { if (localizedLabel.LanguageCode == 1033) { text = localizedLabel.Label; } } } if (string.IsNullOrEmpty(text)) { text = string.Format(CultureInfo.InvariantCulture, "UnknownLabel{0}", optionMetadata.Value.Value); } text = NamingService.CreateValidName(text); if (optionSetMetadata.MetadataId != null) { if (optionMetadata.Value != null) { this._knowNames.Add( optionSetMetadata.MetadataId.Value.ToString() + optionMetadata.Value.Value.ToString(CultureInfo.InvariantCulture), text); } } await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStopAsync("Exiting {0}", MethodBase.GetCurrentMethod().Name); return(text); }
async Task <string> INamingService.GetNameForResponseFieldAsync(SdkMessageResponse response, SdkMessageResponseField responseField, IServiceProvider services) { await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStartAsync("Entering {0}", MethodBase.GetCurrentMethod().Name); if (this._knowNames.ContainsKey(response.Id.ToString() + responseField.Index.ToString(CultureInfo.InvariantCulture))) { await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStopAsync("Exiting {0}", MethodBase.GetCurrentMethod().Name); return(this._knowNames[response.Id.ToString() + responseField.Index.ToString(CultureInfo.InvariantCulture)]); } var text = NamingService.CreateValidName(responseField.Name); this._knowNames.Add(response.Id.ToString() + responseField.Index.ToString(CultureInfo.InvariantCulture), text); await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStopAsync("Exiting {0}", MethodBase.GetCurrentMethod().Name); return(text); }
async Task <string> INamingService.GetNameForRelationshipAsync(EntityMetadata entityMetadata, RelationshipMetadataBase relationshipMetadata, EntityRole?reflexiveRole, IServiceProvider services) { await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStartAsync("Entering {0}", MethodBase.GetCurrentMethod().Name); var arg = (reflexiveRole != null) ? reflexiveRole.Value.ToString() : string.Empty; if (relationshipMetadata.MetadataId != null && (entityMetadata.MetadataId != null && this._knowNames.ContainsKey(entityMetadata.MetadataId.Value.ToString() + relationshipMetadata.MetadataId.Value + arg))) { await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStopAsync("Exiting {0}", MethodBase.GetCurrentMethod().Name); return(this._knowNames[entityMetadata.MetadataId.Value.ToString() + relationshipMetadata.MetadataId.Value + arg]); } var text = (reflexiveRole == null) ? relationshipMetadata.SchemaName : ((reflexiveRole.Value == EntityRole.Referenced) ? ("Referenced" + relationshipMetadata.SchemaName) : ("Referencing" + relationshipMetadata.SchemaName)); text = NamingService.CreateValidName(text); var dictionary = (from d in this._knowNames where entityMetadata.MetadataId != null && d.Key.StartsWith(entityMetadata.MetadataId.Value.ToString()) select d).ToDictionary((KeyValuePair <string, string> d) => d.Key, (KeyValuePair <string, string> d) => d.Value); var namingService = (INamingService)services?.GetService(typeof(INamingService)); if (this._reservedAttributeNames.Contains(text) || text == await namingService.GetNameForEntityAsync(entityMetadata, services) || dictionary.ContainsValue(text)) { text += "1"; } if (entityMetadata.MetadataId != null) { if (relationshipMetadata.MetadataId != null) { this._knowNames.Add( entityMetadata.MetadataId.Value.ToString() + relationshipMetadata.MetadataId.Value + arg, text); } } await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStopAsync("Exiting {0}", MethodBase.GetCurrentMethod().Name); return(text); }