Exemplo n.º 1
0
        protected override ExpectList getData(string strHtml)
        {
            ExpectList  ret = new ExpectList();
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.LoadXml(strHtml);
                XmlNodeList rows = doc.SelectNodes("/xml/row");
                if (rows.Count == 0)
                {
                    return(ret);
                }
                for (int i = rows.Count - 1; i >= 0; i--)
                {
                    ExpectData ed = new ExpectData();
                    ed.Expect   = rows[i].Attributes["expect"].Value;
                    ed.OpenCode = rows[i].Attributes["opencode"].Value;
                    ed.OpenTime = DateTime.Parse(rows[i].Attributes["opentime"].Value);
                    ret.Add(ed);
                }
            }
            catch
            {
            }
            return(ret);
        }
Exemplo n.º 2
0
        public ExpectList getNewestData(ExpectList NewestData, ExpectList ExistData)
        {
            ExpectList ret = new ExpectList();

            if (NewestData == null)
            {
                return(ret);
            }
            if (ExistData == null)
            {
                return(NewestData);
            }
            HashSet <string> existDic = new HashSet <string>();

            for (int i = 0; i < ExistData.Count; i++)
            {
                existDic.Add(ExistData[i].Expect);
            }
            for (int i = NewestData.Count - 1; i >= 0; i--)
            {
                if (existDic.Contains(NewestData[i].Expect))
                {
                    continue;
                }
                ret.Add((ExpectData)NewestData[i].Clone());
            }
            return(ret);
        }
Exemplo n.º 3
0
        public bool Matched(ExpectData data, out int MatchCnt)
        {
            //MatchCnt = 0;
            ExpectList el = new ExpectList();

            el.Add(data);
            return(Matched(el, out MatchCnt, false));
        }
Exemplo n.º 4
0
        protected override ExpectList getHisData(string strHtml)
        {
            ExpectList ret    = new ExpectList();
            string     strBeg = "<table cellspacing=\"0\" cellpadding=\"0\" class=\"dt caipiao mbm\"";
            string     strEnd = "</table>";
            int        ibeg   = strHtml.IndexOf(strBeg);

            strHtml = strHtml.Substring(ibeg);
            int iend = strHtml.IndexOf(strEnd) + strEnd.Length;

            if (ibeg == 0)
            {
                return(ret);
            }
            if (iend <= 0)
            {
                return(ret);
            }
            string      txtTable = strHtml.Substring(0, iend);
            XmlDocument doc      = new XmlDocument();

            try
            {
                doc.LoadXml(txtTable);
                XmlNodeList nodelist = doc.SelectNodes("table/tr");
                for (int i = 0; i < nodelist.Count; i++)
                {
                    if (i == 0)
                    {
                        continue;
                    }
                    XmlNodeList tdlist = nodelist[i].SelectNodes("td");
                    if (tdlist.Count == 0)
                    {
                        continue;
                    }
                    ExpectData ed           = new ExpectData();
                    string     strExpect    = tdlist[0].InnerText;
                    string     strIndex     = tdlist[1].InnerText;
                    string     strOpenCodes = string.Join(",", tdlist[2].InnerText.Substring(0, 5).ToCharArray());
                    string[]   strTimes     = strExpect.Split(' ');
                    DateTime   dt           = DateTime.ParseExact(strExpect, "yyyyMMdd HH:mm", CultureInfo.InvariantCulture);
                    DateTime   bdt          = DateTime.Parse(dt.ToShortDateString());
                    string     strRindex    = "0000" + dt.Subtract(bdt).TotalMinutes.ToString();
                    ed.Expect   = string.Format("{0}{1}", strTimes[0], strRindex.Substring(strRindex.Length - 4));
                    ed.OpenCode = strOpenCodes;
                    ed.OpenTime = dt;
                    ret.Add(ed);
                }
            }
            catch (Exception ce)
            {
            }
            return(ret);
        }
Exemplo n.º 5
0
        public ExpectList getSubArray(int FromIndex, int len)
        {
            ExpectList ret = new ExpectList();

            if (MyData.Count < FromIndex + len)
            {
                throw new Exception("选区的子段超出母数据长度!");
            }
            for (int i = FromIndex; i < FromIndex + len; i++)
            {
                ret.Add(MyData[i]);
            }
            return(ret);
        }
Exemplo n.º 6
0
        public ExpectList FirstDatas(int RecLng)
        {
            ExpectList ret = new ExpectList();

            if (RecLng == this.Count)
            {
                return(this);
            }
            if (RecLng > this.Count)
            {
                throw new Exception("请求长度超出目标列表长度!");
            }
            for (int i = 0; i < RecLng - 1; i++)
            {
                ret.Add(this[i].Clone() as ExpectData);
            }
            return(ret);
        }
Exemplo n.º 7
0
        protected override ExpectList getData(string strHtml)
        {
            ExpectList ret    = new ExpectList();
            string     strBeg = "<table";
            string     strEnd = "</table>";
            int        ibeg   = strHtml.IndexOf(strBeg);
            int        iend   = strHtml.IndexOf(strEnd) + strEnd.Length;

            if (ibeg == 0)
            {
                return(ret);
            }
            if (iend <= ibeg)
            {
                return(ret);
            }
            string      txtTable = strHtml.Substring(ibeg, iend - ibeg);
            XmlDocument doc      = new XmlDocument();

            try
            {
                doc.LoadXml(txtTable);
                XmlNodeList nodelist = doc.SelectNodes("table/tr");
                for (int i = 0; i < nodelist.Count; i++)
                {
                    XmlNodeList tdlist = nodelist[i].SelectNodes("td");
                    if (tdlist.Count == 0)
                    {
                        continue;
                    }
                    ExpectData ed = new ExpectData();
                    ed.Expect   = tdlist[1].InnerText.Replace("-", "");
                    ed.OpenCode = tdlist[4].InnerText;
                    ed.OpenTime = DateTime.Parse(tdlist[2].InnerText);
                    ret.Add(ed);
                }
            }
            catch (Exception ce)
            {
            }
            return(ret);
        }
Exemplo n.º 8
0
        public ExpectList getFileData(string filename)
        {
            ExpectList   ret  = new ExpectList();
            FileStream   file = new FileStream(filename, FileMode.Open, FileAccess.Read);
            StreamReader str  = new StreamReader(file, Encoding.Default);

            try
            {
                //用以接受FileStream对象中的数据,第2个参数是字节数组中开始写入数据的位置,它通常是0,
                //表示从数组的开端文件中向数组写数据,最后一个参数规定从文件读多少字符.
                Decoder d = Encoding.Default.GetDecoder();

                int    lcnt = 0;
                string txtline;
                while ((txtline = str.ReadLine()) != null)
                {
                    lcnt++;
                    if (lcnt <= 1)
                    {
                        continue;//标题跳过
                    }
                    if (txtline.Trim().Length == 0)
                    {
                        continue;
                    }
                    txtline = txtline.Replace("	", ",");
                    string[] items = txtline.Split(',');
                    if (items.Length != 2)
                    {
                        throw new Exception(string.Format("{0}第{1}行数据异常!", filename, lcnt));
                    }
                    ExpectData ed = new ExpectData();
                    ed.OpenCode = string.Join(",", items[1].ToCharArray());
                    string   strOrg  = items[0];
                    string[] strOrgs = strOrg.Split('-');
                    if (strOrgs.Length > 1)
                    {
                        string   strDate  = strOrgs[0];
                        string   strId    = strOrgs[1];
                        string   DstrDate = string.Format("{0}-{1}-{2}", strDate.Substring(0, 4), strDate.Substring(4, 2), strDate.Substring(6));
                        DateTime etime    = DateTime.Parse(DstrDate);
                        ed.OpenTime = etime.AddMinutes(int.Parse(strId)).AddSeconds(6);
                        ed.Expect   = ed.OpenTime.ToString("yyyy-MM-dd HH-mm-SS").Replace("-", "").Replace("/", "").Replace(":", "").Replace(" ", "").Substring(0, 12);
                    }
                    else
                    {
                        ed.Expect = strOrg;
                        string   strDate  = strOrg.Substring(0, 8);
                        string   strId    = ed.Expect.Substring(8);
                        string   DstrDate = string.Format("{0}-{1}-{2} {3}:{4}:{5}", strDate.Substring(0, 4), strDate.Substring(4, 2), strDate.Substring(6), strId.Substring(0, 2), strId.Substring(2), "06");
                        DateTime etime    = DateTime.Parse(DstrDate);
                        ed.OpenTime = etime;
                    }
                    //ed.Expect = items[0].Replace("-", "");

                    //if (ed.OpenCode == "0,0,0,0,0")



                    ret.Add(ed);
                }

                str.Close();
                //file.Close();
            }
            catch (IOException e)
            {
                str.Close();
                //file.Close();
                throw e;
            }
            return(ret);
        }