Esempio n. 1
0
		private Task StartCommitTask(
			BlockingCollection<QueuedMemoryWriter> threadWriter, SequentialFileWriter data, SequentialFileWriter index)
		{
			Task commitTask = Task.Factory.StartNew(
				() =>
				{
					while (!(threadWriter.IsCompleted))
					{
						QueuedMemoryWriter writer;

						try
						{
							writer = threadWriter.Take();
						}
						catch (InvalidOperationException)
						{
							//Per MSDN, it's fine if we're here, successful completion of adding can rarely put us into this state.
							break;
						}

						writer.CommitTo(data, index);
					}
				});

			return commitTask;
		}
Esempio n. 2
0
		public void CommitTo(SequentialFileWriter dataFile, SequentialFileWriter indexFile)
		{
			Flush();

			var memLength = (int)_memStream.Position;

			if (memLength > 0)
			{
				byte[] memBuffer = _memStream.GetBuffer();

				long actualPosition = dataFile.Position;

				dataFile.Write(memBuffer, 0, memLength); //The buffer contains the data from many items.

				//Console.WriteLine("Writing {0} bytes starting at {1}, with {2} things", memLength, actualPosition, _orderedIndexInfo.Count);

				var indexBuffer = new byte[20];

				//int indexWritten = _orderedIndexInfo.Count * indexBuffer.Length;
				//int totalWritten = memLength + indexWritten

				foreach (IndexInfo info in _orderedIndexInfo)
				{
					/*
					int typeCode = info.typeCode;
					int serial = info.serial;
					int length = info.size;
					*/
					indexBuffer[0] = (byte)(info.typeCode);
					indexBuffer[1] = (byte)(info.typeCode >> 8);
					indexBuffer[2] = (byte)(info.typeCode >> 16);
					indexBuffer[3] = (byte)(info.typeCode >> 24);

					indexBuffer[4] = (byte)(info.serial);
					indexBuffer[5] = (byte)(info.serial >> 8);
					indexBuffer[6] = (byte)(info.serial >> 16);
					indexBuffer[7] = (byte)(info.serial >> 24);

					indexBuffer[8] = (byte)(actualPosition);
					indexBuffer[9] = (byte)(actualPosition >> 8);
					indexBuffer[10] = (byte)(actualPosition >> 16);
					indexBuffer[11] = (byte)(actualPosition >> 24);
					indexBuffer[12] = (byte)(actualPosition >> 32);
					indexBuffer[13] = (byte)(actualPosition >> 40);
					indexBuffer[14] = (byte)(actualPosition >> 48);
					indexBuffer[15] = (byte)(actualPosition >> 56);

					indexBuffer[16] = (byte)(info.size);
					indexBuffer[17] = (byte)(info.size >> 8);
					indexBuffer[18] = (byte)(info.size >> 16);
					indexBuffer[19] = (byte)(info.size >> 24);

					indexFile.Write(indexBuffer, 0, indexBuffer.Length);

					actualPosition += info.size;
				}
			}

			Close(); //We're done with this writer.
		}
Esempio n. 3
0
        public int CommitTo(SequentialFileWriter dataFile, SequentialFileWriter indexFile, int typeCode, int serial)
        {
            this.Flush();

            byte[] buffer = this.stream.GetBuffer();
            int length = (int)this.stream.Length;

            long position = dataFile.Position;

            dataFile.Write(buffer, 0, length);

            if (indexBuffer == null)
            {
                indexBuffer = new byte[20];
            }

            indexBuffer[0] = (byte)(typeCode);
            indexBuffer[1] = (byte)(typeCode >> 8);
            indexBuffer[2] = (byte)(typeCode >> 16);
            indexBuffer[3] = (byte)(typeCode >> 24);

            indexBuffer[4] = (byte)(serial);
            indexBuffer[5] = (byte)(serial >> 8);
            indexBuffer[6] = (byte)(serial >> 16);
            indexBuffer[7] = (byte)(serial >> 24);

            indexBuffer[8] = (byte)(position);
            indexBuffer[9] = (byte)(position >> 8);
            indexBuffer[10] = (byte)(position >> 16);
            indexBuffer[11] = (byte)(position >> 24);
            indexBuffer[12] = (byte)(position >> 32);
            indexBuffer[13] = (byte)(position >> 40);
            indexBuffer[14] = (byte)(position >> 48);
            indexBuffer[15] = (byte)(position >> 56);

            indexBuffer[16] = (byte)(length);
            indexBuffer[17] = (byte)(length >> 8);
            indexBuffer[18] = (byte)(length >> 16);
            indexBuffer[19] = (byte)(length >> 24);

            indexFile.Write(indexBuffer, 0, indexBuffer.Length);

            this.stream.SetLength(0);

            return length;
        }
Esempio n. 4
0
		private void WriteCount(SequentialFileWriter indexFile, int count)
		{
			//Equiv to GenericWriter.Write( (int)count );
			var buffer = new byte[4];

			buffer[0] = (byte)(count);
			buffer[1] = (byte)(count >> 8);
			buffer[2] = (byte)(count >> 16);
			buffer[3] = (byte)(count >> 24);

			indexFile.Write(buffer, 0, buffer.Length);
		}
Esempio n. 5
0
		private void OpenFiles()
		{
			_itemData = new SequentialFileWriter(World.ItemDataPath, _metrics);
			_itemIndex = new SequentialFileWriter(World.ItemIndexPath, _metrics);

			_mobileData = new SequentialFileWriter(World.MobileDataPath, _metrics);
			_mobileIndex = new SequentialFileWriter(World.MobileIndexPath, _metrics);

			_guildData = new SequentialFileWriter(World.GuildDataPath, _metrics);
			_guildIndex = new SequentialFileWriter(World.GuildIndexPath, _metrics);

			_customData = new SequentialFileWriter(World.DataBinaryPath, _metrics);
			_customIndex = new SequentialFileWriter(World.DataIndexPath, _metrics);

			WriteCount(_itemIndex, World.Items.Count);
			WriteCount(_mobileIndex, World.Mobiles.Count);
			WriteCount(_guildIndex, BaseGuild.List.Count);
			WriteCount(_customIndex, World.Data.Count);
		}
Esempio n. 6
0
        private void OpenFiles()
        {
            this._itemData = new SequentialFileWriter(World.ItemDataPath, this._metrics);
            this._itemIndex = new SequentialFileWriter(World.ItemIndexPath, this._metrics);

            this._mobileData = new SequentialFileWriter(World.MobileDataPath, this._metrics);
            this._mobileIndex = new SequentialFileWriter(World.MobileIndexPath, this._metrics);

            this._guildData = new SequentialFileWriter(World.GuildDataPath, this._metrics);
            this._guildIndex = new SequentialFileWriter(World.GuildIndexPath, this._metrics);

            this._coreData = new SequentialFileWriter(World.CoresDataPath, this._metrics);
            this._coreIndex = new SequentialFileWriter(World.CoreIndexPath, this._metrics);

            this._moduleData = new SequentialFileWriter(World.ModulesDataPath, this._metrics);
            this._moduleIndex = new SequentialFileWriter(World.ModuleIndexPath, this._metrics);

            this._serviceData = new SequentialFileWriter(World.ServicesDataPath, this._metrics);
            this._serviceIndex = new SequentialFileWriter(World.ServiceIndexPath, this._metrics);

            this.WriteCount(_itemIndex, World.Items.Count);
            this.WriteCount(_mobileIndex, World.Mobiles.Count);
            this.WriteCount(_guildIndex, BaseGuild.List.Count);
            this.WriteCount(_coreIndex, World.Cores.Count);
            this.WriteCount(_moduleIndex, World.Modules.Count);
            this.WriteCount(_serviceIndex, World.Services.Count);
        }