예제 #1
0
파일: fops.cs 프로젝트: seamys/csharp-sdk
        static void Main(string[] args)
        {
            //初始化AK,SK
            Qiniu.Conf.Config.ACCESS_KEY = "Access_Key";
            Qiniu.Conf.Config.SECRET_KEY = "Secret_Key";

            //设置要转码的空间和key,并且这个key在你空间中存在
            String bucket = "Bucket_Name";
            String key    = "Bucket_key";

            //实例化一个entry对象
            EntryPath entry = new EntryPath(bucket, key);

            //设置转码操作参数
            String fops = "avthumb/mp4/s/640x360/vb/1.25m";
            //设置转码的队列
            String pipeline = "yourpipelinename";

            //可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
            String urlbase64 = Qiniu.Util.Base64URLSafe.Encode("保存的空间:保存的key");
            String pfops     = fops + "|saveas/" + urlbase64;

            //实例化一个fop对象主要进行后续转码操作
            Qiniu.RS.Pfop fop = new Qiniu.RS.Pfop();

            Uri uri = null;

            string s = fop.Do(entry, pfops, uri, pipeline, 1);

            Console.WriteLine(s);
            Console.ReadLine();
        }
예제 #2
0
 public IEnumerable <FileEntry> GetFilesInFolder(EntryPath Path)
 {
     foreach (var File in FileEntryTable.Select("directory=?", Path.FullPath))
     {
         yield return(File);
     }
 }
예제 #3
0
 public PK3Entry(EntryPath path, ResourceNamespace resourceNamespace, byte[] data)
 {
     Path      = path;
     Name      = path.Name;
     Namespace = resourceNamespace;
     Data      = data;
 }
예제 #4
0
        private CallRet Mkfile(Client client, string key, long fsize)
        {
            EntryPath entry = new EntryPath(extra.Bucket, key);
            string    url   = string.Format("{0}/rs-mkfile/{1}/fsize/{2}/", Config.UP_HOST, entry.Base64EncodedURI, fsize);

            if (!string.IsNullOrEmpty(extra.MimeType))
            {
                url += (string.Format("/mimeType/{0}", extra.MimeType.ToBase64URLSafe()));
            }
            if (!string.IsNullOrEmpty(extra.CustomMeta))
            {
                url += (string.Format("/meta/{0}", extra.CustomMeta.ToBase64URLSafe()));
            }
            if (!string.IsNullOrEmpty(extra.CallbackParams))
            {
                url += (string.Format("/params/{0}", extra.CallbackParams.ToBase64URLSafe()));
            }
            int proCount = extra.Progresses.Length;

            using (Stream body = new MemoryStream()) {
                for (int i = 0; i < proCount; i++)
                {
                    byte[] bctx = Encoding.ASCII.GetBytes(extra.Progresses [i].ctx);
                    body.Write(bctx, 0, bctx.Length);
                    if (i != proCount - 1)
                    {
                        body.WriteByte((byte)',');
                    }
                }
                body.Seek(0, SeekOrigin.Begin);
                return(client.CallWithBinary(url, "text/plain", body, body.Length));
            }
        }
예제 #5
0
        /// <summary>
        /// Pres the fetch.
        /// </summary>
        /// <returns><c>true</c>, if fetch was pred, <c>false</c> otherwise.</returns>
        /// <param name="path">Path.</param>
        public bool PreFetch(EntryPath path)
        {
            string  url = Config.PREFETCH_HOST + "/prefetch/" + path.Base64EncodedURI;
            CallRet ret = Call(url);

            return(ret.OK);
        }
예제 #6
0
 /// <summary>
 /// Creates a new wad entry.
 /// </summary>
 /// <param name="name">The wad entry name.</param>
 /// <param name="resourceNamespace">The resource namespace of this
 /// entry.</param>
 /// <param name="data">The data for this entry.</param>
 public WadEntry(UpperString name, ResourceNamespace resourceNamespace, byte[] data)
 {
     Path      = new EntryPath(name);
     Name      = Path.Name;
     Namespace = resourceNamespace;
     Data      = data;
 }
예제 #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");;
        }
예제 #8
0
        private static bool UploadRemoteFile(string url, EntryPath path)
        {
            RSClient client = new RSClient();
            CallRet  result = client.Fetch(url, path);

            return(result.OK);
        }
예제 #9
0
        public async Task <bool> PreFetchAsync(EntryPath path)
        {
            string  url = Config.PREFETCH_HOST + "/prefetch/" + path.Base64EncodedURI;
            CallRet ret = await CallAsync(url);

            return(ret.OK);
        }
예제 #10
0
        public static void WaterMarkPop(FileTypeDirEnum dir, string key)
        {
            Qiniu.Conf.Config.ACCESS_KEY = QiniuConfig.AccessKey;
            Qiniu.Conf.Config.SECRET_KEY = QiniuConfig.SecretKey;

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

            //实例化一个entry对象
            EntryPath entry = new EntryPath(bucket, key);
            string    ext   = QiniuUtil.GetKeyWithExt(key);
            string    fops  = string.Format("avthumb/{0}/{1}", ext, QiniuConfig.GetWaterText());

            //设置切片的队列
            string pipeline = "yihui_queue";

            //可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
            String urlbase64 = Qiniu.Util.Base64URLSafe.Encode(String.Format("{0}:{1}", bucket, key));
            String pfops     = fops + "|saveas/" + urlbase64;

            //实例化一个fop对象主要进行后续转码操作
            Qiniu.RS.Pfop fop = new Qiniu.RS.Pfop();

            Uri uri = new Uri(QiniuConfig.UploadCallback);

            try
            {
                string s = fop.Do(entry, new[] { pfops }, uri, pipeline, 1);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }
예제 #11
0
        public static bool VideoCutPiece(FileTypeDirEnum dir, string key)
        {
            Qiniu.Conf.Config.ACCESS_KEY = QiniuConfig.AccessKey;
            Qiniu.Conf.Config.SECRET_KEY = QiniuConfig.SecretKey;

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

            //实例化一个entry对象
            EntryPath entry = new EntryPath(bucket, key);

            //设置切片操作参数
            String fops = "avthumb/m3u8/segtime/15/vb/240k";
            //设置切片的队列
            string pipeline = "yihui_queue";

            //可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
            String urlbase64 = Qiniu.Util.Base64URLSafe.Encode(String.Format("{0}:cut_{1}", bucket, key));
            String pfops     = fops + "|saveas/" + urlbase64;

            //实例化一个fop对象主要进行后续转码操作
            Qiniu.RS.Pfop fop = new Qiniu.RS.Pfop();

            Uri uri = new Uri(QiniuConfig.UploadCallback);

            try
            {
                string s = fop.Do(entry, new[] { pfops }, uri, pipeline);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
            return(false);
        }
예제 #12
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);
        }
예제 #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);
        }
예제 #14
0
 public FileEntry GetFileInFolder(EntryPath Path)
 {
     foreach (var File in FileEntryTable.Select("directory=? AND name=?", Path.Directory, Path.BaseName))
     {
         return(File);
     }
     throw (new Exception("Can't find file '" + Path.Directory + '/' + Path.BaseName + "'"));
 }
예제 #15
0
 public void AddFile(EntryPath Path)
 {
     AddFile(new FileEntry()
     {
         directory = Path.Directory,
         name      = Path.BaseName,
         type      = FileEntryType.File,
         reference = 0,
     });
 }
예제 #16
0
        public string GetCurrentDirectoryName()
        {
            if (!EntryPath.Contains('/'))
            {
                return(EntryPath);
            }
            var pathParts = EntryPath.Split('/');

            return(pathParts[pathParts.Length - 1]);
        }
예제 #17
0
        private static PK3Entry ReadZipEntry(ZipArchiveEntry zipEntry)
        {
            string            pathText          = ProcessZipPath(zipEntry);
            EntryPath         path              = new EntryPath(pathText);
            ResourceNamespace resourceNamespace = ResourceNamespaceHelper.From(path);

            byte[] data = DecompressZipEntry(zipEntry);

            return(new PK3Entry(path, resourceNamespace, data));
        }
예제 #18
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");
        }
예제 #19
0
        public static string UploadFile(string url, string channel = "")
        {
            var       guid = Guid.NewGuid().ToString().RemoveDash();
            EntryPath path = new EntryPath(Buket, channel + "/" + guid);

            if (UploadRemoteFile(url, path))
            {
                return(channel + "/" + guid);
            }
            return(string.Empty);
        }
예제 #20
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");
        }
예제 #21
0
        protected override ICopyCallback GetCopyCallback(string destination)
        {
            var xaml = EntryPath;

            if (string.IsNullOrWhiteSpace(xaml))
            {
                return(new CopyCallback(null));
            }

            var resources = EntryPath.ApartFromLast(".xaml", StringComparison.OrdinalIgnoreCase);

            return(new CopyCallback(info => {
                var filename = info.Key;
                return FileUtils.ArePathsEqual(filename, xaml) ? Path.Combine(destination, Path.GetFileName(xaml))
                        : FileUtils.IsAffectedBy(filename, resources) ? Path.Combine(destination, FileUtils.GetRelativePath(filename, resources)) : null;
            }));
        }
예제 #22
0
        public async Task StatTest()
#endif
        {
            RSClient target = new RSClient();
            //YES

            EntryPath scope = new EntryPath(Bucket, tmpKeys[0]);
            Entry     actual;

#if NET20 || NET40
            actual = target.Stat(scope);
            Assert.IsTrue(actual.OK, "StatTest Failure");
#else
            actual = await target.StatAsync(scope);

            Assert.True(actual.OK, "StatTest Failure");
#endif
        }
예제 #23
0
        protected override ICopyCallback GetCopyCallback(string destination)
        {
            var bitmapExtension = Path.GetExtension(EntryPath);
            var mainEntry       = EntryPath.ApartFromLast(bitmapExtension) + FontObject.FontExtension;

            return(new CopyCallback(info => {
                if (FileUtils.ArePathsEqual(info.Key, mainEntry))
                {
                    return destination;
                }

                if (FileUtils.ArePathsEqual(info.Key, EntryPath))
                {
                    return destination.ApartFromLast(FontObject.FontExtension) + bitmapExtension;
                }

                return null;
            }));
        }
예제 #24
0
        public async Task BatchStatTest()
#endif
        {
            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;

#if NET20 || NET40
            actual = target.BatchStat(keys);
            Assert.IsTrue(actual.Count == 2, "BatchStatTest Failure");
#else
            actual = await target.BatchStatAsync(keys);

            Assert.True(actual.Count == 2, "BatchStatTest Failure");
#endif
        }
예제 #25
0
        /// <summary>
        /// 处理视频缩略图
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="key"></param>
        /// <param name="fileImg"></param>
        /// <returns></returns>
        public static bool GetVideoThumbnailImg(FileTypeDirEnum dir, string key, out string fileImg)
        {
            Qiniu.Conf.Config.ACCESS_KEY = QiniuConfig.AccessKey;
            Qiniu.Conf.Config.SECRET_KEY = QiniuConfig.SecretKey;

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

            //实例化一个entry对象
            EntryPath entry = new EntryPath(bucket, key);

            string name = String.Format("thumbnail-{0}.jpg", QiniuUtil.GetKeyWithoutExt(key));

            fileImg = QiniuUtil.GetFullUrl(name, dir);

            //设置操作参数
            String fops = "vframe/jpg/offset/5";
            //设置队列
            string pipeline = "yihui_queue";

            //可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。
            String urlbase64 = Qiniu.Util.Base64URLSafe.Encode(String.Format("{0}:{1}", bucket, name));
            String pfops     = fops + "|saveas/" + urlbase64;

            //实例化一个fop对象主要进行后续转码操作
            Qiniu.RS.Pfop fop = new Qiniu.RS.Pfop();

            Uri uri = new Uri(QiniuConfig.UploadCallback);

            try
            {
                string s = fop.Do(entry, new[] { pfops }, uri, pipeline);
                return(true);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }

            return(false);
        }
예제 #26
0
        public async Task BatchDeleteTest()
#endif
        {
#if NET20 || NET40
            List <string> tmps = RSHelper.RSPut(Bucket, 2);
#else
            List <string> tmps = await RSHelper.RSPut(Bucket, 2);
#endif

            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;
#if NET20 || NET40
            actual = target.BatchDelete(keys);
            if (actual.OK)
            {
                foreach (string k in tmps)
                {
                    RSHelper.RSDel(Bucket, k);
                }
            }
            Assert.IsTrue(actual.OK, "BatchStatTest Failure");
#else
            actual = await target.BatchDeleteAsync(keys);

            if (actual.OK)
            {
                foreach (string k in tmps)
                {
                    await RSHelper.RSDel(Bucket, k);
                }
            }
            Assert.True(actual.OK, "BatchStatTest Failure");
#endif
        }
예제 #27
0
        /// <summary>
        /// Takes an entry path and gets the namespace from it.
        /// </summary>
        /// <param name="path">The entry path.</param>
        /// <returns>The namespace for the path.</returns>
        public static ResourceNamespace From(EntryPath path)
        {
            if (path.Folders.Empty())
            {
                return(ResourceNamespace.Global);
            }

            switch (path.Folders.First().ToUpper())
            {
            case "ACS":
                return(ResourceNamespace.ACS);

            case "FLATS":
                return(ResourceNamespace.Flats);

            case "FONTS":
                return(ResourceNamespace.Fonts);

            case "GRAPHICS":
                return(ResourceNamespace.Graphics);

            case "MUSIC":
                return(ResourceNamespace.Music);

            case "SOUNDS":
                return(ResourceNamespace.Sounds);

            case "SPRITES":
                return(ResourceNamespace.Sprites);

            case "TEXTURES":
                return(ResourceNamespace.Textures);

            default:
                return(ResourceNamespace.Global);
            }
        }
예제 #28
0
 public void CreateFolder(EntryPath Path, uint mode)
 {
     Console.WriteLine("CreateFolder: '{0}'", Path.FullPath);
     _CreateFolder(Path.Directory, Path.BaseName, mode);
     _CreateFolder(Path.FullPath, null, mode);
 }
예제 #29
0
 private void _entryPathPair(string bucketSrc, string keySrc, string bucketDest, string keyDest)
 {
     this.src  = new EntryPath(bucketSrc, keySrc);
     this.dest = new EntryPath(bucketDest, keyDest);
 }
예제 #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Qiniu.RS.EntryPathPair"/> class.
 /// </summary>
 public EntryPathPair(EntryPath src, EntryPath des)
 {
     this.src  = src;
     this.dest = des;
 }
예제 #31
0
		private void _entryPathPair (string bucketSrc, string keySrc, string bucketDest, string keyDest)
		{
			this.src = new EntryPath (bucketSrc, keySrc);
			this.dest = new EntryPath (bucketDest, keyDest);
		}
예제 #32
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Qiniu.RS.EntryPathPair"/> class.
		/// </summary>
		public EntryPathPair (EntryPath src, EntryPath des)
		{
			this.src = src;
			this.dest = des;
		}
예제 #33
0
 public void AddFile(EntryPath Path)
 {
     AddFile(new FileEntry()
     {
         directory = Path.Directory,
         name = Path.BaseName,
         type = FileEntryType.File,
         reference = 0,
     });
 }
예제 #34
0
 public void CreateFolder(EntryPath Path, uint mode)
 {
     Console.WriteLine("CreateFolder: '{0}'", Path.FullPath);
     _CreateFolder(Path.Directory, Path.BaseName, mode);
     _CreateFolder(Path.FullPath, null, mode);
 }
예제 #35
0
 public FileEntry GetFileInFolder(EntryPath Path)
 {
     foreach (var File in FileEntryTable.Select("directory=? AND name=?", Path.Directory, Path.BaseName))
     {
         return File;
     }
     throw (new Exception("Can't find file '" + Path.Directory + '/' + Path.BaseName + "'"));
 }
예제 #36
0
 public IEnumerable<FileEntry> GetFilesInFolder(EntryPath Path)
 {
     foreach (var File in FileEntryTable.Select("directory=?", Path.FullPath))
     {
         yield return File;
     }
 }