/// <summary> /// 如果是从历史纪录载入并且未更改Bucket,则EntryDomain等设置保持不变 /// 否则(新建任务,或者载入记录但又更改了Bucket),则会根据用户AK&Bucket试图查找合适的上传入口 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SyncTargetBucketsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.SyncTargetBucketsComboBox.SelectedIndex < 0) { this.TextBlockTargetZone.Text = ""; return; } try { string targetBucket = this.SyncTargetBucketsComboBox.SelectedItem.ToString(); ZoneID zid = ZoneID.Default; if (isLoadFromRecord && string.Equals(targetBucket, this.syncSetting.TargetBucket)) { // 如果是从历史记录载入并且未更改Bucket,则无需查询,直接抽取 zid = (ZoneID)(this.syncSetting.TargetZoneID); } else { // 否则(如果是新建任务或者更改了Bucket),则需要向UC发送请求查询 zid = AutoZone.Query(this.account.AccessKey, targetBucket); } // 根据ZoneID完成相应配置 Qiniu.Common.Config.ConfigZone(zid); this.TextBlockTargetZone.Text = zoneNames[zid]; } catch (Exception ex) { this.SettingsErrorTextBlock.Text = ex.Message; } }
//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 = "未知错误,请联系七牛"; })); } }
/// <summary> /// 自动配置Zone /// </summary> /// <param name="accessKey"></param> /// <param name="bucket"></param> public static void ConfigZoneAuto(string accessKey, string bucket) { ZoneID zoneId = AutoZone.Query(accessKey, bucket); ConfigZone(zoneId); }
public void autoZoneTest() { //Settings.load(); Settings.LoadFromFile(); ZoneID zid = AutoZone.Query(Settings.AccessKey, Settings.Bucket); }