public GetTypeTagName ( |
||
type | ||
Результат | string |
public static void SetupConventions(DocumentConvention conventions) { conventions.TransformTypeTagNameToDocumentKeyPrefix = typeTagName => typeTagName; conventions.RegisterIdConvention<SiddurSnippet>((commands, snippet) => string.Format("{0}/{1}", conventions.GetTypeTagName(snippet.GetType()), snippet.Slug)); conventions.RegisterIdConvention<SiddurPrayer>((commands, prayer) => string.Format("{0}/{1}", conventions.GetTypeTagName(prayer.GetType()), prayer.Slug)); }
/// <summary> /// Generates the document key. /// </summary> /// <param name="conventions">The conventions.</param> /// <param name="entity">The entity.</param> /// <returns></returns> public string GenerateDocumentKey(DocumentConvention conventions, object entity) { var typeTagName = conventions.GetTypeTagName(entity.GetType()); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags return null; var tag = conventions.TransformTypeTagNameToDocumentKeyPrefix(typeTagName); HiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) return value.GenerateDocumentKey(conventions, entity); lock(generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) return value.GenerateDocumentKey(conventions, entity); value = new HiLoKeyGenerator(DatabaseCommands, tag, capacity); // doing it this way for thread safety keyGeneratorsByTag = new Dictionary<string, HiLoKeyGenerator>(keyGeneratorsByTag) { {tag, value} }; } return value.GenerateDocumentKey(conventions, entity); }
/// <summary> /// Generates the document key. /// </summary> /// <param name="conventions">The conventions.</param> /// <param name="entity">The entity.</param> /// <returns></returns> public string GenerateDocumentKey(DocumentConvention conventions, object entity) { var typeTagName = conventions.GetTypeTagName(entity.GetType()); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags { return(null); } var tag = typeTagName.ToLowerInvariant(); HiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKey(conventions, entity)); } lock (generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKey(conventions, entity)); } value = new HiLoKeyGenerator(documentStore, tag, capacity); // doing it this way for thread safety keyGeneratorsByTag = new Dictionary <string, HiLoKeyGenerator>(keyGeneratorsByTag) { { tag, value } }; } return(value.GenerateDocumentKey(conventions, entity)); }
/// <summary> /// Generates the document key. /// </summary> /// <param name="conventions">The conventions.</param> /// <param name="entity">The entity.</param> /// <returns></returns> public string GenerateDocumentKey(IDatabaseCommands databaseCommands, DocumentConvention conventions, object entity) { var typeTagName = conventions.GetTypeTagName(entity.GetType()); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags { return(null); } var tag = conventions.TransformTypeTagNameToDocumentKeyPrefix(typeTagName); HiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKey(databaseCommands, conventions, entity)); } lock (generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKey(databaseCommands, conventions, entity)); } value = new HiLoKeyGenerator(tag, capacity); // doing it this way for thread safety keyGeneratorsByTag = new Dictionary <string, HiLoKeyGenerator>(keyGeneratorsByTag) { { tag, value } }; } return(value.GenerateDocumentKey(databaseCommands, conventions, entity)); }
public string GenerateDocumentKey(DocumentConvention conventions, object entity) { var tag = conventions.GetTypeTagName(entity.GetType()).ToLowerInvariant(); HiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKey(entity)); } lock (generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKey(entity)); } value = new HiLoKeyGenerator(databaseCommands, tag, capacity); // doing it this way for thread safety keyGeneratorsByTag = new Dictionary <string, HiLoKeyGenerator>(keyGeneratorsByTag) { { tag, value } }; } return(value.GenerateDocumentKey(entity)); }
public Task <string> GenerateDocumentKeyAsync(IAsyncDatabaseCommands databaseCommands, DocumentConvention conventions, object entity) { var typeTagName = conventions.GetTypeTagName(entity.GetType()); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags { return(CompletedTask.With <string>(null)); } var tag = conventions.TransformTypeTagNameToDocumentKeyPrefix(typeTagName); AsyncHiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity)); } lock (generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) { return(value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity)); } value = new AsyncHiLoKeyGenerator(tag, capacity); keyGeneratorsByTag.TryAdd(tag, value); } return(value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity)); }
public IndexDefinition ToIndexDefinition(DocumentConvention convention) { return(new IndexDefinition { Map = PruneToFailureLinqQueryAsStringToWorkableCode(Map, "docs." + convention.GetTypeTagName(typeof(TDocument))), Reduce = PruneToFailureLinqQueryAsStringToWorkableCode(Reduce, "results"), Indexes = ConvertToStringDictionary(Indexes), Stores = ConvertToStringDictionary(Stores) }); }
public Task<string> GenerateDocumentKeyAsync(IAsyncDatabaseCommands databaseCommands, DocumentConvention conventions, object entity) { var typeTagName = conventions.GetTypeTagName(entity.GetType()); if (string.IsNullOrEmpty(typeTagName)) //ignore empty tags return CompletedTask.With<string>(null); var tag = conventions.TransformTypeTagNameToDocumentKeyPrefix(typeTagName); AsyncHiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) return value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity); lock(generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) return value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity); value = new AsyncHiLoKeyGenerator(tag, capacity); keyGeneratorsByTag.TryAdd(tag, value); } return value.GenerateDocumentKeyAsync(databaseCommands, conventions, entity); }
/// <summary> /// Generates the document key. /// </summary> /// <param name="conventions">The conventions.</param> /// <param name="entity">The entity.</param> /// <returns></returns> public string GenerateDocumentKey(DocumentConvention conventions, object entity) { var tag = conventions.GetTypeTagName(entity.GetType()).ToLowerInvariant(); HiLoKeyGenerator value; if (keyGeneratorsByTag.TryGetValue(tag, out value)) return value.GenerateDocumentKey(conventions, entity); lock(generatorLock) { if (keyGeneratorsByTag.TryGetValue(tag, out value)) return value.GenerateDocumentKey(conventions, entity); value = new HiLoKeyGenerator(documentStore, tag, capacity); // doing it this way for thread safety keyGeneratorsByTag = new Dictionary<string, HiLoKeyGenerator>(keyGeneratorsByTag) { {tag, value} }; } return value.GenerateDocumentKey(conventions, entity); }