FastQuant.EventBus.Dequeue_me C# (CSharp) Méthode

Dequeue_me() private méthode

private Dequeue_me ( ) : Event
Résultat Event
        private Event Dequeue_me()
        {
            if (Mode == EventBusMode.Simulation)
            {
                while (true)
                {
                    if (!DataPipe.IsEmpty() && this.@event == null)
                    {
                        var e = DataPipe.Read();
                        if (e.dateTime < this.framework.Clock.DateTime)
                        {
                            if (e.TypeId != EventType.OnQueueOpened && e.TypeId != EventType.OnQueueClosed && e.TypeId != EventType.OnSimulatorStop)
                            {
                                if (e.TypeId != EventType.OnSimulatorProgress)
                                {
                                    if (ShowWarnings)
                                        Console.WriteLine($"EventBus::Dequeue Skipping: {e} {e.dateTime} <> {this.framework.Clock.DateTime}");
                                    continue;
                                }
                            }
                            e.DateTime = this.framework.Clock.DateTime;
                            this.@event = e;
                        }
                        else
                            this.@event = e;
                    }

                    if (!ExecutionPipe.IsEmpty())
                        return this.ExecutionPipe.Read();

                    if (!LocalClockEventQueue.IsEmpty() && this.@event != null)
                    {
                        if (ReminderOrder == ReminderOrder.Before)
                        {
                            if (LocalClockEventQueue.PeekDateTime() <= [email protected])
                                return LocalClockEventQueue.Read();
                        }
                        else if (this.LocalClockEventQueue.PeekDateTime() < [email protected])
                            return LocalClockEventQueue.Read();
                    }

                    if (!LocalClockEventQueue.IsEmpty() && this.@event != null && ([email protected] == EventType.Bid || [email protected] == EventType.Ask || [email protected] == EventType.Trade))
                    {
                        if (ReminderOrder == ReminderOrder.Before)
                        {
                            if (ExchangeClockEventQueue.PeekDateTime() <= ((Tick)this.@event).ExchangeDateTime)
                                return this.ExchangeClockEventQueue.Read();
                        }
                        else if (ExchangeClockEventQueue.PeekDateTime() < ((Tick)this.@event).ExchangeDateTime)
                            return ExchangeClockEventQueue.Read();
                    }

                    if (!CommandPipe.IsEmpty())
                        return CommandPipe.Read();

                    if (!ServicePipe.IsEmpty())
                        return ServicePipe.Read();

                    if (this.@event != null)
                    {
                        // forward the event to externally attached queues
                        var e = this.@event;
                        this.@event = null;
                        for (int i = 0; i < this.attachedCount; i++)
                            if (e.TypeId != EventType.OnQueueOpened && e.TypeId != EventType.OnQueueClosed)
                                this.attached[i].Enqueue(e);
                        return e;
                    }

                    // still not getting any event, try later
                    Thread.Sleep(1);
                }
            }

            // Mode == EventBusMode.Realtime
            while (true)
            {
                if (!DataPipe.IsEmpty() && this.@event == null)
                    this.@event = DataPipe.Read();

                if (!LocalClockEventQueue.IsEmpty())
                {
                    if (ReminderOrder == ReminderOrder.Before)
                    {
                        if (LocalClockEventQueue.PeekDateTime() <= this.framework.Clock.DateTime)
                            return LocalClockEventQueue.Read();
                    }
                    else if (LocalClockEventQueue.PeekDateTime() < this.framework.Clock.DateTime)
                        return LocalClockEventQueue.Read();
                }

                if (!ExchangeClockEventQueue.IsEmpty() && this.@event != null && ([email protected] == EventType.Bid || [email protected] == EventType.Ask || [email protected] == EventType.Trade))
                {
                    if (ReminderOrder == ReminderOrder.Before)
                    {
                        if (ExchangeClockEventQueue.PeekDateTime() <= ((Tick)this.@event).ExchangeDateTime)
                            return this.ExchangeClockEventQueue.Read();
                    }
                    else if (ExchangeClockEventQueue.PeekDateTime() < ((Tick)this.@event).ExchangeDateTime)
                        return ExchangeClockEventQueue.Read();
                }

                if (!ExecutionPipe.IsEmpty())
                    return ExecutionPipe.Read();

                if (!CommandPipe.IsEmpty())
                    return CommandPipe.Read();

                if (!ServicePipe.IsEmpty())
                    return ServicePipe.Read();

                if (this.@event != null)
                {
                    var result = this.@event;
                    this.@event = null;
                    return result;
                }

                // still not getting an event, go idle for a while
                switch (IdleMode)
                {
                    case EventBusIdleMode.Sleep:
                        Thread.Sleep(1);
                        break;
                    case EventBusIdleMode.Wait:
                        this.hasWorkEvent.Reset();
                        this.hasWorkEvent.Wait(1);
                        break;
                }
            }
        }