Esempio n. 1
0
        private void SearchDataWeatherCitys(object sender, RoutedEventArgs e)
        {
            if (IsConnected)
            {
                switch (TextBoxLocation.Text == "")
                {
                case true:
                    MessageError MessageErrorObject = new MessageError("Fill in the field");
                    MessageErrorObject.Show();
                    //LabelDirections.Content = "Fill in the field";
                    break;

                case false:
                    LabelDirections.Content = "Wait please";
                    JsonWeatherApi.CreateJsonRequest(TextBoxLocation.Text);
                    DispatcherTimer DispatherTimerObject = new DispatcherTimer()
                    {
                        Interval = TimeSpan.FromMilliseconds(1000)
                    };
                    DispatherTimerObject.Start();

                    DispatherTimerObject.Tick += new EventHandler((object e, EventArgs a) =>
                    {
                        LabelDirections.Content = "Choose your position";
                        DispatherTimerObject.Stop();
                    });
                    break;
                }
            }
        }
Esempio n. 2
0
 private void ShowCreateATest()
 {
     if (CurrentUser.Instance.Role == Roles.Master)
     {
         RedirectDecorator.ToViewModel(typeof(CreateTestViewModel));
     }
     else
     {
         MessageError.Show(ErrorResources.OnlyMasterCanCreateTests);
     }
 }
Esempio n. 3
0
        //Get Cities
        public static void CreateJsonRequest(string city)
        {
            DispatcherTimer DispatherTimerObject = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMilliseconds(1000)
            };

            DispatherTimerObject.Start();

            DispatherTimerObject.Tick += new EventHandler((object e, EventArgs a) =>
            {
                try
                {
                    string Url = $"http://api.openweathermap.org/data/2.5/weather?q={city}&units=metric&appid=82630901bb3f9ed64d98d0a72e3ad275";
                    HttpWebRequest httpWebRequest   = (HttpWebRequest)WebRequest.Create(Url);
                    HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    string Response;
                    using (StreamReader SR = new StreamReader(httpWebResponse.GetResponseStream()))
                    {
                        Response = SR.ReadToEnd();
                    }
                    JsonWeatherApi.Wr = JsonConvert.DeserializeObject <WeatherResponse>(Response);
                    DataAboutWeather DataAboutWeatherObject = new DataAboutWeather();
                    Application.Current.Windows[0].Close();
                    DataAboutWeatherObject.Show();
                }
                catch (WebException ex)
                {
                    HttpWebResponse ErrorRespose = ex.Response as HttpWebResponse;
                    if (ErrorRespose.StatusCode == HttpStatusCode.NotFound)
                    {
                        MessageError MessageErrorObject = new MessageError("Not found");
                        MessageErrorObject.Show();
                    }
                }
                DispatherTimerObject.Stop();
            });
        }