Ejemplo n.º 1
0
        public Information(Classes.Dapper dapper, SpriteDocument document)
        {
            InitializeComponent();

            this.lvwColumnSorter = new Classes.ListViewColumnSorter();
            this.listviewCount.ListViewItemSorter = lvwColumnSorter;
            this.documentLoaded = document;
            this.levelLoaded    = new Level(dapper.Code);
            this.Text           = string.Format("{0} Properties", this.levelLoaded.Name);
            this.SetLevelInfo(this.levelLoaded);

            // Set the Pouetpu-Games information
            this.labelAverageRatingValue.Text          = string.Format("{0:P} ({1:N}/20)", dapper.Ratings, dapper.Ratings * 20);
            this.labelDatePublishedValue.Text          = dapper.Published.ToLongDateString();
            this.labelStatusValue.Text                 = dapper.Status;
            this.labelViewsValue.Text                  = string.Format("{0:N} view(s)", dapper.Views);
            this.labelVotesValue.Text                  = string.Format("{0:N} vote(s)", dapper.Votes);
            this.linkAuthorValue.Links[0].LinkData     = dapper.AuthorUri.ToString();
            this.linkAuthorValue.Text                  = dapper.Author;
            this.linkOnlineNameValue.Links[0].LinkData = dapper.Uri.ToString();
            this.linkOnlineNameValue.Text              = dapper.Name;
            this.textboxDescription.Text               = dapper.Description;
        }
Ejemplo n.º 2
0
        public Load()
        {
            InitializeComponent();

            // WebClient: UploadStringCompleted
            this.downloader.UploadStringCompleted += delegate(object s, UploadStringCompletedEventArgs e)
            {
                if (e.Cancelled == true)
                {
                    this.buttonCancel.Text = "&Close";
                    this.EnableControls(true);
                    return;
                }
                else if (e.Error != null)
                {
                    this.buttonCancel.Text = "&Close";
                    this.EnableControls(true);
                    MessageBox.Show("Unable to download the requested website. The following error had occured:\n\n" + e.Error.Message, "Level2Pic", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    this.labelGetCode.Text = "Reading website's source for level codes... Please wait.";

                    // Is this Dapper?
                    if (this.IsDapper == true)
                    {
                        Classes.Dapper dapper = new Classes.Dapper(e.Result);

                        // Make sure the Dapper doesn't report any errors
                        if (dapper.Error != null)
                        {
                            this.buttonCancel.Text = "&Close";
                            this.EnableControls(true);
                            MessageBox.Show("Unable to obtain the level code from Pouetpu-Games. The service used to retrieve the webpage gave the following error:\n\n" + dapper.Error.Message, "Level2Pic", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else
                    {
                        HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();
                        html.LoadHtml(e.Result);

                        // Are there any levels?
                        if ((html.DocumentNode.SelectNodes("//textarea") == null) || (html.DocumentNode.SelectNodes("//textarea").Count == 0))
                        {
                            this.buttonCancel.Text = "&Close";
                            MessageBox.Show("Unable to find any levels. Level2Pic did not locate any \"textarea\" tags in the website's source.", "Level2Pic: No Code Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            this.EnableControls(true);
                            return;
                        }
                        else
                        {
                            List <string> codes = new List <string>();
                            foreach (HtmlNode textarea in html.DocumentNode.SelectNodes("//textarea"))
                            {
                                // Parse all "levels" found and see if it's valid
                                Level levelToParse;
                                if (Level.TryParse(HttpUtility.HtmlDecode(textarea.InnerText), out levelToParse))
                                {
                                    codes.Add(HttpUtility.HtmlDecode(textarea.InnerText));
                                }
                            }

                            // If there's no valid level, then return
                            if (codes.Count == 0)
                            {
                                this.buttonCancel.Text = "&Close";
                                MessageBox.Show("Unable to find any levels. Level2Pic did not find any valid level code inside the \"textarea\" tags in the website's source.", "Level2Pic: No Code Available", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                this.EnableControls(true);
                                return;
                            }
                            else
                            {
                                this.Levels = codes.ToArray();
                            }
                        }
                    }

                    this.WebsiteSource = e.Result;
                    this.DialogResult  = DialogResult.OK;
                    this.Close();
                }
            };
        }