Esempio n. 1
0
        private static void SetRound(GenericScore score)
        {
            // get main page
            string html = s_cache.GetScore(score.Url, "", true);

            // load it as html document
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.OptionReadEncoding = false;
            doc.LoadHtml(html);
            // search for nodes
            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes(ROUND_XPATH);

            if (nodes != null)
            {
                int max   = nodes.Count;
                int round = -1;

                foreach (var node in nodes)
                {
                    if (node.GetAttributeValue("selected", "") == "selected")
                    {
                        string rr       = node.GetAttributeValue("value", "");
                        var    elements = rr.Split('/');
                        int.TryParse(elements[elements.Length - 3], out round);
                        break;
                    }
                }

                if (round > 0)
                {
                    score.Url  += String.Format("/spieltag/{0}/mandant/89", VariableUrl.PARAM);
                    score.Range = new VariableUrl(round, 1, max, LocalizationManager.GetString(Labels.RoundLabel));
                }
            }
        }
        private async Task <int?> GetScore(string title)
        {
            var scores = (Dictionary <string, int?>)HttpRuntime.Cache.Get("scores");
            var score  = ScoreCache.GetScore(title);

            if (score == null)
            {
                // Get score
                using (var client = new HttpClient())
                {
                    var response = await client.GetAsync("http://bechdeltest.com/api/v1/getMoviesByTitle?title=" + HttpUtility.UrlEncode(title));

                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new FileNotFoundException(string.Format("Could not find Bechdel score for '{0}'.", title));
                    }

                    var rawJson = await response.Content.ReadAsStringAsync();

                    JArray array = JArray.Parse(rawJson);
                    if (array.Count != 0)
                    {
                        score = array.First.Value <int>("rating");
                    }
                }

                // Put in cache
                ScoreCache.UpsertScore(title, score);
            }

            return((int?)score);
        }
Esempio n. 3
0
    // Load replays from files.
    void LoadReplays()
    {
        scores = null;

        if (locality == Locality.Local)
        {
            recordings = HighScores.GetHighScores(oldLevel, scoreType);

            // Generate an array of names for the GUI stuff
            names = new string[recordings.Count];
            for (int i = 0; i < names.Length; ++i)
            {
                if (scoreType == HighScores.ScoreType.Speed)
                {
                    names[i] += recordings[i].playername + ": " + recordings[i].score.speed.ToString(".#") + "%";
                }
                else
                {
                    names[i] += recordings[i].playername + ": " + recordings[i].score.time.ToString(".#") + " seconds";
                }
            }
        }
        else
        {
            // We need to get scores from the interwebs.
            names = new string[] { "Retrieving scores..." };
            cache.GetScore(oldLevel.name, scoreType);
        }
    }
Esempio n. 4
0
        private void btnIcon_Click(object sender, EventArgs e)
        {
            if (tbxLeague.Text.Length > 0)
            {
                if (pictureBox1.Image != null)
                {
                    pictureBox1.Image.Dispose();
                    pictureBox1.Image = null;
                }

                string     url   = Tools.ParseUrl(GetUrl(), m_center.Parameters);
                ScoreCache cache = new ScoreCache(0);
                string     home  = cache.GetScore(url, "", false);

                string emblemUrl = WorldFootballScoreParser.GetEmblemUrl(home);
                if (String.IsNullOrEmpty(emblemUrl))
                {
                    return;
                }

                string tmpfile = Path.GetTempFileName();
                File.Delete(tmpfile);
                tmpfile += ".png";
                Bitmap bmp = null;
                try
                {
                    cache.GetImage(emblemUrl, tmpfile);
                    bmp = new Bitmap(tmpfile);
                    Image icon = Tools.FixedBitmapSize(bmp, 48, 48, Color.White);
                    pictureBox1.Image = icon;

                    string relpath = Path.Combine("Football", GetFullName());
                    string path    = Config.GetSubFolder(Config.Dir.Thumbs, "ScoreCenter");
                    path = Path.Combine(path, relpath + ".png");
                    icon.Save(path, ImageFormat.Png);
                    NotifySetIcon(relpath);
                }
                finally
                {
                    cache = null;
                    if (bmp != null)
                    {
                        bmp.Dispose();
                    }
                    File.Delete(tmpfile);
                }
            }
        }