예제 #1
0
        private async void LoadCharacter(CharacterInfo character)
        {
            if (character == null)
            {
                return;
            }

            if (character.Id == null)
            {
                TargetCharacter = new CharacterSummary {
                    Name = "<New Character>"
                };
                return;
            }

            OAuthSession   newSession = CreateOAuthSession();
            HttpWebRequest request    = newSession.Request()
                                        .ForUrl(
                $"https://api.obsidianportal.com/v1/campaigns/{character.CampaignId}/characters/{character.Id}.json")
                                        .Get().
                                        ToWebRequest();

            JObject charObject;

            using (
                WebResponse response = await Task.Factory.FromAsync(
                    request.BeginGetResponse,
                    request.EndGetResponse,
                    null))
                using (var streamReader = new StreamReader(response.GetResponseStream()))
                    using (var jsonReader = new JsonTextReader(streamReader))
                        charObject = JObject.Load(jsonReader);

            TargetCharacter = ToSummary(charObject);
        }
예제 #2
0
        private static CharacterSummary ToSummary(JObject charObject)
        {
            JToken jToken = charObject["dynamic_sheet"];

            if (jToken.Type != JTokenType.Object)
            {
                return(null);
            }

            var sheet = (JObject)jToken;

            var characterSummary = new CharacterSummary
            {
                Name        = (string)charObject["name"],
                Alignment   = (string)sheet["alignment"],
                ClassLevels = (string)sheet["level"],
                Gender      = (string)sheet["gender"],
                Race        = (string)sheet["race"]
            };

            return(characterSummary);
        }