Ejemplo n.º 1
0
        /// <summary>
        /// 读数据线程
        /// </summary>
        protected override void DoWork()
        {
            try
            {
                while (m_runFlag)
                {
                    while (m_kLineQueue.Count > 0)
                    {
                        USeKLine kLine = null;
                        m_kLineQueue.TryDequeue(out kLine);
                        Debug.Assert(kLine != null);

                        FileStorer storer = GetFileStorer(kLine);
                        try
                        {
                            storer.Write(ToKLineLog(kLine));
                            Interlocked.Increment(ref m_sotreCount);
                        }
                        catch (Exception ex)
                        {
                            Interlocked.Increment(ref m_errorStoreCount);
                            USeNotifyEventArgs arg = new USeNotifyEventArgs(USeNotifyLevel.Error, "文件保存K线失败," + ex.Message);
                            SafeRaiseNotifyEvent(this, arg);
                        }
                    }

                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private FileStorer GetFileStorer(USeKLine kLine)
        {
            string key = string.Format("{0}_{1}", kLine.Cycle.ToString(), kLine.InstrumentCode);

            FileStorer storer = null;

            if (m_fileStorerDic.TryGetValue(key, out storer) == false)
            {
                string fileName = Path.Combine(m_kLineFolderPath, GetTradeDayPath(), key + ".csv");
                storer = new FileStorer(fileName);
                m_fileStorerDic.Add(key, storer);
            }

            return(storer);
        }