예제 #1
0
        }//

        public async void GetBackground()
        {
            var url = $"https://api.pexels.com/v1/search?query={Location}&per%20page=15&page=1";

            var result = await
                         ApiCaller.Get(
                url,
                "563492ad6f917000010000016cbc65bf4f724840ab22e86ed18b2c15"
                );

            if (result.Successful)
            {
                var bgInfo = JsonConvert.DeserializeObject <BackgroundInfo>(result.Response);

                if (bgInfo != null & bgInfo.photos.Length > 0)
                {
                    Debug.WriteLine("GetBackground - we are here!");
                    Debug.WriteLine(bgInfo.photos.Length);
                    // case 1: get first photo from photo collection
                    //bgImg.Source = ImageSource.FromUri(new Uri(bgInfo.photos[0].src.medium));

                    // case 2: get random photo from photo collection
                    bgImg.Source = ImageSource.FromUri
                                       (new Uri
                                       (
                                           bgInfo.photos[new Random().Next(0, bgInfo.photos.Length - 1)].src.medium
                                       )
                                       );
                }
            }
            else
            {
                Debug.WriteLine("GetBackground problems: " + result.ErrorMessage);
            }
        }
        private async void GetWeatherInfo()
        {
            var url = $"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={APIKey}&units=imperial";

            var result = await ApiCaller.Get(url);

            if (result.Successful)
            {
                try
                {
                    var weatherInfo = JsonConvert.DeserializeObject <WeatherInfo>(result.Response);
                    descriptionTxt.Text = weatherInfo.weather[0].description.ToUpper();
                    iconImg.Source      = $"w{weatherInfo.weather[0].icon}";
                    cityTxt.Text        = weatherInfo.name.ToUpper();
                    temperatureTxt.Text = weatherInfo.main.temp.ToString("0");
                    humidityTxt.Text    = $"{weatherInfo.main.humidity}%";
                    pressureTxt.Text    = $"{weatherInfo.main.pressure} hpa";
                    windTxt.Text        = $"{weatherInfo.wind.speed} m/s";
                    cloudinessTxt.Text  = $"{weatherInfo.clouds.all}%";

                    DateTime dt = DateTime.Now;
                    dateTxt.Text = dt.ToString("dddd, MMM dd").ToUpper();

                    GetForecast();
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Weather Info", ex.Message, "OK");
                }
            }
            else
            {
                await DisplayAlert("Weather Info", "No weather information found", "OK");
            }
        }
예제 #3
0
        private static void RequestReport(string url)
        {
            var response = ApiCaller.Get <PassSalesResponse>(url);

            ScenarioCache.StoreResponse(response);
            ScenarioCache.Store(ModelKeys.PassSalesReport, response.Data);
        }
예제 #4
0
        /// <summary>
        /// Restful Get function
        /// </summary>
        /// <typeparam name="TRsp">Result generic type</typeparam>
        /// <param name="api">Get api</param>
        /// <returns></returns>
        public async static Task <TRsp> Get <TRsp>(string api, Func <HttpResponseMessage, TRsp> failureAct = null, params object[] jPath)
        {
            try
            {
                HttpResponseMessage response = await ApiCaller.Get(UriFetcher.BaseUri, api,
                                                                   new RequestHeader
                {
                    token = TokenFetcher.Token
                });

                string content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                if (!response.IsSuccessStatusCode)
                {
                    return((failureAct ?? new Func <HttpResponseMessage, TRsp>((rsp) => default(TRsp)))(response));
                }
                if (jPath.Count() == 0)
                {
                    return(JsonConvert.DeserializeObject <TRsp>(content));
                }
                JToken jobject = JObject.Parse(content);
                foreach (object jpath in jPath)
                {
                    jobject = jobject[jpath];
                }
                return(jobject.ToObject <TRsp>());
            }
            catch (Exception ex)
            {
                NetworkLog.ErrorLog?.Invoke(ex);
                throw new Exception("Please check the Network status!");
            }
        }
예제 #5
0
        private async void GetWeatherInfo()
        {
            var url = $"http://api.openweathermap.org/data/2.5/weather?q={Location}&appid=8110f218daad768d9ce7a741f6580aab&units=metric";

            var result = await ApiCaller.Get(url);

            if (result.Successful)
            {
                try
                {
                    var weatherInfo = JsonConvert.DeserializeObject <WeatherInfo>(result.Response);
                    descriptionTxt.Text = weatherInfo.weather[0].description.ToUpper();
                    iconImg.Source      = $"w{weatherInfo.weather[0].icon}";
                    cityTxt.Text        = weatherInfo.name.ToUpper();
                    temperatureTxt.Text = weatherInfo.main.temp.ToString("0");

                    var dt = new DateTime().ToUniversalTime().AddSeconds(weatherInfo.dt);
                    dateTxt.Text = dt.ToString("dddd, MMM dd").ToUpper();
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Weather Info", ex.Message, "OK");
                }
            }
            else
            {
                await DisplayAlert("weather Info", "No weather information found", "OK");
            }
        }
예제 #6
0
        public void ThenTheStudentIsntMarkedAgainstClass()
        {
            var response = ApiCaller.Get <List <UserModel> >(Routes.GetClassAttendance(ScenarioCache.GetId(ModelIdKeys.ClassId)));

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsEmpty(response.Data);
        }
예제 #7
0
        public void ThenTheStudentIsMarkedAgainstClass()
        {
            var response = ApiCaller.Get <List <UserModel> >(Routes.GetClassAttendance(ScenarioCache.GetId(ModelIdKeys.ClassId)));

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.Contains(ScenarioCache.GetId(ModelIdKeys.UserId), response.Data.Select(x => x.Id).ToList());
        }
예제 #8
0
        public void ThenTheBlockIsNotInviteOnly()
        {
            var response = ApiCaller.Get <BlockModel>(Routes.GetById(Routes.Blocks, ScenarioCache.GetId(ModelIdKeys.BlockId)));

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsFalse(response.Data.IsInviteOnly);
        }
예제 #9
0
        private async void GetWeatherInfo()
        {
            var url = $"http://api.openweathermap.org/data/2.5/weather?q={Location}&appid=5f1d9ce0e366e66fa383b1a8a6ff8892&units=metric";

            var result = await ApiCaller.Get(url);

            if (result.Successful)
            {
                try
                {
                    var weatherInfo = JsonConvert.DeserializeObject <WeatherInfo>(result.Response);
                    descriptionTxt.Text = weatherInfo.weather[0].description.ToUpper();
                    //iconImg.Source = $"http://openweathermap.org/img/wn/{weatherInfo.weather[0].icon}@2x.png";
                    iconImg.Source      = $"w{weatherInfo.weather[0].icon}.png";
                    cityTxt.Text        = weatherInfo.name.ToUpper();
                    temperatureTxt.Text = weatherInfo.main.temp.ToString("0");
                    humidityTxt.Text    = $"{weatherInfo.main.humidity}%";
                    pressureTxt.Text    = $"{weatherInfo.main.pressure} hpa";
                    windTxt.Text        = $"{weatherInfo.wind.speed} m/s";
                    cloudinessTxt.Text  = $"{weatherInfo.clouds.all}%";

                    var dt = new DateTime().ToUniversalTime().AddSeconds(weatherInfo.dt);
                    dateTxt.Text = dt.ToString("dddd, MMM dd").ToUpper();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            else
            {
                await DisplayAlert("Weather Information", "No weather information found", "Ok");
            }
        }
예제 #10
0
        private async void PreiaDateVreme(string location)
        {
            var url = $"http://api.openweathermap.org/data/2.5/weather?q={location}&appid={ApiCaller.API_KEY}&units=metric";

            var result = await ApiCaller.Get(url);

            if (result.Successful)
            {
                try
                {
                    var weatherInfo = JsonConvert.DeserializeObject <WeatherInfo>(result.Response);
                    descriptionTxt.Text = weatherInfo.weather[0].description.ToUpper();
                    iconImg.Source      = $"w{weatherInfo.weather[0].icon}";
                    cityTxt.Text        = weatherInfo.name.ToUpper();
                    temperatureTxt.Text = weatherInfo.main.temp.ToString("0");
                    humidityTxt.Text    = $"{weatherInfo.main.humidity}%";
                    pressureTxt.Text    = $"{weatherInfo.main.pressure} hpa";
                    windTxt.Text        = $"{weatherInfo.wind.speed} m/s";
                    cloudinessTxt.Text  = $"{weatherInfo.clouds.all}%";

                    var dt = new DateTime().ToUniversalTime().AddSeconds(weatherInfo.dt);
                    dateTxt.Text = dt.ToString("dddd, MMM dd").ToUpper();
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Weather Info", ex.Message, "OK");
                }
            }
            else
            {
                await DisplayAlert("Weather Info", "No weather information found", "OK");
            }
        }
예제 #11
0
        private async void GetWeatherInfo()
        {
            var url = $"https://api.openweathermap.org/data/2.5/weather?q={Location}&APPID=af0a2f55ea1c08a014e9ac44776623c1&units=metric";

            var result = await ApiCaller.Get(url);

            if (result.Successful)
            {
                try
                {
                    var weatherInfo = JsonConvert.DeserializeObject<WeatherInfo>(result.Response);
                    Temperatura.Text = $"Temperatura: {weatherInfo.main.temp.ToString("0")} °C";
                    PredkoscWiatru.Text = $"Wiatr: {weatherInfo.wind.speed} m/s";
                    
                    var dt = new DateTime().ToUniversalTime().AddSeconds(weatherInfo.dt);
                    
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Weather Info", ex.Message, "OK");
                }
            }
            else
            {
                await DisplayAlert("Weather Info", "No weather information found", "OK");
            }
        }
        private async void GetWeatherInfo()
        {
            var url = $"https://api.openweathermap.org/data/2.5/weather?q={Location}&appid=57fa57ff52ef2cd7db37b5577cd46a64&units=metric";

            var result = await ApiCaller.Get(url);

            if (result.Successful)
            {
                try
                {
                    var weatherInfo = JsonConvert.DeserializeObject <WeatherInfo>(result.Response);
                    descriptionTxt.Text = weatherInfo.weather[0].description.ToUpper();
                    iconImg.Source      = $"w{weatherInfo.weather[0].icon}";
                    cityTxt.Text        = weatherInfo.name.ToUpper();
                    temperatureTxt.Text = weatherInfo.main.temp.ToString("0");
                    humidityTxt.Text    = $"{weatherInfo.main.humidity}%";
                    pressureTxt.Text    = $"{weatherInfo.main.pressure} hpa";
                    windTxt.Text        = $"{weatherInfo.wind.speed} m/s";
                    cloudinessTxt.Text  = $"{weatherInfo.clouds.all}%";

                    var dt = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc).ToUniversalTime().AddSeconds(weatherInfo.dt);

                    dateTxt.Text = dt.ToString("dddd, MMM dd").ToUpper();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
            }
            else
            {
                await DisplayAlert("Weather Info", "Weather information not found", "OK");
            }
        }
예제 #13
0
        private async void GetWeatherInfo()
        {
            var url    = $"http://api.openweathermap.org/data/2.5/weather?q={Location}&appid=55ee76233948b78ed34e59d3fe2f69bc&units=metric";
            var result = await ApiCaller.Get(url);

            if (result.Successful)
            {
                try
                {
                    var weatherInfo = JsonConvert.DeserializeObject <WeatherInfo>(result.Response);

                    descriptionTxt.Text = weatherInfo.weather[0].description.ToUpper();
                    cityTxt.Text        = weatherInfo.name.ToUpper();
                    temperatureTxt.Text = weatherInfo.main.temp.ToString("0");
                    humidityTxt.Text    = $"{weatherInfo.main.humidity}%";
                    pressureTxt.Text    = $"{weatherInfo.main.pressure} hpa";
                    windTxt.Text        = $"{weatherInfo.wind.speed} m/s";
                    cloudinessTxt.Text  = $"{weatherInfo.clouds.all}%";

                    var dt = new DateTime().ToUniversalTime().AddSeconds(weatherInfo.dt);
                    dateTxt.Text = dt.ToString("dddd, MMM dd").ToUpper();

                    GetForecast();
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                await DisplayAlert("weather info", "No weather information found", "OK");
            }
        }
예제 #14
0
 /// <summary>
 /// Restful Get function
 /// </summary>
 /// <param name="api">Get api</param>
 /// <returns></returns>
 public async static Task <HttpResponseMessage> Get(string api)
 => await ApiCaller.Get(
     UriFetcher.BaseUri, api,
     new RequestHeader
 {
     token = TokenFetcher.Token
 });
예제 #15
0
        public void ThenTheStudentIsntMarkedAgainstTheEvent()
        {
            var response = ApiCaller.Get <StandAloneEventModel>(Routes.GetById(Routes.StandAloneEvent, ScenarioCache.GetId(ModelIdKeys.StandAloneEventId)));

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsEmpty(response.Data.ActualStudents);
        }
예제 #16
0
        public void ThenTheUserDoesntHaveAPass()
        {
            var response = ApiCaller.Get <List <PassModel> >(Routes.GetUserPasses(ScenarioCache.GetId(ModelIdKeys.UserId)));

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsEmpty(response.Data);
        }
예제 #17
0
        public void ThenTheStudentIsMarkedAgainstTheEvent()
        {
            var response = ApiCaller.Get <StandAloneEventModel>(Routes.GetById(Routes.StandAloneEvent, ScenarioCache.GetId(ModelIdKeys.StandAloneEventId)));

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.Contains(ScenarioCache.GetId(ModelIdKeys.UserId), response.Data.ActualStudents.Select(x => x.Id).ToList());
        }
    public ActionResult Index()
    {
        SomeClass model = ApiCaller.Get();

        //do something with the instance if required
        return(View(model));
    }
예제 #19
0
        public void WhenTheCurrentUserIsRetrieved()
        {
            var response = ApiCaller.Get <UserModel>(Routes.GetCurrentUser);

            ScenarioCache.Store(ExpectedUserKey, response.Data);
            ScenarioCache.Store(ModelIdKeys.UserId, response.Data.Id);
        }
        private async void GetWeatherInfo()
        {
            //var url = $"api.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=cf8153eb9c27175c43021ba5d379e3c4";
            var url    = $"http://api.openweathermap.org/data/2.5/weather?q=Tehran&appid=cf8153eb9c27175c43021ba5d379e3c4";
            var result = await ApiCaller.Get(url);

            if (result.Successful)
            {
                try
                {
                    var weatherInfo = JsonConvert.DeserializeObject <WeatherInfo>(result.Response);
                    descriptionTxt.Text = weatherInfo.weather[0].description.ToUpper();
                    iconImg.Source      = $"w{weatherInfo.weather[0].icon}";
                    cityTxt.Text        = weatherInfo.name.ToUpper();
                    temperatureTxt.Text = weatherInfo.main.temp.ToString("0");
                    humidityTxt.Text    = $"{weatherInfo.main.humidity}%";
                    pressureTxt.Text    = $"{weatherInfo.main.pressure} hpa";
                    windTxt.Text        = $"{weatherInfo.wind.speed} m/s";
                    cloudinessTxt.Text  = $"{weatherInfo.clouds.all}%";

                    var dt = new DateTime().ToUniversalTime().AddSeconds(weatherInfo.dt);
                    dateTxt.Text = dt.ToString("dddd, MMM dd").ToUpper();

                    GetForecast();
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Weather Info", ex.Message, "OK");
                }
            }
            else
            {
                await DisplayAlert("Weather info", "Please tray later", "OK!");
            }
        }
예제 #21
0
        public void ThenTheBlockClassCapacityIs(int classCapacity)
        {
            var block = ApiCaller.Get <BlockModel>(Routes.GetById(Routes.Blocks, ScenarioCache.GetId(ModelIdKeys.BlockId))).Data;

            Assert.AreEqual(classCapacity, block.ClassCapacity);
            ScenarioCache.Store(ModelKeys.Block, block);
        }
예제 #22
0
        public void ThenBlockCanBeRetrieved()
        {
            var response = ApiCaller.Get <BlockModel>(Routes.GetById(Routes.Blocks, ScenarioCache.GetId(ModelIdKeys.BlockId)));

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Data);
        }
예제 #23
0
        private async void GetForecast()
        {
            var url    = $"http://api.openweathermap.org/data/2.5/forecast?lat={lat}&lon={lon}&appid={APP_ID}&units=metric";
            var result = await ApiCaller.Get(url);

            if (result.Successful)
            {
                try
                {
                    var forcastInfo = JsonConvert.DeserializeObject <ForecastInfo>(result.Response);

                    List <List> allList = new List <List>();


                    foreach (var list in forcastInfo.list)
                    {
                        var date = DateTime.Parse(list.dt_txt);

                        if (date > DateTime.Now && date.Hour == 0 && date.Minute == 0 && date.Second == 0)
                        {
                            allList.Add(list);
                        }
                    }

                    dayOneTxt.Text    = DateTime.Parse(allList[0].dt_txt).ToString("dddd");
                    dateOneTxt.Text   = DateTime.Parse(allList[0].dt_txt).ToString("dd MMM");
                    iconOneImg.Source = $"w{allList[0].weather[0].icon}";
                    tempOneTxt.Text   = allList[0].main.temp.ToString("0");
                    dayOneDesc.Text   = allList[0].weather[0].description.ToUpper();


                    dayTwoTxt.Text    = DateTime.Parse(allList[1].dt_txt).ToString("dddd");
                    dateTwoTxt.Text   = DateTime.Parse(allList[1].dt_txt).ToString("dd MMM");
                    iconTwoImg.Source = $"w{allList[1].weather[0].icon}";
                    tempTwoTxt.Text   = allList[1].main.temp.ToString("0");
                    dayTwoDesc.Text   = allList[1].weather[0].description.ToUpper();

                    dayThreeTxt.Text    = DateTime.Parse(allList[2].dt_txt).ToString("dddd");
                    dateThreeTxt.Text   = DateTime.Parse(allList[2].dt_txt).ToString("dd MMM");
                    iconThreeImg.Source = $"w{allList[2].weather[0].icon}";
                    tempThreeTxt.Text   = allList[2].main.temp.ToString("0");
                    dayThreeDesc.Text   = allList[2].weather[0].description.ToUpper();

                    dayFourTxt.Text    = DateTime.Parse(allList[3].dt_txt).ToString("dddd");
                    dateFourTxt.Text   = DateTime.Parse(allList[3].dt_txt).ToString("dd MMM");
                    iconFourImg.Source = $"w{allList[3].weather[0].icon}";
                    tempFourTxt.Text   = allList[3].main.temp.ToString("0");
                    dayFourDesc.Text   = allList[3].weather[0].description.ToUpper();
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Weather Info", ex.Message, "OK");
                }
            }
            else
            {
                await DisplayAlert("Weather Info", "No forecast information found", "OK");
            }
        }
예제 #24
0
        public void ThenTheBlockDetailsHasTheRoom()
        {
            var block  = ApiCaller.Get <BlockModel>(Routes.GetById(Routes.Blocks, ScenarioCache.GetId(ModelIdKeys.BlockId))).Data;
            var roomId = ScenarioCache.GetId(ModelIdKeys.RoomId);

            Assert.IsNotNull(block.Room);
            Assert.AreEqual(roomId, block.Room.Id);
        }
예제 #25
0
        public static List <TeacherModel> GetAllTeachers()
        {
            var response = ApiCaller.Get <List <TeacherModel> >(Routes.Teachers);

            return(response.StatusCode == HttpStatusCode.NotFound
                ? new List <TeacherModel>()
                : response.Data);
        }
예제 #26
0
        public void ThenTheUsersDetailsCanNotBeRetrieved()
        {
            var userResponse = ApiCaller.Get <List <UserModel> >(Routes.Users);

            Assert.AreEqual(HttpStatusCode.OK, userResponse.StatusCode);

            Assert.IsEmpty(userResponse.Data.Where(x => x.Id == ScenarioCache.GetUserId()));
        }
예제 #27
0
        public void ThenTheClassDetailsHasTheRoom()
        {
            var theClass = ApiCaller.Get <ClassModel>(Routes.GetById(Routes.Classes, ScenarioCache.GetId(ModelIdKeys.ClassId))).Data;
            var roomId   = ScenarioCache.GetId(ModelIdKeys.RoomId);

            Assert.IsNotNull(theClass.Room);
            Assert.AreEqual(roomId, theClass.Room.Id);
        }
예제 #28
0
        private async void GetForecast()
        {
            var url    = $"http://api.openweathermap.org/data/2.5/forecast?q={Location}&appid=5f1d9ce0e366e66fa383b1a8a6ff8892&units=metric";
            var result = await ApiCaller.Get(url);

            if (result.Successful)
            {
                try
                {
                    var forcastInfo = JsonConvert.DeserializeObject <ForecastInfo>(result.Response);

                    List <List> allList = new List <List>();

                    foreach (var list in forcastInfo.list)
                    {
                        //var date = DateTime.ParseExact(list.dt_txt, "yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture);
                        var date = DateTime.Parse(list.dt_txt);

                        if (date > DateTime.Now && date.Hour == 0 && date.Minute == 0 && date.Second == 0)
                        {
                            allList.Add(list);
                        }
                    }

                    dayOneTxt.Text  = DateTime.Parse(allList[0].dt_txt).ToString("dddd");
                    dateOneTxt.Text = DateTime.Parse(allList[0].dt_txt).ToString("dd MMM");
                    //iconOneImg.Source = $"http://openweathermap.org/img/wn/{allList[0].weather[0].icon}@2x.png";
                    iconOneImg.Source = $"w{allList[0].weather[0].icon}.png";
                    tempOneTxt.Text   = allList[0].main.temp.ToString("0");

                    dayTwoTxt.Text    = DateTime.Parse(allList[1].dt_txt).ToString("dddd");
                    dateTwoTxt.Text   = DateTime.Parse(allList[1].dt_txt).ToString("dd MMM");
                    iconTwoImg.Source = $"http://openweathermap.org/img/wn/{allList[1].weather[0].icon}@2x.png";
                    iconTwoImg.Source = $"w{allList[1].weather[0].icon}.png";
                    tempTwoTxt.Text   = allList[1].main.temp.ToString("0");

                    dayThreeTxt.Text  = DateTime.Parse(allList[2].dt_txt).ToString("dddd");
                    dateThreeTxt.Text = DateTime.Parse(allList[2].dt_txt).ToString("dd MMM");
                    //iconThreeImg.Source = $"http://openweathermap.org/img/wn/{allList[2].weather[0].icon}@2x.png";
                    iconThreeImg.Source = $"w{allList[2].weather[0].icon}.png";
                    tempThreeTxt.Text   = allList[2].main.temp.ToString("0");

                    dayFourTxt.Text  = DateTime.Parse(allList[3].dt_txt).ToString("dddd");
                    dateFourTxt.Text = DateTime.Parse(allList[3].dt_txt).ToString("dd MMM");
                    //iconFourImg.Source = $"http://openweathermap.org/img/wn/{allList[3].weather[0].icon}@2x.png";
                    iconFourImg.Source = $"w{allList[3].weather[0].icon}.png";
                    tempFourTxt.Text   = allList[3].main.temp.ToString("0");
                }
                catch (Exception ex)
                {
                    await DisplayAlert("Weather Info", ex.Message, "OK");
                }
            }
            else
            {
                await DisplayAlert("Weather Info", "No forecast information found", "OK");
            }
        }
예제 #29
0
        async void bgImg_Clicked(object sender, System.EventArgs e)
        {
            try
            {
                var request = new GeolocationRequest(GeolocationAccuracy.Medium, TimeSpan.FromSeconds(10));
                cts = new CancellationTokenSource();
                var location = await Geolocation.GetLocationAsync(request, cts.Token);

                if (location != null)
                {
                    Lat = location.Latitude.ToString();
                    Lon = location.Longitude.ToString();
                }

                var url = $"http://api.openweathermap.org/data/2.5/weather?lat={Lat}&lon={Lon}&appid={API_KEY}&units=metric";

                var result = await ApiCaller.Get(url);

                if (result.Successful)
                {
                    try
                    {
                        var weatherInfo = JsonConvert.DeserializeObject <WeatherInfo>(result.Response);
                        descriptionTxt.Text = weatherInfo.weather[0].description.ToUpper();
                        iconImg.Source      = $"w{weatherInfo.weather[0].icon}";
                        cityTxt.Text        = weatherInfo.name.ToUpper();
                        temperatureTxt.Text = weatherInfo.main.temp.ToString("0");
                        humidityTxt.Text    = $"{weatherInfo.main.humidity}%";
                        pressureTxt.Text    = $"{weatherInfo.main.pressure} hpa";
                        windTxt.Text        = $"{weatherInfo.wind.speed} m/s";
                        cloudinessTxt.Text  = $"{weatherInfo.clouds.all}%";

                        var dt = new DateTime().ToUniversalTime().AddSeconds(weatherInfo.dt);
                        dateTxt.Text = dt.ToString("dddd, MMM dd").ToUpper();
                    }
                    catch (Exception ex)
                    {
                        await DisplayAlert("Weather Info", ex.Message, "OK");
                    }
                }
                else
                {
                    await DisplayAlert("Weather Info", "No weather information found", "OK");
                }
            }
            catch (FeatureNotSupportedException fnsEx)
            {
                await DisplayAlert("Faild", fnsEx.Message, "OK");
            }
            catch (PermissionException pEx)
            {
                await DisplayAlert("Faild", pEx.Message, "OK");
            }
            catch (Exception ex)
            {
                await DisplayAlert("Faild", ex.Message, "OK");
            }
        }
예제 #30
0
        public void ThenTheCorrectNumberOfClassesAreCreated()
        {
            var response = ApiCaller.Get <BlockModel>(Routes.GetById(Routes.Blocks, ScenarioCache.GetId(ModelIdKeys.BlockId)));
            var block    = response.Data;

            var expectedBlock = ScenarioCache.Get <BlockModel>(ModelKeys.Block);

            Assert.AreEqual(expectedBlock.NumberOfClasses, block.Classes.Count);
        }