public bool Delete(ceDomainConfig domain, long id, List <string> languages, out string error) { error = null; //var path = string.Format("/casino/games/{0}.game-information", id.ToString(CultureInfo.InvariantCulture)); string path = string.Format("{0}/{1}.{2}", METADATA_PATH, id.ToString(CultureInfo.InvariantCulture), _metadataItemName); using (var sw = new StringWriter()) using (var writer = new JsonTextWriter(sw)) { writer.WriteStartArray(); foreach (var language in languages) { writer.WriteValue(language); } writer.WriteEndArray(); var ret = MetadataClient.DeleteTranslation(domain, path, sw.ToString()); if (ret == "success") { return(true); } error = ret; return(false); } }
public bool Update(ceDomainConfig domain, long id, Dictionary <string, string> translations, out string error) { error = null; //var path = string.Format("/casino/games/{0}.game-information", id.ToString(CultureInfo.InvariantCulture)); string path = string.Format("{0}/{1}.{2}", METADATA_PATH, id.ToString(CultureInfo.InvariantCulture), _metadataItemName); using (var sw = new StringWriter()) using (var writer = new JsonTextWriter(sw)) { writer.WriteStartObject(); foreach (var translation in translations) { writer.WritePropertyName(translation.Key); writer.WriteValue(translation.Value); } writer.WriteEndObject(); var ret = MetadataClient.UpdateTranslation(domain, path, sw.ToString()); if (ret == "success") { return(true); } error = ret; return(false); } }
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()); }
public static void UploadStatistic(ConcurrentDictionary <int, ConcurrentDictionary <ulong, int> > dic) { foreach (var domainItem in dic) { using (StringWriter sw = new StringWriter()) using (JsonTextWriter writer = new JsonTextWriter(sw)) { writer.WriteStartObject(); foreach (var item in domainItem.Value) { writer.WritePropertyName(item.Key.ToString()); writer.WriteValue(item.Value); } writer.WriteEndObject(); MetadataClient.UploadStatistic(domainItem.Key, sw.ToString()); } } }
public List <Translation> Get(ceDomainConfig domain, long id) { //var path = string.Format("/casino/games/{0}.game-information", id.ToString(CultureInfo.InvariantCulture)); string path = string.Format("{0}/{1}.{2}", METADATA_PATH, id.ToString(CultureInfo.InvariantCulture), _metadataItemName); var json = MetadataClient.GetTranslation(domain, path); var translations = new List <Translation>(); using (var sr = new StringReader(json)) using (var reader = new JsonTextReader(sr)) { if (!reader.Read() || reader.TokenType != JsonToken.StartArray) { throw new Exception("Unknown format from metadata"); } while (reader.Read()) { if (reader.TokenType == JsonToken.StartObject) { var translation = Read(reader); if (translation != null) { translations.Add(translation); } } else if (reader.TokenType == JsonToken.EndArray) { break; } else { throw new Exception("Unknown format from metadata"); } } } return(translations); }
/// <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()); }
/// <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()); }