Exemplo n.º 1
0
 private void comboBox_Domain_Click(object sender, EventArgs e)
 {
     if (textBox_AK.Text != "" && textBox_SK.Text != "" && textBox_bucket_name.Text != "")
     {
         comboBox_Domain.Items.Clear();
         comboBox_Domain.Items.Add("Loading...");
         Mac    mac    = new Mac(textBox_AK.Text, textBox_SK.Text);
         Config config = new Config
         {
             // 设置上传区域
             //Zone = Zone.ZONE_CN_East,
             // 设置 http 或者 https 上传
             UseHttps      = true,
             UseCdnDomains = true,
             ChunkSize     = ChunkUnit.U512K
         };
         BucketManager bm        = new BucketManager(mac, config);
         DomainsResult DomainRet = bm.Domains(textBox_bucket_name.Text);
         comboBox_Domain.Items.Clear();
         if (DomainRet.Result != null)
         {
             for (int i = 0; i < DomainRet.Result.Count; i++)
             {
                 comboBox_Domain.Items.Add(DomainRet.Result[i]);
             }
         }
     }
 }
Exemplo n.º 2
0
        private void Upload(string filename, string filepath)
        {
            string bucket;

            if (this.comboBoxBuckets.SelectedIndex == -1)
            {
                bucket = ConfigurationManager.AppSettings["defaultbucket"];
            }
            else
            {
                bucket = this.comboBoxBuckets.SelectedItem.ToString();
            }
            PutPolicy putPolicy = new PutPolicy();

            putPolicy.Scope = bucket;
            putPolicy.SetExpires(3600);
            string        jsonStr       = putPolicy.ToJsonString();
            string        token         = Auth.CreateUploadToken(mac, jsonStr);
            BucketManager bucketManager = new BucketManager(mac);
            string        domain        = bucketManager.Domains(bucket).Result[0];
            FormUploader  formUploader  = new FormUploader();
            HttpResult    result        = formUploader.UploadFile(filepath, filename, token);

            if (result.RefCode == 200)
            {
                this.toolStripStatusLabel.Text = "上传成功";
                #region UpdateDatabase

                string uploadTime  = String.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now);
                string hashValue   = GetMD5Hash(filepath);
                string downloadUrl = "http://" + domain + "/" + filename;
                this.textBoxUrl.Text = downloadUrl;
                string localPath = filepath;

                string connectionString = ConfigurationManager.ConnectionStrings["qiniu"].ConnectionString;
                try
                {
                    using (MySqlConnection connection = new MySqlConnection(connectionString))
                    {
                        connection.Open();
                        string sqlInsert = "INSERT INTO pictures(Bucket,HashValue,UploadTime,DownloadUrl,LocalPath,Description) " +
                                           "values(@Bucket,@HashValue,@UploadTime,@DownloadUrl,@LocalPath,@Description)";
                        MySqlCommand cmd = new MySqlCommand(sqlInsert, connection);
                        cmd.Parameters.AddWithValue("@Bucket", bucket);
                        cmd.Parameters.AddWithValue("@HashValue", hashValue);
                        cmd.Parameters.AddWithValue("@UploadTime", uploadTime);
                        cmd.Parameters.AddWithValue("@DownloadUrl", downloadUrl);
                        cmd.Parameters.AddWithValue("@LocalPath", localPath);
                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    this.toolStripStatusLabel.Text = ex.Message + "数据库操作失败,请检查设置";
                }
                #endregion
            }
        }
Exemplo n.º 3
0
        public void DomainsTest()
        {
            Mac           mac    = new Mac(AccessKey, SecretKey);
            BucketManager target = new BucketManager(mac);

            DomainsResult result = target.Domains(Bucket1);

            Assert.AreEqual((int)HttpCode.OK, result.Code);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取指定bucket对应的域名(可能不止一个),类似于abcxx.bkt.clouddn.com这样
        /// </summary>
        public static void domains()
        {
            Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey);

            string bucket = "test";

            BucketManager bm = new BucketManager(mac);

            var result = bm.Domains(bucket);

            Console.WriteLine(result);
        }
Exemplo n.º 5
0
        public void DomainsTest()
        {
            Config config = new Config();

            config.Zone = Zone.ZONE_CN_East;
            Mac           mac           = new Mac(AccessKey, SecretKey);
            BucketManager bucketManager = new BucketManager(mac, config);
            DomainsResult ret           = bucketManager.Domains(Bucket);

            if (ret.Code != (int)HttpCode.OK)
            {
                Assert.Fail("domains error: " + ret.ToString());
            }
            Console.WriteLine(ret.ToString());
        }
Exemplo n.º 6
0
        private void SyncTargetBucketsComboBox_SelectionChanged(object sender,
                                                                System.Windows.Controls.SelectionChangedEventArgs e)
        {
            num                        = 1;
            marker                     = "";
            btnSearch.Content          = "查询";
            btnSearch.IsEnabled        = true;
            btnUpload.IsEnabled        = true;
            btnBatchDel.IsEnabled      = true;
            btnBatchDownload.IsEnabled = true;
            if (SyncTargetBucketsComboBox.SelectedValue != null)
            {
                bucket = SyncTargetBucketsComboBox.SelectedValue.ToString();
                DomainsComboBox.Items.Clear();

                //多线程处理
                ThreadPool.QueueUserWorkItem((state) =>
                {
                    domainsResult = bucketManager.Domains(bucket);
                    Dispatcher.Invoke(new Action(() =>
                    {
                        if (domainsResult.Result.Count > 0)
                        {
                            foreach (string domain in domainsResult.Result)
                            {
                                DomainsComboBox.Items.Add(domain);
                            }
                            DomainsComboBox.SelectedValue = DomainsComboBox.Items[0];
                        }
                    }));
                });



                //domainsResult = bucketManager.Domains(bucket);
                //if (domainsResult.Result.Count > 0)
                //{

                //    foreach (string domain in domainsResult.Result)
                //    {
                //        DomainsComboBox.Items.Add(domain);
                //    }
                //    DomainsComboBox.SelectedValue = DomainsComboBox.Items[0];
                //}
            }

            qiNiuFileInfoList = new List <QiNiuFileInfo>();
        }
        public async Task DomainsTest()
        {
            var config = new Config {
                Zone = Zone.ZoneCnEast
            };
            var mac           = new Mac(AccessKey, SecretKey);
            var bucketManager = new BucketManager(mac, config);
            var ret           = await bucketManager.Domains(Bucket);

            if (ret.Code != (int)HttpCode.OK)
            {
                Assert.True(false, "domains error: " + ret);
            }

            Console.WriteLine(ret.ToString());
        }
Exemplo n.º 8
0
        public static async Task <List <string> > Domains(string bucketName)
        {
#if MOCK
            return(await Task.FromResult(new List <string>
            {
                "www.domain1.com",
                "www.domain2.com"
            }));
#else
            var bucketManager = new BucketManager(_currentMac, _config);
            var queryResult   = await Task.Factory.StartNew(() => bucketManager.Domains(bucketName));

            if (queryResult.Code == 200)
            {
                return(queryResult.Result);
            }

            return(new List <string>());
#endif
        }
Exemplo n.º 9
0
        /// <summary>
        /// 查询
        /// </summary>
        private void Search()
        {
            if (string.IsNullOrWhiteSpace(marker))
            {
                num = 1;
                btnSearch.Content = "查询";
            }
            else
            {
                btnSearch.Content = "加载更多";
            }
            bucket = SyncTargetBucketsComboBox.Text;
            ListResult listResult = bucketManager.ListFiles(bucket, txtStartWith.Text, marker, 1000, "");

            // DomainsResult domainsResult = bucketManager.Domains(SyncTargetBucketsComboBox.Text);
            domainsResult = bucketManager.Domains(bucket);

            if (listResult.Result.Items.Count >= 1000)
            {
                btnSearch.Content = "加载更多";
            }
            else
            {
                num               = 1;
                marker            = "";
                btnSearch.Content = "查询";
            }

            if (qiNiuFileInfoList == null || num == 1)
            {
                qiNiuFileInfoList = new List <QiNiuFileInfo>();
            }



            foreach (ListItem item in listResult.Result.Items)
            {
                // item.EndUser
                QiNiuFileInfo f = new QiNiuFileInfo
                {
                    Num         = num,
                    FileName    = item.Key,
                    FileType    = item.MimeType,
                    StorageType = QiNiuHelper.GetStorageType(item.FileType),
                    FileSize    = QiNiuHelper.GetFileSize(item.Fsize),
                    EndUser     = item.EndUser,
                    CreateDate  = QiNiuHelper.GetDataTime(item.PutTime)
                };
                qiNiuFileInfoList.Add(f);
                num++;
            }
            marker = listResult.Result.Marker;


            if (qiNiuFileInfoList.Count > 0)
            {
                dgResult.ItemsSource = !string.IsNullOrWhiteSpace(txtEndWith.Text)
                    ? qiNiuFileInfoList.Where(f => f.FileName.EndsWith(txtEndWith.Text.Trim()))
                    : qiNiuFileInfoList;
            }
            else
            {
                dgResult.ItemsSource = new List <QiNiuFileInfo>();
            }
        }