Exemplo n.º 1
0
        private async Task ShowPoster(string search)
        {
            await Program.Fetch.GrabPosterAsync(search);

            if (Program.Fetch.Data == null)
            {
                emptySearch = true;
            }
            else
            {
                jNinja = new JsonNinja(Program.Fetch.Data);

                List <string> names = jNinja.GetNames();
                List <string> vals  = jNinja.GetVals();

                if (vals[1] == "0")
                {
                    invalidSearch = true;
                }
                else
                {
                    filter = jNinja.GetDetails("\"results\"");

                    jNinja = new JsonNinja(filter[0]);

                    posterPath = jNinja.GetPosters("\"poster_path\"");
                    id         = jNinja.GetIds("\"id\"");
                }
            }
        }
Exemplo n.º 2
0
        } // OnPostRemoveWeather()

        public async Task OnPostNews(string Coun, string Articles, int Time)
        {
            display = "grid";

            // SETTINGS
            Program.News.selCoun       = Coun;
            Program.News.numOfArticles = Articles;
            Program.News.selTime       = Convert.ToString(Time);

            // Pulling in information from the API
            await Program.Fetch.GrabNews(Coun, Articles);

            jNinja = new JsonNinja(Program.Fetch.Data);
            List <string> newsNames = jNinja.GetNames();
            List <string> newsVals  = jNinja.GetVals();

            // Retrieve information from News Class
            selCoun       = Program.News.selCoun;
            numOfArticles = Program.News.numOfArticles;
            selTime       = Program.News.selTime;

            // Grab information from NewsDataClass
            headline      = Program.NewsData.headline;
            headlineList  = Program.NewsData.headlineList;
            published     = Program.NewsData.published;
            publishedList = Program.NewsData.publishedList;
            publishedDate = Program.NewsData.publishedDate;
            headlines     = Program.NewsData.headlines;
            publishDates  = Program.NewsData.publishDates;

            int countArticle = Convert.ToInt32(Articles);

            for (int i = 0; i < countArticle; i++)
            {
                headlineList = jNinja.GetDetails("\"title\"");
                headline     = headlineList[i];
                headline     = headline.Replace("\"", "");
                Program.NewsData.AddHeadline(headline);
                publishedList = jNinja.GetDetails("\"publishedAt\"");
                published     = publishedList[i];
                published     = published.Replace("\"", "");
                published     = published.Replace("T", " ");
                published     = published.Replace("Z", "");
                publishedDate = DateTime.ParseExact(published, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); // stops the next line from taking the default time value
                // ^ date format has to be in the exact format as how it is taken in - then you can change it after the fact
                published = publishedDate.ToString("dddd, MMMM dd yyyy HH:mm tt (zzz") + " time zone difference.)";
                Program.NewsData.AddPublished(published);
            }
            headline  = Program.NewsData.GetHeadline();
            published = Program.NewsData.GetPublished();

            if (Program.UserDetails.UserID == 0) // not logged in
            {
                // only display the home page - no settings AKA no settings page to see these options.
            }

            else
            {
                using (SqlConnection myConn = new SqlConnection(Program.Fetch.cs))
                {
                    SqlCommand getNews = new SqlCommand
                    {
                        Connection = myConn
                    };
                    myConn.Open();

                    // Put in same order as the SP & Table (maybe change userId to last - since it's a FK ??)
                    // INSERT DEFAULT VALUES OF canada, 10, 15
                    getNews.Parameters.AddWithValue("@userId", Program.UserDetails.UserID);
                    getNews.Parameters.AddWithValue("@country", selCoun);
                    getNews.Parameters.AddWithValue("@articles", numOfArticles);
                    getNews.Parameters.AddWithValue("@time", Time);

                    getNews.CommandText = ("[spNewsSettings]");
                    getNews.CommandType = System.Data.CommandType.StoredProcedure;

                    getNews.ExecuteNonQuery();

                    myConn.Close();
                }
            }
            // Refresh the settings page @ news pos on page
        } //OnPostNews()
Exemplo n.º 3
0
        public async Task OnPostWeather(string City, string Country, string Unit)
        {
            display = "grid";
            // HAVE TO MAKE A DEFAULT - London, ON & Metric. DONE IN DB NOT DD

            // SETTINGS
            Program.Weather.selCity    = City;
            Program.Weather.selCountry = Country;
            Program.Weather.selUnit    = Unit;

            // Pulling in information from the API
            await Program.Fetch.GrabWeather(City, Country, Unit);

            jNinja = new JsonNinja(Program.Fetch.Data);
            List <string> names = jNinja.GetNames();
            List <string> vals  = jNinja.GetVals();

            Program.Weather.selCity    = jNinja.GetInfo("\"name\"");
            Program.Weather.selCountry = jNinja.GetInfo("\"country\"");

            // Retrieve information from Weather Class
            selCity    = Program.Weather.selCity;
            selCountry = Program.Weather.selCountry;
            selUnit    = Program.Weather.selUnit;

            selCity    = selCity.Replace("\"", "");
            selCountry = selCountry.Replace("\"", "");

            // Retrieve information from WeatherData Class
            // weather
            weather  = Program.WeatherData.weather;
            wetId    = Program.WeatherData.wetId;
            wetMain  = Program.WeatherData.wetMain;
            desc     = Program.WeatherData.desc;
            dayIcon  = Program.WeatherData.dayIcon;
            icon     = Program.WeatherData.icon;
            iconShow = Program.WeatherData.iconShow;
            // main
            temp       = Program.WeatherData.temp;
            tempHigh   = Program.WeatherData.tempHigh;
            tempLow    = Program.WeatherData.tempLow;
            humidity   = Program.WeatherData.humidity;
            pressure   = Program.WeatherData.pressure;
            visibility = Program.WeatherData.visibility;
            // wind
            wind      = Program.WeatherData.wind;
            windSpeed = Program.WeatherData.windSpeed;
            windDir   = Program.WeatherData.windDir;
            windText  = Program.WeatherData.windText;
            // length of day
            sunrise  = Program.WeatherData.sunrise;
            riseTime = Program.WeatherData.riseTime;
            sunset   = Program.WeatherData.sunset;
            setTime  = Program.WeatherData.setTime;
            // clouds
            clouds = Program.WeatherData.clouds;
            all    = Program.WeatherData.all;

            // weather
            listNinja = new JsonNinja(Program.Fetch.Data);
            weather   = listNinja.GetDetails("\"weather\"");
            wetId     = jNinja.GetInfo("\"id\"");          // might not need
            wetMain   = jNinja.GetDetails("\"main\"");     // ie. rain
            desc      = jNinja.GetInfo("\"description\""); // ie. light rain
            desc      = desc.Replace("\"", "");
            dayIcon   = listNinja.GetDetails("\"icon\"");
            icon      = dayIcon[0].Replace("\"]", "");
            icon      = icon.Replace("\"", "");
            iconShow  = "http://openweathermap.org/img/w/" + icon + ".png";

            // main
            temp       = wetMain[1].Replace("\"temp\":", ""); // fix! if rain and mist etc temp doesn't show properly
            tempHigh   = jNinja.GetInfo("\"temp_max\"");
            tempLow    = jNinja.GetInfo("\"temp_min\"");
            humidity   = jNinja.GetInfo("\"humidity\"");
            pressure   = jNinja.GetInfo("\"pressure\"");
            visibility = jNinja.GetInfo("\"visibility\"");

            // wind
            wind      = listNinja.GetDetails("\"wind\"");
            windSpeed = wind[0].Replace("\"speed\":", "");
            windDir   = jNinja.GetInfo("\"deg\"");

            // length of day
            sunrise  = jNinja.GetInfo("\"sunrise\"");
            riseTime = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(sunrise) * 1000).ToLocalTime().ToLongTimeString();
            sunset   = jNinja.GetInfo("\"sunset\"");
            setTime  = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(sunset) * 1000).ToLocalTime().ToLongTimeString();

            // clouds
            clouds = listNinja.GetDetails("\"clouds\"");
            all    = clouds[0].Replace("\"all\":", "");

            metric   = Program.Weather.metric;
            imperial = Program.Weather.imperial;
            kelvin   = Program.Weather.kelvin;

            if (Unit == "Metric") // Metric
            {
                temp       = temp + "°C";
                tempHigh   = tempHigh + "°C";
                tempLow    = tempLow + "°C";
                visibility = visibility + " meters";
                windSpeed  = windSpeed + " meters/second";
            }
            else if (Unit == "Imperial")
            {
                temp       = temp + "°F";
                tempHigh   = tempHigh + "°F";
                tempLow    = tempLow + "°F";
                visibility = visibility + " feet";
                windSpeed  = windSpeed + " miles/hour";
            }
            else // Kelvin
            {
                temp       = temp + "°K";
                tempHigh   = tempHigh + "°K";
                tempLow    = tempLow + "°K";
                visibility = visibility + " meters";
                windSpeed  = windSpeed + " meters/second";
            }

            // When Imperial is selected the input string is not the correct type & only sometimes ??
            // Break down into only N/NE/E/SE/S/SW/W/NW ??
            // Take out decimal values?

            /*double windTemp = Convert.ToDouble(windDir);
             * switch (windTemp)
             * {
             *  case double windDir when (windDir >= 348.75 && windDir <= 11.25):
             *      // 348.75 - 11.25 = N
             *      windText = windDir + " °N";
             *      break;
             *  case double windDir when (windDir >= 11.26 && windDir <= 33.75):
             *      // 11.26 - 33.75 = NNE
             *      windText = windDir + " °NNE";
             *      break;
             *  case double windDir when (windDir >= 33.76 && windDir <= 56.25):
             *      // 33.76 - 56.25 = NE
             *      windText = windDir + " °NE";
             *      break;
             *  case double windDir when (windDir >= 56.26 && windDir <= 78.75):
             *      // 56.26 - 78.75 = ENE
             *      windText = windDir + " °ENE";
             *      break;
             *  case double windDir when (windDir >= 78.76 && windDir <= 101.25):
             *      // 78.76 - 101.25 = E
             *      windText = windDir + " °E";
             *      break;
             *  case double windDir when (windDir >= 101.26 && windDir <= 123.75):
             *      // 101.26 - 123.75 = ESE
             *      windText = windDir + " °ESE";
             *      break;
             *  case double windDir when (windDir >= 123.76 && windDir <= 146.25):
             *      // 123.76 - 146.25 = SE
             *      windText = windDir + " °SE";
             *      break;
             *  case double windDir when (windDir >= 146.26 && windDir <= 168.75):
             *      // 146.26 - 168.75 = SSE
             *      windText = windDir + " °SSE";
             *      break;
             *  case double windDir when (windDir >= 168.76 && windDir <= 191.25):
             *      // 168.76 - 191.25 = S
             *      windText = windDir + " °S";
             *      break;
             *  case double windDir when (windDir >= 191.26 && windDir <= 213.75):
             *      // 191.26 - 213.75 = SSW
             *      windText = windDir + " °SSW";
             *      break;
             *  case double windDir when (windDir >= 213.76 && windDir <= 236.25):
             *      // 213.76 - 236.25 = SW
             *      windText = windDir + " °SW";
             *      break;
             *  case double windDir when (windDir >= 236.26 && windDir <= 258.75):
             *      // 236.26 - 258.75 = WSW
             *      windText = windDir + " °WSW";
             *      break;
             *  case double windDir when (windDir >= 258.76 && windDir <= 281.25):
             *      // 258.76 - 281.25 = W
             *      windText = windDir + " °W";
             *      break;
             *  case double windDir when (windDir >= 281.26 && windDir <= 303.75):
             *      // 281.26 - 303.75 = WNW
             *      windText = windDir + " °WNW";
             *      break;
             *  case double windDir when (windDir >= 303.76 && windDir <= 326.25):
             *      // 303.76 - 326.25 = NW
             *      windText = windDir + " °NW";
             *      break;
             *  case double windDir when (windDir >= 326.26 && windDir <= 348.74):
             *      // 326.26 - 348.75 = NNW
             *      windText = windDir + " °NNW";
             *      break;
             *  default:
             *      break;
             * } //windTemp() - Wind Direction*/

            if (Program.UserDetails.UserID == 0) // not logged in
            {
                // only display the home page - no settings AKA no settings page to see these options.
            }

            else
            {
                using (SqlConnection myConn = new SqlConnection(Program.Fetch.cs))
                {
                    SqlCommand getWeather = new SqlCommand
                    {
                        Connection = myConn
                    };
                    myConn.Open();

                    // Put in same order as the SP & Table (maybe change userId to last - since it's a FK ??)
                    // INSERT DEFAULT VALUES OF LONDON, CANADA AND METRIC - Done in Database????
                    getWeather.Parameters.AddWithValue("@userId", Program.UserDetails.UserID);
                    getWeather.Parameters.AddWithValue("@country", selCountry);
                    getWeather.Parameters.AddWithValue("@city", selCity);
                    getWeather.Parameters.AddWithValue("@unit", Unit);

                    getWeather.CommandText = ("[spWeatherSettings]");
                    getWeather.CommandType = System.Data.CommandType.StoredProcedure;

                    getWeather.ExecuteNonQuery();

                    myConn.Close();
                }
            }
            // Refresh the settings page @ weather pos on page
        } //OnPostWeather()
Exemplo n.º 4
0
        public async Task OnPostMovies(string intent)
        {
            showMoviePosters = "none";
            await ShowPoster(Program.Fetch.Search);

            search      = Program.Fetch.Search;
            this.search = Program.Fetch.Search;

            await Program.Fetch.GrabMovieAsync(intent);

            vidNinja = new JsonNinja(Program.Fetch.Videos);

            filter = vidNinja.GetDetails("\"results\"");

            vidNinja = new JsonNinja(filter[0]);

            List <string> vidNames = vidNinja.GetNames();
            List <string> vidVals  = vidNinja.GetVals();

            jNinja = new JsonNinja(Program.Fetch.Details);
            List <string> detailNames = jNinja.GetNames();
            List <string> detailVals  = jNinja.GetVals();

            //get movie details
            display = "grid";
            title   = jNinja.GetDetails("\"title\"");
            List <string> ratings = jNinja.GetIds("\"vote_average\"");

            rating = ratings[0] + "/10.0";
            List <string> descriptions = jNinja.GetDetails("\"overview\"");

            description = descriptions[0];
            List <string> backDrops = jNinja.GetDetails("\"poster_path\"");

            if (backDrops.Count == 2)
            {
                backDrop = backDrops[1];// backdrop or movieposter
            }
            else
            {
                backDrop = backDrops[0];// backdrop or movieposter
            }

            //get youtube movie keys for poster
            vidClips = vidNinja.GetDetails("\"key\"");

            //get movie cast
            jNinja = new JsonNinja(Program.Fetch.Credits);
            List <string> creditNames = jNinja.GetNames();
            List <string> creditVals  = jNinja.GetVals();

            filter = jNinja.GetDetails("\"cast\"");

            jNinja = new JsonNinja(filter[0]);

            History.SetMovieID(creditVals[0]); //to be used by rental method
            History.SetBackDrop(backDrop);     //same as poster, for cast page backdrop and rental method
            History.SetMovieTitle(title[0]);   //for use with rental method


            List <string> actorName = jNinja.GetDetails("\"name\"");

            castID   = jNinja.GetIds("\"id\"");
            actorImg = jNinja.GetDetails("\"profile_path\"");

            List <string> character = jNinja.GetDetails("\"character\"");

            int voteStat = DisplayVote();

            if (voteStat == 2)
            {
                thumbsDown = 0.4f;
                inBetween  = 0.4f;
            }
            else if (voteStat == 1)
            {
                thumbsUp   = 0.4f;
                thumbsDown = 0.4f;
            }
            else if (voteStat == 0)
            {
                thumbsUp  = 0.4f;
                inBetween = 0.4f;
            }
            else
            {
                //do nothing
            }
            moviePosterShow = "block";
        }