//Json aus http request serialisieren und zur Objektliste hinzufügen und speichern void parseAccount(IAsyncResult result) { WebResponse response = ((WebRequest)result.AsyncState).EndGetResponse(result); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); Console.WriteLine(responseFromServer); reader.Close(); response.Close(); mAccount = JsonConvert.DeserializeObject<Account>(responseFromServer); DataSetChangedEventArgs args = new DataSetChangedEventArgs(); callDataChangeCallback(args); save(); refreshGuilds(); }
//account daten aus datenbank laden public void queryAccount() { OleDbCommand command; try { command = new OleDbCommand("Select * From Account", connection); OleDbDataReader reader = command.ExecuteReader(); if (reader.HasRows) { mCharacters.Clear(); while (reader.Read()) { String guildIds = reader.GetString(1); string[] guildIdsArray = guildIds.Split(new[] {";"}, StringSplitOptions.None); List<String> guildIdsList = new List<String>(); foreach(String guildId in guildIdsArray){ guildIdsList.Add(guildId); } mAccount = new Account(); mAccount.Name = reader.GetString(0); mAccount.Guilds = guildIdsList; } save(); } else { Console.WriteLine("No rows found."); } reader.Close(); command.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }