예제 #1
0
 //定时器进行登陆判定和跳转
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (webBrowser1.Url != null && webBrowser1.ReadyState == WebBrowserReadyState.Complete)
     {
         timer1.Enabled = false;
         //My.Show(webBrowser1.Document.Cookie);
         //My.Show(webBrowser1.DocumentText);
         if (webBrowser1.Url != null && webBrowser1.ReadyState == WebBrowserReadyState.Complete && webBrowser1.Url.ToString() == "https://portal.qiniu.com/")
         {
             if (My.Logined < 2)
             {
                 this.Opacity       = 0;
                 this.ShowInTaskbar = false;
                 My.Logined         = 1;
                 My.LoginedEmail    = My.SeekCode(webBrowser1.DocumentText, "_mail = \"", "\";");
                 //My.Show(My.LoginEmail);
                 webBrowser1.Navigate("https://portal.qiniu.com/api/rs/buckets");
             }
             else
             {
                 My.LoginForm.Opacity       = 1;
                 My.LoginForm.ShowInTaskbar = true;
                 My.LoginForm.TopMost       = true;
                 My.LoginForm.BringToFront();
                 My.LoginForm.TopMost = false;
             }
         }
         if (webBrowser1.Url != null && webBrowser1.ReadyState == WebBrowserReadyState.Complete && webBrowser1.Url.ToString() == "https://portal.qiniu.com/api/rs/buckets")
         {
             Index = 0;
             string[] TempString = My.SeekCodeArray(webBrowser1.DocumentText, "\"", "\"");
             My.LoginedBuckets = new My.Buckets[TempString.Length];
             for (int i = 0; i < TempString.Length; i++)
             {
                 My.LoginedBuckets[i]      = new My.Buckets();
                 My.LoginedBuckets[i].Name = TempString[i];
                 //My.Show(TempString[i]);
             }
             if (TempString.Length > Index)
             {
                 Index = Index + 1;
                 Byte[] TempBytes = System.Text.Encoding.UTF8.GetBytes("bucket");
                 My.CombineArray(ref TempBytes, System.Text.Encoding.ASCII.GetBytes("="));
                 My.CombineArray(ref TempBytes, System.Text.Encoding.UTF8.GetBytes(My.LoginedBuckets[Index - 1].Name));
                 webBrowser1.Navigate(
                     "https://portal.qiniu.com/api/uc/bucketInfo?name=" + My.LoginedBuckets[Index - 1].Name,
                     null,
                     TempBytes,
                     "Content-Type: application/x-www-form-urlencoded\r\nReferer:https://portal.qiniu.com/bucket/\r\n"
                     );
             }
         }
         if (webBrowser1.Url != null && webBrowser1.ReadyState == WebBrowserReadyState.Complete && webBrowser1.Url.ToString().Contains("https://portal.qiniu.com/api/uc/bucketInfo?name="))
         {
             string TempName = webBrowser1.Url.ToString().Replace("https://portal.qiniu.com/api/uc/bucketInfo?name=", "");
             for (int i = 0; i < My.LoginedBuckets.Length; i++)
             {
                 if (My.LoginedBuckets[i].Name == TempName)
                 {
                     My.LoginedBuckets[i].Domain = My.SeekCodeArray(webBrowser1.DocumentText.Substring(webBrowser1.DocumentText.IndexOf("\"bind_domains\":") + 15), "\"", "\"");
                     //My.Show(My.LoginedBuckets[i].Domain);
                     //这里的My.Show会阻拦下面的代码执行,导致弹出N个对话框
                     break;
                 }
             }
             if (My.LoginedBuckets.Length > Index)
             {
                 Index = Index + 1;
                 Byte[] TempBytes = System.Text.Encoding.UTF8.GetBytes("bucket");
                 My.CombineArray(ref TempBytes, System.Text.Encoding.ASCII.GetBytes("="));
                 My.CombineArray(ref TempBytes, System.Text.Encoding.UTF8.GetBytes(My.LoginedBuckets[Index - 1].Name));
                 webBrowser1.Navigate(
                     "https://portal.qiniu.com/api/uc/bucketInfo?name=" + My.LoginedBuckets[Index - 1].Name,
                     null,
                     TempBytes,
                     "Content-Type: application/x-www-form-urlencoded\r\nReferer:https://portal.qiniu.com/bucket/\r\n"
                     );
             }
             else
             {
                 webBrowser1.Navigate("https://portal.qiniu.com/bucket/"
                                      + My.LoginedBuckets[0].Name
                                      + "/files?marker=" + ""
                                      + "&limit=" + My.MainForm.Limit
                                      + "&prefix=" + My.MainForm.Prefix);
             }
         }
         if (CheckGetFile() == true)
         {
             My.Logined = 2;
             webBrowser1.DocumentCompleted
                 -= new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted1);
             webBrowser1.DocumentCompleted
                 += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted2);
         }
         if (My.Logined < 2)
         {
             timer1.Enabled = true;
         }
     }
 }
예제 #2
0
        //检查登录和获取文件
        private Boolean CheckGetFile()
        {
            if (webBrowser1.Url != null && webBrowser1.ReadyState == WebBrowserReadyState.Complete && webBrowser1.Url.ToString().Contains("https://portal.qiniu.com/bucket/") && webBrowser1.Url.ToString().Contains("?marker="))
            {
                My.MainForm.dataGridView1.Columns.Clear();
                My.MainForm.dataGridView1.Rows.Clear();
                DataGridViewTextBoxColumn Column1 = new DataGridViewTextBoxColumn();
                DataGridViewTextBoxColumn Column2 = new DataGridViewTextBoxColumn();
                DataGridViewTextBoxColumn Column3 = new DataGridViewTextBoxColumn();
                DataGridViewTextBoxColumn Column4 = new DataGridViewTextBoxColumn();
                DataGridViewTextBoxColumn Column5 = new DataGridViewTextBoxColumn();
                DataGridViewTextBoxColumn Column6 = new DataGridViewTextBoxColumn();
                Column1.HeaderText = "文件名 Key";
                Column2.HeaderText = "类型 MimeType";
                Column3.HeaderText = "大小 Fsize";
                Column4.HeaderText = "上传时间 PutTime";
                Column5.HeaderText = "散列值 Hash";
                Column6.HeaderText = "下载链接 Url";
                Column1.Width      = (My.MainForm.dataGridView1.Width - 58) * 1 / 6;
                Column2.Width      = (My.MainForm.dataGridView1.Width - 58) * 1 / 6;
                Column3.Width      = (My.MainForm.dataGridView1.Width - 58) * 1 / 6;
                Column4.Width      = (My.MainForm.dataGridView1.Width - 58) * 1 / 6;
                Column5.Width      = (My.MainForm.dataGridView1.Width - 58) * 1 / 6;
                Column6.Width      = (My.MainForm.dataGridView1.Width - 58) * 1 / 6;
                My.MainForm.dataGridView1.Columns.Add(Column1);
                My.MainForm.dataGridView1.Columns.Add(Column2);
                My.MainForm.dataGridView1.Columns.Add(Column3);
                My.MainForm.dataGridView1.Columns.Add(Column4);
                My.MainForm.dataGridView1.Columns.Add(Column5);
                My.MainForm.dataGridView1.Columns.Add(Column6);
                String[] Data = new String[0];
                //无数据:{"bucketType":"public","hasSensitiveWord":false,"items":[]}
                if (webBrowser1.DocumentText == "\"获取空间文件列表失败\"")
                {
                    My.MainForm.label2.Text = "七牛云反馈:获取空间文件列表失败。推测可能为网络或服务器故障,请稍后再试。";
                    My.MainForm.Refresh();
                    My.Show("七牛云反馈:获取空间文件列表失败。推测可能为网络或服务器故障,请稍后再试。");
                }
                else if (webBrowser1.DocumentText.Contains("\"items\":[]"))
                {
                    My.MainForm.label2.Text = "文件列表获取完成,满足条件的文件的数量为0。";
                    My.MainForm.Refresh();
                }
                else if (My.ExtractCode(webBrowser1.DocumentText, "\"items\":[{", "}]") == "")
                {
                    My.MainForm.label2.Text = "文件列表获取失败,请稍后再试。";
                    My.MainForm.Refresh();
                }
                else
                {
                    //My.Show(webBrowser1.DocumentText.Contains("\"items\":[{"));
                    //My.Show(webBrowser1.DocumentText.Contains("}],\"marker\""));
                    Data = System.Text.RegularExpressions.Regex.Split(My.ExtractCode(webBrowser1.DocumentText, "\"items\":[{", "}]"), "},{");
                    //My.Show(Data);
                    for (int i = 0; i < Data.Length; i++)
                    {
                        try
                        {
                            My.MainForm.dataGridView1.Rows.Add(
                                My.SeekCode(Data[i], "\"key\":\"", "\""),
                                My.SeekCode(Data[i], "\"mimeType\":\"", "\""),
                                Convert.ToDecimal(Convert.ToDouble(My.SeekCode(Data[i], "\"fsize\":", ","))),
                                My.ConvertIntDateTime((double)Convert.ToDouble(My.SeekCode(Data[i], "\"putTime\":", ",")) / 10000000),
                                My.SeekCode(Data[i], "\"hash\":\"", "\""),
                                My.SeekCode(Data[i], "\"signed_download_url\":\"", "\"")
                                );
                        }
                        catch (Exception EX)
                        {
                            My.Show(EX.ToString());
                            //My.Show(webBrowser1.DocumentText);
                            //My.Show(Data[i]);
                        }
                    }
                    My.MainForm.dataGridView1.ClearSelection();

                    String Temp = My.MainForm.dataGridView1.Rows[My.MainForm.dataGridView1.RowCount - 2].Cells[0].Value.ToString();
                    Temp = "{\"c\":0,\"k\":\"" + Temp + "\"}";
                    My.MainForm.Marker = My.ChangeIntoSafeBase64(Temp);

                    My.MainForm.label2.Text = "文件列表获取完成,满足条件的文件的数量为" + Data.Length + "。";
                    My.MainForm.Refresh();
                }
                return(true);
            }
            return(false);
        }