private void Delete() { //1.获得表中选中的数据 if (dgResult.ItemsSource == null && dgResult.SelectedItems.Count <= 0) { return; } List <QiNiuFileInfo> list = new List <QiNiuFileInfo>(); foreach (var item in dgResult.SelectedItems) { QiNiuFileInfo info = (QiNiuFileInfo)item; if (info != null) { list.Add(info); } } if (list.Count > 0) { string msg = string.Join(",\r\n", list.Select(q => q.FileName)); MessageBoxResult confirmToDel = MessageBox.Show("确认要删除所选行吗?\r\n" + msg, "提示", MessageBoxButton.YesNo, MessageBoxImage.Question); if (confirmToDel != MessageBoxResult.Yes) { return; } //执行批量删除 List <string> ops = new List <string>(); foreach (var key in list) { string op = bucketManager.DeleteOp(bucket, key.FileName); ops.Add(op); } BatchResult ret = bucketManager.Batch(ops); StringBuilder sb = new StringBuilder(); if (ret.Code / 100 != 2) { MessageBox.Show("批量删除error: " + ret.ToString()); return; } MessageBox.Show("批量删除成功!"); Search(); Thread.Sleep(10); } }
/// <summary> /// 批量操作 /// </summary> public static void batch() { Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey); // 批量操作类似于 // op=<op1>&op=<op2>&op=<op3>... string batchOps = "op=OP1&op=OP2"; BucketManager bm = new BucketManager(mac); var result = bm.Batch(batchOps); // 或者 //string[] batch_ops={"<op1>","<op2>","<op3>",...}; //bm.Batch(batch_ops); Console.WriteLine(result); }
public void BatchTest() { Mac mac = new Mac(AccessKey, SecretKey); BucketManager target = new BucketManager(mac); string s1 = target.StatOp(Bucket1, FileKey1); string s2 = target.ChgmOp(Bucket2, FileKey2, "MimeType"); string[] ops = new string[] { s1, s2, "OP-UNDEF" }; BatchResult result = target.Batch(ops); bool cond = (result.Code == (int)HttpCode.OK || result.Code == (int)HttpCode.BAD_REQUEST || result.Code == (int)HttpCode.PARTLY_OK); Assert.IsTrue(cond); }
public void BatchStatTest() { BatchCopyTest(); Config config = new Config(); config.Zone = Zone.ZONE_CN_East; //config.Region = Region.Region_CN_East; Mac mac = new Mac(AccessKey, SecretKey); BucketManager bucketManager = new BucketManager(mac, config); string[] keys = { "qiniu-0.png", "qiniu-1.png", "qiniu-2.png" }; List <string> ops = new List <string>(); foreach (string key in keys) { string op = bucketManager.StatOp(Bucket, key); ops.Add(op); } BatchResult ret = bucketManager.Batch(ops); if (ret.Code / 100 != 2) { Assert.Fail("batch error: " + ret.ToString()); } foreach (BatchInfo info in ret.Result) { if (info.Code == (int)HttpCode.OK) { Console.WriteLine("{0}, {1}, {2}, {3}, {4}", info.Data.MimeType, info.Data.PutTime, info.Data.Hash, info.Data.Fsize, info.Data.FileType); } else { Console.WriteLine(info.Data.Error); } } }
public async Task BatchDeleteAfterDaysTest() { await BatchCopyTest(); var config = new Config { Zone = Zone.ZoneCnEast }; var mac = new Mac(AccessKey, SecretKey); var bucketManager = new BucketManager(mac, config); string[] keys = { "qiniu-0.png", "qiniu-1.png", "qiniu-2.png" }; var ops = new List <string>(); foreach (var key in keys) { var op = bucketManager.DeleteAfterDaysOp(Bucket, key, 7); ops.Add(op); } var ret = await bucketManager.Batch(ops); if (ret.Code / 100 != 2) { Assert.True(false, "batch error: " + ret); } foreach (var info in ret.Result) { if (info.Code == (int)HttpCode.OK) { Console.WriteLine("deleteAfterDays success"); } else { Console.WriteLine(info.Data.Error); } } }
public void BatchDeleteAfterDaysTest() { BatchCopyTest(); Config config = new Config(); config.Zone = Zone.ZONE_CN_East; //config.Region = Region.Region_CN_East; Mac mac = new Mac(AccessKey, SecretKey); BucketManager bucketManager = new BucketManager(mac, config); string[] keys = { "qiniu-0.png", "qiniu-1.png", "qiniu-2.png" }; List <string> ops = new List <string>(); foreach (string key in keys) { string op = bucketManager.DeleteAfterDaysOp(Bucket, key, 7); ops.Add(op); } BatchResult ret = bucketManager.Batch(ops); if (ret.Code / 100 != 2) { Assert.Fail("batch error: " + ret.ToString()); } foreach (BatchInfo info in ret.Result) { if (info.Code == (int)HttpCode.OK) { Console.WriteLine("deleteAfterDays success"); } else { Console.WriteLine(info.Data.Error); } } }
private void Delete() { //1.获得表中选中的数据 if (dgResult.ItemsSource == null && dgResult.SelectedItems.Count <= 0) { return; } List <QiNiuFileInfo> list = new List <QiNiuFileInfo>(); foreach (var item in dgResult.SelectedItems) { QiNiuFileInfo info = (QiNiuFileInfo)item; if (info != null) { list.Add(info); } } if (list.Count > 0) { //执行批量删除 List <string> ops = new List <string>(); foreach (var key in list) { string op = bucketManager.DeleteOp(bucket, key.FileName); ops.Add(op); } BatchResult ret = bucketManager.Batch(ops); StringBuilder sb = new StringBuilder(); if (ret.Code / 100 != 2) { MessageBox.Show("批量删除error: " + ret.ToString()); return; } MessageBox.Show("批量删除成功!"); Search(); Thread.Sleep(10); } }
public async Task BatchChangeTypeTestAsync() { await BatchCopyTest(); var config = new Config { Zone = Zone.ZoneCnEast }; var mac = new Mac(AccessKey, SecretKey); var bucketManager = new BucketManager(mac, config); string[] keys = { "qiniu-0.png", "qiniu-1.png", "qiniu-2.png" }; var ops = keys.Select(key => bucketManager.ChangeTypeOp(Bucket, key, 0)).ToList(); var ret = await bucketManager.Batch(ops); if (ret.Code / 100 != 2) { Assert.True(false, "batch error: " + ret); } foreach (var info in ret.Result) { if (info.Code == (int)HttpCode.OK) { Console.WriteLine("chtype success"); } else { Console.WriteLine(info.Data.Error); } } }