Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <c>QuoteDataProvider</c> class.
 /// </summary>
 public QuoteDataProvider()
 {
     m_runByState     = Idle;
     m_status         = QuoteProviderStatus.Inactive;
     m_listeners      = new List <IQuoteDataListener>();
     m_providerThread = null;
     m_stopSignal     = new AutoResetEvent(false);
 }
Esempio n. 2
0
        /// <summary>
        /// Changes the status of a quote data provider and notifies listeners.
        /// </summary>
        /// <param name="current">the status to change to.</param>
        protected void ChangeStatus(QuoteProviderStatus current)
        {
            if (m_status == current)
            {
                return;
            }

            OnStatusChanged(new StatusChangedEventArgs(m_status, current));
            m_status = current;
        }
Esempio n. 3
0
        /// <summary>
        /// Event handler for status change. It prints out notifications.
        /// </summary>
        /// <param name="e">the event args that contains the data of this event.</param>
        public void OnStatusChanged(object sender, StatusChangedEventArgs e)
        {
            QuoteProviderStatus previous = e.Old;
            QuoteProviderStatus current  = e.New;

            if (previous != QuoteProviderStatus.Inactive && current == QuoteProviderStatus.Open)
            {
                Console.WriteLine("Attempting to reopen resource...");
            }
            else if ((previous == QuoteProviderStatus.Open || previous == QuoteProviderStatus.Authenticate) && current == QuoteProviderStatus.Read)
            {
                Console.WriteLine("Resource opened successfully.\n");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Tries to reconnect to the remote server, and gives up if trials exceeds a set limit.
        /// </summary>
        /// <returns>Time to sleep in milliseconds till executing next state.</returns>
        private int RetryOrGiveup(QuoteProviderStatus previous)
        {
            if (++m_retryTimes >= 3)
            {
                OnErrorOccurred(new Exception("Max number of reconnection trials reached."), true);
                m_runByState = Close;
                return(0);
            }

            Close();               // first, close
            m_runByState = Create; // then, re-create

            return(1000 + m_rand.Next(2000));
        }
 /// <summary>
 /// Initializes a new instance of the <c>StatusChangedEventArgs</c> class with the given previous and next status.
 /// </summary>
 /// <param name="old"></param>
 /// <param name="current"></param>
 public StatusChangedEventArgs(QuoteProviderStatus old, QuoteProviderStatus current)
 {
     m_old = old;
     m_new = current;
 }