Beispiel #1
0
        private void textBoxSK_TextChanged(object sender, EventArgs e)
        {
            string AK = this.textBoxAK.Text;
            string SK = this.textBoxSK.Text;

            if (String.IsNullOrEmpty(AK) || String.IsNullOrEmpty(SK))
            {
                MessageBox.Show("请设置AK和SK");
                this.textBoxAK.Focus();
            }
            else
            {
                Mac           mac          = new Mac(AK, SK);
                BucketManager bucketManger = new BucketManager(mac);
                BucketsResult bucketResult = bucketManger.Buckets();
                if (bucketResult.Code == 200)
                {
                    for (int i = 0; i < bucketResult.Result.Count; i++)
                    {
                        comboBoxBuckets.Items.Add(bucketResult.Result[i]);
                    }
                    this.comboBoxBuckets.SelectedIndex = 0;
                }
                else
                {
                    MessageBox.Show("认证失败,请重新设置AK和SK");
                    this.textBoxAK.Focus();
                }
            }
        }
        private void reloadBuckets()
        {
            BucketsResult bucketsResult = bucketManager.Buckets(true);

            if (bucketsResult.Code == 200)
            {
                //todo:保存ak&sk

                if (File.Exists("QiNiuClientCfg.Json"))
                {
                    File.Delete("QiNiuClientCfg.Json");
                }



                string json = JsonConvert.SerializeObject(qiNiuClientCfg);
                File.WriteAllText("QiNiuClientCfg.Json", json);


                List <string> buckets = bucketsResult.Result;

                Dispatcher.Invoke(new Action(() =>
                {
                    this.SyncTargetBucketsComboBox.ItemsSource = buckets;
                    BtnConnet.IsEnabled = true;
                    pb1.Visibility      = Visibility.Hidden;
                    MessageBox.Show("连接成功!");
                }));
            }
        }
        //reload buckets
        private void reloadBuckets()
        {
            //get new bucket list
            BucketsResult bucketsResult = this.bucketManager.Buckets();

            if (bucketsResult.Code == (int)HttpCode.OK)
            {
                List <string> buckets = bucketsResult.Result;

                zoneDict.Clear();
                foreach (string bucket in buckets)
                {
                    ZoneID zoneId = ZoneHelper.QueryZone(SystemConfig.ACCESS_KEY, bucket);
                    zoneDict.Add(bucket, zoneId);
                }

                Dispatcher.Invoke(new Action(delegate
                {
                    this.SyncTargetBucketsComboBox.ItemsSource = buckets;
                }));
            }
            else
            {
                Log.Error("get buckets error, " + bucketsResult.Text);
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = "获取空间列表时出错";
                }));
            }
        }
        public void BucketsTest()
        {
            Mac           mac    = new Mac(AccessKey, SecretKey);
            BucketManager target = new BucketManager(mac);

            BucketsResult result = target.Buckets();

            Assert.AreEqual((int)HttpCode.OK, result.Code);
        }
        public async Task BucketsTest()
        {
            Mac           mac    = new Mac(AccessKey, SecretKey);
            BucketManager target = new BucketManager(mac);

            BucketsResult result = await target.BucketsAsync();

            Assert.AreEqual((int)HttpCode.OK, result.Code);
        }
Beispiel #6
0
        private void reloadBuckets()
        {
            BucketsResult bucketsResult = bucketManager.Buckets(true);

            if (bucketsResult.Code == 200)
            {
                //todo:保存ak&sk

                if (File.Exists("QiNiuClientCfg.Json"))
                {
                    File.Delete("QiNiuClientCfg.Json");
                }



                string json = JsonConvert.SerializeObject(qiNiuClientCfg);
                File.WriteAllText("QiNiuClientCfg.Json", json);


                List <string> buckets = bucketsResult.Result;

                Dispatcher.Invoke(new Action(() =>
                {
                    this.SyncTargetBucketsComboBox.ItemsSource = buckets;
                    BtnConnet.IsEnabled = true;
                    pb1.Visibility      = Visibility.Hidden;
                    if (!string.IsNullOrWhiteSpace(TxtAK.Text.Trim()))
                    {
                        string ak = TxtAK.Text.Trim();
                        if (ak.Length >= 40 && !ak.Contains("*"))
                        {
                            TxtAK.Text = ak.Substring(0, 4) + "********************************" + ak.Substring(ak.Length - 5, 4);
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(TxtSk.Text.Trim()))
                    {
                        string sk = TxtSk.Text.Trim();
                        if (sk.Length >= 40 && !sk.Contains("*"))
                        {
                            TxtSk.Text = sk.Substring(0, 4) + "********************************" + sk.Substring(sk.Length - 5, 4);
                        }
                    }
                    MessageBox.Show("连接成功!");
                }));
            }
            else
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    BtnConnet.IsEnabled = true;
                    pb1.Visibility      = Visibility.Hidden;

                    MessageBox.Show("连接失败!");
                }));
            }
            progressbarNeedStop = true;
        }
        /// <summary>
        /// 列举所有的bucket
        /// </summary>
        public static void buckets()
        {
            Mac           mac    = new Mac(Settings.AccessKey, Settings.SecretKey);
            BucketManager bm     = new BucketManager(mac);
            BucketsResult result = bm.buckets();

            foreach (string bucket in result.Buckets)
            {
                System.Console.WriteLine(bucket);
            }
        }
Beispiel #8
0
        //reload buckets
        private void reloadBuckets()
        {
            DateTime start = System.DateTime.Now;
            //get new bucket list
            BucketsResult bucketsResult = this.bucketManager.Buckets(true);

            if (bucketsResult.Code == 200)
            {
                List <string> buckets = bucketsResult.Result;
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SyncTargetBucketsComboBox.ItemsSource = buckets;
                    if (this.syncSetting != null)
                    {
                        this.SyncTargetBucketsComboBox.SelectedItem = this.syncSetting.SyncTargetBucket;
                    }
                    Log.Info("load buckets last for " + System.DateTime.Now.Subtract(start).TotalSeconds + " seconds");
                }));
            }
            else if (bucketsResult.Code == 401)
            {
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = "AK 或 SK 不正确";
                }));
            }
            else
            {
                string xReqId = "N/A";
                if (bucketsResult.RefInfo != null && bucketsResult.RefInfo.ContainsKey("X-Reqid"))
                {
                    xReqId = bucketsResult.RefInfo["X-Reqid"];
                }
                Log.Error(string.Format("get buckets unknown error, {0}:{1}:{2}:{3}", bucketsResult.Code, bucketsResult.Text, xReqId,
                                        bucketsResult.Text));
                string message = null;
                if (!string.IsNullOrEmpty(bucketsResult.RefText))
                {
                    message = string.Format("获取空间列表失败 {0}", bucketsResult.RefText);
                }
                else
                {
                    message = "获取空间列表失败,网络故障!";
                }

                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = message;
                }));
            }
        }
Beispiel #9
0
        //reload buckets
        private void reloadBuckets()
        {
            //get new bucket list
            BucketsResult bucketsResult = this.bucketManager.buckets();

            if (bucketsResult.ResponseInfo.isOk())
            {
                List <string> buckets = bucketsResult.Buckets;

                zoneDict.Clear();
                foreach (string bucket in buckets)
                {
                    ZoneID zoneId = AutoZone.Query(account.AccessKey, bucket);
                    zoneDict.Add(bucket, zoneId);
                }

                Dispatcher.Invoke(new Action(delegate
                {
                    this.SyncTargetBucketsComboBox.ItemsSource = buckets;
                }));
            }
            else if (bucketsResult.ResponseInfo.isNetworkBroken())
            {
                Log.Error("get buckets network error, " + bucketsResult.ResponseInfo.ToString());
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = "网络故障";
                }));
            }
            else if (bucketsResult.ResponseInfo.StatusCode == 401)
            {
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = "AK 或 SK 不正确";
                }));
            }
            else if (bucketsResult.ResponseInfo.StatusCode != 0)
            {
                //status code exists,ignore
            }
            else
            {
                Log.Error(string.Format("get buckets unknown error, {0}:{1}:{2}:{3}", bucketsResult.ResponseInfo.StatusCode,
                                        bucketsResult.ResponseInfo.Error, bucketsResult.ResponseInfo.ReqId, bucketsResult.Response));
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = "未知错误,请联系七牛";
                }));
            }
        }
Beispiel #10
0
        private void QiniuGui_Load(object sender, EventArgs e)
        {
            //获取所有Buckets
            var    appSettings = ConfigurationManager.AppSettings;
            string AK          = appSettings["AK"];
            string SK          = appSettings["SK"];

            mac = new Mac(AK, SK);
            BucketManager bucketManger = new BucketManager(mac);
            BucketsResult bucketResult = bucketManger.Buckets();

            for (int i = 0; i < bucketResult.Result.Count; i++)
            {
                comboBoxBuckets.Items.Add(bucketResult.Result[i]);
            }
        }
        //reload buckets
        private void reloadBuckets()
        {
            //get new bucket list
            BucketsResult bucketsResult = this.bucketManager.buckets();

            if (bucketsResult.ResponseInfo.isOk())
            {
                List <string> buckets = bucketsResult.Buckets;
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SyncTargetBucketsComboBox.ItemsSource = buckets;
                    if (this.syncSetting != null)
                    {
                        this.SyncTargetBucketsComboBox.SelectedItem = this.syncSetting.TargetBucket;
                    }
                }));
            }
            else if (bucketsResult.ResponseInfo.isNetworkBroken())
            {
                Log.Error("get buckets network error, " + bucketsResult.ResponseInfo.ToString());
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = "网络故障";
                }));
            }
            else if (bucketsResult.ResponseInfo.StatusCode == 401)
            {
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = "AK 或 SK 不正确";
                }));
            }
            else if (bucketsResult.ResponseInfo.StatusCode != 0)
            {
                //status code exists,ignore
            }
            else
            {
                Log.Error(string.Format("get buckets unknown error, {0}:{1}:{2}:{3}", bucketsResult.ResponseInfo.StatusCode,
                                        bucketsResult.ResponseInfo.Error, bucketsResult.ResponseInfo.ReqId, bucketsResult.Response));
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = "未知错误,请联系七牛";
                }));
            }
        }
Beispiel #12
0
        public void BucketsTest()
        {
            Config config = new Config();

            config.Zone = Zone.ZONE_CN_East;
            Mac           mac           = new Mac(AccessKey, SecretKey);
            BucketManager bucketManager = new BucketManager(mac, config);
            BucketsResult ret           = bucketManager.Buckets(true);

            if (ret.Code != (int)HttpCode.OK)
            {
                Assert.Fail("buckets error: " + ret.ToString());
            }

            foreach (string bucket in ret.Result)
            {
                Console.WriteLine(bucket);
            }
        }
        public void bktMgrTest()
        {
            //Settings.load();
            Settings.LoadFromFile();
            string        testResUrl = "http://test.fengyh.cn/qiniu/files/hello.txt";
            Mac           mac        = new Mac(Settings.AccessKey, Settings.SecretKey);
            BucketManager target     = new BucketManager(mac);

            target.fetch(testResUrl, Settings.Bucket, "test_BucketManager.txt");

            target.stat(Settings.Bucket, "test_BucketManager.txt");

            target.copy(Settings.Bucket, "test_BucketManager.txt", Settings.Bucket, "copy_BucketManager.txt", true);

            target.move(Settings.Bucket, "copy_BucketManager.txt", Settings.Bucket, "move_BucketManager.txt", true);

            target.delete(Settings.Bucket, "test_BucketManager.txt");

            DomainsResult domainsResult = target.domains(Settings.Bucket);

            BucketsResult bucketsResult = target.buckets();
        }
        //reload buckets
        private void reloadBuckets()
        {
            DateTime start = System.DateTime.Now;
            //get new bucket list
            BucketsResult bucketsResult = this.bucketManager.Buckets(true);

            if (bucketsResult.Code == 200)
            {
                List <string> buckets = bucketsResult.Result;
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SyncTargetBucketsComboBox.ItemsSource = buckets;
                    if (this.syncSetting != null)
                    {
                        this.SyncTargetBucketsComboBox.SelectedItem = this.syncSetting.SyncTargetBucket;
                    }
                    Log.Info("load buckets last for " + System.DateTime.Now.Subtract(start).TotalSeconds + " seconds");
                }));
            }
            else if (bucketsResult.Code == 401)
            {
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = "AK 或 SK 不正确";
                }));
            }
            else
            {
                Log.Error(string.Format("get buckets unknown error, {0}:{1}:{2}:{3}", bucketsResult.Code,
                                        bucketsResult.Text, bucketsResult.RefInfo["X-Reqid"],
                                        System.Text.Encoding.UTF8.GetString(bucketsResult.Data)));
                Dispatcher.Invoke(new Action(delegate
                {
                    this.SettingsErrorTextBlock.Text = "未知错误,请联系七牛";
                }));
            }
        }
Beispiel #15
0
        private void freshBuckets()
        {
            Mac mac = this.GetMac();

            BucketManager bm = new BucketManager(mac);
            BucketsResult rs = bm.buckets();

            if (rs.ResponseInfo.StatusCode != 200)
            {
                MessageBox.Show(rs.ResponseInfo.Error);
                return;
            }

            comboBox1.Enabled = true;
            button1.Enabled   = true;

            comboBox1.Items.Clear();
            foreach (string buc in rs.Buckets)
            {
                //DomainsResult domains = bm.domains(buc);
                comboBox1.Items.Add(buc);
            }
            comboBox1.SelectedIndex = 0;
        }