예제 #1
0
        //
        //

        /*
         * public bool RequestAddHub(FillHub fillHub)
         * {
         *  string name = fillHub.Name;
         *  if (string.IsNullOrEmpty(name))
         *      name = DefaultHubName;
         *  // Submit request to hub thread.
         *  TalkerHubEventArg request = new TalkerHubEventArg(TalkerHubRequest.RequestAddHub);
         *  request.Data = new List<object>();
         *  request.Data.Add(fillHub);
         *  return HubEventEnqueue(request);
         * }// ConnectHub()
         * //
         */
        public bool RequestAddHub(Hub hub)
        {
            string name = hub.HubName;

            if (string.IsNullOrEmpty(name))
            {
                name = DefaultHubName;
            }
            // Submit request to hub thread.
            TalkerHubEventArg request = new TalkerHubEventArg(TalkerHubRequest.RequestAddHub);

            request.Data = new List <object>();
            request.Data.Add(hub);
            return(HubEventEnqueue(request));
        }// ConnectHub()
예제 #2
0
        }//HubEventHandler()

        //
        //
        // *********************************************************
        // ****             Process Hub Request                 ****
        // *********************************************************
        /// <summary>
        /// Direct requests from outsiders for managing this TalkerHub.
        /// </summary>
        private void ProcessRequest(TalkerHubEventArg eventArg)
        {
            switch (eventArg.Request)
            {
            case TalkerHubRequest.AmberXLConnect:                         // try to connect to Excel
                if (m_SocketBreTalker == null)
                {
                    m_SocketBreTalker                  = new SocketManager();
                    m_SocketBreTalker.Connected       += new EventHandler(HubEventEnqueue);
                    m_SocketBreTalker.Disconnected    += new EventHandler(HubEventEnqueue);
                    m_SocketBreTalker.MessageReceived += new EventHandler(HubEventEnqueue);
                }
                if (!TryToConnectToExcel())
                {       // Failed to connect.
                        // TODO: Put this request in our waiting queue and try again periodically.
                    m_AmbreXLReconnectFailureCount++;
                    m_AmbreXLReconnectCounter = Math.Min(AmbreXLReconnectCounterMin * m_AmbreXLReconnectFailureCount, AmbreXLReconnectCounterMax);
                    Log.NewEntry(LogLevel.Major, "ProcessRequest: Failed {0} times to connect to socket. Try again in {1:0.0} seconds.", m_AmbreXLReconnectFailureCount, (m_AmbreXLReconnectCounter / 1000.0));
                }
                else
                {
                    Log.NewEntry(LogLevel.Major, "ProcessRequest: Connected to Socket.");
                }
                break;

            case TalkerHubRequest.AmbreXLDisconnect:
                m_SocketBreTalker.StopConversation();
                break;

            case TalkerHubRequest.StopService:
                if (m_SocketBreTalker != null)
                {
                    m_SocketBreTalker.StopConversation();
                    if (m_SocketBreTalker.IsServing)
                    {
                        m_SocketBreTalker.StopServer();
                    }
                }
                this.Stop();
                break;

            case TalkerHubRequest.RequestAddHub:
                if (eventArg.Data != null)
                {
                    foreach (object newHub in eventArg.Data)
                    {
                        if (newHub is FillHub)
                        {
                            FillHub newFillHub = (FillHub)newHub;
                            FillHub oldFillHub;
                            if (m_FillHubs.TryGetValue(newFillHub.Name, out oldFillHub))
                            {                                                                        // User must want to replace fill hub with same name...
                                m_FillHubs.Remove(oldFillHub.Name);
                                oldFillHub.PositionBookCreated -= new EventHandler(HubEventEnqueue); // unsubscribe to this old hub
                                oldFillHub.PositionBookChanged -= new EventHandler(HubEventEnqueue);
                                oldFillHub.PositionBookDeleted -= new EventHandler(HubEventEnqueue);
                            }
                            m_FillHubs.Add(newFillHub.Name, newFillHub);
                            newFillHub.PositionBookCreated += new EventHandler(HubEventEnqueue);            // subscribe to this new hub
                            newFillHub.PositionBookChanged += new EventHandler(HubEventEnqueue);
                            newFillHub.PositionBookDeleted += new EventHandler(HubEventEnqueue);
                        }    // if new hub is FillHub type.
                        else if (newHub is MarketTTAPI)
                        {
                            //UV.Lib.MarketHubs.MarketHub marketHub = (UV.Lib.MarketHubs.MarketHub)newHub;
                            MarketTTAPI marketHub = (MarketTTAPI)newHub;
                            m_MarketHub = marketHub;
                        }
                    } //for each hub passed to us.
                }     // if request contains data.
                break;

            default:
                break;
            }
        }//ProcessRequest()