RavenFS.Storage.TransactionalStorage.Batch C# (CSharp) Method

Batch() private method

private Batch ( Action action ) : void
action Action
return void
		public void Batch(Action<StorageActionsAccessor> action)
		{
			if (Id == Guid.Empty)
				throw new InvalidOperationException("Cannot use Storage before Initialize was called");
			if (disposed)
			{
				Trace.WriteLine("Storage.Batch was called after it was disposed, call was ignored.");
				return; // this may happen if someone is calling us from the finalizer thread, so we can't even throw on that
			}
			if (current.Value != null)
			{
				action(current.Value);
				return;
			}
			disposerLock.EnterReadLock();
			try
			{
				ExecuteBatch(action);
			}
			catch (EsentErrorException e)
			{
				switch (e.Error)
				{
					case JET_err.WriteConflict:
					case JET_err.SessionWriteConflict:
					case JET_err.WriteConflictPrimaryIndex:
						throw new ConcurrencyException("Concurrent modification to the same file are not allowed", e);
					default:
						throw;
				}
			}
			finally
			{
				disposerLock.ExitReadLock();
				current.Value = null;
			}
		}

Usage Example

		protected StorageStream(TransactionalStorage transactionalStorage, string fileName,
		                        StorageStreamAccess storageStreamAccess,
		                        NameValueCollection metadata, IndexStorage indexStorage, StorageOperationsTask operations)
		{
			TransactionalStorage = transactionalStorage;
			StorageStreamAccess = storageStreamAccess;
			Name = fileName;

			switch (storageStreamAccess)
			{
				case StorageStreamAccess.Read:
					TransactionalStorage.Batch(accessor => fileHeader = accessor.ReadFile(fileName));
					if (fileHeader.TotalSize == null)
					{
						throw new FileNotFoundException("File is not uploaded yet");
					}
					Metadata = fileHeader.Metadata;
					Seek(0, SeekOrigin.Begin);
					break;
				case StorageStreamAccess.CreateAndWrite:
					TransactionalStorage.Batch(accessor =>
						                           {
							                           operations.IndicateFileToDelete(fileName);
							                           accessor.PutFile(fileName, null, metadata);
							                           indexStorage.Index(fileName, metadata);
						                           });
					Metadata = metadata;
					break;
				default:
					throw new ArgumentOutOfRangeException("storageStreamAccess", storageStreamAccess, "Unknown value");
			}
		}
All Usage Examples Of RavenFS.Storage.TransactionalStorage::Batch