Пример #1
0
        private void RestartPump(PumpServer aPump)
        {
            aPump.Timer.Stop();
            if (!EnableRunning)
            {
                if (aPump.MT4 != null)
                {
                    FreeMT4(aPump);
                }
                return;
            }
            int retryTimes = 5;
            var mt4        = new MT4API(true);

            while (retryTimes-- > 0)
            {
                if (!mt4.IsPumpAlive())
                {
                    var logger = Utils.CommonLog;
                    logger.Warn(
                        string.Format("MT4推送接收连接建立失败,一秒之后重试,剩余机会{0}",
                                      retryTimes + 1));
                    System.Threading.Thread.Sleep(1000);
                    mt4.ConnectPump();
                    continue;
                }
                break;
            }
            if (retryTimes == -1)
            {
                var logger = Utils.CommonLog;
                logger.Error("MT4推送接收连接建立失败,请立即采取措施保障丢失的数据!");
            }
            else
            {
                mt4.OnNewTrade += WhenNewTrade;
                mt4.OnNewQuote += WhenNewQuote;
                if (aPump.MT4 != null)
                {
                    FreeMT4(aPump);
                }
                aPump.MT4 = mt4;
            }
            aPump.Timer.Start();
        }
Пример #2
0
 private void StartPump()
 {
     if (_tradeThread == null)
     {
         _tradeThread = new System.Threading.Thread(SaveTradeProc);
         _tradeThread.IsBackground = true;
         _tradeThread.Start();
         for (int i = 0; i < PumperCount; i++)
         {
             var timer = new Timer(10000);
             timer.Interval = 10000;
             var pump = new PumpServer();
             pump.Timer     = timer;
             timer.Elapsed += (sender, e) =>
             {
                 pump.RestartPump(pump);
             };
             _lstRunning.Add(pump);
             pump.RestartPump(pump);
         }
     }
 }