public override bool TransactionProcessing()
        {
            bool ret = false;

            if (mSymbols != null)
            {
                List <Thread> SubTask = new List <Thread>();

                int Index = 0;
                while (Index < mSymbols.Count)
                {
                    List <int> SubSymbols = mSymbols.GetRange(Index, Math.Min(mPerThreadCount, mSymbols.Count - Index));
                    Index += mPerThreadCount;

                    Thread NewThread = new Thread(o =>
                    {
                        DataCapture.SinaStockSubscription Capture = DataCapture.StockQuotesManager.Instance().CreateSinaStockSubscription(SubSymbols);
                        mCapture.Add(Capture);

                        Capture.SetTerminationCondition(DataCapture.TerminationCondition.TC_MarketClosed);
                        Capture.SetSubscriptionType(Level2DataType.Quotation);
                        Capture.SetDataDelegation(null, this.QuotationDataProcessor, null);
                        Capture.ConnectToSina();
                    });
                    NewThread.Start();

                    SubTask.Add(NewThread);
                }

                ret = true;

                while (true)
                {
                    if (DateTime.Now.Subtract(mLastCheck).Minutes >= GetInterval())
                    {
                        mLastCheck = DateTime.Now;

                        RecordDataToDisk();
                    }

                    bool AllCompleted = true;

                    foreach (var ele in SubTask)
                    {
                        AllCompleted &= (ele.ThreadState == ThreadState.Stopped);

                        ret &= (ele.ThreadState != ThreadState.Aborted);
                    }

                    if (AllCompleted)
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                }
            }

            return(ret);
        }
Пример #2
0
        public override bool TransactionProcessing()
        {
            bool ret = false;

            if (mSymbols != null)
            {
                List <Thread> SubTask = new List <Thread>();

                int Index = 0;
                while (Index < mSymbols.Count)
                {
                    List <int> SubSymbols = mSymbols.GetRange(Index, Math.Min(mPerThreadCount, mSymbols.Count - Index));
                    Index += mPerThreadCount;

                    Thread NewThread = new Thread(o =>
                    {
                        DataCapture.SinaStockSubscription Capture = DataCapture.StockQuotesManager.Instance().CreateSinaStockSubscription(SubSymbols);
                        Capture.SetTerminationCondition(DataCapture.TerminationCondition.TC_MarketClosed);
                        Capture.SetSubscriptionType(Level2DataType.Orders & Level2DataType.Quotation & Level2DataType.Transaction);
                        Capture.SetDataDelegation(DataMining.DataHub.PushOrdersDataInHub,
                                                  DataMining.DataHub.PushQuotationDataInHub,
                                                  (int Symbol, List <TransactionData> Transaction) => { DataMining.DataHub.PushTransactionDataInHub(Symbol, Transaction, false); });
                        Capture.ConnectToSina();
                    });
                    NewThread.Start();

                    SubTask.Add(NewThread);
                }

                ret = true;

                while (true)
                {
                    bool AllCompleted = true;

                    foreach (var ele in SubTask)
                    {
                        AllCompleted &= (ele.ThreadState == ThreadState.Stopped);

                        ret &= (ele.ThreadState != ThreadState.Aborted);
                    }

                    if (AllCompleted)
                    {
                        break;
                    }

                    Thread.Sleep(100);
                }
            }

            return(ret);
        }