OnItemSaved() публичный Метод

public OnItemSaved ( int numberOfBytes ) : void
numberOfBytes int
Результат void
Пример #1
0
        protected void SaveItems(SaveMetrics metrics)
        {
            Dictionary <Serial, Item> items = World.Items;

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (UseSequentialWriters)
            {
                idx = new BinaryFileWriter(World.ItemIndexPath, false);
                tdb = new BinaryFileWriter(World.ItemTypesPath, false);
                bin = new BinaryFileWriter(World.ItemDataPath, true);
            }
            else
            {
                idx = new AsyncWriter(World.ItemIndexPath, false);
                tdb = new AsyncWriter(World.ItemTypesPath, false);
                bin = new AsyncWriter(World.ItemDataPath, true);
            }

            idx.Write((int)items.Count);

            DateTime n = DateTime.UtcNow;

            foreach (Item item in items.Values)
            {
                if (item.Decays && item.Parent == null && item.Map != Map.Internal && (item.LastMoved + item.DecayTime) <= n)
                {
                    _decayQueue.Enqueue(item);
                }

                long start = bin.Position;

                idx.Write((int)item.m_TypeRef);
                idx.Write((int)item.Serial);
                idx.Write((long)start);

                item.Serialize(bin);

                if (metrics != null)
                {
                    metrics.OnItemSaved((int)(bin.Position - start));
                }

                idx.Write((int)(bin.Position - start));

                item.FreeCache();
            }

            tdb.Write((int)World.m_ItemTypes.Count);
            for (int i = 0; i < World.m_ItemTypes.Count; ++i)
            {
                tdb.Write(World.m_ItemTypes[i].FullName);
            }

            idx.Close();
            tdb.Close();
            bin.Close();
        }
Пример #2
0
        private Task SaveItems()
        {
            //Start the blocking consumer; this runs in background.
            Task commitTask = StartCommitTask(_itemThreadWriters, _itemData, _itemIndex);

            IEnumerable <Item> items = World.Items.Values;

            //Start the producer.
            Parallel.ForEach(
                items,
                () => new QueuedMemoryWriter(),
                (item, state, writer) =>
            {
                long startPosition = writer.Position;

                item.Serialize(writer);

                var size = (int)(writer.Position - startPosition);

                writer.QueueForIndex(item, size);

                if (item.Decays && item.Parent == null && item.Map != Map.Internal &&
                    DateTime.UtcNow > (item.LastMoved + item.DecayTime))
                {
                    _decayBag.Add(item);
                }

                if (_metrics != null)
                {
                    _metrics.OnItemSaved(size);
                }

                return(writer);
            },
                writer =>
            {
                writer.Flush();

                _itemThreadWriters.Add(writer);
            });

            _itemThreadWriters.CompleteAdding();             //We only get here after the Parallel.ForEach completes.  Lets our task

            return(commitTask);
        }
Пример #3
0
        protected void SaveItems(SaveMetrics metrics)
        {
            Dictionary<Serial, Item> items = World.Items;

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (UseSequentialWriters)
            {
                idx = new BinaryFileWriter( World.ItemIndexPath, false );
                tdb = new BinaryFileWriter( World.ItemTypesPath, false );
                bin = new BinaryFileWriter( World.ItemDataPath, true );
            } else {
                idx = new AsyncWriter( World.ItemIndexPath, false );
                tdb = new AsyncWriter( World.ItemTypesPath, false );
                bin = new AsyncWriter( World.ItemDataPath, true );
            }

            idx.Write( ( int ) items.Count );
            foreach ( Item item in items.Values ) {
                if ( item.Decays && item.Parent == null && item.Map != Map.Internal && ( item.LastMoved + item.DecayTime ) <= DateTime.Now ) {
                    _decayQueue.Enqueue( item );
                }

                long start = bin.Position;

                idx.Write( ( int ) item.m_TypeRef );
                idx.Write( ( int ) item.Serial );
                idx.Write( ( long ) start );

                item.Serialize( bin );

                if ( metrics != null ) {
                    metrics.OnItemSaved( ( int ) ( bin.Position - start ) );
                }

                idx.Write( ( int ) ( bin.Position - start ) );

                item.FreeCache();
            }

            tdb.Write( ( int ) World.m_ItemTypes.Count );
            for ( int i = 0; i < World.m_ItemTypes.Count; ++i )
                tdb.Write( World.m_ItemTypes[i].FullName );

            idx.Close();
            tdb.Close();
            bin.Close();
        }
Пример #4
0
        protected void SaveItems(SaveMetrics metrics)
        {
            Dictionary <Serial, Item> items = World.Items;
            List <Item> decaying            = new List <Item>();

            GenericWriter idx;
            GenericWriter tdb;
            GenericWriter bin;

            if (World.SaveType == World.SaveOption.Normal)
            {
                idx = new BinaryFileWriter(World.ItemIndexPath, false);
                tdb = new BinaryFileWriter(World.ItemTypesPath, false);
                bin = new BinaryFileWriter(World.ItemDataPath, true);
            }
            else
            {
                idx = new AsyncWriter(World.ItemIndexPath, false);
                tdb = new AsyncWriter(World.ItemTypesPath, false);
                bin = new AsyncWriter(World.ItemDataPath, true);
            }

            idx.Write(( int )items.Count);
            foreach (Item item in items.Values)
            {
                if (item.Decays && item.Parent == null && item.Map != Map.Internal && (item.LastMoved + item.DecayTime) <= DateTime.Now)
                {
                    decaying.Add(item);
                }

                long start = bin.Position;

                idx.Write(( int )item.m_TypeRef);
                idx.Write(( int )item.Serial);
                idx.Write(( long )start);

                item.Serialize(bin);

                if (metrics != null)
                {
                    metrics.OnItemSaved(( int )(bin.Position - start));
                }

                idx.Write(( int )(bin.Position - start));

                item.FreeCache();
            }

            tdb.Write(( int )World.m_ItemTypes.Count);
            for (int i = 0; i < World.m_ItemTypes.Count; ++i)
            {
                tdb.Write(World.m_ItemTypes[i].FullName);
            }

            idx.Close();
            tdb.Close();
            bin.Close();

            for (int i = 0; i < decaying.Count; ++i)
            {
                Item item = decaying[i];

                if (item.OnDecay())
                {
                    item.Delete();
                }
            }
        }