コード例 #1
0
        static OMovie RandomInput(string apiKey) // ----- change string to string[]
        {
            OMovie     movieInfo  = new OMovie();
            InvalidOId contentsIn = new InvalidOId();
            string     contents;


            // -- push the contents from random generation into the object
            do
            {
                string id = RandomGenerate();

                using (var client = new WebClient())
                {
                    string address = "http://www.omdbapi.com/?i=" + id + apiKey;
                    //Console.WriteLine(address);
                    contents = client.DownloadString(address);    // contents was originally of type var not string, declared here      // http://www.omdbapi.com/  ?i=tt389619   8&apikey=d6b3c2ae
                    if (contents.Contains("False"))
                    {
                        contentsIn = JsonConvert.DeserializeObject <InvalidOId>(contents);   // if the json string includes the word error then deserialise into contents(invalid)
                    }
                    else
                    {
                        movieInfo = JsonConvert.DeserializeObject <OMovie>(contents);
                    }
                }
            } while (movieInfo.title == null);
            return(movieInfo);
        }
コード例 #2
0
        private void button3_Click(object sender, EventArgs e)         // wishlist button
        {
            apiKey = "&apikey=d6b3c2ae";
            //wList = new Wishlist();
            OMovie movieInfo = new OMovie();
            //ReadWishlist(ref wList);
            string s = "", contents = "";
            int    i = 0;

            while ((i <= 19) & (wList.IDs[i] != ""))
            {
                using (var client = new WebClient()) // possible put this section of the code into a seperate function as it is used many other times in the program
                {
                    string address = "http://www.omdbapi.com/?i=" + wList.IDs[i] + apiKey;
                    contents = client.DownloadString(address);    // contents was originally of type var not string, declared here      // http://www.omdbapi.com/  ?i=tt389619   &apikey=d6b3c2ae
                    if (contents.Contains("False"))
                    {
                        Console.WriteLine("Random ID is not valid");
                    }
                    else
                    {
                        movieInfo = JsonConvert.DeserializeObject <OMovie>(contents);
                    }
                }
                if (movieInfo.title != "-1")
                {
                    s = s + (i + 1) + ". " + movieInfo.title + "\r\n"; // write the output to textbox
                }
                i++;
            }
            textBox2.Text = s + "\r\nMovie Wishlist";
        }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e) // section for omdbAPI button click
        {
            string textBoxValue = textBox1.Text;

            webAddress = "http://www.omdbapi.com/";
            apiKey     = "&apikey=d6b3c2ae";
            //TextBoxString mc = new TextBoxString();
            //mc.MyProperty = textBox1_TextChanged.Text;
            string     sAddress    = webAddress + "?t=" + textBoxValue + apiKey;
            OMovie     searchMovie = new OMovie();
            InvalidOId invalid     = new InvalidOId();
            string     contents;

            using (var client = new WebClient())
            {
                contents = client.DownloadString(sAddress); // apikey unauthorized
                if (contents.Contains("False"))
                {
                    invalid = JsonConvert.DeserializeObject <InvalidOId>(contents);
                    //OSearch_Results(invalid);
                }
                else
                {
                    searchMovie = JsonConvert.DeserializeObject <OMovie>(contents);
                    OSearch_Results(searchMovie);
                }
            }

            currentID = searchMovie.imdbID;
        }
コード例 #4
0
        private void ReadWishlist(ref Wishlist wList) // read the wishlist file into a string to then be split up into an arrary of movie obejct
        {
            OMovie movieInfo = new OMovie();

            string[] readWishlist = { "" };
            if (File.Exists(@"C:\Users\tomwe\Documents\University\Software Engineering\ACMEv2\ACME_Interface\Wishlist.txt") == false)
            {
                System.IO.File.WriteAllLines(@"C:\Users\tomwe\Documents\University\Software Engineering\ACMEv2\ACME_Interface\Wishlist.txt", readWishlist);
            }

            string filmListStr;
            int    count = 0;

            foreach (string j in wList.IDs)     // initiate wishlist values
            {
                wList.IDs[count] = "";
                count++;
            }

            // break whole string down into an array of strings, one element for each imdb id
            using (StreamReader r = new StreamReader(@"C:\Users\tomwe\Documents\University\Software Engineering\ACMEv2\ACME_Interface\Wishlist.txt")) // I think this section needs some json extension to work as there is no .net library built in.  // "..\\WishList.txt"
            {
                filmListStr = r.ReadToEnd();                                                                                                          // this section works.
            }

            if (filmListStr != null)
            {
                count = 0;
                foreach (char c in filmListStr)
                {
                    if (c == ';') // when the character is a semi-colon move onto the next index
                    {
                        count++;
                    }
                    else
                    {
                        wList.IDs[count] = wList.IDs[count] + c;
                    }
                }
            }
            else
            {
                textBox2.Text = "Wish List file is empty, please add a film before trying to look at it again";
            }
        }
コード例 #5
0
        public Form1() // equivelent to the Main() in a program.cs, it is the first thing that runs which is where things should be initialised.
        {
            InitializeComponent();
            radioButton1.Checked = true;
            string OApiKey  = "&apikey=d6b3c2ae";
            string OAddress = "http://www.omdbapi.com/";

            //Wishlist wList = new Wishlist();  // initialise wishlist object
            wList = new Wishlist();
            OMovie movieInfo = new OMovie();

            apiKey = OApiKey;
            ReadWishlist(ref wList);
            textBox2.Text = "Open Load Movie";


            WriteWishList(); // do this on close
        }
コード例 #6
0
        private void OSearch_Results(OMovie movieInfo)
        {
            const String Name    = "Film Name: ";         // +flimName + "ID:" +;
            string       message = "" +
                                   "\r\nTitle:    " + movieInfo.title.ToString() +
                                   "\r\nYear:     " + movieInfo.year.ToString() +
                                   "\r\nRating:   " + movieInfo.rated.ToString() +
                                   "\r\nReleased: " + movieInfo.released.ToString() +
                                   "\r\nRuntime:  " + movieInfo.runtime.ToString() +
                                   "\r\nGenre:    " + movieInfo.genre.ToString() +
                                   "\r\nDirector: " + movieInfo.director.ToString();

            //"\r\nPoster:   " + movieInfo.poster.ToString();
            //var result = MessageBox.Show(message,  "Search Results");
            textBox2.Text             = message;
            pictureBox1.ImageLocation = movieInfo.poster.ToString();
            //if (result == DialogResult.yes)
            //database.add = id;
        }
コード例 #7
0
        // region for random
        #region
        //____________________ start of random functionality
        private void button4_Click(object sender, EventArgs e) // Random Film Button
        {
            string OApiKey   = "&apikey=d6b3c2ae";
            OMovie movieInfo = new OMovie();

            movieInfo = RandomInput(OApiKey);
            string message =
                "\nTitle:    " + movieInfo.title.ToString() +
                "\r\nYear:     " + movieInfo.year.ToString() +
                "\r\nRating:   " + movieInfo.rated.ToString() +
                "\r\nReleased: " + movieInfo.released.ToString() +
                "\r\nRuntime:  " + movieInfo.runtime.ToString() +
                "\r\nGenre:    " + movieInfo.genre.ToString() +
                "\r\nDirector: " + movieInfo.director.ToString();
            //"\r\nPoster:   " + movieInfo.poster.ToString();
            string caption = "Randomly generated film";

            textBox2.Text = message;

            //MessageBox.Show(message, caption);
            pictureBox1.ImageLocation = movieInfo.poster.ToString();
        }