Пример #1
0
        private async Task ProcessInstructionQueue()
        {
            if (!Amnesia.LastInstructionWasExecuted())
            {
                return;
            }

            TimedInstruction extension;

            for (var i = 0; i < _instructionQueue.Count; i++)
            {
                if (_instructionQueue.TryDequeue(out extension) == false)
                {
                    Console.WriteLine("Failed to dequeue an instruction");
                    return;
                }

                if (DateTime.Now >= extension.ExecuteAfterDateTime)
                {
                    await Amnesia.ExecuteAsync(extension.Angelcode);

                    return;
                }

                _instructionQueue.Enqueue(extension);
            }
        }
Пример #2
0
        private async Task ProcessAntidoteQueue()
        {
            if (!Amnesia.LastInstructionWasExecuted())
            {
                return;
            }

            PayloadAntidote antidote;

            for (var i = 0; i < _antidoteQueue.Count; i++)
            {
                antidote = _antidoteQueue.ElementAt(i);
                if (DateTime.Now < antidote.ExecuteAfterDateTime)
                {
                    continue;
                }

                await Amnesia.ExecuteAsync(antidote.Angelcode);

                _antidoteQueue.Remove(antidote);
                return;
            }

            return;
        }
Пример #3
0
        private async Task ProcessPayload(Payload payload)
        {
            await Amnesia.ExecuteAsync(payload.Angelcode);

            if (string.IsNullOrWhiteSpace(payload.ReverseAngelcode) || payload.PayloadDuration is null)
            {
                return;
            }

            _antidoteQueue.Add(new PayloadAntidote
            {
                Angelcode            = payload.ReverseAngelcode,
                ExecuteAfterDateTime = DateTime.Now.Add(payload.PayloadDuration.Value)
            });
        }
Пример #4
0
        private Task ProcessCommandQueue()
        {
            if (_payloadQueue.Count == 0)
            {
                return(Task.CompletedTask);
            }

            if (!Amnesia.LastInstructionWasExecuted())
            {
                return(Task.CompletedTask);
            }

            var payload = _payloadQueue.Dequeue();

            return(ProcessPayload(payload));
        }
Пример #5
0
        private void ProcessCommandQueue()
        {
            if (_payloadQueue.Count == 0)
            {
                return;
            }

            if (!Amnesia.LastInstructionWasExecuted())
            {
                return;
            }

            if (_payloadQueue.TryDequeue(out var payload) == false)
            {
                Console.WriteLine("A dequeue of a payload failed");
                return;
            }

            ProcessPayload(payload);
        }