Example #1
0
        public async System.Threading.Tasks.Task DownloadAirportStatus(string url)
        {
            try
            {
                this.RingVisible = Visibility.Visible;

                var connectionId = (string)Globals.LogonCore.LogonContext.RegistrationContext.ConnectionData["ApplicationConnectionId"];

                // Create an HttpClient instance
                var client = new SAP.Net.Http.HttpClient(
                    new System.Net.Http.HttpClientHandler()
                {
                    Credentials =
                        new System.Net.NetworkCredential(
                            Globals.LogonCore.LogonContext.RegistrationContext.BackendUserName,
                            Globals.LogonCore.LogonContext.RegistrationContext.BackendPassword), UseProxy = false
                },
                    true);             // will be disposed by the store!

                client.DefaultRequestHeaders.TryAddWithoutValidation("X-SMP-APPCID", connectionId);
                client.DefaultRequestHeaders.TryAddWithoutValidation("X-SUP-APPCID", connectionId);
                client.ShouldHandleXcsrfToken = true;

                // Send a request asynchronously continue when complete
                HttpResponseMessage response = await client.GetAsync(url);

                // Check that response was successful or throw exception
                response.EnsureSuccessStatusCode();

                // Read response asynchronously as JsonValue
                var content = await response.Content.ReadAsStringAsync();

                // Parse the content into a JsonObject
                var jsonContent = JObject.Parse(content);

                var airlineId    = (string)RelatedEntity.Properties["carrid"].Value;
                var flightNumber = (string)RelatedEntity.Properties["connid"].Value;
                var flightDate   = (DateTime)RelatedEntity.Properties["fldate"].Value;
                var price        = (decimal)RelatedEntity.Properties["PRICE"].Value;
                var currency     = (string)RelatedEntity.Properties["CURRENCY"].Value;

                var airport = jsonContent["name"].ToString();
                jsonContent = jsonContent["weather"].ToObject <JObject>();
                var weather = jsonContent["weather"].ToString();
                var temp    = jsonContent["temp"].ToString();
                var wind    = jsonContent["wind"].ToString();

                SharedContext.JsonContext = new JsonContext(airlineId, flightNumber, flightDate, price, currency, airport, weather, temp, wind);

                this.RingVisible = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                this.RingVisible = Visibility.Collapsed;
                throw;
            }
        }
        public async System.Threading.Tasks.Task DownloadAirportStatus(string url)
        {
            try
            {
                this.RingVisible = Visibility.Visible;

                var connectionId = (string)Globals.LogonCore.LogonContext.RegistrationContext.ConnectionData["ApplicationConnectionId"];

                // Create an HttpClient instance
                var client = new SAP.Net.Http.HttpClient(
                                new System.Net.Http.HttpClientHandler()
                                {
                                    Credentials =
                                        new System.Net.NetworkCredential(
                                        Globals.LogonCore.LogonContext.RegistrationContext.BackendUserName,
                                        Globals.LogonCore.LogonContext.RegistrationContext.BackendPassword), UseProxy = false
                                },
                                true); // will be disposed by the store!

                client.DefaultRequestHeaders.TryAddWithoutValidation("X-SMP-APPCID", connectionId);
                client.DefaultRequestHeaders.TryAddWithoutValidation("X-SUP-APPCID", connectionId);
                client.ShouldHandleXcsrfToken = true;

                // Send a request asynchronously continue when complete
                HttpResponseMessage response = await client.GetAsync(url);

                // Check that response was successful or throw exception
                response.EnsureSuccessStatusCode();

                // Read response asynchronously as JsonValue 
                var content = await response.Content.ReadAsStringAsync();

                // Parse the content into a JsonObject
                var jsonContent = JObject.Parse(content);

                var airlineId = (string)RelatedEntity.Properties["carrid"].Value;
                var flightNumber = (string)RelatedEntity.Properties["connid"].Value;
                var flightDate = (DateTime)RelatedEntity.Properties["fldate"].Value;
                var price = (decimal)RelatedEntity.Properties["PRICE"].Value;
                var currency = (string)RelatedEntity.Properties["CURRENCY"].Value;

                var airport = jsonContent["name"].ToString();
                jsonContent = jsonContent["weather"].ToObject<JObject>();
                var weather = jsonContent["weather"].ToString();
                var temp = jsonContent["temp"].ToString();
                var wind = jsonContent["wind"].ToString();

                SharedContext.JsonContext = new JsonContext(airlineId, flightNumber, flightDate, price, currency, airport, weather, temp, wind);

                this.RingVisible = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                this.RingVisible = Visibility.Collapsed;
                throw;
            }
        }