Exemplo n.º 1
0
        public static void batchStat()
        {
            Mac mac = new Mac(Settings.AccessKey, Settings.SecretKey);

            string bucket = "test";

            int N = 5;

            // 待查询的N个文件keys
            string[] keys = new string[N];
            for (int i = 0; i < N; ++i)
            {
                keys[i] = string.Format("{0:D3}.txt", i + 1);
            }

            BucketManager bm = new BucketManager(mac);

            var result = bm.BatchStat(bucket, keys);

            Console.WriteLine(result);
        }
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);

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

            #region LOOP
            for (int g = 0; g < G; ++g)
            {
                string[] keys_1 = new string[X];
                for (i = 0; i < X; ++i)
                {
                    keys_1[i] = keys[g * X + i];
                }

                var r1 = bktMgr.BatchStat(bucket, keys_1);

                for (i = 0; i < X; ++i)
                {
                    var s1r = r1.Result[i];
                    if (s1r.Code == (int)HttpCode.OK)
                    {
                        var s = JsonConvert.DeserializeObject <StatInfo>(s1r.Data.ToString());
                        // FOUND
                        remoteHash[g * X + i] = s.Hash;
                    }
                }
            }
            #endregion LOOP

            #region RESIDUE

            string[] keys_2 = new string[M];
            for (i = 0; i < M; ++i)
            {
                keys_2[i] = keys[G * X + i];
            }

            var r2 = bktMgr.BatchStat(bucket, keys_2);

            for (i = 0; i < M; ++i)
            {
                var s2r = r2.Result[i];

                if (s2r.Code == (int)HttpCode.OK)
                {
                    var s = JsonConvert.DeserializeObject <StatInfo>(s2r.Data.ToString());
                    // FOUND
                    remoteHash[G * X + i] = s.Hash;
                }
                //if (r2[i].Code == 200)
                //{
                //    remoteHash[G * X + i] = r2[i].StatInfo.Hash;
                //}
            }

            #endregion RESIDUE

            return(remoteHash);
        }