Esempio n. 1
0
        public void ProcessMessage(int index)
        {
            var bytes  = Encoding.Default.GetBytes(Messages[index]);
            var output = MD5Digest.ComputeMD5(bytes);

            Assert.AreEqual(Digests[index], output.Aggregate("", (current, b) => current + b.ToString("x2")));
        }
Esempio n. 2
0
        /// <inheritdoc />
        public string GetCachedFileName(string url)
        {
            var stringBuilder = new StringBuilder();

            var uri = new Uri(url);

            stringBuilder.Append(uri.Host + "/");

            if (uri.LocalPath.Contains("/profile/"))
            {
                // Example: http://eu.battle.net/api/d3/profile/Tok-2360 >> eu.battle.net/Tok-2360.json
                var splitted = uri.LocalPath.Split(new[] { "/profile/" }, StringSplitOptions.None);
                stringBuilder.Append(splitted[1]);
                stringBuilder.Append(".json");
            }
            else if (uri.LocalPath.Contains("/hero/"))
            {
                // Example: http://eu.battle.net/api/d3/profile/Tok-2360/hero/17023 >> eu.battle.net/Tok-2360/hero/17023.json
                var splitted = uri.LocalPath.Split(new[] { "/hero/" }, StringSplitOptions.None);
                stringBuilder.Append(splitted[1]);
                stringBuilder.Append(".json");
            }
            else if (uri.LocalPath.Contains("/item/"))
            {
                // Example: http://eu.battle.net/api/d3/data/item/Amethyst_14 >> eu.battle.net/items/Amethyst_14.json (or a hash)
                stringBuilder.Append("items/");
                var splitted = uri.LocalPath.Split(new[] { "/item/" }, StringSplitOptions.None);
                if (splitted[1].Length < 32)
                {
                    stringBuilder.Append(splitted[1]);
                    stringBuilder.Append("-");
                }
                else
                {
                    var hash = MD5Digest.ComputeMD5(PortableEncoding.Default.GetBytes(url));
                    foreach (var hashByte in hash)
                    {
                        stringBuilder.Append(hashByte.ToString("x2"));
                    }
                }
                stringBuilder.Append(".json");
            }
            else if (uri.LocalPath.Contains("/icons/"))
            {
                // Example: http://media.blizzard.com/d3/icons/items/small/amethyst_12_demonhunter_male.png >> media.blizzard.com/icons/items/small/amethyst_12_demonhunter_male.png
                stringBuilder.Append("icons/");
                var splitted = uri.LocalPath.Split(new[] { "/icons/" }, StringSplitOptions.None);
                stringBuilder.Append(splitted[1]);
            }
            else
            {
                var hash = MD5Digest.ComputeMD5(PortableEncoding.Default.GetBytes(url));
                foreach (var hashByte in hash)
                {
                    stringBuilder.Append(hashByte.ToString("x2"));
                }

                stringBuilder.Append(".json");
            }

            return(stringBuilder.ToString());
        }