コード例 #1
0
ファイル: Form1.cs プロジェクト: shakybaker/snowhub
        public void GetResortPage(string countryName, string resortUrl)
        {
            string[] arrUrl = resortUrl.Split(',');
            string html = GetPage(arrUrl[0]);
            string tmp;
            Resort resort = new Resort();
            resort.Name = arrUrl[1].Replace(" - ", "-");
            Country country = new Country();
            country.CountryName = countryName;
            resort.Country = country;
            ResortStats stats = new ResortStats();
            stats.GreenRuns = GetValue(html, "Beginner Runs\" border=\"0\" />(?<VALUE>.+?)%</strong>");
            stats.BlueRuns = GetValue(html, "Intermediate Runs\" border=\"0\" />(?<VALUE>.+?)%</strong>");
            stats.RedRuns = GetValue(html, "Advanced Runs\" border=\"0\" />(?<VALUE>.+?)%</strong>");
            stats.BlackRuns = GetValue(html, "Expert Runs\" border=\"0\" />(?<VALUE>.+?)%</strong>");

            stats.LiftTotal = GetValue(html, "Total # Of Lifts\" border=\"0\" align=\"absmiddle\" />(?<VALUE>.+?)</strong>");
            stats.GondolaCount = GetValue(html, "Gondolas & Trams\" border=\"0\" align=\"absmiddle\" />(?<VALUE>.+?)</strong>");
            stats.QuadPlusCount = GetValue(html, "High Speed Sixes\" border=\"0\" align=\"absmiddle\" />(?<VALUE>.+?)</strong>");
            int quads = 0;
            tmp = GetValue(html, "High Speed Quads\" border=\"0\" align=\"absmiddle\" />(?<VALUE>.+?)</strong>");
            quads = (string.IsNullOrEmpty(tmp)) ? 0 : int.Parse(tmp);
            tmp = GetValue(html, "Quad Chairs\" border=\"0\" align=\"absmiddle\" />(?<VALUE>.+?)</strong>");
            quads += (string.IsNullOrEmpty(tmp)) ? 0 : int.Parse(tmp);
            stats.QuadCount = (quads == 0) ? string.Empty : quads.ToString();
            stats.TripleCount = GetValue(html, "Triple Chairs\" border=\"0\" align=\"absmiddle\" />(?<VALUE>.+?)</strong>");
            stats.DoubleCount = GetValue(html, "Double Chairs\" border=\"0\" align=\"absmiddle\" />(?<VALUE>.+?)</strong>");
            stats.SurfaceCount = GetValue(html, "Surface Lifts\" border=\"0\" align=\"absmiddle\" />(?<VALUE>.+?)</strong>");
            stats.AverageSnowfall = GetValue(html, "Average Snowfall\" border=\"0\" align=\"absmiddle\" />(?<VALUE>.+?)  cm</strong>");

            stats.TopLevel = GetValue(html, "Top: <strong>(?<VALUE>.+?) m</strong>");
            stats.VerticalDrop = GetValue(html, "Vertical Drop: <strong>(?<VALUE>.+?) m</strong>");
            stats.BaseLevel = GetValue(html, "Bottom: <strong>(?<VALUE>.+?) m</strong>");
            stats.LongestRunDistance = GetValue(html, "Longest Run: <strong>(?<VALUE>.+?) km</strong>");
            decimal hectares = 0;
            tmp = GetValue(html, "Longest Run: <strong>(?<VALUE>.+?) km</strong>");
            if (!tmp.Contains("N/A"))
            {
                hectares = (string.IsNullOrEmpty(tmp)) ? 0 : decimal.Parse(tmp);
                decimal metres = hectares * 10000;
                stats.SkiableTerrianSize = metres.ToString();
            }
            stats.SnowmakingCoverage = GetValue(html, "Snow Making: <strong>(?<VALUE>.+?) km</strong>");

            //insert
            int retid = ResortDataManager.AddScrapeResortStats(resort, stats);
        }
コード例 #2
0
        public static Country GetCountryByName(string prettyUrl)
        {
            Country country = new Country();

            //TODO: put all this in a method
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL2005_615410_sporthubConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("GetCountryByName", conn);
            cmd.Parameters.Add(new SqlParameter("@PrettyUrl", prettyUrl));
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet dataSet = new DataSet();
            da.Fill(dataSet);

            //TODO: error handle
            try
            {
                country = DataConverter.ToType<Country>(dataSet.Tables[0].Rows[0]);
                country.Continent = DataConverter.ToType<Continent>(dataSet.Tables[1].Rows[0]);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }

            return country;
        }