Example #1
0
		public Queue GetOrCreateQueue(string name)
		{
			var queue = GetQueue(name);
			if (queue != null)
				return queue;
			var pos = writer.Position;
			queue = new Queue(reader, writer, StartMode.Create);
			queue.Flush();
			queuesInMem.Add(name, queue);
			queues.Add(name, pos);
			return queue;
		}
Example #2
0
		public Queue GetQueue(string name)
		{
			Queue value;
			if (queuesInMem.TryGetValue(name, out value))
				return value;
			var queuePos = queues.FindValue(name);
			if (queuePos == null)
				return null;
			reader.Position = queuePos.Value;
			var q = new Queue(reader, writer, StartMode.Open);
			queuesInMem.Add(name, q);
			return q;
		}
		private void CreateFromScratch()
		{
			binaryWriter.Write(HeaderSignature);
			binaryWriter.Write7BitEncodedInt(Version);
			binaryWriter.Write(Guid.NewGuid().ToByteArray());
			using (var reader = OpenReader())
			{
				var docs = new Tree(reader, writer, StartMode.Create);
				var docsInTx = new Tree(reader, writer, StartMode.Create);
				var docById = new Tree(reader, writer, StartMode.Create);
				var docByEtag = new Tree(reader, writer, StartMode.Create);
				var tx = new Tree(reader, writer, StartMode.Create);
				var attachments = new Tree(reader, writer, StartMode.Create);
				var tasks = new Queue(reader, writer, StartMode.Create);
				var tasksByIndex = new Tree(reader, writer, StartMode.Create);
				var identity = new Tree(reader, writer, StartMode.Create);
				var indexes = new Tree(reader, writer, StartMode.Create);
				var queues = new TreeOfQueues(reader, writer, StartMode.Create);
				var mapResultsByDocId = new TreeOfBags(reader, writer, StartMode.Create);
				var mapResultsByReduceKey = new TreeOfBags(reader, writer, StartMode.Create);
				docs.Flush();
				docsInTx.Flush();
				docById.Flush();
				docByEtag.Flush();
				tx.Flush();
				attachments.Flush();
				tasks.Flush();
				tasksByIndex.Flush();
				identity.Flush();
				indexes.Flush();
				queues.Flush();
				mapResultsByDocId.Flush();
				mapResultsByReduceKey.Flush();

				WriteTransaction(new StorageTransaction
				{
					AttachmentPosition = attachments.RootPosition,
					AttachmentsCount = 0,
					DocumentsPosition = docs.RootPosition,
					DocumentsCount = 0,
					DocumentsInTransactionPosition = docsInTx.RootPosition,
					DocumentsByIdPosition = docById.RootPosition,
					DocumentsByEtagPosition = docByEtag.RootPosition,
					TasksPosition = tasks.RootPosition,
					TasksCount = 0,
					TransactionPosition = tx.RootPosition,
					IdentityPosition = identity.RootPosition,
					IndexesPosition = indexes.RootPosition,
					QueuesPosition = queues.RootPosition,
					TasksByIndexPosition = tasksByIndex.RootPosition,
					MappedResultsByDocumentIdPosition = mapResultsByDocId.RootPosition,
					MappedResultsByReduceKeyPosition = mapResultsByReduceKey.RootPosition
				});
				writer.Flush(true);
			}
		}