Exemplo n.º 1
0
        private async Task LoadContacts()
        {
            if (!await RefreshTokenIfRequired())
                return;
            // ReSharper disable once JoinDeclarationAndInitializer
            Contact[] contacts;
            StatusLbl.Content = "Loading contacts...";
#if DEBUG
            contacts = new[]
            {
                new Contact
                {
                    Id = "1",
                    ScaleUserId = "*****@*****.**",
                    AvailableFeatures = new []
                    {
                        new Availablefeature { Enabled = true, Id = "1", Name = "CalendarPresence"},
                        new Availablefeature { Enabled = true, Id = "2", Name = "CallPresence"},
                        new Availablefeature { Enabled = true, Id = "3", Name = "ExtendedPresence"},
                        new Availablefeature { Enabled = true, Id = "4", Name = "JobPrivatePresence"},
                    },
                },
            };
#else
            const string url = "https://api.cloud.mobileservices.dk/contact/api/contact";
            var client = HttpClientHelpers.CreateWithToken(OcpApimSubscriptionKeyTxb.Text, token);
            var response = await client.GetAsync(url);
            var stringResponse = await response.Content.ReadAsStringAsync();
            if (response.IsSuccessStatusCode)
            {
                contacts = JsonConvert.DeserializeObject<Contact[]>(stringResponse);
            }
            else
            {
                StatusLbl.Content = "HTTP " + ((int)response.StatusCode) + " " + response.StatusCode;
                contacts = new Contact[0];
            }
#endif
            if (!StatusLbl.Content.ToString().StartsWith("HTTP"))
                StatusLbl.Content = $"Done! Got {contacts.Length} contact(s).";

            lvDataBinding.ItemsSource = contacts.OrderBy(c => c.ScaleUserId).ToArray();
        }
Exemplo n.º 2
0
        private async Task<Presence> GetPresence(Contact selectedContact)
        {
            if (!await RefreshTokenIfRequired())
                return null;
            string url = $"https://api.cloud.mobileservices.dk/presence/api/presence/{selectedContact.Id}";
            var client = HttpClientHelpers.CreateWithToken(OcpApimSubscriptionKeyTxb.Text, token);
            var response = await client.GetAsync(url);
            var stringResponse = await response.Content.ReadAsStringAsync();
            if (response.IsSuccessStatusCode)
            {
                return JsonConvert.DeserializeObject<Presence>(stringResponse);
            }
            StatusLbl.Content = "HTTP " + ((int)response.StatusCode) + " " + response.StatusCode;

            return null;
        }