Ejemplo n.º 1
0
        /// <summary>
        /// Get all the casino games for a specific vendor
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="reloadCache"></param>
        /// <returns></returns>
        public static Dictionary <long, CasinoGame> GetAll(ceDomainConfig domain, bool reloadCache = false)
        {
            string cacheFile = MetadataFileCache.GetPath <CasinoGame>(domain.DomainID.ToString(CultureInfo.InvariantCulture));

            if (reloadCache)
            {
                DelayUpdateCache <Dictionary <long, CasinoGame> > .SetExpired(cacheFile);
            }

            Func <Dictionary <long, CasinoGame> > func = () =>
            {
                var dic = new Dictionary <long, CasinoGame>();

                try
                {
                    // {"8101":{"game-information":"12027250142368842869"},"8102":{"game-information":"5380242421959168179"}}
                    string json = MetadataClient.GetCasinoGames(domain);
                    using (StringReader sr = new StringReader(json))
                        using (JsonTextReader reader = new JsonTextReader(sr))
                        {
                            if (!reader.Read() || reader.TokenType != JsonToken.StartObject)
                            {
                                throw new Exception("Unknown format from metadata");
                            }

                            CasinoGame casinoGame = null;
                            while (reader.Read())
                            {
                                if (casinoGame == null)
                                {
                                    if (reader.TokenType == JsonToken.PropertyName)
                                    {
                                        casinoGame = new CasinoGame()
                                        {
                                            Domain = domain
                                        };
                                        dic[ConvertHelper.ToInt64(reader.Value)] = casinoGame;

                                        if (!reader.Read() || reader.TokenType != JsonToken.StartObject)
                                        {
                                            throw new Exception("Unknown format from metadata");
                                        }
                                    }
                                    else if (reader.TokenType == JsonToken.EndObject)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        throw new Exception("Unknown format from metadata");
                                    }
                                }
                                else
                                {
                                    if (reader.TokenType == JsonToken.EndObject)
                                    {
                                        casinoGame = null;
                                    }
                                    else if (reader.TokenType == JsonToken.PropertyName)
                                    {
                                        string propertyName = reader.Value.ToString().ToLowerInvariant();
                                        reader.Read();
                                        switch (propertyName)
                                        {
                                        case "game-information":
                                            casinoGame.GameInformationHash = ConvertHelper.ToUInt64(reader.Value);
                                            break;


                                        default:
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        throw new Exception("Unknown format from metadata");
                                    }
                                }
                            }
                        }
                }
                catch
                {
                }

                return(dic);
            };

            Dictionary <long, CasinoGame> cache = null;
            bool ret = DelayUpdateCache <Dictionary <long, CasinoGame> > .TryGetValue(cacheFile, out cache, func, 36000);

            if (ret)
            {
                return(cache);
            }

            return(func());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get All the languages for the current domain
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="reloadCache"></param>
        /// <returns></returns>
        public static Language[] GetAll(ceDomainConfig domain, bool reloadCache = false)
        {
            string cacheFile = MetadataFileCache.GetPath <Language>(domain.DomainID.ToString(CultureInfo.InvariantCulture));

            if (reloadCache)
            {
                DelayUpdateCache <Dictionary <string, Language> > .SetExpired(cacheFile);
            }

            Func <Language[]> func = () =>
            {
                List <Language> list = new List <Language>();

                // {"ar":{"name":"\u0627\u0644\u0639\u0631\u0628\u064A\u0629"},"cs":{"name":"\u010Ce\u0161tina"},"en":{"name":"English"}}
                string json = MetadataClient.GetLanguages(domain);
                using (StringReader sr = new StringReader(json))
                    using (JsonTextReader reader = new JsonTextReader(sr))
                    {
                        if (!reader.Read() || reader.TokenType != JsonToken.StartObject)
                        {
                            throw new Exception("Unknown format from metadata");
                        }

                        Language lang = null;
                        while (reader.Read())
                        {
                            if (lang == null)
                            {
                                if (reader.TokenType == JsonToken.PropertyName && reader.ValueType == typeof(string))
                                {
                                    lang = new Language()
                                    {
                                        RFC1766 = reader.Value as string
                                    };
                                    if (!reader.Read() || reader.TokenType != JsonToken.StartObject)
                                    {
                                        throw new Exception("Unknown format from metadata");
                                    }
                                }
                                else if (reader.TokenType == JsonToken.EndObject)
                                {
                                    break;
                                }
                                else
                                {
                                    throw new Exception("Unknown format from metadata");
                                }
                            }
                            else
                            {
                                if (reader.TokenType == JsonToken.EndObject)
                                {
                                    list.Add(lang);
                                    lang = null;
                                }
                                else if (reader.TokenType == JsonToken.PropertyName)
                                {
                                    if (reader.ValueType == typeof(string) &&
                                        reader.Value as string == "name")
                                    {
                                        if (!reader.Read() || reader.TokenType != JsonToken.String)
                                        {
                                            throw new Exception("Unknown format from metadata");
                                        }
                                        lang.DisplayName = reader.Value as string;
                                    }
                                }
                                else
                                {
                                    throw new Exception("Unknown format from metadata");
                                }
                            }
                        }
                    }

                return(list.ToArray());
            };

            Language[] cache = null;
            bool       ret   = DelayUpdateCache <Language[]> .TryGetValue(cacheFile, out cache, func, 36000);

            if (ret)
            {
                return(cache);
            }

            return(func());
        }