batch() public method

public batch ( string ops ) : Qiniu.Http.HttpResult
ops string
return Qiniu.Http.HttpResult
Exemplo n.º 1
0
        /// <summary>
        /// 批量操作
        /// </summary>
        public static void batch()
        {
            Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey);

            // 批量操作类似于
            // op=<op1>&op=<op2>&op=<op3>...
            string batchOps = "BATCH_OPS";
            BucketManager bm = new BucketManager(mac);
            HttpResult result = bm.batch(batchOps);
            // 或者
            //string[] batch_ops={"<op1>","<op2>","<op3>",...};
            //bm.batch(batch_ops);

            System.Console.WriteLine(result.Response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 批量获取文件的hash
        /// 注意:单次请求的文件数量在1000以下
        /// </summary>
        /// <param name="bktMgr"></param>
        /// <param name="bucket"></param>
        /// <param name="keys"></param>
        /// <returns></returns>
        public static string[] BatchStat(Mac mac, string bucket, string[] keys)
        {
            string[] remoteHash = new string[keys.Length];

            BucketManager bktMgr = new BucketManager(mac);

            StringBuilder opsb = new StringBuilder();

            int N = keys.Length;
            int X = 1000;
            int G = N / X;
            int M = N % X;
            int i;
            bool first = false;

            string s1 = "op=/stat/";
            string s2 = "&op=/stat/";
            string s = "";

            HttpResult result = null;
            StatResponse[] statResults = null;

            #region LOOP
            for (int g = 0; g < G; ++g)
            {
                opsb.Clear();
                first = true;
                for (i = 0; i < X; ++i)
                {
                    s = s2;
                    if (first)
                    {
                        s = s1;
                        first = false;
                    }
                    opsb.Append(s + StringUtils.encodedEntry(bucket, keys[g*X+i]));
                }

                result = bktMgr.batch(opsb.ToString());

                statResults = JsonConvert.DeserializeObject<StatResponse[]>(result.Response);

                for (i = 0; i < X; ++i)
                {
                    if (statResults[i].CODE == 200)
                    {
                        // FOUND
                        remoteHash[g * X + i] = statResults[i].DATA.hash;
                    }
                }
            }
            #endregion LOOP

            #region RESIDUE

            opsb.Clear();
            first = true;
            for (i = 0; i < M; ++i)
            {
                s = s2;
                if (first)
                {
                    s = s1;
                    first = false;
                }
                opsb.Append(s + StringUtils.encodedEntry(bucket, keys[G*X+i]));
            }

            result = bktMgr.batch(opsb.ToString());

            statResults = JsonConvert.DeserializeObject<StatResponse[]>(result.Response);

            for (i = 0; i < M; ++i)
            {
                if (statResults[i].CODE == 200)
                {
                    remoteHash[G * X + i] = statResults[i].DATA.hash;
                }
            }

            #endregion RESIDUE

            return remoteHash;
        }