private static void OnLiftRequest(PacketReader reader)
 {
     Engine.LastActionPacket     = DateTime.Now;
     Engine.Player.Holding       = reader.ReadInt32();
     Engine.Player.HoldingAmount = reader.ReadUInt16();
     CountersManager.GetInstance().RecountAll?.Invoke();
 }
        public CountersTabViewModel()
        {
            CountersManager manager = CountersManager.GetInstance();

            manager.Items      = Items;
            manager.RecountAll = () => Recount(null);
        }
Exemple #3
0
        /// <summary>
        /// Allocate an indicator for tracking the status of a channel endpoint.
        /// </summary>
        /// <param name="tempBuffer">      to be used for labels and metadata. </param>
        /// <param name="name">            of the counter for the label. </param>
        /// <param name="typeId">          of the counter for classification. </param>
        /// <param name="countersManager"> from which to allocated the underlying storage. </param>
        /// <param name="channel">         for the stream of messages. </param>
        /// <returns> a new <seealso cref="AtomicCounter"/> for tracking the status. </returns>
        public static AtomicCounter Allocate(IMutableDirectBuffer tempBuffer, string name, int typeId,
                                             CountersManager countersManager, string channel)
        {
            int keyLength =
                tempBuffer.PutStringWithoutLengthAscii(CHANNEL_OFFSET + BitUtil.SIZE_OF_INT, channel, 0,
                                                       MAX_CHANNEL_LENGTH);

            tempBuffer.PutInt(CHANNEL_OFFSET, keyLength);

            int labelLength = 0;

            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, name);
            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, ": ");
            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, channel, 0,
                                                                  CountersReader.MAX_LABEL_LENGTH - labelLength);


            if (labelLength < CountersReader.MAX_LABEL_LENGTH)
            {
                tempBuffer.PutByte(keyLength + labelLength, (byte)' ');
                labelLength += 1;
            }

            return(countersManager.NewCounter(typeId, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelLength));
        }
Exemple #4
0
 /// <summary>
 /// Map a position over a buffer and this indicator owns the counter for reclamation.
 /// </summary>
 /// <param name="buffer">          containing the counter. </param>
 /// <param name="counterId">       identifier of the counter. </param>
 /// <param name="countersManager"> to be used for freeing the counter when this is closed. </param>
 public UnsafeBufferPosition(UnsafeBuffer buffer, int counterId, CountersManager countersManager)
 {
     _buffer          = buffer;
     _counterId       = counterId;
     _countersManager = countersManager;
     _offset          = CountersReader.CounterOffset(counterId);
 }
Exemple #5
0
 /// <summary>
 /// Map a position over a buffer and this indicator owns the counter for reclamation.
 /// </summary>
 /// <param name="buffer">          containing the counter. </param>
 /// <param name="counterId">       identifier of the counter. </param>
 /// <param name="countersManager"> to be used for freeing the counter when this is closed. </param>
 public UnsafeBufferPosition(UnsafeBuffer buffer, int counterId, CountersManager countersManager)
 {
     _buffer = buffer;
     _counterId = counterId;
     _countersManager = countersManager;
     _offset = CountersReader.CounterOffset(counterId);
 }
Exemple #6
0
 /// <summary>
 /// Allocate a counter for tracking the last heartbeat of an entity.
 /// </summary>
 /// <param name="tempBuffer">      to be used for labels and key. </param>
 /// <param name="name">            of the counter for the label. </param>
 /// <param name="typeId">          of the counter for classification. </param>
 /// <param name="countersManager"> from which to allocated the underlying storage. </param>
 /// <param name="registrationId">  to be associated with the counter. </param>
 /// <returns> a new <seealso cref="AtomicCounter"/> for tracking the last heartbeat. </returns>
 public static AtomicCounter Allocate(
     IMutableDirectBuffer tempBuffer,
     string name,
     int typeId,
     CountersManager countersManager,
     long registrationId)
 {
     return(new AtomicCounter(countersManager.ValuesBuffer,
                              AllocateCounterId(tempBuffer, name, typeId, countersManager, registrationId), countersManager));
 }
Exemple #7
0
        public void Setup()
        {
            _consumer = A.Fake <IntObjConsumer <string> >();
            _metaData = A.Fake <CountersReader.MetaData>();

            _labelsBuffer  = new UnsafeBuffer(new byte[NumberOfCounters * CountersReader.METADATA_LENGTH]);
            _counterBuffer = new UnsafeBuffer(new byte[NumberOfCounters * CountersReader.COUNTER_LENGTH]);

            _manager      = new CountersManager(_labelsBuffer, _counterBuffer);
            _otherManager = new CountersManager(_labelsBuffer, _counterBuffer);
        }
Exemple #8
0
        public void Setup()
        {
            _consumer = A.Fake <IntObjConsumer <string> >();
            _metaData = A.Fake <CountersReader.MetaData>();

            _labelsBuffer  = new UnsafeBuffer(BufferUtil.AllocateDirect(NumberOfCounters * CountersReader.METADATA_LENGTH));
            _counterBuffer = new UnsafeBuffer(BufferUtil.AllocateDirect(NumberOfCounters * CountersReader.COUNTER_LENGTH));

            _manager      = new CountersManager(_labelsBuffer, _counterBuffer, Encoding.ASCII);
            _otherManager = new CountersManager(_labelsBuffer, _counterBuffer, Encoding.ASCII);
        }
Exemple #9
0
        public static int Counter(string name)
        {
            CountersManager manager = CountersManager.GetInstance();

            CountersAgentEntry entry = manager.Items.FirstOrDefault(cae => cae.Name.ToLower() == name.ToLower());

            if (entry != null)
            {
                return(entry.Count);
            }

            UOC.SystemMessage(Strings.Invalid_counter_agent_name___);
            return(0);
        }
Exemple #10
0
        public void Setup()
        {
            _testClock = new TestEpochClock();

            _consumer = A.Fake <IntObjConsumer <string> >();
            _metaData = A.Fake <CountersReader.MetaData>();

            _labelsBuffer  = new UnsafeBuffer(BufferUtil.AllocateDirect(NumberOfCounters * CountersReader.METADATA_LENGTH));
            _counterBuffer = new UnsafeBuffer(BufferUtil.AllocateDirect(NumberOfCounters * CountersReader.COUNTER_LENGTH));

            _manager             = new CountersManager(_labelsBuffer, _counterBuffer, Encoding.ASCII);
            _reader              = new CountersManager(_labelsBuffer, _counterBuffer, Encoding.ASCII);
            _managerWithCooldown = new CountersManager(_labelsBuffer, _counterBuffer, Encoding.ASCII, _testClock, FREE_TO_REUSE_TIMEOUT);
        }
Exemple #11
0
        public static int AllocateCounterId(
            IMutableDirectBuffer tempBuffer,
            string name,
            int typeId,
            CountersManager countersManager,
            long registrationId)
        {
            tempBuffer.PutLong(REGISTRATION_ID_OFFSET, registrationId);
            int keyLength = REGISTRATION_ID_OFFSET + BitUtil.SIZE_OF_LONG;

            int labelLength = 0;

            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, name);
            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, ": ");
            labelLength += tempBuffer.PutLongAscii(keyLength + labelLength, registrationId);

            return(countersManager.Allocate(typeId, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelLength));
        }
Exemple #12
0
        public void CounterWillCountType()
        {
            PlayerMobile player   = new PlayerMobile(0x01);
            Item         backpack = new Item(0x02)
            {
                Layer = Layer.Backpack, Container = new ItemCollection(0x02)
            };

            player.SetLayer(Layer.Backpack, backpack.Serial);
            Engine.Items.Add(backpack);
            Engine.Player = player;

            CountersManager manager = CountersManager.GetInstance();

            manager.Items.Add(new CountersAgentEntry {
                Name = "test", Color = -1, Graphic = 0xff
            });

            backpack.Container.Add(new Item(0x03)
            {
                ID = 0xff, Owner = 0x02, Count = 1
            });

            manager.RecountAll = () =>
            {
                foreach (CountersAgentEntry entry in manager.Items)
                {
                    entry.Recount();
                }
            };

            manager.RecountAll();

            int count = AgentCommands.Counter("test");

            Assert.AreEqual(1, count);
        }