Raven.Client.Document.AsyncHiLoKeyGenerator.GenerateDocumentKeyAsync C# (CSharp) Method

GenerateDocumentKeyAsync() public method

Generates the document key.
public GenerateDocumentKeyAsync ( IAsyncDatabaseCommands databaseCommands, DocumentConvention convention, object entity ) : Task
databaseCommands IAsyncDatabaseCommands
convention DocumentConvention The convention.
entity object The entity.
return Task
		public Task<string> GenerateDocumentKeyAsync(IAsyncDatabaseCommands databaseCommands, DocumentConvention convention, object entity)
		{
			return NextIdAsync(databaseCommands).ContinueWith(task => GetDocumentKeyFromId(convention, task.Result));
		}

Usage Example

        public Task <string> GenerateDocumentKeyAsync(IAsyncDatabaseCommands databaseCommands, DocumentConvention conventions, object entity)
        {
            var typeTagName = conventions.GetDynamicTagName(entity);

            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));
        }
All Usage Examples Of Raven.Client.Document.AsyncHiLoKeyGenerator::GenerateDocumentKeyAsync