public static Bitmap Get(int key) { var name = ChampNames.GetOrDefault(key); if (name == null) { StaticLogger.Debug("Unknown champid " + key); return(_unknown); } var bmp = FindCached(key); if (bmp != null) { return(bmp); } bmp = SafeBitmap(string.Format("{0}{1}_Square_0.png", ChampPath, name)); if (bmp == null) { StaticLogger.Debug("Unknown champ icon " + name); return(_unknown); } AddCached(key, bmp); return(bmp); }
static Bitmap SafeBitmap(string file) { try { return(File.Exists(file) ? new Bitmap(file) : null); } catch (Exception e) { StaticLogger.Debug(e); return(null); } }
/// <summary> /// Lock the database and commit changes. /// </summary> public void Commit() { Stopwatch sw; lock (DatabaseLock) { sw = Stopwatch.StartNew(); Database.Commit(); } sw.Stop(); StaticLogger.Debug(string.Format("Committed in {0}ms", sw.ElapsedMilliseconds)); }
public virtual void OnException(ProxyClient sender, Exception ex) { lock (Clients) { int idx = Clients.IndexOf(sender); if (idx != -1) { Clients.RemoveAt(idx); } } sender.Dispose(); StaticLogger.Debug(ex); }
public void CommitGame(EndOfGameStats game) { Stopwatch sw; lock (DatabaseLock) { sw = Stopwatch.StartNew(); RecordGame(game); Database.Commit(); } sw.Stop(); StaticLogger.Debug(string.Format("EndOfGameStats committed in {0}ms", sw.ElapsedMilliseconds)); }
/// <summary> /// Records/Commits the player to the database. Locking the database lock. /// </summary> /// <param name="entry">Player to record</param> /// <returns>The PlayerEntry from the database</returns> public void CommitPlayer(PlayerEntry entry) { Stopwatch sw; lock (DatabaseLock) { sw = Stopwatch.StartNew(); RecordPlayer(entry, true); Database.Commit(); } sw.Stop(); StaticLogger.Debug(string.Format("PlayerEntry committed in {0}ms", sw.ElapsedMilliseconds)); }
/// <summary> /// Used to invoke a service which you don't know what it returns. /// </summary> /// <param name="service"></param> /// <param name="operation"></param> /// <param name="args"></param> /// <returns>ASObject body</returns> public object InvokeServiceUnknown(string service, string operation, params object[] args) { var msg = new RemotingMessage(); msg.operation = operation; msg.destination = service; msg.headers["DSRequestTimeout"] = 60; msg.headers["DSId"] = RtmpUtil.RandomUidString(); msg.headers["DSEndpoint"] = "my-rtmps"; msg.body = args; msg.messageId = RtmpUtil.RandomUidString(); string endpoint = service + "." + operation; var result = Host.Call(msg); if (result == null) { StaticLogger.Warning(string.Format("Invoking {0} returned null", endpoint)); return(null); } if (RtmpUtil.IsError(result)) { var error = RtmpUtil.GetError(result); var errordetail = error != null && error.faultDetail != null?string.Format(" [{0}]", error.faultDetail) : ""; var errorstr = error != null && error.faultString != null?string.Format(", {0}", error.faultString) : ""; StaticLogger.Warning(string.Format( "{0} returned an error{1}{2}", endpoint, errorstr, errordetail )); return(null); } var body = RtmpUtil.GetBodies(result).FirstOrDefault(); if (body == null) { StaticLogger.Debug(endpoint + " RtmpUtil.GetBodies returned null"); return(null); } return(body.Item1); }
public bool Save(string file) { try { using (var sw = new StreamWriter(File.Open(file, FileMode.Create, FileAccess.Write))) { sw.Write(JsonConvert.SerializeObject(this, Formatting.Indented)); return(true); } } catch (IOException io) { StaticLogger.Debug(io); return(false); } }
public void Load(string file) { try { if (!File.Exists(file)) { return; } using (var sr = new StreamReader(File.Open(file, FileMode.Open, FileAccess.Read))) { JsonConvert.PopulateObject(sr.ReadToEnd(), this); } OnLoad(); } catch (IOException io) { StaticLogger.Debug(io); } }
/// <summary> /// Records/Commits the lobby to the database. Locking the database lock. /// </summary> /// <param name="lobby"></param> public void CommitLobby(GameDTO lobby) { bool committed = false; Stopwatch sw; lock (DatabaseLock) { sw = Stopwatch.StartNew(); committed = RecordLobby(lobby); if (committed) { Database.Commit(); } } sw.Stop(); if (committed) { StaticLogger.Debug(string.Format("Lobby committed in {0}ms", sw.ElapsedMilliseconds)); } }
public T InvokeService <T>(string service, string operation, params object[] args) where T : class { var msg = new RemotingMessage(); msg.operation = operation; msg.destination = service; msg.headers["DSRequestTimeout"] = 60; msg.headers["DSId"] = RtmpUtil.RandomUidString(); msg.headers["DSEndpoint"] = "my-rtmps"; msg.body = args; msg.messageId = RtmpUtil.RandomUidString(); string endpoint = service + "." + operation; var result = Host.Call(msg); if (result == null) { StaticLogger.Warning(string.Format("Invoking {0} returned null", endpoint)); return(null); } if (RtmpUtil.IsError(result)) { var error = RtmpUtil.GetError(result); var errordetail = error != null && error.faultDetail != null?string.Format(" [{0}]", error.faultDetail) : ""; var errorstr = error != null && error.faultString != null?string.Format(", {0}", error.faultString) : ""; StaticLogger.Warning(string.Format( "{0} returned an error{1}{2}", endpoint, errorstr, errordetail )); return(null); } var body = RtmpUtil.GetBodies(result).FirstOrDefault(); if (body == null) { StaticLogger.Debug(endpoint + " RtmpUtil.GetBodies returned null"); return(null); } if (body.Item1 == null) { StaticLogger.Debug(endpoint + " Body.Item1 returned null"); return(null); } object obj = null; if (body.Item1 is ASObject) { var ao = (ASObject)body.Item1; obj = MessageTranslator.Instance.GetObject <T>(ao); if (obj == null) { StaticLogger.Debug(endpoint + " expected " + typeof(T) + ", got " + ao.TypeName); return(null); } } else if (body.Item1 is ArrayCollection) { try { obj = Activator.CreateInstance(typeof(T), (ArrayCollection)body.Item1); } catch (Exception ex) { StaticLogger.Warning(endpoint + " failed to construct " + typeof(T)); StaticLogger.Debug(ex); return(null); } } else { StaticLogger.Debug(endpoint + " unknown object " + body.Item1.GetType()); return(null); } if (obj is MessageObject) { ((MessageObject)obj).TimeStamp = body.Item2; } return((T)obj); }
/// <summary> /// Query and cache player data /// </summary> /// <param name="player">Player to load</param> /// <param name="control">Control to update</param> void LoadPlayer(PlayerParticipant player, PlayerControl control) { PlayerCache existing; var ply = new PlayerCache(); try { lock (PlayersCache) { //Clear the cache every 1000 players to prevent crashing afk lobbies. if (PlayersCache.Count > 1000) { PlayersCache.Clear(); } //Does the player already exist in the cache? if ((existing = PlayersCache.Find(p => p.Player != null && p.Player.Id == player.SummonerId)) == null) { PlayersCache.Add(ply); } } //If another thread is loading the player data, lets wait for it to finish and use its data. if (existing != null) { existing.LoadWait.WaitOne(); LoadPlayerUIFinish(existing, control); return; } using (SimpleLogTimer.Start("Player query")) { var entry = Recorder.GetPlayer(player.SummonerId); ply.Player = entry ?? ply.Player; } using (SimpleLogTimer.Start("Stats query")) { var cmd = new PlayerCommands(Connection); var summoner = cmd.GetPlayerByName(player.Name); if (summoner != null) { ply.Summoner = summoner; ply.Stats = cmd.RetrievePlayerStatsByAccountId(summoner.AccountId); ply.RecentChamps = cmd.RetrieveTopPlayedChampions(summoner.AccountId, "CLASSIC"); ply.Games = cmd.GetRecentGames(summoner.AccountId); } else { StaticLogger.Debug(string.Format("Player {0} not found", player.Name)); ply.LoadWait.Set(); return; } } using (SimpleLogTimer.Start("Seen query")) { if (SelfSummoner != null && SelfSummoner.SummonerId != ply.Summoner.SummonerId && ply.Games != null) { ply.SeenCount = ply.Games.GameStatistics.Count(pgs => pgs.FellowPlayers.Any(fp => fp.SummonerId == SelfSummoner.SummonerId)); } } ply.LoadWait.Set(); LoadPlayerUIFinish(ply, control); } catch (Exception ex) { ply.LoadWait.Set(); // StaticLogger.Warning(ex); } }