Esempio n. 1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public TaManager()
        {
            // 获取当天以及上一交易日
            LoadMarketDbConn();
            GetCurrentMarketDay();
            GetLastMarketDay();



            _taHqList = new List <TaHq>();

            // 判断配置文件是否存在,不存在抛出异常
            if (!File.Exists(Path.Combine(Environment.CurrentDirectory, "cfg.xml")))
            {
                throw new Exception("未能找到配置文件cfg.xml,请重新配置该文件后重启程序!");
            }

            // 读取配置文件
            XmlDocument       doc      = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments = true;     //忽略文档里面的注释
            using (XmlReader reader = XmlReader.Create(@"cfg.xml", settings))
            {
                doc.Load(reader);

                // 检查根节点
                XmlNode rootNode = doc.SelectSingleNode("config");   // 根节点
                if (rootNode == null)
                {
                    throw new Exception("无法找到配置文件的根节点<config>,请检查配置文件格式是否正确!");
                }

                // 找TA行情通配索引
                XmlNode xnHqIdx = rootNode.SelectSingleNode("//hqidx");
                if (xnHqIdx != null)
                {
                    _taHqIdx = Util.Filename_Date_Convert(xnHqIdx.InnerText.Trim(), _dtJYR, _dtLastJYR);
                }
                else
                {
                    throw new Exception("无法找到配置文件节点<hqidx>(行情索引文件名),请检查配置文件格式是否正确!");
                }

                // 找TA行情通配索引
                XmlNode xnHqIdxCnt = rootNode.SelectSingleNode("//hqidxcnt");
                if (xnHqIdxCnt != null)
                {
                    if (!int.TryParse(xnHqIdxCnt.InnerText.Trim(), out _taHqIdxCnt))
                    {
                        throw new Exception("请确定节点<hqidxcnt>(行情索引文件中文件数量所在行)为数字!");
                    }
                }
                else
                {
                    throw new Exception("无法找到配置文件节点<hqidxcnt>(行情索引文件中文件数量所在行),请检查配置文件格式是否正确!");
                }


                // 找TA清算通配索引
                XmlNode xnQsIdx = rootNode.SelectSingleNode("//qsidx");
                if (xnQsIdx != null)
                {
                    _taQsIdx = Util.Filename_Date_Convert(xnQsIdx.InnerText.Trim(), _dtJYR, _dtLastJYR);
                }
                else
                {
                    throw new Exception("无法找到配置文件节点<qsidx>(清算索引文件名),请检查配置文件格式是否正确!");
                }


                // 直接找talist子节点。形成ta对象,加入到TaManager列表。
                XmlNode xnTa = rootNode.SelectSingleNode("//talist");
                _taHqList = new List <TaHq>();
                //_taQsList = new List<TaQs>();
                if (xnTa != null)
                {
                    foreach (XmlNode xnTaChild in xnTa.ChildNodes)                                                           // 循环talist下的子节点
                    {
                        if (string.Equals(xnTaChild.Name.Trim().ToLower(), "ta", StringComparison.CurrentCultureIgnoreCase)) // 如果子节点名字是ta,开始遍历attribute
                        {
                            // Part1.行情配置
                            string        id             = string.Empty;                // ta代码
                            string        desc           = string.Empty;                // 备注(仅仅显示)
                            string        hqRootMove     = string.Empty;
                            List <string> hqRootMovePath = new List <string>();

                            string        hqSource    = string.Empty;
                            string        hqchecktype = string.Empty;
                            string        hqIdx       = _taHqIdx;
                            List <string> hqFiles     = new List <string>();
                            List <string> hqDestPath  = new List <string>();
                            string        hqStartTime = string.Empty;


                            foreach (XmlNode xnTaChildAttr in xnTaChild)
                            {
                                switch (xnTaChildAttr.Name.ToLower().Trim())
                                {
                                case "id":
                                    id = xnTaChildAttr.InnerText;
                                    break;

                                case "desc":
                                    desc = xnTaChildAttr.InnerText;
                                    break;

                                case "hqsource":
                                    hqSource = Util.Filename_Date_Convert(xnTaChildAttr.InnerText.Trim(), _dtJYR, _dtLastJYR);
                                    break;

                                case "hqrootmove":
                                    hqRootMove = xnTaChildAttr.InnerText.Trim();
                                    break;

                                case "hqrootmovepath":
                                    if (xnTaChildAttr.ChildNodes.Count > 0)
                                    {
                                        hqRootMovePath.Clear();
                                        foreach (XmlNode xnTaChildAttrValue in xnTaChildAttr.ChildNodes)
                                        {
                                            string tmpValue = Util.Filename_Date_Convert(xnTaChildAttrValue.InnerText.Trim(), _dtJYR, _dtLastJYR);
                                            tmpValue = Ta.ReplaceTaFileNameWithPattern(tmpValue, id);
                                            if (!string.IsNullOrEmpty(tmpValue))
                                            {
                                                hqRootMovePath.Add(tmpValue);
                                            }
                                        }
                                    }
                                    break;

                                case "hqchecktype":
                                    hqchecktype = xnTaChildAttr.InnerText.Trim();
                                    break;

                                case "hqfiles":
                                {
                                    if (xnTaChildAttr.ChildNodes.Count > 0)
                                    {
                                        hqFiles.Clear();
                                        foreach (XmlNode xnTaChildAttrValue in xnTaChildAttr.ChildNodes)
                                        {
                                            string tmpValue = Util.Filename_Date_Convert(xnTaChildAttrValue.InnerText.Trim(), _dtJYR, _dtLastJYR);
                                            tmpValue = Ta.ReplaceTaFileNameWithPattern(tmpValue, id);
                                            if (!string.IsNullOrEmpty(tmpValue))
                                            {
                                                hqFiles.Add(tmpValue);
                                            }
                                        }
                                    }
                                    break;
                                }

                                case "hqdestpath":
                                {
                                    if (xnTaChildAttr.ChildNodes.Count > 0)
                                    {
                                        hqDestPath.Clear();
                                        foreach (XmlNode xnTaChildAttrValue in xnTaChildAttr.ChildNodes)
                                        {
                                            string tmpValue = Util.Filename_Date_Convert(xnTaChildAttrValue.InnerText.Trim(), _dtJYR, _dtLastJYR);
                                            if (!string.IsNullOrEmpty(tmpValue))
                                            {
                                                hqDestPath.Add(tmpValue);
                                            }
                                        }
                                    }
                                    break;
                                }

                                case "hqstarttime":
                                    hqStartTime = xnTaChildAttr.InnerText.Trim();
                                    break;
                                } //eof switch ta attr
                            }     //eof foreach ta

                            _taHqList.Add(new TaHq(id, desc, hqSource, hqRootMove, hqRootMovePath, hqchecktype, hqIdx, _taHqIdxCnt, hqFiles, hqDestPath, hqStartTime));


                            // Part2.清算配置(还没写)
                        } //eof if ta
                    }     //eof foreach
                }         //eof if taListNode not null
            }
        }
Esempio n. 2
0
        private bool _isIdxFileParse;                  // 行情索引文件解析完成



        #region ***************************方法



        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="id"></param>
        /// <param name="desc"></param>
        /// <param name="hqSource"></param>
        /// <param name="hqRootMove"></param>
        /// <param name="hqCheckType"></param>
        /// <param name="idxFile"></param>
        /// <param name="hqFiles"></param>
        /// <param name="hqDestPath"></param>
        public TaHq(string id, string desc, string hqSource, string hqRootMove, List <string> hqRootMovePath, string hqCheckType, string idxFile, int idxFileCnt, List <string> hqFiles, List <string> hqDestPath, string hqStartTime)
        {
            //********1.TA行情配置变量初始化
            _id         = id;       // 代码
            _desc       = desc;     // 描述
            _sourcePath = hqSource; // 行情路径

            // 行情移动到根目录模式
            if (!int.TryParse(hqRootMove, out _hqRootMove))
            {
                _hqRootMove = 0;        // 默认是0,不移动
            }
            // 行情移动到根目录,模式2额外
            _hqRootMovePath = hqRootMovePath;

            // 行情文件检查模式
            int tmpHqCheckType = 0;

            if (!int.TryParse(hqCheckType.Trim(), out tmpHqCheckType))
            {
                throw new Exception(string.Format("hqCheckType参数非法(请参照配置文件注释修改)"));
            }
            _hqCheckType = (HqCheckType)tmpHqCheckType;


            // 行情索引
            idxFile     = Ta.ReplaceTaFileNameWithPattern(idxFile, id);
            _idxFile    = idxFile;
            _idxFileCnt = idxFileCnt;

            // 行情文件列表
            _hqFiles = new Dictionary <string, bool>();
            foreach (string tmpStr in hqFiles)
            {
                _hqFiles.Add(tmpStr, false);
            }

            // 行情文件到齐后移动的目的
            _destPaths = new Dictionary <string, bool>();
            foreach (string tmpStr in hqDestPath)
            {
                _destPaths.Add(tmpStr, false);
            }


            // 20180709行情开始检查时间
            DateTime tmpDT;

            if (DateTime.TryParse(hqStartTime, out tmpDT))
            {
                _hqStartTime = tmpDT;
            }

            _isRequired = true;


            //********2.TA行情运行时变量初始化
            _isRunning         = false;
            _isSourceAvailable = false;
            _isIdxFileParse    = false;
        }