Example #1
0
        private List <string> DownLoadFiles()
        {
            string        url      = null;
            string        fileName = null;
            List <string> result   = new List <string>();

            try
            {
                foreach (string key in downloadUrl.Keys)
                {
                    Regex           regex   = new Regex(key + @"\.[0-9]+\.xls");
                    MatchCollection matches = regex.Matches(downloadUrl[key]);
                    fileName = mFileFolder + matches[0].Value;
                    url      = @"https://contracts.deutsche-boerse.com/indexdata/" + downloadUrl[key];
                    DataStreamRicCreationWithFileDownload.DownLoadFiles(url, fileName, cookies);
                    result.Add(fileName);
                }
            }
            catch (System.Exception ex)
            {
                listFileNameError.Add(url);
                Logger.Log(string.Format("error when try to download file :{0} Exception:{1}", fileName, ex.ToString()));
                return(result);
            }
            return(result);
        }
        private List <string> DownLoadFiles()
        {
            string        url      = null;
            string        fileName = null;
            List <string> result   = new List <string>();

            try
            {
                foreach (string key in downloadUrl.Keys)
                {
                    Regex           regex   = new Regex(key + @"\.[0-9]+\.xls");
                    MatchCollection matches = regex.Matches(downloadUrl[key]);

                    fileName = mFileFolder + matches[0].Value;
                    url      = @"https://contracts.deutsche-boerse.com/indexdata/" + downloadUrl[key];
                    //获取当天时间
                    string correctDate = DateTime.Now.ToUniversalTime().AddDays(-1).ToString("yyyyMMdd");
                    correctDate = key + "." + correctDate + ".xls";
                    if (string.Compare(correctDate, matches[0].Value) != 0)
                    {
                        continue;
                    }

                    DataStreamRicCreationWithFileDownload.DownLoadFiles(url, fileName, cookies);
                    result.Add(fileName);
                }
            }
            catch (System.Exception ex)
            {
                listFileNameError.Add(url);
                Logger.Log(string.Format("error when try to download file :{0} Exception:{1}", fileName, ex.ToString()));
                return(result);
            }
            return(result);
        }
Example #3
0
        private void GetFilesUrl()
        {
            try
            {
                StreamReader SrResult = DataStreamRicCreationWithFileDownload.LoginWebSite(usrName, passWord, cookies);

                HtmlDocument doc = new HtmlDocument();
                doc.Load(SrResult);
                if (doc == null)
                {
                    return;
                }
                HtmlNode node = doc.DocumentNode.SelectSingleNode("//input[@id='ajaxDynaToken']");
                if (node == null)
                {
                    node = doc.DocumentNode.SelectSingleNode("//input[@name='org.apache.struts.taglib.html.TOKEN']");
                }
                string token = node.Attributes["value"].Value.Trim();


                node = doc.DocumentNode.SelectSingleNode("//form[@name='mainForm']");
                string actionStr = null;
                if (node != null)
                {
                    actionStr = node.Attributes["action"].Value.Trim();
                }

                string StResult = DataStreamRicCreationWithFileDownload.ExpandDropDownBox(actionStr, token, @"37_0%3DExpand%3D-10", cookies);


                Regex           regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+CDAX_Weighting_File\.[0-9]+\.xls");
                MatchCollection matches = regex.Matches(StResult);
                downloadUrl["CDAX_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+CLASSIC_ALL_SHARE_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["CLASSIC_ALL_SHARE_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAX_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAX_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+Entry_All_Share_Index_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["Entry_All_Share_Index_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+Entry_Standard_Index_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["Entry_Standard_Index_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"<!--delta.+-->");
                matches = regex.Matches(StResult);
                token   = matches[0].Value;

                //goto next page
                int i = token.IndexOf(";");
                token    = token.Substring(i + 1, 32);
                StResult = DataStreamRicCreationWithFileDownload.ChangePage(actionStr, token, @"37_0%3DPage%3D1", cookies);

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+GEX_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["GEX_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+HDAX_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["HDAX_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+MDAX_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["MDAX_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+MID_CAP_MARKET_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["MID_CAP_MARKET_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+PRIME_ALL_SHARE_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["PRIME_ALL_SHARE_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+SDAX_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["SDAX_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+TecDAX_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["TecDAX_Weighting_File"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+TECHNOLOGY_ALL_SHARE_Weighting_File\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["TECHNOLOGY_ALL_SHARE_Weighting_File"] = matches[0].Value;
            }
            catch (System.Exception ex)
            {
                Logger.Log(string.Format("error when getting files url,exception is {0}", ex.ToString()));
            }
        }
        private void GetFilesUrl()
        {
            try
            {
                StreamReader SrResult = DataStreamRicCreationWithFileDownload.LoginWebSite(usrName, passWord, cookies);

                HtmlDocument doc = new HtmlDocument();
                doc.Load(SrResult);
                if (doc == null)
                {
                    return;
                }
                HtmlNode node = doc.DocumentNode.SelectSingleNode("//input[@id='ajaxDynaToken']");
                if (node == null)
                {
                    node = doc.DocumentNode.SelectSingleNode("//input[@name='org.apache.struts.taglib.html.TOKEN']");
                }
                string token = node.Attributes["value"].Value.Trim();


                node = doc.DocumentNode.SelectSingleNode("//form[@name='mainForm']");
                string actionStr = null;
                if (node != null)
                {
                    actionStr = node.Attributes["action"].Value.Trim();
                }
                string StResult = DataStreamRicCreationWithFileDownload.ChangeTab(actionStr, token, "1", cookies);

                Regex           regex   = new Regex(@"<!--delta.+-->");
                MatchCollection matches = regex.Matches(StResult);
                token = matches[0].Value;
                int i = token.IndexOf(";");
                token = token.Substring(i + 1, 32);

                StResult = DataStreamRicCreationWithFileDownload.ExpandDropDownBox(actionStr, token, @"37_1%3DExpand%3D-30", cookies);

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalAfricaIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalAfricaIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalAgribusinessIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalAgribusinessIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalAsiaBranchenindizes_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalAsiaBranchenindizes_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalAlternativeEnergy_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalAlternativeEnergy_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalAsiaIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalAsiaIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalAustriaIndices_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalAustriaIndices_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalBRICIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalBRICIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalChinaIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalChinaIndex_IWB"] = matches[0].Value;

                //page 2
                regex   = new Regex(@"<!--delta.+-->");
                matches = regex.Matches(StResult);
                token   = matches[0].Value;

                //goto next page
                i        = token.IndexOf(";");
                token    = token.Substring(i + 1, 32);
                StResult = DataStreamRicCreationWithFileDownload.ChangePage(actionStr, token, @"37_1%3DPage%3D1", cookies);

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalChinaBranchenindices_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalChinaBranchenindices_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalChinaUrbIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalChinaUrbIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalCoalIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalCoalIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalEmerging11Index_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalEmerging11Index_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalGCCIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalGCCIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalGoldMinersIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalGoldMinersIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalLatinAmericaIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalLatinAmericaIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalNuclearEnergyIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalNuclearEnergyIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalRussiaPlusIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalRussiaPlusIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalRussiaIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalRussiaIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalSarasinSust_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalSarasinSust_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalShippingIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalShippingIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalSteelIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalSteelIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalVietnamIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalVietnamIndex_IWB"] = matches[0].Value;

                //page 3
                regex   = new Regex(@"<!--delta.+-->");
                matches = regex.Matches(StResult);
                token   = matches[0].Value;

                //goto next page
                i        = token.IndexOf(";");
                token    = token.Substring(i + 1, 32);
                StResult = DataStreamRicCreationWithFileDownload.ChangePage(actionStr, token, @"37_1%3DPage%3D2", cookies);

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DAXglobalWaterIndex_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DAXglobalWaterIndex_IWB"] = matches[0].Value;

                regex   = new Regex(@"download\/[0-9A-Z]+\.vong_00[a-z0-9_\/]+DBIXIndia_IWB\.[0-9]+\.xls");
                matches = regex.Matches(StResult);
                downloadUrl["DBIXIndia_IWB"] = matches[0].Value;
            }
            catch (System.Exception ex)
            {
                Logger.Log(string.Format("error when getting files url,exception is {0}", ex.ToString()));
            }
        }