Пример #1
0
        }                                                                                                   //= new System.Collections.Concurrent.BlockingCollection<CCommandStucture> ();


        public CConnection(string name, string protocol, string ip, string port, string appName, List <CSettingsListener> listenersSettings, List <CSettingsPublisher> publisherSettings, CPlaza2Connector p2con, int sleepTime)
        {
            Name       = name;
            m_settings = string.Format(@"{0}://{1}:{2};app_name={3}_{4}", protocol, ip, port, appName, name);

            BotId = 0;
            IsConnectionOrderControl = CUtilConnection.IsConnectionOrderControl(Name, ref BotId);

            m_listenersSettings = listenersSettings;
            m_publisherSettings = publisherSettings;
            Exit = false;
            m_plaza2Connector = p2con;


            m_threadProc = new System.Threading.Thread(ThreadProc);
            m_threadProc.Start();
            if (name == "ConnectionMarketData" || name == "ConnectionStockData" /*|| name == "ConnectionHeartBeat"*/)
            {
                m_threadProc.Priority = ThreadPriority.Highest;
            }


            m_sleepTime = sleepTime;

            IsConnectionProblem = false;
            _sleeper            = new CSleeper();
        }
Пример #2
0
        private void ProcessListeners()
        {
            foreach (CPlaza2Listener lstn in m_listenersList)
            {
                try
                {       //tempo
                        // if (lstn.Name == "ListenerStock" || lstn.Name == "ListenerDeals")
                        //     Log("start process listener "+ lstn.Name);

                    lstn.CheckOnOff();

                    if (!lstn.Disabled && lstn.StateIS == State.Closed)
                    {
                        //  if (this.Name != "ConnectionOrderControl_1" ||
                        //    (this.Name == "ConnectionOrderControl_1"  && m_publishersList.Count!=0 &&  m_publishersList[0].StateIS == State.Active))//to remove exceptions
                        if (!IsConnectionOrderControl ||
                            (IsConnectionOrderControl && m_publishersList.Count != 0 && m_publishersList[0].StateIS == State.Active))    //to remove exceptions

                        {
                            /* if (lstn.Name == "ListenerPosition")
                             *   lstn.Open("mode=snapshot+online;lifenum=1;rev.position=8075354");
                             * else if (lstn.Name == "ListenerUserDeals")
                             *   lstn.Open("mode=snapshot+online;lifenum=402;rev.user_deal=1374328895");
                             *
                             *
                             * else
                             */


                            if (lstn.Name == "ListenerHeartBeat")
                            {
                                lstn.Open("mode=online");
                            }

                            else if (lstn.Name == "ListenerDeals")
                            {
                                if (m_plaza2Connector.NeedHistoricalDeals)
                                {
                                    lstn.Open("rev.deal=" + m_plaza2Connector.LastDealRevId + ";lifenum=" +
                                              m_plaza2Connector.LastDealLifeNum);
                                }
                                //lstn.Open("rev.deal=" + m_plaza2Connector.LastDealRevId);
                                else
                                {
                                    lstn.Open("mode=online");
                                }
                            }
                            //2018-07-02
                            else if (lstn.Name == "ListenerASTSCurrALL_TRADES")
                            {
                                lstn.Open("rev.ALL_TRADES=" + m_plaza2Connector.LastASTSCurrDealRevId + ";lifenum=" +
                                          m_plaza2Connector.LastASTSCurrDealLifeNum);

                                // lstn.Open(String.Format("rev.ALL_TRADES={0};lifenum=0", m_plaza2Connector.LastASTSCurrDealRevId ));// + m_plaza2Connector.LastASTSCurrDealRevId);
                                // lstn.Open("");
                            }

                            else if (lstn.Name == "ListenerStock")
                            {
                                lstn.Open("mode=snapshot+online" /*"mode=online"*/);
                            }
                            //  else if (lstn.Name == "ListenerUserOrderLog")
                            //    lstn.Open("rev.orders_log=" + m_plaza2Connector.LastUserOrderLogRevId);

                            // else if (lstn.Name == "ListenerUserDeals")
                            //   lstn.Open("rev.user_deal=" + m_plaza2Connector.LastUserDealRevId);
                            else
                            {
                                lstn.Open("");
                            }
                        }
                    }
                    else if (lstn.StateIS == State.Opening)
                    {
                    }

                    else if (!lstn.Disabled && lstn.StateIS == State.Error)
                    {
                        lstn.Disabled = true;
                        lstn.TimerRetry.Set();

                        lstn.Close();
                        lstn.OnError();
                    }
                    else if (!lstn.Disabled && lstn.StateIS == State.Active)
                    {
                        lstn.TimerRetry.Reset();
                        lstn.Disabled = false;

                        // if (lstn.Name == "ListenerOrderControlReply")
                        //m_plaza2Connector.IsOrderControlAvailable = true;

                        if (CUtilConnection.IsConnectionOrderControl(this.Name, ref BotId) &&
                            !this.IsOrderControlReady)
                        {
                            (new Thread(ThreadProcessCommands)).Start();
                            System.Threading.Thread.Sleep(100);   //wait full init of blocking coll


                            this.IsOrderControlReady = true;



                            if (m_plaza2Connector.IsAllContolConnectionReady())
                            {
                                m_plaza2Connector.IsOrderControlAvailable = true;
                            }
                        }
                    }

                    //     if (lstn.Name == "ListenerStock" || lstn.Name == "ListenerDeals")
                    //      Log("end process listener " + lstn.Name);
                }
                catch (Exception e)
                {
                    string err = "Error pocessing listener " + lstn.Name;
                    Log(lstn.Name + " " + e.Message);
                    m_plaza2Connector.Alarmer.Error(err, e);
                }
            }
        }