Esempio n. 1
0
 void ConnectToPositionListener(RediScraper rs, bool canConnect)
 {
     if (!rs.IsPositionListenerStarted && IsRediRunning && canConnect)
     {
         rs.ConnectPositionListener();
     }
 }
Esempio n. 2
0
 void ConnectoToMessageListener(RediScraper rs, bool canConnect)
 {
     if (!rs.IsMessageListenerStarted && IsRediRunning && canConnect)
     {
         rs.ConnectMessageListener();
     }
 }
Esempio n. 3
0
        void ApplicationWork()
        {
            log.Info("Worker thread started");
            rediScraper = new RediScraper(appConfig.UserId, appConfig.Password);
            rediScraper.StatusChanged      += RediStatusChanged;
            rediScraper.ShouldProcessEvents = true;

            amqPublisher = new ActiveMQPublisher(appConfig.BrokerUrl);
            amqPublisher.Connect();

            pingTimer = new Timer(RediPingHandler, rediScraper, 500, 10 * 1000);
            long millisToWait;

            shutdownTimer = CreateShutdownTime(DateTime.Now, ShutdownTimerHandler, out millisToWait);

            SendingToActiveMQ = true;

            while (SendingToActiveMQ)
            {
                while (rediScraper.PositionCount > 0 && amqPublisher.IsConnected && SendingToActiveMQ)
                {
                    var positionMessage = rediScraper.GetNextPosition();
                    if (positionMessage == null)
                    {
                        continue;
                    }

                    // remove the yellow key/product code
                    var bid = positionMessage["BID"].Split(' ');
                    positionMessage["BID"] = bid[0];

                    if (bid.Length > 1)
                    {
                        positionMessage.Add("YELLOWKEY", bid[1]);
                    }

                    var topicName = positionMessage["ACCOUNT"] + "." + positionMessage["BID"];
                    positionMessage.Add("SOURCE", "REDI");

                    amqPublisher.Publish("Redi.Positions." + topicName, positionMessage);
                }

                while (rediScraper.ExecutionCount > 0 && amqPublisher.IsConnected && SendingToActiveMQ)
                {
                    var executionMessage = rediScraper.GetNextExecution();
                    if (executionMessage == null)
                    {
                        continue;
                    }

                    var topicName = executionMessage["ACCOUNT"] + "." + executionMessage["BID"];
                    amqPublisher.Publish("Redi.Executions." + topicName, executionMessage);
                }

                Thread.Sleep(10);
            }
            log.Info("Worker thread stopped");
        }