本文整理汇总了C#中Raven.Client.Indexes.AbstractIndexCreationTask.CreateIndexDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# AbstractIndexCreationTask.CreateIndexDefinition方法的具体用法?C# AbstractIndexCreationTask.CreateIndexDefinition怎么用?C# AbstractIndexCreationTask.CreateIndexDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Client.Indexes.AbstractIndexCreationTask
的用法示例。
在下文中一共展示了AbstractIndexCreationTask.CreateIndexDefinition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PutIndex
public void PutIndex(AbstractIndexCreationTask index)
{
var response = httpClient
.PutAsync(databaseUrl + "/indexes/" + Uri.EscapeUriString(index.IndexName), new JsonContent(RavenJObject.FromObject(index.CreateIndexDefinition())))
.ResultUnwrap();
if (response.IsSuccessStatusCode == false)
throw new InvalidOperationException(string.Format("PUT failed on '{0}'. Code: {1}.", index.IndexName, response.StatusCode));
}
示例2: SafelyCreateIndex
/// <summary>
/// Safely add the index to the RavenDB database, protect against possible failures caused by documented
/// and undocumented possibilities of failure.
/// Will throw iff index registration failed and index doesn't exist or it exists but with a non-current definition.
/// </summary>
/// <param name="store"></param>
/// <param name="index"></param>
internal static void SafelyCreateIndex(IDocumentStore store, AbstractIndexCreationTask index)
{
try
{
index.Execute(store);
}
catch (Exception) // Apparently ArgumentException can be thrown as well as a WebException; not taking any chances
{
var existingIndex = store.DatabaseCommands.GetIndex(index.IndexName);
if (existingIndex == null || !index.CreateIndexDefinition().Equals(existingIndex))
throw;
}
}