public Task <string> GenerateDocumentIdAsync(object entity) { var typeTagName = _conventions.GetCollectionName(entity); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags { return(NullStringCompletedTask); } var tag = _conventions.TransformTypeCollectionNameToDocumentIdPrefix(typeTagName); AsyncHiLoIdGenerator value; if (_idGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentIdAsync(entity)); } lock (_generatorLock) { if (_idGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentIdAsync(entity)); } value = new AsyncHiLoIdGenerator(tag, _store, _dbName, _conventions.IdentityPartsSeparator); _idGeneratorsByTag.TryAdd(tag, value); } return(value.GenerateDocumentIdAsync(entity)); }
public Task <string> GenerateDocumentIdAsync(object entity) { var typeTagName = Conventions.GetCollectionName(entity); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags { return(NullStringCompletedTask); } var tag = Conventions.TransformTypeCollectionNameToDocumentIdPrefix(typeTagName); if (_idGeneratorsByTag.TryGetValue(tag, out var value)) { return(value.GenerateDocumentIdAsync(entity)); } lock (_generatorLock) { if (_idGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentIdAsync(entity)); } value = CreateGeneratorFor(tag); _idGeneratorsByTag.TryAdd(tag, value); } return(value.GenerateDocumentIdAsync(entity)); }
public static string GetPrefixedIncludePath <TInclude>(string basePath, DocumentConventions conventions) { var idPrefix = conventions.GetCollectionName(typeof(TInclude)); if (idPrefix != null) { idPrefix = conventions.TransformTypeCollectionNameToDocumentIdPrefix(idPrefix); idPrefix += conventions.IdentityPartsSeparator; } return(basePath + "(" + idPrefix + ")"); }
public async Task <string> GenerateDocumentIdAsync(object entity) { var identityPartsSeparator = Conventions.IdentityPartsSeparator; if (_identityPartsSeparator != identityPartsSeparator) { await MaybeRefresh(identityPartsSeparator).ConfigureAwait(false); } var typeTagName = Conventions.GetCollectionName(entity); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags { return(null); } var tag = Conventions.TransformTypeCollectionNameToDocumentIdPrefix(typeTagName); if (_idGeneratorsByTag.TryGetValue(tag, out var value)) { return(await value.GenerateDocumentIdAsync(entity).ConfigureAwait(false)); } await _generatorLock.WaitAsync().ConfigureAwait(false); try { if (_idGeneratorsByTag.TryGetValue(tag, out value)) { return(await value.GenerateDocumentIdAsync(entity).ConfigureAwait(false)); } value = CreateGeneratorFor(tag); _idGeneratorsByTag.TryAdd(tag, value); } finally { _generatorLock.Release(); } return(await value.GenerateDocumentIdAsync(entity).ConfigureAwait(false)); }