Пример #1
0
        }//end HubEvent

        //
        //
        //
        //
        #endregion// Hub Event Handler overrides

        #region Public Methods
        // *****************************************************************
        // ****                     Public Methods                      ****
        // *****************************************************************
        //
        //
        //***********************************************
        // ****             Start()                 ****
        //***********************************************
        public override void Start()
        {
            //
            // Create needed hubs
            //
            m_DatabaseWriterHub = new DatabaseWriterHub(m_DataBaseInfo);
            m_DatabaseWriterHub.Log.AllowedMessages = LogLevel.ShowAllMessages;
            m_DatabaseWriterHub.Log.IsViewActive    = true;
            m_DatabaseWriterHub.WriteCompleted     += new EventHandler(this.HubEventEnqueue);
            m_DatabaseWriterHub.Start();
            m_QueryBuilderHub = new QueryBuilderHub(this, m_DatabaseWriterHub);



            //
            // Set datetime bars.
            //
            DateTime dt           = Log.GetTime();
            double   totalSeconds = dt.Minute * 60.0 + dt.Second;

            dt            = dt.AddSeconds(-totalSeconds);                                   // rip off minutes and seconds.
            totalSeconds  = Math.Ceiling(totalSeconds / m_BarTimeStep) * m_BarTimeStep;     // rounding off to nearest bar.
            totalSeconds += m_BarTimeStep;                                                  // increment to next bar.
            dt            = dt.AddSeconds(totalSeconds);                                    // set bar time.
            dt            = dt.AddMilliseconds(-dt.Millisecond);
            m_NextBar     = dt;
            base.m_WaitListenUpdatePeriod = 100;                                            // update every n ms

            //
            // Find stop time.
            //
            DateTime today     = DateTime.Today;
            DateTime startTime = DateTime.Now;

            m_EndRecordingDateTime = today.AddMinutes(60 * 16 + 20);                        // we want to stop each day at 4:20 pm
            if (m_StopFrequency == StopFrequency.Daily)
            {
                if (startTime > m_EndRecordingDateTime)                                         // it is already past 4:20, so stop the next day at 4:20
                {
                    m_EndRecordingDateTime = m_EndRecordingDateTime.AddDays(1);
                }
            }
            else if (m_StopFrequency == StopFrequency.Weekly)
            {
                int daysToAdd = ((int)DayOfWeek.Friday - (int)startTime.DayOfWeek + 7) % 7;
                m_EndRecordingDateTime = m_EndRecordingDateTime.AddDays(daysToAdd);
            }
            Log.NewEntry(LogLevel.Major, "DataHub: Scheduled Shutdown for {0} ", m_EndRecordingDateTime);

            //
            List <ProductRequest> startingRequestList;

            ProductRequest.TryCreateFromFile("ProductRequest.txt", out startingRequestList);
            //
            // Split requests into smaller subsets to avoid TT Choking.
            //
            if (startingRequestList.Count > m_MaxProductsPerRequest)
            {                                                                                                // we need to subset.
                int reqCount = 0;                                                                            //dummy counter varialble
                while (reqCount < startingRequestList.Count)
                {                                                                                            // iterate through and subset lists until we are completed.
                    List <ProductRequest> subsettedList = new List <ProductRequest>();
                    int endOfList = Math.Min(m_MaxProductsPerRequest, startingRequestList.Count - reqCount); //this ensures we don't mess up the indexing
                    subsettedList = startingRequestList.GetRange(reqCount, endOfList);
                    m_SplitProdReqs.Add(subsettedList);
                    reqCount += m_MaxProductsPerRequest;
                }
            }
            else
            {
                m_SplitProdReqs.Add(startingRequestList);               // no need to subset, just add them all.
            }
            m_nProductRequested = startingRequestList.Count;            // store for reporting purposes
            //
            // Send email's on startup
            //
            if (m_IsEmailOnStartStop)
            { // we can abuse the DataBaseWrtiter to send start and stop emails
                DatabaseWriterEventArgs emailEvent = new DatabaseWriterEventArgs();
                emailEvent.Request = DatabaseWriterRequests.SendEmail;
                emailEvent.QueryBase.AppendFormat("Data Hub Starting {0}", DateTime.Now);
                emailEvent.QueryValues.AppendFormat("Data Hub requesting {0} products to be recorded to {1}. Scheduled for shutdown at {2}",
                                                    m_nProductRequested,
                                                    m_DataBaseInfo.Location,
                                                    m_EndRecordingDateTime);
                m_DatabaseWriterHub.HubEventEnqueue(emailEvent);
            }

            base.Start();
            m_IsReadyToRequest = true;
        }// Start()