本文整理汇总了C#中Raven.Abstractions.Data.BulkInsertOptions类的典型用法代码示例。如果您正苦于以下问题:C# BulkInsertOptions类的具体用法?C# BulkInsertOptions怎么用?C# BulkInsertOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BulkInsertOptions类属于Raven.Abstractions.Data命名空间,在下文中一共展示了BulkInsertOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChunkedRemoteBulkInsertOperation
public ChunkedRemoteBulkInsertOperation(BulkInsertOptions options, AsyncServerClient client, IDatabaseChanges changes, int chunkSize)
{
this.options = options;
this.client = client;
this.changes = changes;
this.chunkSize = chunkSize;
}
示例2: Respond
public override void Respond(IHttpContext context)
{
if (string.IsNullOrEmpty(context.Request.QueryString["no-op"]) == false)
{
// this is a no-op request which is there just to force the client HTTP layer to handle the authentication
// only used for legacy clients
return;
}
if("generate-single-use-auth-token".Equals(context.Request.QueryString["op"],StringComparison.InvariantCultureIgnoreCase))
{
// using windows auth with anonymous access = none sometimes generate a 401 even though we made two requests
// instead of relying on windows auth, which require request buffering, we generate a one time token and return it.
// we KNOW that the user have access to this db for writing, since they got here, so there is no issue in generating
// a single use token for them.
var token = server.RequestAuthorizer.GenerateSingleUseAuthToken(Database, context.User);
context.WriteJson(new
{
Token = token
});
return;
}
if (HttpContext.Current != null)
{
HttpContext.Current.Server.ScriptTimeout = 60*60*6; // six hours should do it, I think.
}
var options = new BulkInsertOptions
{
CheckForUpdates = context.GetCheckForUpdates(),
CheckReferencesInIndexes = context.GetCheckReferencesInIndexes()
};
var operationId = ExtractOperationId(context);
var sp = Stopwatch.StartNew();
var status = new BulkInsertStatus();
int documents = 0;
var mre = new ManualResetEventSlim(false);
var currentDatbase = Database;
var task = Task.Factory.StartNew(() =>
{
currentDatbase.BulkInsert(options, YieldBatches(context, mre, batchSize => documents += batchSize), operationId);
status.Documents = documents;
status.Completed = true;
});
long id;
Database.AddTask(task, status, out id);
mre.Wait(Database.WorkContext.CancellationToken);
context.Log(log => log.Debug("\tBulk inserted received {0:#,#;;0} documents in {1}, task #: {2}", documents, sp.Elapsed, id));
context.WriteJson(new
{
OperationId = id
});
}
示例3: Respond
public override void Respond(IHttpContext context)
{
if (string.IsNullOrEmpty(context.Request.QueryString["no-op"]) == false)
{
// this is a no-op request which is there just to force the client HTTP layer
// to handle the authentication
return;
}
var options = new BulkInsertOptions
{
CheckForUpdates = context.GetCheckForUpdates(),
CheckReferencesInIndexes = context.GetCheckReferencesInIndexes()
};
var sp = Stopwatch.StartNew();
var documents = Database.BulkInsert(options, YieldBatches(context));
context.Log(log => log.Debug("\tBulk inserted {0:#,#;;0} documents in {1}", documents, sp.Elapsed));
context.WriteJson(new
{
Documents = documents
});
}
示例4: ChunkedRemoteBulkInsertOperation
public ChunkedRemoteBulkInsertOperation(BulkInsertOptions options, AsyncServerClient client, IDatabaseChanges changes)
{
this.options = options;
this.client = client;
this.changes = changes;
currentChunkSize = 0;
current = GetBulkInsertOperation();
}
示例5: ChunkedRemoteBulkInsertOperation
public ChunkedRemoteBulkInsertOperation(BulkInsertOptions options, AsyncServerClient client, IDatabaseChanges changes, int chunkSize,long? documentSizeInChunkLimit = null)
{
this.options = options;
this.client = client;
this.changes = changes;
this.chunkSize = chunkSize;
this.documentSizeInChunkLimit = documentSizeInChunkLimit;
documentSizeInChunk = 0;
}
示例6: EmbeddedBulkInsertOperation
/// <summary>
/// Create new instance of this class
/// </summary>
public EmbeddedBulkInsertOperation(DocumentDatabase database,BulkInsertOptions options)
{
this.options = options;
queue = new BlockingCollection<JsonDocument>(options.BatchSize * 8);
doBulkInsert = Task.Factory.StartNew(() =>
{
database.BulkInsert(options, YieldDocuments());
});
}
示例7: ChunkedRemoteBulkInsertOperation
public ChunkedRemoteBulkInsertOperation(BulkInsertOptions options, AsyncServerClient client, IDatabaseChanges changes, int chunkSize,long? documentSizeInChunkLimit = null)
{
this.options = options;
this.client = client;
this.changes = changes;
this.chunkSize = chunkSize;
this.documentSizeInChunkLimit = documentSizeInChunkLimit;
documentSizeInChunk = 0;
if(documentSizeInChunkLimit.HasValue)
Console.WriteLine("Limit of document size in chunk = " + documentSizeInChunkLimit.Value);
}
示例8: BulkInsertOperation
public BulkInsertOperation(string database, IDocumentStore documentStore, DocumentSessionListeners listeners, BulkInsertOptions options)
{
this.documentStore = documentStore;
databaseCommands = database == null
? documentStore.DatabaseCommands.ForSystemDatabase()
: documentStore.DatabaseCommands.ForDatabase(database);
generateEntityIdOnTheClient = new GenerateEntityIdOnTheClient(documentStore, entity => documentStore.Conventions.GenerateDocumentKey(database, databaseCommands, entity));
operation = databaseCommands.GetBulkInsertOperation(options);
entityToJson = new EntityToJson(documentStore, listeners);
}
示例9: ShardedBulkInsertOperation
public ShardedBulkInsertOperation(string database, ShardedDocumentStore shardedDocumentStore, BulkInsertOptions options)
{
this.database = database;
this.shardedDocumentStore = shardedDocumentStore;
this.options = options;
shards = shardedDocumentStore.ShardStrategy.Shards;
Bulks = new Dictionary<string, BulkInsertOperation>();
generateEntityIdOnTheClient = new GenerateEntityIdOnTheClient(shardedDocumentStore.Conventions,
entity => AsyncHelpers.RunSync(() => shardedDocumentStore.Conventions.GenerateDocumentKeyAsync(database, DatabaseCommands, entity)));
shardResolutionStrategy = shardedDocumentStore.ShardStrategy.ShardResolutionStrategy;
shardStrategy = this.shardedDocumentStore.ShardStrategy;
}
示例10: Respond
public override void Respond(IHttpContext context)
{
if (string.IsNullOrEmpty(context.Request.QueryString["no-op"]) == false)
{
// this is a no-op request which is there just to force the client HTTP layer
// to handle the authentication
return;
}
if (HttpContext.Current != null)
{
HttpContext.Current.Server.ScriptTimeout = 60*60*6; // six hours should do it, I think.
}
var options = new BulkInsertOptions
{
CheckForUpdates = context.GetCheckForUpdates(),
CheckReferencesInIndexes = context.GetCheckReferencesInIndexes()
};
var sp = Stopwatch.StartNew();
var status = new RavenJObject
{
{"Documents", 0},
{"Completed", false}
};
int documents = 0;
var mre = new ManualResetEventSlim(false);
var currentDatbase = Database;
var task = Task.Factory.StartNew(() =>
{
documents = currentDatbase.BulkInsert(options, YieldBatches(context, mre));
status["Documents"] = documents;
status["Completed"] = true;
});
long id;
Database.AddTask(task, status, out id);
mre.Wait(Database.WorkContext.CancellationToken);
context.Log(log => log.Debug("\tBulk inserted received {0:#,#;;0} documents in {1}, task #: {2}", documents, sp.Elapsed, id));
context.WriteJson(new
{
OperationId = id
});
}
示例11: BulkInsertOperation
public BulkInsertOperation(string database, IDocumentStore documentStore, DocumentSessionListeners listeners, BulkInsertOptions options, IDatabaseChanges changes)
{
this.documentStore = documentStore;
database = database ?? MultiDatabase.GetDatabaseName(documentStore.Url);
// Fitzchak: Should not be ever null because of the above code, please refactor this.
DatabaseCommands = database == null
? documentStore.AsyncDatabaseCommands.ForSystemDatabase()
: documentStore.AsyncDatabaseCommands.ForDatabase(database);
generateEntityIdOnTheClient = new GenerateEntityIdOnTheClient(documentStore.Conventions, entity => documentStore.Conventions.GenerateDocumentKeyAsync(database, DatabaseCommands, entity).ResultUnwrap());
Operation = GetBulkInsertOperation(options, DatabaseCommands, changes);
entityToJson = new EntityToJson(documentStore, listeners);
}
示例12: RemoteBulkInsertOperation
public RemoteBulkInsertOperation(BulkInsertOptions options, ServerClient client)
{
this.client = client;
items = new BlockingCollection<RavenJObject>(options.BatchSize*8);
string requestUrl = "/bulkInsert?";
if (options.CheckForUpdates)
requestUrl += "checkForUpdates=true";
if (options.CheckReferencesInIndexes)
requestUrl += "&checkReferencesInIndexes=true";
// this will force the HTTP layer to authenticate, meaning that our next request won't have to
HttpJsonRequest req = client.CreateRequest("POST", requestUrl + "&no-op=for-auth-only",
disableRequestCompression: true);
req.ExecuteRequest();
httpJsonRequest = client.CreateRequest("POST", requestUrl, disableRequestCompression: true);
// the request may take a long time to process, so we need to set a large timeout value
httpJsonRequest.Timeout = TimeSpan.FromHours(6);
nextTask = httpJsonRequest.GetRawRequestStream()
.ContinueWith(task =>
{
Stream requestStream = task.Result;
while (true)
{
var batch = new List<RavenJObject>();
RavenJObject item;
while (items.TryTake(out item, 200))
{
if (item == null) // marker
{
FlushBatch(requestStream, batch);
return;
}
batch.Add(item);
if (batch.Count >= options.BatchSize)
break;
}
FlushBatch(requestStream, batch);
}
});
}
示例13: Index
public ActionResult Index()
{
var sw = Stopwatch.StartNew();
var data = new string('a', 2000);
var options = new BulkInsertOptions() { CheckForUpdates = true, BatchSize = 2048};
using (var bulkInsert = MvcApplication.DocumentStore.BulkInsert(options: options))
{
for (int i = 0; i < Quantity; i++)
{
bulkInsert.Store(new Document { Data = data });
}
}
sw.Stop();
var result = string.Format("Initialized {0:n0} documents in {1} minutes. {2} per second",
Quantity,
sw.Elapsed.TotalMinutes,
Math.Round(Quantity / sw.Elapsed.TotalSeconds));
return Content(result);
}
示例14: RemoteBulkInsertOperation
public RemoteBulkInsertOperation(BulkInsertOptions options, ServerClient client)
{
this.options = options;
this.client = client;
items = new BlockingCollection<RavenJObject>(options.BatchSize*8);
string requestUrl = "/bulkInsert?";
if (options.CheckForUpdates)
requestUrl += "checkForUpdates=true";
if (options.CheckReferencesInIndexes)
requestUrl += "&checkReferencesInIndexes=true";
var expect100Continue = client.Expect100Continue();
// this will force the HTTP layer to authenticate, meaning that our next request won't have to
HttpJsonRequest req = client.CreateRequest("POST", requestUrl + "&op=generate-single-use-auth-token",
disableRequestCompression: true);
var token = req.ReadResponseJson();
httpJsonRequest = client.CreateRequest("POST", requestUrl, disableRequestCompression: true);
// the request may take a long time to process, so we need to set a large timeout value
httpJsonRequest.PrepareForLongRequest();
httpJsonRequest.AddOperationHeader("Single-Use-Auth-Token", token.Value<string>("Token"));
nextTask = httpJsonRequest.GetRawRequestStream()
.ContinueWith(task =>
{
try
{
expect100Continue.Dispose();
}
catch (Exception)
{
}
WriteQueueToServer(task);
});
}
示例15: ChunkedBulkInsertOperation
public ChunkedBulkInsertOperation(string database, IDocumentStore documentStore, DocumentSessionListeners listeners, BulkInsertOptions options, IDatabaseChanges changes, int chunkSize)
: base(database, documentStore, listeners, options, changes)
{
Operation = new ChunkedRemoteBulkInsertOperation(options, (AsyncServerClient)DatabaseCommands, changes, chunkSize);
}