Raven.Client.Document.MultiTypeHiLoKeyGenerator.GenerateDocumentKey C# (CSharp) Method

GenerateDocumentKey() public method

public GenerateDocumentKey ( DocumentConvention conventions, object entity ) : string
conventions DocumentConvention
entity object
return string
        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(databaseCommands, tag, capacity);
                // doing it this way for thread safety
                keyGeneratorsByTag = new Dictionary<string, HiLoKeyGenerator>(keyGeneratorsByTag)
                {
                    {tag, value}
                };
            }

			return value.GenerateDocumentKey(conventions, entity);
        }
    }

Usage Example

Ejemplo n.º 1
0
        public IDocumentStore Initialise()
        {
            try
            {
#if !CLIENT
                if (configuration != null)
                {
                    var embeddedDatabase = new Raven.Database.DocumentDatabase(configuration);
                    embeddedDatabase.SpinBackgroundWorkers();
                    DatabaseCommands = new EmbededDatabaseCommands(embeddedDatabase, Conventions);
                }
                else
#endif
                {
                    DatabaseCommands = new ServerClient(Url, Conventions, credentials);
                }
                if (Conventions.DocumentKeyGenerator == null)// don't overwrite what the user is doing
                {
                    var generator = new MultiTypeHiLoKeyGenerator(DatabaseCommands, 1024);
                    Conventions.DocumentKeyGenerator = entity => generator.GenerateDocumentKey(Conventions, entity);
                }
            }
            catch (Exception)
            {
                Dispose();
                throw;
            }

            return(this);
        }
All Usage Examples Of Raven.Client.Document.MultiTypeHiLoKeyGenerator::GenerateDocumentKey