本文整理汇总了C#中IDatabaseCommands类的典型用法代码示例。如果您正苦于以下问题:C# IDatabaseCommands类的具体用法?C# IDatabaseCommands怎么用?C# IDatabaseCommands使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IDatabaseCommands类属于命名空间,在下文中一共展示了IDatabaseCommands类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateDocumentKey
public string GenerateDocumentKey(IDatabaseCommands databaseCommands, DocumentConvention conventions, object entity)
{
var shardId = shardedDocumentStore.ShardStrategy.ShardResolutionStrategy.MetadataShardIdFor(entity);
if (shardId == null)
throw new InvalidOperationException(string.Format(
"ShardResolutionStrategy.MetadataShardIdFor cannot return null. You must specify where to store the metadata documents for the entity type '{0}'.", entity.GetType().FullName));
MultiTypeHiLoKeyGenerator value;
if (generatorsByShard.TryGetValue(shardId, out value))
{
return value.GenerateDocumentKey(databaseCommands, conventions, entity);
}
lock (this)
{
if (generatorsByShard.TryGetValue(shardId, out value) == false)
{
value = new MultiTypeHiLoKeyGenerator(capacity);
generatorsByShard = new Dictionary<string, MultiTypeHiLoKeyGenerator>(generatorsByShard)
{
{shardId, value}
};
}
}
return value.GenerateDocumentKey(databaseCommands, conventions, entity);
}
示例2: HiLoKeyGenerator
/// <summary>
/// Initializes a new instance of the <see cref="HiLoKeyGenerator"/> class.
/// </summary>
public HiLoKeyGenerator(IDatabaseCommands databaseCommands, string tag, long capacity)
{
this.databaseCommands = databaseCommands;
this.tag = tag;
this.capacity = capacity;
current = 0;
}
示例3: GenerateDocumentKey
/// <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.GetDynamicTagName(entity);
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);
}
示例4: HiLoKeyGenerator
public HiLoKeyGenerator(IDatabaseCommands commands, string tag, long capacity)
{
currentHi = 0;
this.commands = commands;
this.tag = tag;
this.capacity = capacity;
currentLo = capacity + 1;
}
示例5: CreateIndexes
/// <summary>
/// Creates the indexes found in the specified catalog
/// </summary>
/// <param name="catalogToGetnIndexingTasksFrom">The catalog to get indexing tasks from.</param>
public static void CreateIndexes(ExportProvider catalogToGetnIndexingTasksFrom, IDatabaseCommands databaseCommands, DocumentConvention conventions)
{
var tasks = catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>();
foreach (var task in tasks)
{
task.Execute(databaseCommands, conventions);
}
}
示例6: GetWindowsAuthDocument
static WindowsAuthDocument GetWindowsAuthDocument(IDatabaseCommands systemCommands)
{
var existing = systemCommands.Get("Raven/Authorization/WindowsSettings");
if (existing == null)
{
return new WindowsAuthDocument();
}
return existing
.DataAsJson
.JsonDeserialization<WindowsAuthDocument>();
}
示例7: Execute
/// <summary>
/// Executes the index creation against the specified document database using the specified conventions
/// </summary>
public virtual void Execute(IDatabaseCommands databaseCommands, DocumentConvention documentConvention)
{
Conventions = documentConvention;
var transformerDefinition = CreateTransformerDefinition();
// This code take advantage on the fact that RavenDB will turn an index PUT
// to a noop of the index already exists and the stored definition matches
// the new definition.
databaseCommands.PutTransformer(TransformerName, transformerDefinition);
UpdateIndexInReplication(databaseCommands, documentConvention, (commands, url) =>
commands.PutTransformer(TransformerName, transformerDefinition));
}
示例8: WaitForDocument
private static void WaitForDocument(IDatabaseCommands commands, string expectedId)
{
for (int i = 0; i < RetriesCount; i++)
{
if (commands.Head(expectedId) != null)
break;
Thread.Sleep(100);
}
if(commands.Head(expectedId) == null)
throw new Exception("Document not replicated");
}
示例9: AfterExecute
internal static void AfterExecute(IDatabaseCommands databaseCommands, string indexName, ScriptedIndexResults scripts)
{
var documentId = GetScriptedIndexResultsDocumentId(indexName);
scripts.Id = documentId;
var oldDocument = databaseCommands.Get(documentId);
var newDocument = RavenJObject.FromObject(scripts);
if (oldDocument != null && RavenJToken.DeepEquals(oldDocument.DataAsJson, newDocument))
return;
databaseCommands.Put(documentId, null, newDocument, null);
databaseCommands.ResetIndex(indexName);
}
示例10: SetupReplication
private static void SetupReplication(IDatabaseCommands source, params string[] urls)
{
source.Put(Constants.RavenReplicationDestinations,
null, new RavenJObject
{
{
"Destinations", new RavenJArray(urls.Select(url => new RavenJObject
{
{"Url", url}
}))
}
}, new RavenJObject());
}
示例11: InvokePut
static bool InvokePut(IDatabaseCommands systemCommands, RavenJObject ravenJObject)
{
try
{
systemCommands.Put("Raven/Authorization/WindowsSettings", null, ravenJObject, new RavenJObject());
return true;
}
catch (ErrorResponseException exception)
{
if (exception.Message.Contains("Cannot setup Windows Authentication without a valid commercial license."))
{
throw new Exception("RavenDB requires a Commercial license to configure windows authentication. Please either install your RavenDB license or contact [email protected] if you need a copy of the RavenDB license.");
}
throw;
}
}
示例12: CreateIndexes
/// <summary>
/// Creates the indexes found in the specified catalog
/// </summary>
public static void CreateIndexes(ExportProvider catalogToGetnIndexingTasksFrom, IDatabaseCommands databaseCommands, DocumentConvention conventions)
{
var indexCompilationExceptions = new List<IndexCompilationException>();
try
{
var tasks = catalogToGetnIndexingTasksFrom
.GetExportedValues<AbstractIndexCreationTask>()
.ToList();
var indexesToAdd = tasks
.Select(x => new IndexToAdd
{
Definition = x.CreateIndexDefinition(),
Name = x.IndexName,
Priority = x.Priority ?? IndexingPriority.Normal
})
.ToArray();
databaseCommands.PutIndexes(indexesToAdd);
foreach (var task in tasks)
task.AfterExecute(databaseCommands, conventions);
}
// For old servers that don't have the new entrypoint for executing multiple indexes
catch (Exception)
{
foreach (var task in catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>())
{
try
{
task.Execute(databaseCommands, conventions);
}
catch (IndexCompilationException e)
{
indexCompilationExceptions.Add(new IndexCompilationException("Failed to compile index name = " + task.IndexName, e));
}
}
}
foreach (var task in catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractTransformerCreationTask>())
{
task.Execute(databaseCommands, conventions);
}
if (indexCompilationExceptions.Any())
throw new AggregateException("Failed to create one or more indexes. Please see inner exceptions for more details.", indexCompilationExceptions);
}
示例13: NextId
///<summary>
/// Create the next id (numeric)
///</summary>
public long NextId(IDatabaseCommands commands)
{
while (true)
{
var myRange = Range; // thread safe copy
var current = Interlocked.Increment(ref myRange.Current);
if (current <= myRange.Max)
return current;
lock (generatorLock)
{
if (Range != myRange)
// Lock was contended, and the max has already been changed. Just get a new id as usual.
continue;
Range = GetNextRange(commands);
}
}
}
示例14: CreateIndexes
/// <summary>
/// Creates the indexes found in the specified catalog
/// </summary>
public static void CreateIndexes(ExportProvider catalogToGetnIndexingTasksFrom, IDatabaseCommands databaseCommands, DocumentConvention conventions)
{
var indexCompilationExceptions = new List<IndexCompilationException>();
foreach (var task in catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractIndexCreationTask>())
{
try
{
task.Execute(databaseCommands, conventions);
}
catch (IndexCompilationException e)
{
indexCompilationExceptions.Add(new IndexCompilationException("Failed to compile index name = " + task.IndexName, e));
}
}
foreach (var task in catalogToGetnIndexingTasksFrom.GetExportedValues<AbstractTransformerCreationTask>())
{
task.Execute(databaseCommands, conventions);
}
if (indexCompilationExceptions.Any())
throw new AggregateException("Failed to create one or more indexes. Please see inner exceptions for more details.", indexCompilationExceptions);
}
示例15: PutDocument
private void PutDocument(IDatabaseCommands databaseCommands,JsonDocument document)
{
databaseCommands.Put(HiLoDocumentKey, document.Etag,
document.DataAsJson,
document.Metadata);
}