예제 #1
0
        void login()
        {
            var listofbadcards = "";
            var client         = new CookieAwareWebClient();

            client.Encoding = Encoding.UTF8;



            // Post values

            var values = new NameValueCollection();

            values.Add("Callsign", this.textBox1.Text);
            values.Add("EnteredPassword", this.textBox2.Text);
            values.Add("Login", "Go");   //The button


            // Logging in
            client.UploadValues("http://www.eqsl.cc/qslcard/LoginFinish.cfm", values);     // You may verify the result. It works with https :)


            var html = "";

            string myyear   = dateTimePicker1.Value.ToString("yyyy");
            string mymonth  = dateTimePicker1.Value.ToString("MM");
            string hMyYear  = dateTimePicker2.Value.ToString("yyyy");
            string hMyMonth = dateTimePicker2.Value.ToString("MM");



            // Download some secret page
            if (checkBox1.Checked)
            {
                html = client.DownloadString(Uri.EscapeUriString("http://www.eqsl.cc/qslcard/InBox.cfm?Archive=1&Reject=0&LimitDateLo=" + myyear + " " + mymonth + "&LimitDateHi=" + hMyYear + " " + hMyMonth));
            }
            else
            {
                html = client.DownloadString(Uri.EscapeUriString("http://www.eqsl.cc/qslcard/InBox.cfm?Archive=0&Reject=0&LimitDateLo=" + myyear + " " + mymonth + "&LimitDateHi=" + hMyYear + " " + hMyMonth));
            }

            if (html.IndexOf(@"eQSLs more than can be displayed on this screen") > -1)
            {
                System.Windows.Forms.MessageBox.Show(@"You have too many cards.  You will need to change the date to filter the amount of cards!");
                return;
            }

            //check for debug
            //f2.Show();
            int    i      = 0;
            string mylist = parseDisplay(html);
            string destinationFileName = "";

            foreach (string s in mylist.Split('|'))
            {
                int error_idx_fe = 0;
                try
                {
                    if (s.Trim().Length == 0)
                    {
                        continue;
                    }
                    error_idx_fe = 10;
                    //check to see if file already exists.
                    destinationFileName = s.Substring(s.IndexOf("?") + 1);
                    error_idx_fe        = 20;
                    destinationFileName = Uri.UnescapeDataString(destinationFileName);
                    error_idx_fe        = 30;
                    destinationFileName = destinationFileName.Replace('&', '_');
                    error_idx_fe        = 40;
                    destinationFileName = destinationFileName.Replace(' ', '_');
                    error_idx_fe        = 50;
                    destinationFileName = destinationFileName.Replace('.', '_');
                    error_idx_fe        = 60;
                    destinationFileName = destinationFileName.Replace(';', '_');
                    error_idx_fe        = 70;
                    destinationFileName = destinationFileName.Replace(':', '_');
                    error_idx_fe        = 80;
                    destinationFileName = destinationFileName.Replace('?', '_');
                    destinationFileName = destinationFileName.Replace('@', '_');
                    destinationFileName = destinationFileName.Replace('^', '_');
                    destinationFileName = destinationFileName.Replace('/', '-');

                    error_idx_fe        = 120;
                    destinationFileName = System.IO.Path.Combine(textBox3.Text, destinationFileName);



                    destinationFileName = destinationFileName + ".png";

                    try
                    {
                        if (System.IO.File.Exists(destinationFileName))
                        {
                            System.IO.FileInfo fi = new System.IO.FileInfo(destinationFileName);

                            if (fi.Length > 0)
                            {
                                continue;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                    var h = client.DownloadString("http://www.eqsl.cc/qslcard/" + s);
                    error_idx_fe = 160;

                    string s1 = s.Substring(s.IndexOf("Callsign=") + 9);
                    error_idx_fe = 210;
                    string callsign = s1.Substring(0, s1.IndexOf("&"));
                    error_idx_fe = 220;
                    if (h.IndexOf("ERROR: eQSL Graphic not available") > -1)
                    {
                        listofbadcards = listofbadcards + callsign + ",";
                        continue;
                    }
                    if (h.IndexOf("ERROR - Too many queries overloading the system. Slow down!") > -1)
                    {
                        System.Threading.Thread.Sleep(5000);
                        h = client.DownloadString("http://www.eqsl.cc/qslcard/" + s);

                        //continue;
                    }

                    //one last final check..
                    if (h.IndexOf("ERROR") > -1)
                    {
                        MessageBox.Show("An error happened that was not expected(Send screen shot to [email protected]):\r\n" + h.ToString());
                        continue;
                    }

                    error_idx_fe = 510;
                    //System.Console.WriteLine(h);
                    try
                    {
                        h = h.Substring(h.IndexOf("img src="));
                    }
                    catch (Exception imgexp)
                    {
                        // missing image ..  skip it
                        listofbadcards = listofbadcards + callsign + ",";
                        continue;
                    }
                    error_idx_fe = 710;
                    h            = h.Substring(h.IndexOf("\"") + 1);
                    error_idx_fe = 720;
                    h            = h.Substring(0, h.IndexOf("\""));
                    error_idx_fe = 730;
                    if (!(System.IO.Directory.Exists(textBox3.Text)))
                    {
                        System.IO.Directory.CreateDirectory(textBox3.Text);
                    }

                    string filename = System.IO.Path.Combine(textBox3.Text, callsign + "-" + DateTime.Now.ToString("yyMMddmmssff") + ".png");
                    //while (System.IO.File.Exists(filename))
                    //{

                    //}

                    client.DownloadFile("http://www.eqsl.cc" + h, destinationFileName);
                    i = i + 1;
                    //10 seconds as per API guide
                    System.Threading.Thread.Sleep(10000);
                    //<CENTER>
                    //<img src="/CFFileServlet/_cf_image/_cfimg-632732702018634097.PNG" alt="" />
                    //get call sign
                    // download page
                    // parse image name
                    // download image
                    // save image as call sign...  if exists.. _1,_2 etc...
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error processing has occurred:" + ex.Message);
                    MessageBox.Show("Debug information: " + s);
                    MessageBox.Show("Debug Number: " + error_idx_fe.ToString());
                }
            }
            System.Windows.Forms.MessageBox.Show("Download of " + i.ToString() + " QSL cards Complete");
            if (listofbadcards.Trim().Length > 0)
            {
                MessageBox.Show("Unable to download cards for the following call signs due to bad cards:\r\n" + listofbadcards);
            }
        }
예제 #2
0
        public void DoWork()
        {
            var client = new CookieAwareWebClient();

            client.Encoding = Encoding.UTF8;

            // Post values
            var values = new NameValueCollection();

            values.Add("Callsign", CallSign);
            values.Add("EnteredPassword", PassWord);
            values.Add("Login", "Go");   //The button

            // Logging in
            client.UploadValues("http://www.eqsl.cc/qslcard/LoginFinish.cfm", values); // You may verify the result. It works with https :)

            var html = "";

            // Download some secret page
            if (Archive)
            {
                html = client.DownloadString("http://www.eqsl.cc/qslcard/InBox.cfm?Archive=1&Reject=0");
            }
            else
            {
                html = client.DownloadString("http://www.eqsl.cc/qslcard/InBox.cfm?Archive=0&Reject=0");
            }

            if (html.IndexOf(@"eQSLs more than can be displayed on this screen") > -1)
            {
                System.Windows.Forms.MessageBox.Show(@"You have too many cards.  You will need to wait for an updated version!");
                return;
            }

            currentIndex = 0;
            string mylist = parseDisplay(html);

            string[] items        = mylist.Split('|');
            int      countOfCards = items.Count();

            if (Status != null)
            {
                Status("Downloading " + countOfCards + " eQSL cards");
            }
            foreach (string s in items)
            {
                if (s.Trim().Length == 0)
                {
                    continue;
                }
                string h           = null;
                string tmp         = null;
                string callsign    = null;
                int    deadcounter = 5;
                while (h == null && deadcounter > 0)
                {
                    try
                    {
                        h = client.DownloadString("http://www.eqsl.cc/qslcard/" + s);
                        string s1 = s.Substring(s.IndexOf("Callsign=") + 9);
                        callsign = s1.Substring(0, s1.IndexOf("&"));
                        tmp      = h;
                        h        = h.Substring(h.IndexOf("img src="));
                        h        = h.Substring(h.IndexOf("\"") + 1);
                        h        = h.Substring(0, h.IndexOf("\""));
                    }
                    catch (Exception ex)
                    {
                        //
                        // < !--Application In Root eQSL Folder -->
                        // ERROR - Too many queries overloading the system.Slow down!
                        //
                        if (tmp.Contains("Slow down"))
                        {
                            deadcounter--;
                            if (Status != null)
                            {
                                Status("We have to slow down. Wait 10 seconds.");
                            }
                            System.Threading.Thread.Sleep(10000);
                        }
                    }
                }

                if (!(System.IO.Directory.Exists(StoragePath)))
                {
                    System.IO.Directory.CreateDirectory(StoragePath);
                }

                string filename = System.IO.Path.Combine(StoragePath, callsign + "-" + DateTime.Now.ToString("yyMMddmmssff") + ".png");

                client.DownloadFile("http://www.eqsl.cc" + h, filename);
                currentIndex = currentIndex + 1;
                //<CENTER>
                //<img src="/CFFileServlet/_cf_image/_cfimg-632732702018634097.PNG" alt="" />
                //get call sign
                // download page
                // parse image name
                // download image
                // save image as call sign...  if exists.. _1,_2 etc...
                if (Status != null)
                {
                    Status("Downloading card : " + currentIndex.ToString() + " of " + countOfCards.ToString());
                }
                // slowdown a little bit.
                System.Threading.Thread.Sleep(500);
            }
            if (Done != null)
            {
                Done("Download of " + currentIndex.ToString() + " QSL cards Complete");
            }
        }