Exemple #1
0
        internal static Dictionary <ulong, string> Get(ceDomainConfig domain, string lang, bool reloadCache = false)
        {
            string cacheFile = MetadataFileCache.GetPathWithRegion <Translation>(domain.DomainID.ToString(CultureInfo.InvariantCulture), lang);

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

            Func <Dictionary <ulong, string> > func = () =>
            {
                Dictionary <ulong, string> dic = new Dictionary <ulong, string>();

                // {"6883073332696432216":"Immediately","8464306736891375262":"Visa Credit Card","11378931541622277876":"Free","15079650489870782597":""}
                string json = MetadataClient.GetDumpedTranslation(domain, lang);
                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");
                        }

                        while (reader.Read())
                        {
                            if (reader.TokenType == JsonToken.PropertyName && reader.ValueType == typeof(string))
                            {
                                ulong hash;
                                if (!ulong.TryParse(reader.Value as string, out hash))
                                {
                                    throw new Exception("Unknown format from metadata");
                                }
                                if (!reader.Read() || reader.TokenType != JsonToken.String)
                                {
                                    throw new Exception("Unknown format from metadata");
                                }

                                dic[hash] = reader.Value as string;
                            }
                        }
                    }

                return(dic);
            };

            Dictionary <ulong, string> cache = null;
            bool ret = DelayUpdateCache <Dictionary <ulong, string> > .TryGetValue(cacheFile, out cache, func, 3600);

            if (ret)
            {
                return(cache);
            }

            return(func());
        }
Exemple #2
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());
        }
Exemple #3
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());
        }