private void AppendCharacters(Dictionary <string, ServerCharacterListByAccount> dictionary) { foreach (KeyValuePair <string, ServerCharacterListByAccount> pair in dictionary) { string key = pair.Key; ServerCharacterListByAccount charlist = pair.Value; if (this._data.ContainsKey(key)) { throw new Exception("Shouldn't have two character files for same key: " + key); } else { this._data.Add(key, charlist); } } }
public static void WriteCharacters(string ServerName, string zonename, List <Character> characters) { var launchInfo = LaunchControl.GetLaunchInfo(); if (!launchInfo.IsValid) { log.WriteError("LaunchInfo not valid"); return; } if (!IsValidCharacterName(launchInfo.CharacterName)) { try { log.WriteInfo("WriteCharacters called with no character name, so writing launch response"); LaunchControl.RecordLaunchResponse(DateTime.UtcNow); } catch { log.WriteError("WriteCharacters: Exception trying to record launch response"); } } // Pass info to Heartbeat Heartbeat.RecordServer(launchInfo.ServerName); Heartbeat.RecordAccount(launchInfo.AccountName); string key = GetKey(server: launchInfo.ServerName, accountName: launchInfo.AccountName); var clist = new ServerCharacterListByAccount() { ZoneId = zonename, CharacterList = characters }; // Create a dictionary of only our characters to save Dictionary <string, ServerCharacterListByAccount> solodict = new Dictionary <string, ServerCharacterListByAccount>(); solodict[key] = clist; string contents = JsonConvert.SerializeObject(solodict, Formatting.Indented); string path = FileLocations.GetCharacterFilePath(ServerName: launchInfo.ServerName, AccountName: launchInfo.AccountName); using (var file = new StreamWriter(path, append: false)) { file.Write(contents); } }