private void menuImportCharacter_Click(object sender, RoutedEventArgs e)
        {
            Dialogs.DialogImportCharacter importCharacterDialog = new Dialogs.DialogImportCharacter(activeClusterList);

            if (importCharacterDialog.ShowDialog() == true)
            {
                string characterId = importCharacterDialog.CharacterId;

                string     url  = "http://api.camelotherald.com/character/info/" + characterId;
                HttpClient http = new HttpClient();

                try {
                    HttpContent responseMessage = http.GetAsync(url).Result.Content;

                    if (responseMessage != null)
                    {
                        string         characterData = responseMessage.ReadAsStringAsync().Result;
                        Json.ErrorJson errorJson     = new Json.ErrorJson();
                        var            options       = new JsonSerializerOptions
                        {
                            AllowTrailingCommas = true
                        };

                        try {
                            errorJson = JsonSerializer.Deserialize <Json.ErrorJson>(characterData, options);
                        } catch (Exception exception) {
                            MessageBox.Show(exception.ToString());
                        }

                        if (errorJson.error != "")
                        {
                            MessageBox.Show("Error : " + errorJson.error);
                        }
                        else
                        {
                            try {
                                Json.CharacterInfoJson characterInfoJson = new Json.CharacterInfoJson();
                                characterInfoJson = JsonSerializer.Deserialize <Json.CharacterInfoJson>(characterData, options);
                                Character character = new Character(characterInfoJson.character_web_id, characterInfoJson.name, characterInfoJson.server_name, characterInfoJson.ClassName);
                                character.RealmPoints    = characterInfoJson.realm_war_stats.current.realm_points;
                                character.ClassName      = characterInfoJson.ClassName;
                                character.TotalKills     = characterInfoJson.realm_war_stats.current.player_kills.total.kills;
                                character.TotalSoloKills = characterInfoJson.realm_war_stats.current.player_kills.total.solo_kills;

                                CharacterManager.CreateCharacter(character);

                                characterList.Add(character);
                            } catch (Exception exception) {
                                MessageBox.Show(exception.ToString());
                            }
                        }
                    }
                } catch (Exception exception) {
                }
            }
        }
示例#2
0
        public static void UpdateCharacter(Character character)
        {
            string url = "http://api.camelotherald.com/character/info/" + character.Id;

            HttpClient http = new HttpClient();

            try {
                HttpContent responseMessage = http.GetAsync(url).Result.Content;

                if (responseMessage != null)
                {
                    string         characterData = responseMessage.ReadAsStringAsync().Result;
                    Json.ErrorJson errorJson     = new Json.ErrorJson();
                    var            options       = new JsonSerializerOptions
                    {
                        AllowTrailingCommas = true
                    };

                    try {
                        errorJson = JsonSerializer.Deserialize <Json.ErrorJson>(characterData, options);
                    } catch (Exception exception) {
                        MessageBox.Show(exception.ToString());
                    }

                    if (errorJson.error != "")
                    {
                        MessageBox.Show("Error : " + errorJson.error);
                    }
                    else
                    {
                        try {
                            Json.CharacterInfoJson characterInfoJson = new Json.CharacterInfoJson();
                            characterInfoJson = JsonSerializer.Deserialize <Json.CharacterInfoJson>(characterData, options);
                            //Character character = new Character( characterInfoJson.character_web_id, characterInfoJson.name, characterInfoJson.server_name, characterInfoJson.ClassName );
                            character.RealmPoints    = characterInfoJson.realm_war_stats.current.realm_points;
                            character.ClassName      = characterInfoJson.ClassName;
                            character.TotalKills     = characterInfoJson.realm_war_stats.current.player_kills.total.kills;
                            character.TotalSoloKills = characterInfoJson.realm_war_stats.current.player_kills.total.solo_kills;

                            CharacterManager.CreateCharacter(character);
                        } catch (Exception exception) {
                            MessageBox.Show(exception.ToString());
                        }
                    }
                }
            } catch (Exception exception) {
            }
        }