/// <summary> /// Begins the async save changes operation /// </summary> /// <returns></returns> public async Task SaveChangesAsync(CancellationToken token = default(CancellationToken)) { using (AsyncTaskHolder()) { if (_asyncDocumentIdGeneration != null) { await _asyncDocumentIdGeneration.GenerateDocumentIdsForSaveChanges().WithCancellation(token).ConfigureAwait(false); } var saveChangesOperation = new BatchOperation(this); using (var command = saveChangesOperation.CreateRequest()) { if (command == null) { return; } if (NoTracking) { throw new InvalidOperationException($"Cannot execute '{nameof(SaveChangesAsync)}' when entity tracking is disabled in session."); } await RequestExecutor.ExecuteAsync(command, Context, _sessionInfo, token).ConfigureAwait(false); UpdateSessionAfterSaveChanges(command.Result); saveChangesOperation.SetResult(command.Result); } } }
/// <summary> /// Saves all the changes to the Raven server. /// </summary> public void SaveChanges() { var saveChangesOperation = new BatchOperation(this); var command = saveChangesOperation.CreateRequest(); if (command != null) { RequestExecuter.Execute(command, Context); saveChangesOperation.SetResult(command.Result); } }
/// <summary> /// Saves all the changes to the Raven server. /// </summary> public void SaveChanges() { var saveChangesOperation = new BatchOperation(this); using (var command = saveChangesOperation.CreateRequest()) { if (command == null) { return; } RequestExecutor.Execute(command, Context, sessionInfo: SessionInfo); saveChangesOperation.SetResult(command.Result); } }
/// <summary> /// Begins the async save changes operation /// </summary> /// <returns></returns> public async Task SaveChangesAsync(CancellationToken token = default(CancellationToken)) { await asyncDocumentKeyGeneration.GenerateDocumentKeysForSaveChanges().WithCancellation(token).ConfigureAwait(false); var saveChangesOeration = new BatchOperation(this); var command = saveChangesOeration.CreateRequest(); if (command != null) { await RequestExecuter.ExecuteAsync(command, Context, token); saveChangesOeration.SetResult(command.Result); } }
/// <summary> /// Saves all the changes to the Raven server. /// </summary> public void SaveChanges() { var saveChangesOperation = new BatchOperation(this); using (var command = saveChangesOperation.CreateRequest()) { if (command == null) { return; } if (NoTracking) { throw new InvalidOperationException($"Cannot execute '{nameof(SaveChanges)}' when entity tracking is disabled in session."); } RequestExecutor.Execute(command, Context, sessionInfo: SessionInfo); UpdateSessionAfterSaveChanges(command.Result); saveChangesOperation.SetResult(command.Result); } }
/// <summary> /// Begins the async save changes operation /// </summary> /// <returns></returns> public async Task SaveChangesAsync(CancellationToken token = default(CancellationToken)) { if (_asyncDocumentIdGeneration != null) { await _asyncDocumentIdGeneration.GenerateDocumentIdsForSaveChanges().WithCancellation(token).ConfigureAwait(false); } var saveChangesOperation = new BatchOperation(this); using (var command = saveChangesOperation.CreateRequest()) { if (command == null) { return; } await RequestExecutor.ExecuteAsync(command, Context, SessionInfo, token).ConfigureAwait(false); saveChangesOperation.SetResult(command.Result); } }
public async Task PutAttachmentsWithFailover_Session() { const int size = 512 * 1024; const string hash = "BfKA8g/BJuHOTHYJ+A6sOt9jmFSVEDzCM3EcLLKCRMU="; UseNewLocalServer(); var leader = await CreateRaftClusterAndGetLeader(3); using (var store = GetDocumentStore(new Options { Server = leader, ModifyDatabaseRecord = record => { record.Topology = new DatabaseTopology { DynamicNodesDistribution = false, Members = { leader.ServerStore.NodeTag, Servers.First(x => x != leader).ServerStore.NodeTag } }; } })) { using (var session = (DocumentSession)store.OpenSession()) { session.Store(new User { Name = "Fitzchak" }, "users/1"); session.SaveChanges(); Assert.True(await WaitForDocumentInClusterAsync <User>( session, "users/1", u => u.Name.Equals("Fitzchak"), TimeSpan.FromSeconds(10))); } using (var session = (DocumentSession)store.OpenSession()) using (var stream = new BigDummyStream(size)) { session.Advanced.StoreAttachment("users/1", "File", stream, "application/pdf"); // SaveSession with failover var saveChangesOperation = new BatchOperation(session); using (var command = saveChangesOperation.CreateRequest()) { var(currentIndex, currentNode) = await session.RequestExecutor.GetPreferredNode(); Assert.Equal(currentNode.ClusterTag, leader.ServerStore.NodeTag); var currentServer = Servers.Single(x => x.ServerStore.NodeTag == currentNode.ClusterTag); stream.Position++; // simulating that we already started to call this and we need to reset DisposeServerAndWaitForFinishOfDisposal(currentServer); var task = session.RequestExecutor.ExecuteAsync(currentNode, currentIndex, session.Context, command); await task; saveChangesOperation.SetResult(command.Result); } } using (var session = store.OpenSession()) using (var dummyStream = new BigDummyStream(size)) using (var attachment = session.Advanced.GetAttachment("users/1", "File")) { attachment.Stream.CopyTo(dummyStream); Assert.Equal("File", attachment.Details.Name); Assert.Equal(size, dummyStream.Position); Assert.Equal(size, attachment.Details.Size); Assert.Equal("application/pdf", attachment.Details.ContentType); Assert.Equal(hash, attachment.Details.Hash); var user = session.Load <User>("users/1"); var metadata = session.Advanced.GetMetadataFor(user); Assert.Contains(DocumentFlags.HasAttachments.ToString(), metadata.GetString(Constants.Documents.Metadata.Flags)); var attachments = metadata.GetObjects(Constants.Documents.Metadata.Attachments); var attachmentMetadata = attachments.Single(); Assert.Equal("File", attachmentMetadata.GetString(nameof(AttachmentName.Name))); Assert.Equal("application/pdf", attachmentMetadata.GetString(nameof(AttachmentName.ContentType))); Assert.Equal(hash, attachmentMetadata.GetString(nameof(AttachmentName.Hash))); Assert.Equal(size, attachmentMetadata.GetLong(nameof(AttachmentName.Size))); } } }