Exemple #1
0
        /// <summary>
        /// 删除单个文件
        /// </summary>
        /// <param name="fileName">文件名</param>
        public static async Task <bool> DeleteAsync(string fileName)
        {
            RSClient client = new RSClient();
            CallRet  ret    = await client.DeleteAsync(new EntryPath(_bucket, fileName));

            return(ret.OK);
        }
Exemple #2
0
        private static bool UploadRemoteFile(string url, EntryPath path)
        {
            RSClient client = new RSClient();
            CallRet  result = client.Fetch(url, path);

            return(result.OK);
        }
Exemple #3
0
        public static void RSClientPutFileWithCRC32()
        {
            Console.WriteLine("\n===> RSClientPutFileWithCRC32 Generate CRC32");
            UInt32 crc = CRC32.CheckSumFile(localFile);

            Console.WriteLine("CRC32: " + crc.ToString());

            Console.WriteLine("\n===> RSClientPutFileWithCRC32 Generate UpToken");
            var    authPolicy = new AuthPolicy(bucketName, 3600);
            string upToken    = authPolicy.MakeAuthTokenString();

            Console.WriteLine("upToken: " + upToken);

            Console.WriteLine("\n===> RSClient.PutFileWithUpToken(CRC32)");
            PutFileRet putFileRet = RSClient.PutFileWithUpToken(upToken, bucketName, key, null, localFile, null, "key=<key>", crc);

            PrintRet(putFileRet);
            if (putFileRet.OK)
            {
                Console.WriteLine("Hash: " + putFileRet.Hash);
            }
            else
            {
                Console.WriteLine("Failed to RSClient.PutFileWithUpToken(CRC32)");
            }
        }
Exemple #4
0
        public async Task BatchCopyTest()
#endif
        {
            RSClient target = new RSClient();                      // TODO: 初始化为适当的值

            EntryPathPair[] entryPathPairs = new EntryPathPair[2]; // TODO: 初始化为适当的值
            string          tmpKey         = NewKey;
            string          tmpKey2        = NewKey;

            entryPathPairs[0] = new EntryPathPair(Bucket, tmpKeys[0], tmpKey);
            entryPathPairs[1] = new EntryPathPair(Bucket, tmpKeys[1], tmpKey2);
            CallRet actual;

#if NET20 || NET40
            actual = target.BatchCopy(entryPathPairs);
            if (actual.OK)
            {
                RSHelper.RSDel(Bucket, tmpKey);
                RSHelper.RSDel(Bucket, tmpKey2);
            }
            Assert.IsTrue(actual.OK, "BatchStatTest Failure");
#else
            actual = await target.BatchCopyAsync(entryPathPairs);

            if (actual.OK)
            {
                await RSHelper.RSDel(Bucket, tmpKey);

                await RSHelper.RSDel(Bucket, tmpKey2);
            }
            Assert.True(actual.OK, "BatchStatTest Failure");
#endif
        }
Exemple #5
0
        public async Task MoveTest()
#endif
        {
            RSClient      target   = new RSClient();                              // TODO: 初始化为适当的值
            string        key      = NewKey;
            EntryPathPair pathPair = new EntryPathPair(Bucket, tmpKeys[0], key);; // TODO: 初始化为适当的值
            CallRet       actual;

            //YES
#if NET20 || NET40
            actual = target.Move(pathPair);
            if (actual.OK)
            {
                tmpKeys [0] = key;
            }
            Assert.IsTrue(actual.OK, "MoveTest Failure");
#else
            actual = await target.MoveAsync(pathPair);

            if (actual.OK)
            {
                tmpKeys[0] = key;
            }
            Assert.True(actual.OK, "MoveTest Failure");
#endif
        }
Exemple #6
0
        public async Task CopyTest()
#endif
        {
            RSClient      target   = new RSClient();                             // TODO: 初始化为适当的值
            string        key      = NewKey;
            EntryPathPair pathPair = new EntryPathPair(Bucket, tmpKeys[0], key); // TODO: 初始化为适当的值
            CallRet       actual;

#if NET20 || NET40
            actual = target.Copy(pathPair);
            if (actual.OK)
            {
                RSHelper.RSDel(Bucket, key);
            }
            Assert.IsTrue(actual.OK, "CopyTest Failure");
#else
            actual = await target.CopyAsync(pathPair);

            if (actual.OK)
            {
                await RSHelper.RSDel(Bucket, key);
            }
            Assert.True(actual.OK, "CopyTest Failure");
#endif
        }
Exemple #7
0
        public void BatchDeleteTest()
        {
            List <string> tmps = RSHelper.RSPut(Bucket, 2);

            RSClient target = new RSClient();             // TODO: 初始化为适当的值

            EntryPath[] keys = new EntryPath[2];          // TODO: 初始化为适当的值
            int         i    = 0;

            foreach (string k in tmps)
            {
                keys [i++] = new EntryPath(Bucket, k);
            }

            CallRet actual;

            actual = target.BatchDelete(keys);
            if (actual.OK)
            {
                foreach (string k in tmps)
                {
                    RSHelper.RSDel(Bucket, k);
                }
            }
            Assert.IsTrue(actual.OK, "BatchStatTest Failure");;
        }
Exemple #8
0
        /// <summary>
        /// 复制单个文件
        /// </summary>
        /// <param name="keySrc">需要复制的文件key</param>
        /// <param name="keyDest">标文件key</param>
        public static CallRet Copy(string keyDest)
        {
            RSClient client = new RSClient();
            CallRet  ret    = client.Copy(new EntryPathPair(bucket, key, bucket, keyDest));

            return(ret);
        }
Exemple #9
0
        /// <summary>
        /// 批量移动文件
        /// </summary>
        /// <param name="batchObjs"></param>
        /// <returns></returns>
        public static async Task <bool> BatchMoveAsync(IEnumerable <BatchObj> batchObjs)
        {
            RSClient client = new RSClient();
            CallRet  ret    = await client.BatchMoveAsync(batchObjs.Select(i => new EntryPathPair(i.BucketSrc, i.FileNameSrc, i.BucketDest, i.FileNameDest)).ToArray());

            return(ret.OK);
        }
Exemple #10
0
        /// <summary>
        /// 复制单个文件
        /// </summary>
        /// <param name="bucketSrc">需要复制的文件所在的空间名</param>
        /// <param name="fileNameSrc">需要复制的文件名</param>
        /// <param name="bucketDest">目标文件所在的空间名</param>
        /// <param name="fileNameDest">目标文件名</param>
        public static async Task <bool> CopyAsync(string bucketSrc, string fileNameSrc, string bucketDest, string fileNameDest)
        {
            RSClient client = new RSClient();
            CallRet  ret    = await client.CopyAsync(new EntryPathPair(bucketSrc, fileNameSrc, bucketDest, fileNameDest));

            return(ret.OK);
        }
Exemple #11
0
        public static bool DeleteServerFile(FileTypeDirEnum dir, string key)
        {
            Qiniu.Conf.Config.ACCESS_KEY = QiniuConfig.AccessKey;
            Qiniu.Conf.Config.SECRET_KEY = QiniuConfig.SecretKey;

            try
            {
                //设置空间
                string bucket = QiniuUtil.GetServerBucket(dir);

                //实例化一个RSClient对象,用于操作BucketManager里面的方法
                RSClient client = new RSClient();
                CallRet  ret    = client.Delete(new EntryPath(bucket, key));
                if (!ret.OK)
                {
                    Trace.WriteLine(ret.Response);
                    Trace.WriteLine(ret.Exception);
                }
                return(ret.OK);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
            return(false);
        }
Exemple #12
0
        /// <summary>
        /// 删除单个文件
        /// </summary>
        /// <param name="fileNames">文件名集合</param>
        public static async Task <bool> BatchDeleteAsync(IEnumerable <string> fileNames)
        {
            RSClient client = new RSClient();
            CallRet  ret    = await client.BatchDeleteAsync(fileNames.Select(i => new EntryPath(_bucket, i)).ToArray());

            return(ret.OK);
        }
Exemple #13
0
        public static void RSDel(string bucket, string key)
        {
            RSClient  target = new RSClient();             // TODO: 初始化为适当的值
            EntryPath scope  = new EntryPath(bucket, key); // TODO: 初始化为适当的值
            CallRet   actual;

            actual = target.Delete(scope);
        }
Exemple #14
0
        /// <summary>
        /// 删除单个文件
        /// </summary>
        /// <param name="bucket">文件所在的空间名</param>
        /// <param name="key">文件key</param>
        public static bool Delete(string bucket, string key)
        {
            Console.WriteLine("\n===> Delete {0}:{1}", bucket, key);
            RSClient client = new RSClient();
            CallRet  ret    = client.Delete(new EntryPath(bucket, key));

            return(ret.OK);
        }
Exemple #15
0
        /// <summary>
        /// 查看单个文件属性信息
        /// </summary>
        public static Entry Stat(string fileKey = "")
        {
            fileKey = string.IsNullOrEmpty(fileKey) ? key : fileKey;
            RSClient client = new RSClient();
            Entry    entry  = client.Stat(new EntryPath(bucket, fileKey));

            return(entry);
        }
Exemple #16
0
        public static bool Delete(string bucket_name, string key)
        {
            //实例化一个RSClient对象,用于操作BucketManager里面的方法
            RSClient client = new RSClient();
            CallRet  ret    = client.Delete(new EntryPath(bucket_name, key));

            return(ret.OK);
        }
Exemple #17
0
        public static async Task RSDel(string bucket, string key)
        {
            RSClient  target = new RSClient();             // TODO: 初始化为适当的值
            EntryPath scope  = new EntryPath(bucket, key); // TODO: 初始化为适当的值
            CallRet   actual;

            actual = await target.DeleteAsync(scope);
        }
Exemple #18
0
        public int DeleteAttachment(string key)
        {
            Config.Init();
            //实例化一个RSClient对象,用于操作BucketManager里面的方法
            RSClient client = new RSClient();
            CallRet  ret    = client.Delete(new EntryPath(YXManage.Common.Common.QNBucket, key));

            return(ret.OK ? 1 : 0);
        }
Exemple #19
0
        /// <summary>
        /// 移动单个文件
        /// </summary>
        /// <param name="bucketSrc">需要移动的文件所在的空间名</param>
        /// <param name="keySrc">需要移动的文件</param>
        /// <param name="bucketDest">目标文件所在的空间名</param>
        /// <param name="keyDest">目标文件</param>
        public static async Task <bool> MoveAsync(string bucketSrc, string keySrc, string bucketDest, string keyDest)
        {
            Console.WriteLine("\n===> Move {0}:{1} To {2}:{3}",
                              bucketSrc, keySrc, bucketDest, keyDest);
            RSClient client = new RSClient();
            CallRet  ret    = await client.MoveAsync(new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest));

            return(ret.OK);
        }
Exemple #20
0
        public void StatTest()
        {
            RSClient target = new RSClient();
            //YES
            EntryPath scope = new EntryPath(Bucket, tmpKeys[0]);
            Entry     actual;

            actual = target.Stat(scope);
            Assert.IsTrue(actual.OK, "StatTest Failure");
        }
Exemple #21
0
        /// <summary>
        /// 批量删除数据
        /// </summary>
        /// <param name="keys"></param>
        public static void DeleteDatas(string keys)
        {
            var client     = new RSClient();
            var entryPaths = new List <EntryPath>();

            foreach (string key in keys.Split(','))
            {
                entryPaths.Add(new EntryPath(Scope, key.Replace("'", "")));
            }
            client.BatchDelete(entryPaths.ToArray());
        }
Exemple #22
0
        public bool MoveQiniuFile(string bucketSrc, string keySrc, string bucketDest, string keyDest)
        {
            //Console.WriteLine("\n===> Move {0}:{1} To {2}:{3}",
            //bucketSrc, keySrc, bucketDest, keyDest);
            RSClient client = new RSClient();

            new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest);
            CallRet ret = client.Move(new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest));

            return(ret.OK);
        }
Exemple #23
0
        public void BatchStatTest()
        {
            RSClient target = new RSClient();             // TODO: 初始化为适当的值

            EntryPath[] keys = new EntryPath[2];          // TODO: 初始化为适当的值
            keys[0] = new EntryPath(Bucket, tmpKeys[0]);
            keys[1] = new EntryPath(Bucket, tmpKeys[1]);  //error params
            List <BatchRetItem> actual;

            actual = target.BatchStat(keys);
            Assert.IsTrue(actual.Count == 2, "BatchStatTest Failure");
        }
Exemple #24
0
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="keys"></param>
        public static bool BatchDelete(string[] keys)
        {
            RSClient         client     = new RSClient();
            List <EntryPath> entryPaths = new List <EntryPath>();

            foreach (string key in keys)
            {
                Console.WriteLine(@"\n===> Stat {0}:{1}", bucket, key);
                entryPaths.Add(new EntryPath(bucket, key));
            }
            var e = client.BatchDelete(entryPaths.ToArray());

            return(e.OK);
        }
Exemple #25
0
        /// <summary>
        /// 批量查看文件的属性信息
        /// </summary>
        /// <param name="fileNames">文件名集合。aa.jpg</param>
        /// <returns></returns>
        public static async Task BatchStatAsync(IEnumerable <string> fileNames)
        {
            RSClient            client    = new RSClient();
            List <BatchRetItem> entryList = await client.BatchStatAsync(fileNames.Select(i => new EntryPath(_bucket, i)).ToArray());

            foreach (var entry in entryList)
            {
                Console.WriteLine("Hash: " + entry.data.Hash);
                Console.WriteLine("Fsize: " + entry.data.FSize);
                Console.WriteLine("PutTime: " + entry.data.PutTime);
                Console.WriteLine("MimeType: " + entry.data.Mime);
                Console.WriteLine("Customer: " + entry.data.EndUser);
            }
        }
Exemple #26
0
        public void CopyTest()
        {
            RSClient      target   = new RSClient();                             // TODO: 初始化为适当的值
            string        key      = NewKey;
            EntryPathPair pathPair = new EntryPathPair(Bucket, tmpKeys[0], key); // TODO: 初始化为适当的值
            CallRet       actual;

            actual = target.Copy(pathPair);
            if (actual.OK)
            {
                RSHelper.RSDel(Bucket, key);
            }
            Assert.IsTrue(actual.OK, "CopyTest Failure");
        }
Exemple #27
0
        /// <summary>
        /// 删除图片
        /// </summary>
        /// <param name="imgkey"></param>
        public bool DeleteImage(string imgkey)
        {
            try
            {
                RSClient client = new RSClient();
                CallRet  ret    = client.Delete(new EntryPath(Bucket, imgkey));

                return(ret.OK);
            }
            catch (Exception ex)
            {
                LogUtil.WriteLog(ex);
                return(false);
            }
        }
Exemple #28
0
        public static void Copy(string bucketSrc, string keySrc, string bucketDest, string keyDest)
        {
            //实例化一个RSClient对象,用于操作BucketManager里面的方法
            RSClient client = new RSClient();
            CallRet  ret    = client.Copy(new EntryPathPair(bucketSrc, keySrc, bucketDest, keyDest));

            if (ret.OK)
            {
                Console.WriteLine("Copy OK");
            }
            else
            {
                Console.WriteLine("Failed to Copy");
            }
        }
Exemple #29
0
        public void MoveTest()
        {
            RSClient      target   = new RSClient();                              // TODO: 初始化为适当的值
            string        key      = NewKey;
            EntryPathPair pathPair = new EntryPathPair(Bucket, tmpKeys[0], key);; // TODO: 初始化为适当的值
            CallRet       actual;

            //YES
            actual = target.Move(pathPair);
            if (actual.OK)
            {
                tmpKeys [0] = key;
            }
            Assert.IsTrue(actual.OK, "MoveTest Failure");
        }
Exemple #30
0
        public static void Delete(string bucket, string key)
        {
            //实例化一个RSClient对象,用于操作BucketManager里面的方法
            RSClient client = new RSClient();
            CallRet  ret    = client.Delete(new EntryPath(bucket, key));

            if (ret.OK)
            {
                Console.WriteLine("Delete OK");
            }
            else
            {
                Console.WriteLine("Failed to delete");
            }
        }